Repository navigation
fix: make MultiMatchQuery serde lossless - #9753
Merged
Merged
Conversation
MultiMatchQuery serialized only `{query, columns, boost}` from its first
leaf and decoded every leaf as a default MatchQuery, so each leaf's terms,
operator, fuzziness, max_expansions, prefix_length and document
granularity were lost over JSON. An AND multi-match came back as OR.
Serialize every leaf under `match_queries` (the shape the JSON parser and
the namespace spec already use) and read it first on decode. The legacy
keys are still written when every leaf names a column, so a reader that
predates `match_queries` degrades as before, and the legacy shape still
decodes unchanged.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
hamersaw
marked this pull request as ready for review
October 7, 2026 16:43
zhangyue19921010
approved these changes
Oct 8, 2026
zhangyue19921010
left a comment
Collaborator
There was a problem hiding this comment.
(non-blocking) We may want to pay attention to the upgrade order: upgrade servers first, then clients.
- New server + old client: safe. Old clients only write
query/columns/boost, which the new server decodes exactly as before, so behavior is unchanged. - Old server + new client: silently wrong. The old server doesn't recognize
match_queriesand rebuilds every leaf from the legacy keys (query/columns/boost). A query that relies on per-leaf settings therefore runs as a different query, and no error is raised: every leaf searches the first leaf'sterms,operatorchanges fromAndtoOr,fuzzinesschanges from auto (null) to exact (0), anddocument_granularityis dropped. (If any leaf has nocolumn, the old server fails withmissing field "query"instead.)
jackye1995
approved these changes
Oct 8, 2026
xuanyu-z
approved these changes
Oct 8, 2026
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.
Problem
MultiMatchQuery's custom serde wrote only{query, columns, boost}, taken from the first leaf, and decoded every leaf as a defaultMatchQuery. Each leaf's terms, operator, fuzziness,max_expansions,prefix_lengthand document granularity were lost over JSON, so anANDmulti-match came back asOR.Anything that ships an
FtsQueryas JSON hits this. In LanceDB that includes the remote client's structured FTS body (rust/lancedb/src/remote/table.rs), soMultiMatchQuery(operator=AND)from Python is evaluated as OR server-side.Fix
MatchQueryundermatch_queries, the shape the JSON parser (MultiMatchQuery::from_json) and the namespace spec already use.match_queriesis read first.query/columns/boostkeys are still written. A reader that predatesmatch_queriesignores the new key and degrades exactly as it does today, so a rolling upgrade doesn't break plain multi-matches.match_queriesis written. An old reader then fails withmissing field "query"; the old writer panicked on the columnunwrap().No other
FtsQueryvariant's serde loses fields. Boost and Boolean only lost data when nesting a multi-match, which the nested round-trip test covers.Tests
test_multi_match_query_serde_round_trip: per-leaf AND, fuzziness, max_expansions, prefix_length, boost, granularity, and different terms per leaf.test_multi_match_query_serde_nested_round_trip: a Boost wrapping a Boolean that contains a MultiMatch.test_multi_match_query_legacy_serde: the legacy shape decodes as before; new output still carries the legacy keys.All three fail without the fix.
cargo test -p lance-index --lib scalar::inverted::passes (912 tests), and clippy forlance-indexis clean.Downstream
Two LanceDB tests encode the old behaviour and will need updating on the bump:
python/python/tests/test_fts.py:1267asserts the exact multi-match JSON string.rust/lancedb/src/table/datafusion/udtf/fts.rs:1488expects one row from leaves with different terms; it only passed because the second leaf's terms were dropped.🤖 Generated with Claude Code