Skip to content

feat(fts): add with_limit to MatchQueryExec and FlatMatchQueryExec - #10658

Merged
hamersaw merged 4 commits into
lance-format:mainfrom
hamersaw:feat/fts-match-with-limit
Nov 24, 2026
Merged

hamersaw merged 4 commits into
lance-format:mainfrom
hamersaw:feat/fts-match-with-limit

Conversation

@hamersaw

@hamersaw hamersaw commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

We recently added a SharedFtsScorerExec node 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 the limit configuration on these nodes broke because rebuilding doesn't maintain the inflated limit.

In this PR we add with_limit functions that allow us to inflate the existing limit.

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]>
@github-actions github-actions Bot added the enhancement New feature or request label Nov 3, 2026
hamersaw and others added 2 commits November 24, 2026 10:58
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]>
@hamersaw
hamersaw marked this pull request as ready for review November 24, 2026 18:56

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Nov 24, 2026

@ChilePiquin ChilePiquin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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 relevance SortExec.fetch for the final top-k. Flat rows must never be truncated early in scan order because later rows may score higher.
  2. rust/lance/src/io/exec/fts.rs:933-938: Construct widened_flat once and assert widened_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]>
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 24, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 24, 2026
@hamersaw
hamersaw merged commit a40c2a2 into lance-format:main Nov 24, 2026
42 checks passed
@hamersaw
hamersaw deleted the feat/fts-match-with-limit branch November 24, 2026 21:57
hamersaw added a commit that referenced this pull request Dec 2, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants