Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-01-2020 04:20 AM
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.
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)?
All the sessions of the conference are now available online