# Failed to perform k-Nearest Neighbors on my graph

**URL:** <https://community.neo4j.com/t/failed-to-perform-k-nearest-neighbors-on-my-graph/62450>\
**Category:** Graph Data Science / Graph Analytics\
**Tags:** gds\
**Created:** [May 9, 2023, 7:27pm UTC](https://community.neo4j.com/t/failed-to-perform-k-nearest-neighbors-on-my-graph/62450 "2023-05-09T19:27:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kbnguyen1606](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/kbnguyen1606/32/28638_2.png) [@kbnguyen1606](https://community.neo4j.com/u/kbnguyen1606)\
**Post date:** [May 9, 2023, 7:27pm UTC](https://community.neo4j.com/t/failed-to-perform-k-nearest-neighbors-on-my-graph/62450/1 "2023-05-09T19:27:08Z")

</div>

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({"

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [May 10, 2023, 5:41am UTC](https://community.neo4j.com/t/failed-to-perform-k-nearest-neighbors-on-my-graph/62450/2 "2023-05-10T05:41:36Z")

</div>

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](https://neo4j.com/docs/graph-data-science/current/algorithms/knn/).

Moreover, to execute the algorithm, you need to create an in-memory graph as shown [here](https://neo4j.com/docs/graph-data-science/current/management-ops/projections/graph-project/).

Best regards,  
Cobra
