Skip to content
Closed
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: 5 additions & 3 deletions graphiti_core/driver/falkordb/operations/search_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ async def edge_fulltext_search(
'edge_name_and_fact', limit=limit, provider=GraphProvider.FALKORDB
)
+ """
YIELD relationship AS rel, score
MATCH (n:Entity)-[e:RELATES_TO {uuid: rel.uuid}]->(m:Entity)
YIELD relationship AS e, score
WITH e, score, startNode(e) AS n, endNode(e) AS m
"""
+ filter_query
+ """
Expand Down Expand Up @@ -415,7 +415,9 @@ async def edge_bfs_search(
UNWIND $bfs_origin_node_uuids AS origin_uuid
MATCH path = (origin {{uuid: origin_uuid}})-[:RELATES_TO|MENTIONS*1..{max_depth}]->(:Entity)
UNWIND relationships(path) AS rel
MATCH (n:Entity)-[e:RELATES_TO {{uuid: rel.uuid}}]-(m:Entity)
WITH rel
WHERE type(rel) = 'RELATES_TO'
WITH rel AS e, startNode(rel) AS n, endNode(rel) AS m
"""
+ filter_query
+ """
Expand Down
52 changes: 52 additions & 0 deletions tests/driver/test_falkordb_search_ops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from typing import Any

import pytest

from graphiti_core.driver.falkordb.operations.search_ops import FalkorSearchOperations
from graphiti_core.search.search_filters import SearchFilters


class RecordingExecutor:
def __init__(self):
self.cypher_query = ''
self.params: dict[str, Any] = {}

async def execute_query(self, cypher_query_: str, **kwargs: Any):
self.cypher_query = cypher_query_
self.params = kwargs
return [], None, None


@pytest.mark.asyncio
async def test_edge_fulltext_search_uses_returned_relationship_endpoints():
executor = RecordingExecutor()
operations = FalkorSearchOperations()

await operations.edge_fulltext_search(
executor,
'api test system',
SearchFilters(),
group_ids=['group-a'],
)

assert 'YIELD relationship AS e, score' in executor.cypher_query
assert 'WITH e, score, startNode(e) AS n, endNode(e) AS m' in executor.cypher_query
assert 'uuid: rel.uuid' not in executor.cypher_query


@pytest.mark.asyncio
async def test_edge_bfs_search_uses_path_relationship_endpoints():
executor = RecordingExecutor()
operations = FalkorSearchOperations()

await operations.edge_bfs_search(
executor,
['origin-uuid'],
2,
SearchFilters(),
group_ids=['group-a'],
)

assert "WHERE type(rel) = 'RELATES_TO'" in executor.cypher_query
assert 'WITH rel AS e, startNode(rel) AS n, endNode(rel) AS m' in executor.cypher_query
assert 'uuid: rel.uuid' not in executor.cypher_query
Loading