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.

text similarity using cosine similarity

Riri2022
Node Link

Please how do I compute the cosine similarity between two text in Neo4j? I tried using the approach below but the function does not exist. On the Neo4j page I only see how to compute the cosine similarity between two numeric vectors and not text.

MATCH (n1:Node), (n2:Node)
WHERE n1.text = 'A string of text' AND n2.text = 'Another string of text'
WITH n1, n2, apoc.algo.cosineSimilarity(n1.text, n2.text) AS similarity
RETURN n1, n2, similarity

I equally tried with

apoc.text.cosineSimilarity

but it won't work. The functions are unknown This :

 gds.similarity.cosine 

works for vectors of numeric values

2 REPLIES 2

ameyasoft
Graph Maven
Try this:

with "A string of text" as s1, "Another string of text" as s2
with toInteger(apoc.text.jaroWinklerDistance(s1, s2) * 100) as similarity
return similarity

Thank you!

This was useful, however, it takes a very long amount of time to compute so I had to stop it because it won't finish.

I am wondering if there is a way to speed up calculations on Neo4j, I have around 16825 nodes, and computing this after more than 3 days, was not over yet.