Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix node distance reranker #231

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions graphiti_core/search/search_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ async def node_distance_reranker(
) -> list[str]:
# filter out node_uuid center node node uuid
filtered_uuids = list(filter(lambda node_uuid: node_uuid != center_node_uuid, node_uuids))
scores: dict[str, float] = {}
scores: dict[str, float] = {center_node_uuid: 0.0}

# Find the shortest path to center node
query = Query("""
Expand All @@ -649,9 +649,13 @@ async def node_distance_reranker(

for result in path_results:
uuid = result['uuid']
score = result['score'] if 'score' in result else float('inf')
score = result['score']
scores[uuid] = score

for uuid in filtered_uuids:
if uuid not in scores:
scores[uuid] = float('inf')

# rerank on shortest distance
filtered_uuids.sort(key=lambda cur_uuid: scores[cur_uuid])

Expand Down
1 change: 1 addition & 0 deletions tests/test_graphiti_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ async def test_graphiti_init():
COMBINED_HYBRID_SEARCH_CROSS_ENCODER,
group_ids=['test'],
)

pretty_results = {
'edges': [edge.fact for edge in results.edges],
'nodes': [node.name for node in results.nodes],
Expand Down
Loading