Showing results for 
Search instead for 
Did you mean: 

Is there a way to make this writing statement faster?

Graph Fellow

I am using Python Bolt driver, with the session object. I am writing a new property to each existing node in the graph. My property writing cypher is:

property_writing query = 

UNWIND $data as record
    MATCH (n:Topic {})
    SET n.embedding = record.embedding

'nodes' are existing ones from the graph

with driver.session() as session:
for index, node in enumerate(nodes):
            node_embeddings.append({'id': id, 'embedding': embedding})
            if len(node_embeddings) % 200 == 0:
       query, {'data': node_embeddings})
                node_embeddings = []

Each iteration the node_embeddings list has 64 elements and the writing statement takes about 400 millseconds. The code is on the same machine with neo4j deployment and each node is indexed on the 'id' field.

Is there a way to make this property writing faster?


It sounds like the query itself is optimal.

You may want to check your query logs (and ensure your query logs are configure to output info like CPU, planning, and pagecache hit/miss info) and see what you can find for where the time is being spent, and whether there are cache misses in these queries.

Also try to figure out the time spent for query processing vs network transfer of results and materialization/handling of results client-side.

400/64 = 6.25 ms. It's not too bad. If I accumulate more elements in the list to be written, that may help too?