Repository navigation
fix(query): match stopwords and weights before escaping tokens - #854
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Follow-up to #831: same helper, same class of bug (tokens compared after escaping).
Motivation
FullTextQueryHelper._tokenize_and_escape_queryescapes each token and only then compares it with the stopword set and thetext_weightskeys. Escaping rewrites punctuation, sodon'tbecomesdon\'t, which is not in the English stopword list (don'tis), andstate-of-the-artbecomesstate\-of\-the\-art, which no longer matches a weight set forstate-of-the-art. Result:TextQuery("don't panic", ...)keepsdon\'tin the query, and weights on hyphenated or apostrophe words are silently ignored.TextQueryandHybridQueryshare the helper.Changes
tests/unit/test_query_types.py:"don't panic"now produces@body:(panic), and a weight onstate-of-the-artis applied tostate\-of\-the\-art.Release Notes
Stopwords containing punctuation (e.g.
don't) are now removed from text queries, and weights on words with punctuation are now applied.Reviewer Brief
Start here:
redisvl/utils/full_text_query_helper.py,_tokenize_and_escape_query.Where it could fail: output for tokens without punctuation is unchanged; tokens with punctuation that were previously (wrongly) kept now get dropped if they are stopwords, which changes the query string for those inputs.
Not verified: a live Redis search; the unit tests ran with
--confcutdir=tests/unit(no Docker Redis).Reviewed: commit 1f24503, pre-PR review by Claude (Opus 5.5); change written with Claude (Sonnet 5.5).
Beyond CI: with the helper restored to
mainthe 2 new tests fail; with the fix all oftest_query_types.pyandtest_text_query_weights.pypass (79 passed).Prepared with the help of an AI coding assistant (Claude).
Note
Low Risk
Localized change to query-string construction with targeted unit tests; only affects tokens containing punctuation that were previously mishandled.
Overview
Fixes full-text tokenization so stopword filtering and text weights are evaluated on normalized raw tokens, with Redis escaping applied only afterward. Previously, escaping ran first (e.g.
don't→don\'t, hyphenated phrases backslash-escaped), so punctuation-bearing stopwords were not removed and weighted keys on those tokens did not match.FullTextQueryHelper._tokenize_and_escape_querynow strips/lowercases tokens, drops stopwords and attaches weights using the unescaped form, then escapes each surviving token before building the OR query string. Behavior for plain tokens is unchanged; queries that include apostrophe or hyphen stopwords/weights now produce the intended Redis syntax.Unit tests cover
"don't panic"dropping the stopword and weightedstate-of-the-artapplying on the escaped token.Reviewed by Cursor Bugbot for commit 1f24503. Bugbot is set up for automated code reviews on this repo. Configure here.