Skip to content

fix(falkordb): strip backticks and guard empty token list in fulltext query builder#1450

Open
octo-patch wants to merge 1 commit into
getzep:mainfrom
octo-patch:fix/issue-1440-falkordb-fulltext-query-backtick-stopword
Open

fix(falkordb): strip backticks and guard empty token list in fulltext query builder#1450
octo-patch wants to merge 1 commit into
getzep:mainfrom
octo-patch:fix/issue-1440-falkordb-fulltext-query-backtick-stopword

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #1440

Problem

_build_falkor_fulltext_query (and FalkorDriver.build_fulltext_query) had two bugs that caused RediSearch Syntax error failures during dedup-search:

  1. Backtick tokens leak through to RediSearch. The separator translation map omitted the backtick character `, so entity names from code-fenced text (e.g. `add_episode`) survived sanitization and broke RediSearch parsing.

  2. Empty parenthesis on stopword-only or punctuation-only queries. When every token was filtered out as a stopword (or the input was all separators/backticks), filtered_words became empty but the builder still constructed (@group_id:"…") (), which RediSearch rejects with a syntax error.

Both failure modes existed in two upstream copies of the function:

  • graphiti_core/driver/falkordb/operations/search_ops.py_build_falkor_fulltext_query
  • graphiti_core/driver/falkordb_driver.pyFalkorDriver.sanitize / build_fulltext_query

Solution

Two surgical changes applied to both copies:

  1. Add ` to the separator translation map so backticks are replaced with whitespace before tokenization.
  2. Return '' early when filtered_words is empty after stopword filtering, so callers skip the RediSearch query rather than issuing a malformed one.

Testing

Added unit tests in tests/driver/test_falkordb_driver.py covering:

  • Backtick tokens are stripped from the query string
  • Stopword-only queries return ''
  • Punctuation-only queries return ''
  • Backtick-only queries return ''
  • Normal queries still produce valid non-empty results
  • Backtick mixed with normal tokens strips backticks but keeps the tokens

All 6 new tests pass. No existing tests were broken.

… query builder

Both copies of the FalkorDB fulltext query builder had two bugs:

1. Backtick (`) was missing from the separator map, so entity names
   extracted from code-fenced text (e.g. `add_episode`) would reach
   RediSearch as-is and trigger a syntax error.

2. When all tokens were stopwords or the input was punctuation-only,
   filtered_words was empty but the builder still produced the malformed
   query `(@group_id:…) ()`, which RediSearch rejects.

Fix both issues in:
- graphiti_core/driver/falkordb/operations/search_ops.py (_SEPARATOR_MAP + early return)
- graphiti_core/driver/falkordb_driver.py (sanitize separator_map + early return)

Adds unit tests covering backtick stripping and stopword-only / punctuation-only inputs.

Fixes getzep#1440

Co-Authored-By: Octopus <liyuan851277048@icloud.com>
@robowen1
Copy link
Copy Markdown

Reporter here — thanks for picking this up so quickly. The diff matches what I monkey-patched locally to validate the issue, and I can confirm the same fix took my Sonnet 4.6 + FalkorDB corpus rerender from ~30% failure (16/55 episodes) to 0%

Quick note on correctness: returning '' is the right contract — it matches the existing max_query_length overflow branch, and the FalkorSearchOperations.{node,edge,episode,community}_fulltext_search callers already short-circuit on fuzzy_query == '' with return []. So no caller changes are needed and the malformed (@group_id:…) () can't be constructed.

LGTM — happy to see this land.

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.

[BUG] FalkorDB fulltext query builder produces malformed RediSearch queries on backtick tokens and stopword-only inputs

2 participants