Skip to content

Commit 5668bdc

Browse files
authored
Neo4jWriter fix relationship query (#155)
* Fix relationship upsert query: - Prevent full db scan by using node labels - Prevent Cypher syntax error by escaping the relationship type with backticks * Add note in changelog
1 parent 56bc660 commit 5668bdc

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
### Fixed
2020
- Resolved import issue with the Vertex AI Embeddings class.
2121
- Resolved issue where Neo4jWriter component would raise an error if the start or end node ID was not defined properly in the input.
22+
- Resolved issue where relationship types was not escaped in the insert Cypher query.
23+
- Improved query performance in Neo4jWriter.
2224

2325
### Changed
2426
- Moved the Embedder class to the neo4j_graphrag.embeddings directory for better organization alongside other custom embedders.

src/neo4j_graphrag/neo4j_queries.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
)
5454

5555
UPSERT_RELATIONSHIP_QUERY = (
56-
"MATCH (start {{ id: $start_node_id }}) "
57-
"MATCH (end {{ id: $end_node_id }}) "
58-
"MERGE (start)-[r:{type}]->(end) "
56+
"MATCH (start:__Entity__ {{ id: $start_node_id }}) "
57+
"MATCH (end:__Entity__ {{ id: $end_node_id }}) "
58+
"MERGE (start)-[r:`{type}`]->(end) "
5959
"WITH r SET r += $properties "
6060
"WITH r CALL {{ "
6161
"WITH r WITH r WHERE $embeddings IS NOT NULL "

0 commit comments

Comments
 (0)