Skip to content

Fix group precedence in MilvusFilterExpressionConverter - #6543

Merged
ericbottard merged 1 commit into
spring-projects:mainfrom
Seol-JY:fix-milvus-filter-group-precedence
Jul 2, 2026
Merged

Fix group precedence in MilvusFilterExpressionConverter#6543
ericbottard merged 1 commit into
spring-projects:mainfrom
Seol-JY:fix-milvus-filter-group-precedence

Conversation

@Seol-JY

@Seol-JY Seol-JY commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

The doGroup override in MilvusFilterExpressionConverter converted a parenthesized filter group into content && content, duplicating the group body and dropping the parentheses that expressed the grouping.

Because Milvus binds && tighter than ||, a filter such as:

(year >= 2020 OR country == 'BG') AND city != 'Sofia'

was emitted without parentheses:

metadata["year"] >= 2020 || metadata["country"] == "BG" && metadata["year"] >= 2020 || metadata["country"] == "BG" && metadata["city"] != "Sofia"

so the trailing AND no longer applied to the whole group, and the query silently matched the wrong documents.

This replaces the override with the conventional doStartGroup/doEndGroup hooks that wrap the group content in parentheses, consistent with the other filter expression converters (for example PgVectorFilterExpressionConverter) and with the base AbstractFilterExpressionConverter contract. Making the grouping explicit also means the result no longer relies on Milvus's operator precedence.

The existing testGroup assertion codified the incorrect output and has been corrected; a testGroupAsRightOperand test was added to cover a group used as the right-hand operand.

The `doGroup` override converted a parenthesized filter group into
`content && content`, duplicating the group body and dropping the
parentheses that expressed the grouping. Because Milvus binds `&&`
tighter than `||`, a filter such as

    (year >= 2020 OR country == 'BG') AND city != 'Sofia'

was emitted without parentheses, so the trailing `AND` no longer
applied to the whole group and the query silently matched the wrong
documents.

Replace the override with the conventional `doStartGroup`/`doEndGroup`
hooks that wrap the group content in parentheses, consistent with the
other filter expression converters such as
`PgVectorFilterExpressionConverter`. Update the affected test, which
asserted the incorrect output, and add a test covering a group used as
the right-hand operand.

Signed-off-by: Seol-JY <70826982+Seol-JY@users.noreply.github.com>
@Seol-JY
Seol-JY force-pushed the fix-milvus-filter-group-precedence branch from c421373 to 72c34e6 Compare July 2, 2026 02:59
@ericbottard ericbottard added bug Something isn't working and removed status: waiting-for-triage labels Jul 2, 2026
@ericbottard ericbottard self-assigned this Jul 2, 2026
@ericbottard
ericbottard merged commit cb28ba3 into spring-projects:main Jul 2, 2026
5 checks passed
@ericbottard ericbottard added this to the 2.0.1 milestone Jul 2, 2026
@ericbottard

Copy link
Copy Markdown
Member

Thanks for yet another useful contribution @Seol-JY !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants