mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-04 12:18:24 +00:00
Neo4j: Update with non-deprecated cypher methods, and new method to associate relationship embeddings (#23725)
**Description:** At the moment neo4j wrapper is using setVectorProperty, which is deprecated ([link](https://neo4j.com/docs/operations-manual/5/reference/procedures/#procedure_db_create_setVectorProperty)). I replaced with the non-deprecated version. Neo4j recently introduced a new cypher method to associate embeddings into relations using "setRelationshipVectorProperty" method. In this PR I also implemented a new method to perform this association maintaining the same format used in the "add_embeddings" method which is used to associate embeddings into Nodes. I also included a test case for this new method.
This commit is contained in:
parent
2a3288b15d
commit
cf28708e7b
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user