Skip to content

feat(fts): export CompoundQueryExec and support an injected base scorer - #8131

Merged
BubbleCal merged 2 commits into
mainfrom
lu/v10-compound-export
Aug 1, 2026
Merged

BubbleCal merged 2 commits into
mainfrom
lu/v10-compound-export

Conversation

@LuQQiu

@LuQQiu LuQQiu commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

CompoundQueryExec (the single-column compound FTS boundary introduced with the posting-backed compound scorer) is pub(crate), so engines that rewrite physical plans cannot rebuild it against a subset of segments the way they already do with MatchQueryExec/PhraseQueryExec. This PR gives it the same surface:

  • pub struct CompoundQueryExec with query() / params() / prefilter_source() / dataset() / base_scorer() / explicit_segment_uuids() accessors, a pub new_with_segments, and a new_with_segment_uuids constructor (mirroring MatchQueryExec)
  • with_base_scorer(Arc<MemBM25Scorer>): compound_search / prepare_compound_query take an optional preset scorer; when present every leaf uses it instead of building segment-local stats. A preset scorer carries stats keyed by the full query token set, which covers every leaf's tokens — the same contract MatchQueryExec::with_base_scorer documents for cross-segment BM25 consistency.

No behavior change when no scorer is injected (the default and the only in-crate path).

Note: rebased onto current main. A v10.1.0-beta.1-based twin of the same change lives on branch lu/v10.1-compound-pin for downstream pinning until the next release.

Test plan

  • cargo check clean; exercised end-to-end by a downstream distributed engine: compound boundaries rebuilt per worker with injected corpus-wide scorers return results identical to single-node execution across an e2e suite (44 tests)

🤖 Generated with Claude Code

@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer enhancement New feature or request labels Aug 1, 2026
Distributed engines need to rebuild a compound FTS boundary per worker
(subset of segments) and, for cross-segment BM25 consistency, inject a
corpus-wide scorer — the same contract MatchQueryExec already exposes
via with_base_scorer. Make CompoundQueryExec pub with accessors and a
segment-uuid constructor, and thread an optional preset scorer through
compound_search/prepare_compound_query; when present, every leaf uses
it instead of building segment-local stats.

Co-Authored-By: Claude Fable 5 <[email protected]>

@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 with a non-blocking risk. The distributed compound boundary is a real gap, and a direct two-segment experiment showed the complete corpus-wide scorer path matches monolithic execution exactly. Before broad adoption, preserve the existing public compound_search entry point and make the compound scorer-completeness contract enforceable or canonical; otherwise callers can either fail to compile or silently supply incomplete statistics.

