langchain4j/langchain4j-milvus/src
greymoth e3ded475a9
Escape LIKE wildcards in Milvus containsString filter (match #5522/#5553) (#5600)
`MilvusMetadataFilterMapper.mapContains` builds a `ContainsString` query
as `field LIKE "%" + value + "%"` but never escapes the user value's own
LIKE wildcards. In Milvus, `%` and `_` are wildcards, so
`containsString("50%")` matches "50" + anything and
`containsString("a_b")` matches "axb" — but the contract is a literal
substring (`ContainsString#test` uses `String#contains`).

Parent PR #5577 hardened the same mapper's `formatValue` against
string-literal breakout but left the wildcard side undone. The identical
defect was already fixed in the Hibernate (#5522) and MongoDB (#5553)
mappers; Milvus is the store the sweep missed.

The fix adds a `formatLikePattern` that escapes `\`, `%`, `_`, `"` (the
existing `formatValue` is left untouched — its backslash-doubling would
corrupt `\%`). +4 regression tests. Verified by execution (Java 21): the
wildcard cases fail on the old code and pass after; non-wildcard values
are byte-identical.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-26 10:26:40 +02:00
..
main/java/dev/langchain4j/store/embedding/milvus Escape LIKE wildcards in Milvus containsString filter (match #5522/#5553) (#5600) 2026-06-26 10:26:40 +02:00
test/java/dev/langchain4j/store/embedding/milvus Escape LIKE wildcards in Milvus containsString filter (match #5522/#5553) (#5600) 2026-06-26 10:26:40 +02:00