USE GRAPH financialGraph # create a query CREATE OR REPLACE QUERY q4a (LIST query_vector) SYNTAX v3 { MapAccum @@distances1; MapAccum @@distances2; // do an exact top-k search on "b" using the ORDER BY clause with ASC keyword c1 = SELECT b FROM (a:Account)-[e:transfer]->(b:Account) ORDER BY gds.vector.cosine_distance(b.emb1, query_vector) ASC LIMIT 3; PRINT c1 WITH VECTOR; // an approximate top-k search on the Account vertex set v = vectorSearch({Account.emb1}, query_vector, 3, {distance_map: @@distances1}); PRINT v WITH VECTOR; PRINT @@distances1; // below we use variable length path. // *1.. means 1 to more steps of the edge type "transfer" // select the reachable end point and bind it to vertex alias "b" // do an exact top-k reverse-search on "b" using the ORDER BY clause with DESC keyword c2 = SELECT b FROM (a:Account {name: "Scott"})-[:transfer*1..]->(b:Account) WHERE a.name != b.name ORDER BY gds.vector.cosine_distance(b.emb1, query_vector) DESC LIMIT 3; PRINT c2 WITH VECTOR; // an approximate top-k search on the Account vertex set v = vectorSearch({Account.emb1}, query_vector, 5, {distance_map: @@distances2}); PRINT v WITH VECTOR; PRINT @@distances2; } #compile and install the query as a stored procedure install query q4a #run the query run query q4a([-0.017733968794345856, -0.01019224338233471, -0.016571875661611557])