Failed to perform k-Nearest Neighbors on my graph

Hi everyone, I failed to use gds.knn.stream on my graph and I don't know how to debug it. I use Neo4J Desktop - 1.5.8 with Graph DBMS 5.3. The plugins I used are APOC 5.3 and GDS Library 2.3.5. Please help me take a look at my problem. I was able to generate my graph but I am not able to use gds.knn.stream on it.

LOAD CSV WITH HEADERS FROM 'file:///Drug_Repositioning_5-30-22.csv' AS row
WITH row.Drug_ID AS drugId, row.Original_Indication AS originalIndication, row.New_Indication AS newIndication, row.first_mention_PMID AS firstMentionPMID, row.definitive_mention_PMID AS definitiveMentionPMID
MERGE (d:Drug {id: drugId})
ON CREATE SET d.Original_indication = originalIndication
MERGE (p:New_indication {name: newIndication})
WITH d, p, firstMentionPMID, definitiveMentionPMID
CREATE (d)-[:TREATS {first_mention_PMID: toInteger(firstMentionPMID), definitive_mention_PMID: toInteger(definitiveMentionPMID)}]->(p)
RETURN d, p

CALL gds.knn.stream({
nodeProjection: 'Drug',
relationshipProjection: {
TREATS: {
type: 'TREATS',
orientation: 'UNDIRECTED'
}
},
nodeProperties: ['Original_indication'],
similarityCutoff: 0.5,
topK: 10,
sampleRate: 1.0,
randomSeed: 42,
deltaThreshold: 0.0,
nodeWeightProperty: 'weight',
writeProperty: 'knn',
concurrency: 4,
validateRelationships: false
})
YIELD node1, node2, similarity
RETURN gds.util.asNode(node1).id AS drug1, gds.util.asNode(node2).id AS drug2, similarity
ORDER BY similarity DESC

Error: Type mismatch: expected String but was Map (line 1, column 21 (offset: 20))
"CALL gds.knn.stream({"

Hello @kbnguyen1606 and welcome to the Neo4j community:)

You have two issues, the first one is a syntax error, you can see the right format here.

Moreover, to execute the algorithm, you need to create an in-memory graph as shown here.

Best regards,
Cobra

1 Like