Repository navigation
feat(fts): add with_limit to MatchQueryExec and FlatMatchQueryExec - #10658
Conversation
The FTS top-k lives in `FtsSearchParams`, so a caller that over-fetches (to survive a later dedup) has to rebuild the leaf. Rebuilding through `new` drops private state: segment selection, overlay and external masks, the prepared query, the candidate filter, and the shared scorer. Dropping the shared scorer makes the enclosing `MatchCorpus` node fail at execution, because it requires its consumer and producer to hold the scorer it planned with. `with_limit` re-cuts the leaf and carries everything else over, matching the existing `CompoundQueryExec::with_limit`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The flat leg emits every match and leaves the cut to the consumer, so the unwidened corpus returns one indexed row plus all four residual rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Xuanwo
left a comment
There was a problem hiding this comment.
Based on a source review only (tests were not run locally), keeping both with_limit methods makes sense since params() is public and rebuilding through the public constructor loses the shared scorer identity.
Requesting two changes before merging:
rust/lance/src/io/exec/fts/flat_match.rs:957-958: Please correct the Rustdoc — this setter updates the plan parameter while flat matching still emits every match, so callers need to update the enclosing relevanceSortExec.fetchfor the final top-k. Flat rows must never be truncated early in scan order because later rows may score higher.rust/lance/src/io/exec/fts.rs:933-938: Constructwidened_flatonce and assertwidened_flat.params().limit == Some(10)on the actual returned node, while keeping the execution and 5 → 6 assertions.
FlatMatchQueryExec emits every match; with_limit only records the limit, and the enclosing relevance SortExec.fetch makes the top-k cut. The corpus test now asserts the limit on the node it actually returns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
✅ Gate recommendation: approve.
These methods provide a focused way to rewrite limits while preserving candidate scope and scorer identity. Rebuilding the enclosing corpus through the existing reconstruction API remains a more involved alternative.
This revision addresses the documentation and test concerns: flat matching still emits every match for the enclosing relevance sort, and the test checks the widened limit on the returned flat node. No blocking issues found.
Callers that over-fetch a bounded FTS leaf need to raise `FtsSearchParams::limit`. The limit lives inside the exec, not in a fetch node, so `with_fetch` can't reach it. #10658 added `with_limit` to `MatchQueryExec` and `FlatMatchQueryExec`, and the compound execs already had one. `PhraseQueryExec` was the remaining indexed leaf without it. Without `with_limit`, a caller has to rebuild the node through a constructor. The constructors don't take the overlay block, the external mask or the shared corpus scorer, so a rebuild either drops rows lance excluded as superseded or breaks the binding `SharedFtsScorerExec` checks at execution. `PhraseQueryExec::with_limit` copies the node whole and changes only the limit, following `MatchQueryExec::with_limit`. ## Testing `test_phrase_query_exec_with_limit_keeps_domain`: a phrase leaf scoped to one segment, widened from limit 1 to 20, still returns only that segment's rows even though every fragment matches. A leaf bound to a shared scorer keeps the same scorer by identity after widening. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
We recently added a
SharedFtsScorerExecnode to the FTS query path to ensure accurate scores in scenarios where an FTS query operates over multiple corpus' (ex. indexed + non-indexed data). Processes that rely on inflating thelimitconfiguration on these nodes broke because rebuilding doesn't maintain the inflated limit.In this PR we add
with_limitfunctions that allow us to inflate the existinglimit.