cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Is there a way to make this writing statement faster?

lingvisa
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 {id:record.id})
    SET n.embedding = record.embedding

'nodes' are existing ones from the graph

with driver.session() as session:
for index, node in enumerate(nodes):
            print(index)
            ...
            node_embeddings.append({'id': id, 'embedding': embedding})
            if len(node_embeddings) % 200 == 0:
                session.run(property_writing 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?

2 REPLIES 2

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?