Skip to content

Keep parenthesized groups in Qdrant filters - #7440

Open
r0h1tb wants to merge 1 commit into
spring-projects:mainfrom
r0h1tb:fix/qdrant-filter-groups
Open

r0h1tb wants to merge 1 commit into
spring-projects:mainfrom
r0h1tb:fix/qdrant-filter-groups

Conversation

@r0h1tb

@r0h1tb r0h1tb commented Nov 21, 2026

Copy link
Copy Markdown

QdrantFilterExpressionConverter only handles a Group directly under NOT.
Anywhere else the group falls through to an empty Qdrant Filter, and Qdrant treats an empty filter as "match everything".
The text parser and FilterExpressionBuilder.group(...) both produce a Group for every parenthesized part, so any filter that mixes && and || with parentheses is affected.

On a real Qdrant, with six documents:

Filter Expected Before this change
country == 'BG' && (year >= 2020 || genre == 'drama') 2 documents every BG document
(country == 'BG' && year >= 2020) || genre == 'drama' 3 documents all 6
NOT country == 'BG' 3 documents RuntimeException: Non AND/OR/NOT expression must have Value right argument!
delete("(country == 'BG' && year >= 2020) || genre == 'drama'") 3 documents left 0 left, the collection is emptied

doDelete uses the same converter, which is why the last row deletes everything.

The fix converts a group as its content wherever it appears, negates any NOT operand rather than only a group, and throws for an operand the converter does not know instead of silently matching everything.

Tests:

  • QdrantFilterExpressionConverterTests: groups on either side of AND/OR, nested groups, a builder group(...), NOT with and without parentheses. 4 fail and 1 errors without the fix.
  • QdrantVectorStoreFilterIT (new, Testcontainers only, no OPENAI_API_KEY needed): the search cases above plus the delete. 5 fail and 1 errors without the fix, including the emptied collection.
  • Module: 54 unit tests and QdrantVectorStoreFilterIT 7/7, QdrantVectorStoreUpsertIT 18/18 pass. Checkstyle and spring-javaformat validate are clean.

`QdrantFilterExpressionConverter` only handled a `Group` directly under
NOT. Anywhere else, as in `a && (b || c)`, the group fell through to an
empty Qdrant filter, which matches every point. Searches returned
documents the filter excludes, and `delete("(a && b) || c")` deleted
the whole collection. `NOT` of a plain comparison threw instead of
being converted.

Convert a group as its content wherever it appears, negate any NOT
operand, and reject an operand the converter does not know instead of
matching everything.

Signed-off-by: Rohit Behera <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants