Skip to content

Commit

Permalink
Neo4jWriter fix relationship query (#155)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
stellasia authored Sep 27, 2024
1 parent 56bc660 commit 5668bdc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
### Fixed
- Resolved import issue with the Vertex AI Embeddings class.
- Resolved issue where Neo4jWriter component would raise an error if the start or end node ID was not defined properly in the input.
- Resolved issue where relationship types was not escaped in the insert Cypher query.
- Improved query performance in Neo4jWriter.

### Changed
- Moved the Embedder class to the neo4j_graphrag.embeddings directory for better organization alongside other custom embedders.
Expand Down
6 changes: 3 additions & 3 deletions src/neo4j_graphrag/neo4j_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
)

UPSERT_RELATIONSHIP_QUERY = (
"MATCH (start {{ id: $start_node_id }}) "
"MATCH (end {{ id: $end_node_id }}) "
"MERGE (start)-[r:{type}]->(end) "
"MATCH (start:__Entity__ {{ id: $start_node_id }}) "
"MATCH (end:__Entity__ {{ id: $end_node_id }}) "
"MERGE (start)-[r:`{type}`]->(end) "
"WITH r SET r += $properties "
"WITH r CALL {{ "
"WITH r WITH r WHERE $embeddings IS NOT NULL "
Expand Down

0 comments on commit 5668bdc

Please sign in to comment.