Skip to content

Commit

Permalink
Search optimizations (#280)
Browse files Browse the repository at this point in the history
fix node distance search
  • Loading branch information
prasmussen15 authored Feb 27, 2025
1 parent 93b8b02 commit 1d2417e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
9 changes: 5 additions & 4 deletions graphiti_core/search/search_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ async def edge_similarity_search(

query: LiteralString = (
"""
MATCH (n:Entity)-[r:RELATES_TO]->(m:Entity)
"""
MATCH (n:Entity)-[r:RELATES_TO]->(m:Entity)
"""
+ group_filter_query
+ filter_query
+ """\nWITH DISTINCT r, vector.similarity.cosine(r.fact_embedding, $search_vector) AS score
Expand Down Expand Up @@ -765,8 +765,9 @@ async def node_distance_reranker(
# rerank on shortest distance
filtered_uuids.sort(key=lambda cur_uuid: scores[cur_uuid])

# add back in filtered center uuid
filtered_uuids = [center_node_uuid] + filtered_uuids
# add back in filtered center uuid if it was filtered out
if center_node_uuid in node_uuids:
filtered_uuids = [center_node_uuid] + filtered_uuids

return filtered_uuids

Expand Down
4 changes: 3 additions & 1 deletion graphiti_core/utils/maintenance/node_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ async def extract_nodes(
new_nodes = []
for name in extracted_node_names:
entity_type = node_classifications.get(name)
labels = ['Entity'] if entity_type is None else ['Entity', entity_type]
labels = (
['Entity'] if entity_type is None or entity_type == 'None' else ['Entity', entity_type]
)

new_node = EntityNode(
name=name,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "graphiti-core"
version = "0.7.3"
version = "0.7.4"
description = "A temporal graph building library"
authors = [
"Paul Paliychuk <[email protected]>",
Expand Down
2 changes: 2 additions & 0 deletions tests/test_graphiti_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from graphiti_core.search.search_config_recipes import (
COMBINED_HYBRID_SEARCH_CROSS_ENCODER,
)
from graphiti_core.search.search_filters import SearchFilters

pytestmark = pytest.mark.integration

Expand Down Expand Up @@ -71,6 +72,7 @@ async def test_graphiti_init():
'My name is Alice',
COMBINED_HYBRID_SEARCH_CROSS_ENCODER,
group_ids=['test'],
search_filter=SearchFilters(node_labels=['Entity']),
)

pretty_results = {
Expand Down

0 comments on commit 1d2417e

Please sign in to comment.