diff --git a/graphiti_core/driver/falkordb_driver.py b/graphiti_core/driver/falkordb_driver.py index a28db3016..a3f47ce9d 100644 --- a/graphiti_core/driver/falkordb_driver.py +++ b/graphiti_core/driver/falkordb_driver.py @@ -416,6 +416,9 @@ def build_fulltext_query( filtered_words = [word for word in query_words if word and word.lower() not in STOPWORDS] sanitized_query = ' | '.join(filtered_words) + if not sanitized_query: + return '' + # If the query is too long return no query if len(sanitized_query.split(' ')) + len(group_ids or '') >= max_query_length: return '' diff --git a/tests/utils/search/test_search_security.py b/tests/utils/search/test_search_security.py index ae7477bd1..de46550a2 100644 --- a/tests/utils/search/test_search_security.py +++ b/tests/utils/search/test_search_security.py @@ -74,6 +74,18 @@ def test_falkordb_fulltext_query_rejects_invalid_group_ids(): FalkorDriver.build_fulltext_query(driver, 'test', ['bad"group']) +def test_falkordb_fulltext_query_returns_empty_string_for_stopword_only_query(): + # Import inside the test so collection still works when FalkorDB extras are unavailable. + from graphiti_core.driver.falkordb_driver import FalkorDriver + + driver = MagicMock(spec=FalkorDriver) + driver.sanitize.return_value = 'the and' + + result = FalkorDriver.build_fulltext_query(driver, 'the and', ['standups']) + + assert result == '' + + @pytest.mark.asyncio async def test_shared_search_rejects_invalid_group_ids(): clients = SimpleNamespace(