Skip to content

fix(falkordb): handle empty sanitized query in build_fulltext_query#1415

Open
smcdonnell7 wants to merge 1 commit intogetzep:mainfrom
smcdonnell7:fix/falkordb-empty-fulltext-query
Open

fix(falkordb): handle empty sanitized query in build_fulltext_query#1415
smcdonnell7 wants to merge 1 commit intogetzep:mainfrom
smcdonnell7:fix/falkordb-empty-fulltext-query

Conversation

@smcdonnell7
Copy link
Copy Markdown

Summary

FalkorDriver.build_fulltext_query crashes RediSearch when every token of the input reduces to a stopword.

After line 417 filters stopwords, sanitized_query can become the empty string. The function then emits:

(@group_id:"...") ()

RediSearch rejects this with a syntax error, which surfaces as a 500 from any Graphiti.search_() call whose subject happens to be an all-stopword phrase. Real-world triggers we hit in production:

  • Entity names produced by the LLM extractor like "will send the", "the one", "it is".
  • Any fact text that reduces to stopwords after sanitization.

Repro

Against any running FalkorDB instance:

from graphiti_core.driver.falkordb_driver import FalkorDriver

d = FalkorDriver(host="localhost", port=6379)
q = d.build_fulltext_query("will the it", group_ids=["my_group"])
# before this patch: '(@group_id:"my_group") ()'   <-- RediSearch syntax error
# after  this patch: '(@group_id:"my_group")'
assert "()" not in q

End-to-end, graphiti.search_(query="will send the", group_ids=["x"]) returns an empty result set instead of raising.

Fix

When the sanitized query is empty after stopword filtering, return either the empty string (no group filter) or just the group filter on its own, so RediSearch receives a valid query. Keeps the upstream behaviour for every non-empty case identical.

Test plan

  • Manual repro above passes with the patch
  • Normal queries ("shopify migration") unchanged
  • Searches against a FalkorDB-backed Graphiti no longer 500 on all-stopword entity names

When every token of the input query is a RediSearch stopword (or the
input is empty / whitespace-only), the stopword filter on line 417
collapses `sanitized_query` to an empty string. The function then
emits a fulltext query of the form:

    (@group_id:"...") ()

RediSearch rejects this with a syntax error, which surfaces as a
500 from any graphiti search whose subject happens to be an
all-stopword phrase. Real-world triggers include entity names like
"will send the", "the one", "it is", or any fact text produced by
the LLM extractor that reduces to stopwords.

Minimal repro (against an existing FalkorDB):

    from graphiti_core.driver.falkordb_driver import FalkorDriver
    d = FalkorDriver(host='localhost', port=6379)
    # Before this patch, the resulting fulltext query ends in " ()"
    # and Graphiti.search_() raises a RediSearch syntax error.
    q = d.build_fulltext_query('will the it', group_ids=['my_group'])
    assert '()' not in q

Fix: when the sanitized query is empty after stopword filtering,
return either the empty string (no group filter) or just the
group filter on its own, so RediSearch receives a valid query.
@danielchalef
Copy link
Copy Markdown
Member


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants