Skip to content

Commit 1d2417e

Browse files
authored
Search optimizations (#280)
fix node distance search
1 parent 93b8b02 commit 1d2417e

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

graphiti_core/search/search_utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ async def edge_similarity_search(
229229

230230
query: LiteralString = (
231231
"""
232-
MATCH (n:Entity)-[r:RELATES_TO]->(m:Entity)
233-
"""
232+
MATCH (n:Entity)-[r:RELATES_TO]->(m:Entity)
233+
"""
234234
+ group_filter_query
235235
+ filter_query
236236
+ """\nWITH DISTINCT r, vector.similarity.cosine(r.fact_embedding, $search_vector) AS score
@@ -765,8 +765,9 @@ async def node_distance_reranker(
765765
# rerank on shortest distance
766766
filtered_uuids.sort(key=lambda cur_uuid: scores[cur_uuid])
767767

768-
# add back in filtered center uuid
769-
filtered_uuids = [center_node_uuid] + filtered_uuids
768+
# add back in filtered center uuid if it was filtered out
769+
if center_node_uuid in node_uuids:
770+
filtered_uuids = [center_node_uuid] + filtered_uuids
770771

771772
return filtered_uuids
772773

graphiti_core/utils/maintenance/node_operations.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ async def extract_nodes(
172172
new_nodes = []
173173
for name in extracted_node_names:
174174
entity_type = node_classifications.get(name)
175-
labels = ['Entity'] if entity_type is None else ['Entity', entity_type]
175+
labels = (
176+
['Entity'] if entity_type is None or entity_type == 'None' else ['Entity', entity_type]
177+
)
176178

177179
new_node = EntityNode(
178180
name=name,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "graphiti-core"
3-
version = "0.7.3"
3+
version = "0.7.4"
44
description = "A temporal graph building library"
55
authors = [
66
"Paul Paliychuk <[email protected]>",

tests/test_graphiti_int.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from graphiti_core.search.search_config_recipes import (
3030
COMBINED_HYBRID_SEARCH_CROSS_ENCODER,
3131
)
32+
from graphiti_core.search.search_filters import SearchFilters
3233

3334
pytestmark = pytest.mark.integration
3435

@@ -71,6 +72,7 @@ async def test_graphiti_init():
7172
'My name is Alice',
7273
COMBINED_HYBRID_SEARCH_CROSS_ENCODER,
7374
group_ids=['test'],
75+
search_filter=SearchFilters(node_labels=['Entity']),
7476
)
7577

7678
pretty_results = {

0 commit comments

Comments
 (0)