Repository navigation
fix(query): reject TextQuery text emptied by stopwords - #831
Merged
vishal-bala merged 3 commits intoNov 12, 2026
Merged
Conversation
chrikrah
reviewed
Nov 7, 2026
chrikrah
left a comment
There was a problem hiding this comment.
From my perspective this can be merged. TextQuery("the a an") now raises the same ValueError as AggregateHybridQuery, and the shared helper is byte for byte the old tokenizer plus that check, so no other query changes.
non-blocking: the MCP fulltext tool builds a TextQuery too, and map_exception turns the new ValueError into a clean invalid-request error, which beats the Redis syntax error it got before.
$ python rv_repro.py # construction half of the #821 repro, base 930c14e vs head c18f796
base: 'the a an' -> @body:()
head: 'the a an' -> ValueError: text string cannot be empty after removing stopwords
$ pytest -q --noconftest tests/unit/test_text_query_weights.py tests/unit/test_query_types.py tests/unit/test_aggregation_types.py # head, Python 3.12
83 passed, 1 skipped in 1.21s
$ (same, base query.py, head tests)
FAILED tests/unit/test_text_query_weights.py::test_text_query_rejects_empty_tokenized_text[the a an-english]
4 failed, 79 passed, 1 skipped in 0.62s
# not run: live Redis, the integration suite
I'll send the escaped-token fix as the follow-up once this is in.
vishal-bala
requested changes
Nov 10, 2026
vishal-bala
self-requested a review
November 10, 2026 14:04
vishal-bala
approved these changes
Nov 10, 2026
Collaborator
|
I can get this PR merged as soon as those last comments are addressed 🙌 |
Contributor
Author
|
Fixed in b990e76:
Selected query tests pass: 85 passed, 1 skipped. This comment was drafted with Codex. |
|
🚀 PR was released in |
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 #821 (the stopword-only TextQuery construction error; escaped-token matching remains a separate followup).
Motivation
TextQuery built an empty full-text clause when stopword filtering removed every token. Rejecting that input during construction gives the same early ValueError as hybrid queries, as approved in the issue.
Changes
TextQuery owns a single FullTextQueryHelper, forwarding stopwords and text-weight access and updates instead of duplicating parsing or rebuilding the helper. The constructor validates the filter before text content, rejects blank text with a plain empty-text message, and retains the rendered query so the first execution does not repeat tokenization. Weight and field setters continue to invalidate the cache.
Regression tests cover filtering, validation precedence, empty text, helper reuse during rebuilding, single tokenization, escaping and updated weights. Stopword tests sit with the existing query-type assertions.
Notes
Escaped-token matching remains separate because it changes results for existing users. Use set_text_weights to update weights and invalidate the cached query. Stopwords access follows the shared helper and returns a copy.
Release Notes
TextQuery raises ValueError during construction when text is blank or tokenization and stopword filtering leave no terms, instead of failing with a Redis syntax error during search.
Reviewer Brief
Start here: TextQuery.init and _tokenize_and_escape_query in redisvl/query/query.py. One retained helper parses configuration; construction builds and caches the validated query after checking the filter.
Not verified: live Redis, cluster behavior and the full suite. Selected tests use --noconftest to avoid the shared container setup. All-files spelling found an existing issue outside this change; checks on changed files pass.
Beyond CI: the added followup regressions failed before the fix (5 failed, 82 passed, 1 skipped) and pass after it (87 passed, 1 skipped).
Reviewed 8237317 · Codex (GPT-6) · lenses: correctness, tests, security; separate challenger pass
Prepared with assistance from an AI coding agent (Codex).
Note
Low Risk
Behavior change is limited to failing fast on invalid text input at construction time; shared helper centralizes existing tokenization logic without altering successful query semantics.
Overview
TextQuery now delegates stopword handling, tokenization, and per-word weights to
FullTextQueryHelper, removing duplicated logic fromquery.py. Construction rejects blank input early (text string cannot be empty), applies the filter before text validation, and builds the query string once at init so stopword-only queries fail withValueErrorinstead of producing an invalid Redis clause at search time.Unit tests cover empty or stopword-only text, disabled stopwords, filter validation ordering, and cache invalidation when
set_text_weightsupdates the rendered query.Reviewed by Cursor Bugbot for commit b990e76. Bugbot is set up for automated code reviews on this repo. Configure here.