Skip to content

The agent engineering platform.

Neo4j: Update with non-deprecated cypher methods, and new method to associate relationship embeddings (#23725)

Rafael Pereiracf28708e7b70
diff --git a/libs/community/langchain_community/vectorstores/neo4j_vector.py b/libs/community/langchain_community/vectorstores/neo4j_vector.py
index caefda2042..e083f3ba3e 100644
--- a/libs/community/langchain_community/vectorstores/neo4j_vector.py
+++ b/libs/community/langchain_community/vectorstores/neo4j_vector.py
@@ -854,11 +854,11 @@ class Neo4jVector(VectorStore):
"CALL { WITH row "
f"MERGE (c:`{self.node_label}` {{id: row.id}}) "
"WITH c, row "
- f"CALL db.create.setVectorProperty(c, "
+ f"CALL db.create.setNodeVectorProperty(c, "
f"'{self.embedding_node_property}', row.embedding) "
- "YIELD node "
f"SET c.`{self.text_node_property}` = row.text "
- "SET c += row.metadata } IN TRANSACTIONS OF 1000 ROWS"
+ "SET c += row.metadata "
+ "} IN TRANSACTIONS OF 1000 ROWS "
)
parameters = {
@@ -1462,9 +1462,9 @@ class Neo4jVector(VectorStore):
"UNWIND $data AS row "
f"MATCH (n:`{node_label}`) "
"WHERE elementId(n) = row.id "
- f"CALL db.create.setVectorProperty(n, "
+ f"CALL db.create.setNodeVectorProperty(n, "
f"'{embedding_node_property}', row.embedding) "
- "YIELD node RETURN count(*)",
+ "RETURN count(*)",
params=params,
)
# If embedding calculation should be stopped
diff --git a/libs/community/tests/integration_tests/vectorstores/test_neo4jvector.py b/libs/community/tests/integration_tests/vectorstores/test_neo4jvector.py
index 50869b985f..761450f4a9 100644
--- a/libs/community/tests/integration_tests/vectorstores/test_neo4jvector.py
+++ b/libs/community/tests/integration_tests/vectorstores/test_neo4jvector.py
@@ -199,7 +199,10 @@ def test_neo4jvector_with_metadatas_with_scores() -> None:
password=password,
pre_delete_collection=True,
)
- output = docsearch.similarity_search_with_score("foo", k=1)
+ output = [
+ (doc, round(score, 1))
+ for doc, score in docsearch.similarity_search_with_score("foo", k=1)
+ ]
assert output == [(Document(page_content="foo", metadata={"page": "0"}), 1.0)]
drop_vector_indexes(docsearch)