fix(falkordb): strip backticks and guard empty token list in fulltext query builder#1450
Open
octo-patch wants to merge 1 commit into
Open
Conversation
… 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>
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1440
Problem
_build_falkor_fulltext_query(andFalkorDriver.build_fulltext_query) had two bugs that caused RediSearchSyntax errorfailures during dedup-search: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.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_wordsbecame 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_querygraphiti_core/driver/falkordb_driver.py—FalkorDriver.sanitize/build_fulltext_querySolution
Two surgical changes applied to both copies:
`to the separator translation map so backticks are replaced with whitespace before tokenization.''early whenfiltered_wordsis 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.pycovering:''''''All 6 new tests pass. No existing tests were broken.