// A preset scorer carries corpus-wide stats keyed by the full
// query token set, which covers every leaf's tokens.
let scorer = match &base_scorer {
Some(scorer) => scorer.clone(),

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.

An injected scorer missing any leaf term is accepted, and MemBM25Scorer gives absent terms zero weight, so valid compound results can be silently misranked or pruned. I ran a two-segment SHOULD(lance, alpha) probe against this head: a scorer built from both terms matched the all-segment baseline exactly, while a scorer built only from lance produced different row/score results (expected equality; observed inequality). Please validate coverage for every final leaf token, including fuzzy expansions, or provide and document a canonical compound-aware builder, with this case as regression coverage.

params: &FtsSearchParams,
prefilter: Arc<dyn PreFilter>,
metrics: Arc<dyn MetricsCollector>,
base_scorer: Option<Arc<MemBM25Scorer>>,

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.

compound_search was already public through scalar::inverted::*; requiring this sixth argument breaks every existing five-argument caller. Preserve the five-argument function as a wrapper that passes None, and put scorer injection in a separately named function or private helper so this remains an additive API change.

@jackye1995
jackye1995 force-pushed the lu/v10-compound-export branch from a08937a to 240cba7 Compare August 1, 2026 01:40

@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 with a non-blocking risk. The rebase changes only formatting in the reviewed FTS patch, and focused tests on this head reproduce the prior result: a complete scorer preserves monolithic output, while the scorer-completeness and source-compatibility risks remain. Preserve the existing compound_search entry point and make full-token scorer construction or validation canonical before broad adoption.

@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

Claude Code Review is paused for this repository. To reconnect it, an admin of this repository's GitHub organization (or the account owner, for personal repositories) who can also manage your Claude organization's Code Review settings needs to re-link GitHub in Code Review settings. This is a one-time step.

Tip: disable this comment in your organization's Code Review settings.

@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. The follow-up restores the existing five-argument compound_search contract and adds a separate scorer-aware API. Injected compound scorers now fail closed when any raw or fuzzy-expanded token is missing, while complete corpus-wide scorers preserve monolithic results across segment subsets. The implementation and focused regression coverage address the prior review concerns without changing the default path.

@BubbleCal
BubbleCal merged commit 74bff74 into main Aug 1, 2026
39 of 40 checks passed
@BubbleCal
BubbleCal deleted the lu/v10-compound-export branch August 1, 2026 13:01
sbrunk added a commit to sbrunk/lance that referenced this pull request Aug 2, 2026
The composable scorer stack (lance-format#8092, lance-format#8093, lance-format#8094, lance-format#8131) added `compound.rs`,
a single-pass `ComposableScorer` that runs a whole compound tree against one
column's index with `Match`/`Phrase` leaves scored by a `MemBM25Scorer`. It
matches `FtsQuery` exhaustively, so the `CombinedFields` variant has to be
accounted for in multiple places.

BM25F blends `tf'`, `dl'` and `docFreq'` across columns before scoring, so it
cannot be a leaf that draws its postings from a single index; making it one
needs a multi-index leaf protocol and block-max bounds out of the MAXSCORE
scan. Gate it out instead, leaving those trees on the union/sort plan
`plan_combined_fields_query` already builds:

- `supports_compound_scorer` rejects any tree containing a `CombinedFields`
  node, at the top level or nested.
- The two `compound.rs` entry points return `Error::not_supported` rather than
  `unreachable!()`, so a future planner change fails loudly instead of
  silently misscoring.
- `collect_all_fts_columns` reports the real target columns, `contains_phrase_query`
  is false (BM25F needs no positions), `validate_fts_query_contract` has nothing
  to add (the weights are private and every constructor, `Deserialize` included,
  goes through `try_with_boosts`), and `count_fts_leaves` counts the per-column
  posting scans its partition estimate is approximating.

`test_nested_combined_fields_limit_propagation` covers the gate: it nests a
combined_fields node under MUST, SHOULD and BoostQuery, so a leak surfaces the
`not_supported` error.

Also apply lance-format#8102 to `plan_combined_fields_query`, which still deep-copied the
fragment descriptor list on every plan.
Borrow the slice like `plan_match_query` now does and materialize only the
uncovered subset the flat plan takes ownership of.
sbrunk added a commit to sbrunk/lance that referenced this pull request Aug 5, 2026
The composable scorer stack (lance-format#8092, lance-format#8093, lance-format#8094, lance-format#8131) added `compound.rs`,
a single-pass `ComposableScorer` that runs a whole compound tree against one
column's index with `Match`/`Phrase` leaves scored by a `MemBM25Scorer`. It
matches `FtsQuery` exhaustively, so the `CombinedFields` variant has to be
accounted for in multiple places.

BM25F blends `tf'`, `dl'` and `docFreq'` across columns before scoring, so it
cannot be a leaf that draws its postings from a single index; making it one
needs a multi-index leaf protocol and block-max bounds out of the MAXSCORE
scan. Gate it out instead, leaving those trees on the union/sort plan
`plan_combined_fields_query` already builds:

- `supports_compound_scorer` rejects any tree containing a `CombinedFields`
  node, at the top level or nested.
- The two `compound.rs` entry points return `Error::not_supported` rather than
  `unreachable!()`, so a future planner change fails loudly instead of
  silently misscoring.
- `collect_all_fts_columns` reports the real target columns, `contains_phrase_query`
  is false (BM25F needs no positions), `validate_fts_query_contract` has nothing
  to add (the weights are private and every constructor, `Deserialize` included,
  goes through `try_with_boosts`), and `count_fts_leaves` counts the per-column
  posting scans its partition estimate is approximating.

`test_nested_combined_fields_limit_propagation` covers the gate: it nests a
combined_fields node under MUST, SHOULD and BoostQuery, so a leak surfaces the
`not_supported` error.

Also apply lance-format#8102 to `plan_combined_fields_query`, which still deep-copied the
fragment descriptor list on every plan.
Borrow the slice like `plan_match_query` now does and materialize only the
uncovered subset the flat plan takes ownership of.
sbrunk added a commit to sbrunk/lance that referenced this pull request Aug 6, 2026
The composable scorer stack (lance-format#8092, lance-format#8093, lance-format#8094, lance-format#8131) added `compound.rs`,
a single-pass `ComposableScorer` that runs a whole compound tree against one
column's index with `Match`/`Phrase` leaves scored by a `MemBM25Scorer`. It
matches `FtsQuery` exhaustively, so the `CombinedFields` variant has to be
accounted for in multiple places.

BM25F blends `tf'`, `dl'` and `docFreq'` across columns before scoring, so it
cannot be a leaf that draws its postings from a single index; making it one
needs a multi-index leaf protocol and block-max bounds out of the MAXSCORE
scan. Gate it out instead, leaving those trees on the union/sort plan
`plan_combined_fields_query` already builds:

- `supports_compound_scorer` rejects any tree containing a `CombinedFields`
  node, at the top level or nested.
- The two `compound.rs` entry points return `Error::not_supported` rather than
  `unreachable!()`, so a future planner change fails loudly instead of
  silently misscoring.
- `collect_all_fts_columns` reports the real target columns, `contains_phrase_query`
  is false (BM25F needs no positions), `validate_fts_query_contract` has nothing
  to add (the weights are private and every constructor, `Deserialize` included,
  goes through `try_with_boosts`), and `count_fts_leaves` counts the per-column
  posting scans its partition estimate is approximating.

`test_nested_combined_fields_limit_propagation` covers the gate: it nests a
combined_fields node under MUST, SHOULD and BoostQuery, so a leak surfaces the
`not_supported` error.

Also apply lance-format#8102 to `plan_combined_fields_query`, which still deep-copied the
fragment descriptor list on every plan.
Borrow the slice like `plan_match_query` now does and materialize only the
uncovered subset the flat plan takes ownership of.
sbrunk added a commit to sbrunk/lance that referenced this pull request Aug 10, 2026
The composable scorer stack (lance-format#8092, lance-format#8093, lance-format#8094, lance-format#8131) added `compound.rs`,
a single-pass `ComposableScorer` that runs a whole compound tree against one
column's index with `Match`/`Phrase` leaves scored by a `MemBM25Scorer`. It
matches `FtsQuery` exhaustively, so the `CombinedFields` variant has to be
accounted for in multiple places.

BM25F blends `tf'`, `dl'` and `docFreq'` across columns before scoring, so it
cannot be a leaf that draws its postings from a single index; making it one
needs a multi-index leaf protocol and block-max bounds out of the MAXSCORE
scan. Gate it out instead, leaving those trees on the union/sort plan
`plan_combined_fields_query` already builds:

- `supports_compound_scorer` rejects any tree containing a `CombinedFields`
  node, at the top level or nested.
- The two `compound.rs` entry points return `Error::not_supported` rather than
  `unreachable!()`, so a future planner change fails loudly instead of
  silently misscoring.
- `collect_all_fts_columns` reports the real target columns, `contains_phrase_query`
  is false (BM25F needs no positions), `validate_fts_query_contract` has nothing
  to add (the weights are private and every constructor, `Deserialize` included,
  goes through `try_with_boosts`), and `count_fts_leaves` counts the per-column
  posting scans its partition estimate is approximating.

`test_nested_combined_fields_limit_propagation` covers the gate: it nests a
combined_fields node under MUST, SHOULD and BoostQuery, so a leak surfaces the
`not_supported` error.

Also apply lance-format#8102 to `plan_combined_fields_query`, which still deep-copied the
fragment descriptor list on every plan.
Borrow the slice like `plan_match_query` now does and materialize only the
uncovered subset the flat plan takes ownership of.
sbrunk added a commit to sbrunk/lance that referenced this pull request Aug 10, 2026
The composable scorer stack (lance-format#8092, lance-format#8093, lance-format#8094, lance-format#8131) added `compound.rs`,
a single-pass `ComposableScorer` that runs a whole compound tree against one
column's index with `Match`/`Phrase` leaves scored by a `MemBM25Scorer`. It
matches `FtsQuery` exhaustively, so the `CombinedFields` variant has to be
accounted for in multiple places.

BM25F blends `tf'`, `dl'` and `docFreq'` across columns before scoring, so it
cannot be a leaf that draws its postings from a single index; making it one
needs a multi-index leaf protocol and block-max bounds out of the MAXSCORE
scan. Gate it out instead, leaving those trees on the union/sort plan
`plan_combined_fields_query` already builds:

- `supports_compound_scorer` rejects any tree containing a `CombinedFields`
  node, at the top level or nested.
- The two `compound.rs` entry points return `Error::not_supported` rather than
  `unreachable!()`, so a future planner change fails loudly instead of
  silently misscoring.
- `collect_all_fts_columns` reports the real target columns, `contains_phrase_query`
  is false (BM25F needs no positions), `validate_fts_query_contract` has nothing
  to add (the weights are private and every constructor, `Deserialize` included,
  goes through `try_with_boosts`), and `count_fts_leaves` counts the per-column
  posting scans its partition estimate is approximating.

`test_nested_combined_fields_limit_propagation` covers the gate: it nests a
combined_fields node under MUST, SHOULD and BoostQuery, so a leak surfaces the
`not_supported` error.

Also apply lance-format#8102 to `plan_combined_fields_query`, which still deep-copied the
fragment descriptor list on every plan.
Borrow the slice like `plan_match_query` now does and materialize only the
uncovered subset the flat plan takes ownership of.
sbrunk added a commit to sbrunk/lance that referenced this pull request Aug 12, 2026
The composable scorer stack (lance-format#8092, lance-format#8093, lance-format#8094, lance-format#8131) added `compound.rs`,
a single-pass `ComposableScorer` that runs a whole compound tree against one
column's index with `Match`/`Phrase` leaves scored by a `MemBM25Scorer`. It
matches `FtsQuery` exhaustively, so the `CombinedFields` variant has to be
accounted for in multiple places.

BM25F blends `tf'`, `dl'` and `docFreq'` across columns before scoring, so it
cannot be a leaf that draws its postings from a single index; making it one
needs a multi-index leaf protocol and block-max bounds out of the MAXSCORE
scan. Gate it out instead, leaving those trees on the union/sort plan
`plan_combined_fields_query` already builds:

- `supports_compound_scorer` rejects any tree containing a `CombinedFields`
  node, at the top level or nested.
- The two `compound.rs` entry points return `Error::not_supported` rather than
  `unreachable!()`, so a future planner change fails loudly instead of
  silently misscoring.
- `collect_all_fts_columns` reports the real target columns, `contains_phrase_query`
  is false (BM25F needs no positions), `validate_fts_query_contract` has nothing
  to add (the weights are private and every constructor, `Deserialize` included,
  goes through `try_with_boosts`), and `count_fts_leaves` counts the per-column
  posting scans its partition estimate is approximating.

`test_nested_combined_fields_limit_propagation` covers the gate: it nests a
combined_fields node under MUST, SHOULD and BoostQuery, so a leak surfaces the
`not_supported` error.

Also apply lance-format#8102 to `plan_combined_fields_query`, which still deep-copied the
fragment descriptor list on every plan.
Borrow the slice like `plan_match_query` now does and materialize only the
uncovered subset the flat plan takes ownership of.
sbrunk added a commit to sbrunk/lance that referenced this pull request Aug 14, 2026
The composable scorer stack (lance-format#8092, lance-format#8093, lance-format#8094, lance-format#8131) added `compound.rs`,
a single-pass `ComposableScorer` that runs a whole compound tree against one
column's index with `Match`/`Phrase` leaves scored by a `MemBM25Scorer`. It
matches `FtsQuery` exhaustively, so the `CombinedFields` variant has to be
accounted for in multiple places.

BM25F blends `tf'`, `dl'` and `docFreq'` across columns before scoring, so it
cannot be a leaf that draws its postings from a single index; making it one
needs a multi-index leaf protocol and block-max bounds out of the MAXSCORE
scan. Gate it out instead, leaving those trees on the union/sort plan
`plan_combined_fields_query` already builds:

- `supports_compound_scorer` rejects any tree containing a `CombinedFields`
  node, at the top level or nested.
- The two `compound.rs` entry points return `Error::not_supported` rather than
  `unreachable!()`, so a future planner change fails loudly instead of
  silently misscoring.
- `collect_all_fts_columns` reports the real target columns, `contains_phrase_query`
  is false (BM25F needs no positions), `validate_fts_query_contract` has nothing
  to add (the weights are private and every constructor, `Deserialize` included,
  goes through `try_with_boosts`), and `count_fts_leaves` counts the per-column
  posting scans its partition estimate is approximating.

`test_nested_combined_fields_limit_propagation` covers the gate: it nests a
combined_fields node under MUST, SHOULD and BoostQuery, so a leak surfaces the
`not_supported` error.

Also apply lance-format#8102 to `plan_combined_fields_query`, which still deep-copied the
fragment descriptor list on every plan.
Borrow the slice like `plan_match_query` now does and materialize only the
uncovered subset the flat plan takes ownership of.
sbrunk added a commit to sbrunk/lance that referenced this pull request Aug 14, 2026
The composable scorer stack (lance-format#8092, lance-format#8093, lance-format#8094, lance-format#8131) added `compound.rs`,
a single-pass `ComposableScorer` that runs a whole compound tree against one
column's index with `Match`/`Phrase` leaves scored by a `MemBM25Scorer`. It
matches `FtsQuery` exhaustively, so the `CombinedFields` variant has to be
accounted for in multiple places.

BM25F blends `tf'`, `dl'` and `docFreq'` across columns before scoring, so it
cannot be a leaf that draws its postings from a single index; making it one
needs a multi-index leaf protocol and block-max bounds out of the MAXSCORE
scan. Gate it out instead, leaving those trees on the union/sort plan
`plan_combined_fields_query` already builds:

- `supports_compound_scorer` rejects any tree containing a `CombinedFields`
  node, at the top level or nested.
- The two `compound.rs` entry points return `Error::not_supported` rather than
  `unreachable!()`, so a future planner change fails loudly instead of
  silently misscoring.
- `collect_all_fts_columns` reports the real target columns, `contains_phrase_query`
  is false (BM25F needs no positions), `validate_fts_query_contract` has nothing
  to add (the weights are private and every constructor, `Deserialize` included,
  goes through `try_with_boosts`), and `count_fts_leaves` counts the per-column
  posting scans its partition estimate is approximating.

`test_nested_combined_fields_limit_propagation` covers the gate: it nests a
combined_fields node under MUST, SHOULD and BoostQuery, so a leak surfaces the
`not_supported` error.

Also apply lance-format#8102 to `plan_combined_fields_query`, which still deep-copied the
fragment descriptor list on every plan.
Borrow the slice like `plan_match_query` now does and materialize only the
uncovered subset the flat plan takes ownership of.
sbrunk added a commit to sbrunk/lance that referenced this pull request Aug 16, 2026
The composable scorer stack (lance-format#8092, lance-format#8093, lance-format#8094, lance-format#8131) added `compound.rs`,
a single-pass `ComposableScorer` that runs a whole compound tree against one
column's index with `Match`/`Phrase` leaves scored by a `MemBM25Scorer`. It
matches `FtsQuery` exhaustively, so the `CombinedFields` variant has to be
accounted for in multiple places.

BM25F blends `tf'`, `dl'` and `docFreq'` across columns before scoring, so it
cannot be a leaf that draws its postings from a single index; making it one
needs a multi-index leaf protocol and block-max bounds out of the MAXSCORE
scan. Gate it out instead, leaving those trees on the union/sort plan
`plan_combined_fields_query` already builds:

- `supports_compound_scorer` rejects any tree containing a `CombinedFields`
  node, at the top level or nested.
- The two `compound.rs` entry points return `Error::not_supported` rather than
  `unreachable!()`, so a future planner change fails loudly instead of
  silently misscoring.
- `collect_all_fts_columns` reports the real target columns, `contains_phrase_query`
  is false (BM25F needs no positions), `validate_fts_query_contract` has nothing
  to add (the weights are private and every constructor, `Deserialize` included,
  goes through `try_with_boosts`), and `count_fts_leaves` counts the per-column
  posting scans its partition estimate is approximating.

`test_nested_combined_fields_limit_propagation` covers the gate: it nests a
combined_fields node under MUST, SHOULD and BoostQuery, so a leak surfaces the
`not_supported` error.

Also apply lance-format#8102 to `plan_combined_fields_query`, which still deep-copied the
fragment descriptor list on every plan.
Borrow the slice like `plan_match_query` now does and materialize only the
uncovered subset the flat plan takes ownership of.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-index Vector index, linalg, tokenizer enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants