fix: preserve relationship direction in get_by_node_uuid and BFS edge search#1663
Open
6or7 wants to merge 2 commits into
Open
fix: preserve relationship direction in get_by_node_uuid and BFS edge search#16636or7 wants to merge 2 commits into
6or7 wants to merge 2 commits into
Conversation
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
… search Switch get_entity_edge_return_query to use startNode(e)/endNode(e) for NEO4J/FALKORDB/NEPTUNE so source/target reflect the stored relationship direction regardless of MATCH directionality. Fixes direction reversal in EntityEdge.get_by_node_uuid and edge_bfs_search when the queried node is the relationship target. KUZU is unchanged: its 'e' is a RelatesToNode_ intermediate node, not a relationship, and its MATCH is already directed. Adds unit tests for the return-query builder and a regression assertion in test_entity_edge for the target-side get_by_node_uuid case. Fixes getzep#1662
6or7
force-pushed
the
fix/edge-direction-preservation
branch
from
July 17, 2026 07:57
202b1a3 to
e437bb6
Compare
Author
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1662
get_entity_edge_return_querynow readssource_node_uuid/target_node_uuidfrom the relationship itself viaCypher's
startNode(e)/endNode(e)for NEO4J/FALKORDB/NEPTUNE, instead of from then/mMATCH variables.This fixes direction reversals in:
EntityEdge.get_by_node_uuid— when the queried node is the relationship's targetedge_bfs_search(Neo4j/FalkorDB/search_utils) — same class of bug for undirected MATCHKUZU is unchanged: its
eis aRelatesToNode_intermediate node, not a relationship, sostartNode/endNodedon'tapply. KUZU's MATCH is always directed, so
n/malready reflect the true source/target.Root cause
For undirected MATCH like
MATCH (n {uuid: $node_uuid})-[e]-(m), Cypher binds the queried node tonon every row.The old
RETURN n.uuid AS source_node_uuid, m.uuid AS target_node_uuidtherefore reported the queried node as sourceregardless of the stored relationship direction. See #1662 for full analysis.
Changes
graphiti_core/models/edges/edge_db_queries.py: switch NEO4J/FALKORDB/NEPTUNE branches ofget_entity_edge_return_querytostartNode(e)/endNode(e). KUZU branch unchanged with an explanatory comment.tests/test_edge_db_queries.py: new unit tests covering the return shape per provider.tests/test_edge_int.py: regression assertion —get_by_node_uuid(target_uuid)must preservesource=A, target=B.No call sites needed to change — the fix lives entirely in the return-query builder.
Backward compatibility
No data migration required.
startNode(e)/endNode(e)reads immutable relationship metadata, so historical data readscorrectly without any backfill.
Out of scope
KUZU's
get_by_node_uuidonly matches outgoing edges due to its directed MATCH pattern. Fixing this requires storingsource_uuid/target_uuidonRelatesToNode_and a data backfill — left for a follow-up PR.