您要做的是将嵌入结果存储到图中。下一步是使用Neo4j Graph Data Science 库,并专门运行余弦相似度算法。它看起来应该类似于:
MATCH (p:Word)
WITH {item:id(p), weights: p.embedding} AS wordData
WITH collect(wordData) AS data
CALL gds.alpha.similarity.cosine.write({
nodeProjection: '*',
relationshipProjection: '*',
data: data,
// here is where you define how many nearest neighbours should be stored
topK: 1,
// here you define what is the minimal similarity between a
// given pair of node to be still relevant
similarityCutoff: 0.1
})
YIELD nodes, similarityPairs, writeRelationshipType, writeProperty, min, max, mean, stdDev, p25, p50, p75, p90, p95, p99, p999, p100
RETURN nodes, similarityPairs, writeRelationshipType, writeProperty, min, max, mean, p95
您现在已经对最近的邻居进行了预处理,并且可以轻松地查询它们,例如:
MATCH (w:Word)-[:SIMILAR]-(other)
RETURN other
希望这会有所帮助,如果您还有其他问题,请告诉我。