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.

Update and create new similarity relationships when adding new nodes to db

Hi, I hope I'm posting this in the right category

I'm building database, that holds image as node and similarities between nodes as relationship.
I have nodes that have properties path and vec.


I created similarity relationships with the following query:

MATCH (p:Image)
WITH {item:id(p), weights: p.vec} as userData
WITH collect(userData) as data
CALL gds.alpha.similarity.cosine.write({
nodeProjection: '',
relationshipProjection: '
',
topK:20,
data:data,
showComputations: true,
writeRelationshipType: "SIMILAR"
})
YIELD nodes, similarityPairs, computations
RETURN nodes,
apoc.number.format(similarityPairs) AS similarityPairs,
apoc.number.format(computations) AS computations

This is working fine when I load data only once. But I need to constantly add new images to database and then I need to create or update similarity relationships between images.

So I tried using triggers, but so far the best approach I got was deleting all relationships when adding new data and then create new similarity relationships between updated database nodes. But this takes toooo much time.

CALL apoc.trigger.add('CRS',"UNWIND {createdNodes} AS node
MATCH (p:Image)-[r:SIMILAR]->()
Delete r
WITH collect({item:id(p), weights:p.vec}) as data
CALL gds.alpha.similarity.cosine.write({
nodeProjection: '',
relationshipProjection: '
',
topK:20,
data:data,
showComputations: true,
writeRelationshipType:'SIMILAR'
})
YIELD nodes, similarityPairs, computations
RETURN nodes,
apoc.number.format(similarityPairs) AS similarityPairs,
apoc.number.format(computations) AS computations", {phase:'after'})

Is there a better way to create and update similarity relationships between a large dataset (10k nodes)?

0 REPLIES 0