Skip to content

feat(mem_wal): make memtable index kinds pluggable - #9803

Merged
hamersaw merged 1 commit into
lance-format:mainfrom
xuanyu-z:memwal-index-plugins
Oct 9, 2026
Merged

hamersaw merged 1 commit into
lance-format:mainfrom
xuanyu-z:memwal-index-plugins

Conversation

@xuanyu-z

@xuanyu-z xuanyu-z commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Why

The memtable maintains exactly three index kinds, and which three is written into the code: an enum of kinds, a config enum paired with it, a per-kind arm in validation, one collection per kind in the store, and two flush loops split by whether a kind trains from a value stream. Adding a kind means touching all of them, and a caller cannot add one at all.

What changes

A kind is a plugin. MemIndexPlugin declares which base-table index it maintains and builds instances; MemIndex is one instance: take rows, answer what it recognises, report its memory, hand the flush what it can save it. The B-tree, HNSW and inverted indexes become three implementations. A MemIndexSpec describes one maintained index (plugin, columns, field ids, resolved settings) and replaces MemIndexConfig and its per-kind structs.

Writers carry a registry. ShardWriterConfig::mem_index_registry (or with_mem_index_registry, with_mem_index_plugin) holds the plugins a writer can maintain; the default is the three built-ins. A type url reaches the plugin whose details message is exactly its own message name. Two specs name the same index only when their plugins are the same Rust type at the same version, so a plugin keeps whatever else decides how it builds in the params it resolves. Under maintain_all_indexes an index no registered plugin claims, or whose columns do not resolve, is skipped with a warning; a named set is validated against the plugins the writer will open with (validate_maintained_indexes_with, update_mem_wal_maintained_indexes_with, InitializeMemWalBuilder::mem_index_registry). A maintained index's columns resolve by field id to their full path, so an index on a nested field is never bound to a top-level field of the same name.

The contract callers rely on. An index is asked, while planning, the query it will be searched with (can_answer); only finding which full-text granularities exist asks a probe. Declining at search time a query it accepted while planning is an error, and so is a failed search; neither becomes an empty answer. A filter may answer with candidates (MemSearchResult::at_most), which the memtable re-checks against the filter before returning them. A row past the readable count is dropped from any answer, since its append may still fail. An index receives every batch of one write in one call (insert_batches), so HNSW inserts them as one graph range.

Lookups go by capability, not type. A query finds its index with IndexStore::index_answering(column, query), first by index name. The primary-key index is a capability an index opts into (MemIndex::as_primary_key). A user index on exactly the key column is shared and remembered by its name, so a plugin may hand out a new capability object on every call; otherwise the memtable keeps its own B-tree outside the named indexes, where no user index name can collide with it, and a filter on the key column still uses it. Rewrite tracking, which decides whether a vector or full-text search may trust its own top-k, runs whenever a primary key exists.

The flush is one loop, one index at a time. Each index writes nothing, asks to be built from the written generation, hands back training rows, or writes its own file (FlushOutcome). As before, the vector and full-text kinds write nothing when they hold no rows, so an empty list-element full-text index is not rebuilt as a whole-row one; a B-tree with no keys is built from the generation's rows. The flush builds only scalar types itself; a vector or full-text plugin asking it to is refused by name. A scalar build takes rows in the shape the plugin declares, through CreateIndexBuilder::preprocessed_stream.

Nulls stay out of B-tree answers. A range walks the backend from its lower bound and never returns null keys, and a filter comparing with null (x IN (1, NULL)) matches no null row. #9796 fixed the range case in the code this replaces; its test passes here.

Behaviour changes

Each was compared with main by running one seeded workload of writes, seals, flushes and reopens against both builds and comparing every read; these are the only differences.

  • A memtable filter x IN (1, NULL) answered by the B-tree no longer returns rows where x is null; main returned them, while SQL and a base-table scan return none.
  • Rewrite tracking (does a write replace a key the memtable holds?) runs on every table with a primary key, since any plugin may cut a search to its own top results; main ran it only beside a vector or full-text index. Results are unchanged, and the cost does not show: 200 puts of 1,000 new keys each into a table with only a B-tree index took 26–27 ms on this branch and 27–30 ms on main (release build, median of 5, 3 runs each).
  • Under maintain_all_indexes, an index whose field is not in the schema is skipped with a warning; main failed the writer open. An index on a nested field is never bound to a top-level field of the same name.
  • Two different indexes under one name are refused; main kept the last one silently. One index listed twice is still one index, as before.

How a caller plugs in an index kind

A caller, such as LanceDB, implements two traits and hands the plugin to the writer; everything else goes through them.

flowchart LR
    subgraph caller["Caller"]
        plugin["impl MemIndexPlugin<br/>name · details_message · version<br/>resolve · validate · create<br/>flush_index_type · training_criteria"]
        index["impl MemIndex<br/>columns · can_answer · search<br/>insert / insert_batches<br/>resident_bytes · flush<br/>as_primary_key (optional)"]
        plugin -- "create()" --> index
    end
    registry["MemIndexRegistry::default()<br/>.with_plugin(plugin)"]
    plugin --> registry
    registry --> config["ShardWriterConfig<br/>.with_mem_index_registry(..)"]
    registry --> check["validate_maintained_indexes_with<br/>update_mem_wal_maintained_indexes_with<br/>InitializeMemWalBuilder::mem_index_registry"]
    config --> writer["Dataset::mem_wal_writer"]
    base[("base-table index<br/>details type url")] -. "claimed by details_message" .-> registry
Loading
sequenceDiagram
    participant W as ShardWriter
    participant P as MemIndexPlugin
    participant S as IndexStore (one per memtable)
    participant I as MemIndex
    participant F as Flush
    Note over W,P: open
    W->>P: resolve(base index) → MemIndexSpec (columns, field ids, params)
    W->>P: validate(spec)
    Note over W,I: each new memtable
    W->>P: create(spec, capacity)
    P-->>S: MemIndex (on exactly the key column, as_primary_key() may share it as the key index)
    Note over W,I: write
    W->>S: insert_batches(one write)
    S->>I: insert_batches(every batch of the write, in one call)
    Note over W,I: read: filter, vector or full-text search
    W->>S: index_answering(column, the query to run)
    S->>I: can_answer(query)
    S->>I: search(query, max_visible)
    I-->>S: Filter{at_least, at_most} or Ranked, best first
    Note over S: candidates (at_most) are re-checked against the filter.<br/>Declining or failing a query it accepted is an error.
    Note over W,I: key lookups and dedup use PrimaryKeyIndex::newest_visible
    Note over W,F: flush, once the memtable is sealed
    F->>I: flush(generation)
    I-->>F: Skip, BuildFromGeneration, TrainingData(rows) or Wrote(metadata)
    F->>F: build the scalar index or record the written one in the generation
Loading

Breaking changes

  • Removed: MemIndexKind, MemIndexConfig, BTreeIndexConfig, HnswIndexConfig, FtsIndexConfig, validate_index_configs, IndexStore::from_configs. Replacements: MemIndexSpec (with btree, hnsw, fts constructors), validate_index_specs, IndexStore::from_specs.
  • ShardWriterConfig gains a public mem_index_registry field; ..Default::default() fills it with the built-ins.
  • ShardWriter::open, ShardWriter::replace_index_configs and ShardWriter::evolve_schema take Vec<MemIndexSpec>.
  • IndexStore::insert_batches returns Result<()>; IndexStore::from_specs and validate_index_specs refuse two different specs under one name.
  • MemIndexPlugin requires Any; PrimaryKeyIndex no longer requires MemIndex. IndexStore's type-keyed lookups (get_btree, get_hnsw_by_column, get_fts_by_column and the like) are removed; index_answering and fts_granularities_on answer the same questions.

Not in this PR

  • Splitting index/fts.rs (7,800 lines) into smaller files: existing code, a follow-up of its own.
  • A {name, field id} column type in place of parallel lists, and fully qualified details names in the registry: shape changes better made with their next users.

Testing

  • A test plugin wraps a built-in under another type with the same name and deviates one way at a time (declines the real search or only the probe, accepts then declines or fails, answers with candidates or with a row past the readable count, hands out a fresh key capability, cannot be a key index, asks the flush to build it, fails or misnames its flush, panics on insert). One table runs the filter, vector, full-text and cross-column full-text searches against each deviation through the real scan; the rest run through the real flush, store or writer.
  • A user index named __pk__id on another column, beside a primary key id, returns what the filter matches through fresh reads, an overwrite, a delete, a flush and a reopen.
  • Writer and API: one index named twice is maintained once and two different ones under one name are refused; an index resolved to another column takes its field id, or is skipped or refused when the column is missing; a B-tree on a nested field is skipped under maintain_all_indexes.
  • Flush: an empty list-element full-text index writes nothing; a full-text index with word positions answers a phrase query once flushed.
  • Compared with main: one seeded workload (puts with overwrites and nulls, deletes, seals, flushes, crash-and-reopen and close-and-reopen; single and composite keys) ran against both builds, reading after every step through filtered and projected scans with limits and offsets, vector search, every full-text query kind, key lookups, contains_pks, the routing of each memtable query, and the indexes of each flushed generation. Over 200 seeds the only difference is the IN (..., NULL) fix above; a run of main against itself shows the same run-to-run variation in approximate vector results and ties at a full-text limit.
  • Every test of a fix was checked to fail with the fix reverted.
  • cargo nextest run -p lance passes (5,152 tests); cargo doc -p lance with -D warnings and cargo fmt --all -- --check are clean; cargo clippy -p lance --all-targets -- -D warnings reports only clippy::chunks_exact_to_as_chunks in index/vector/ivf.rs, which main also fails.

@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 the K-changes Latest Gatekeeper recommendation requests changes. label Oct 8, 2026
@xuanyu-z
xuanyu-z force-pushed the memwal-index-plugins branch from e648867 to 8439f1d Compare October 9, 2026 00:21
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 9, 2026
@xuanyu-z
xuanyu-z force-pushed the memwal-index-plugins branch from 8439f1d to 38529ac Compare October 9, 2026 00:27
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
@xuanyu-z
xuanyu-z force-pushed the memwal-index-plugins branch from 38529ac to b8dee68 Compare October 9, 2026 04:13
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
@xuanyu-z
xuanyu-z force-pushed the memwal-index-plugins branch from b8dee68 to 1f280ef Compare October 9, 2026 05:08
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
@xuanyu-z
xuanyu-z force-pushed the memwal-index-plugins branch from 1f280ef to 7b8d6f3 Compare October 9, 2026 06:06
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
@xuanyu-z
xuanyu-z force-pushed the memwal-index-plugins branch from 7b8d6f3 to 4a730f2 Compare October 9, 2026 06:19
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 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.

This revision changes only comment wording. The previously verified implementation and all five fixes remain intact.

Please mark this PR with the breaking-change label.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026

@jackye1995 jackye1995 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.

🚀

@xuanyu-z
xuanyu-z force-pushed the memwal-index-plugins branch from 4a730f2 to 2da8fb8 Compare October 9, 2026 08:21
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
The memtable maintained three index kinds, and which three was written
into the code: an enum of kinds, a config enum pairing with it, a
per-kind arm in validation, one collection per kind in the store, and two
flush loops split by whether a kind trains from a value stream. Adding a
kind meant touching all of them, and a deployment could not add one at
all.

A kind is now a plugin. `MemIndexPlugin` declares which base-table index
it maintains and builds instances; `MemIndex` is one instance: take rows,
answer what you recognise, report your memory, hand the flush what you
can save it. The B-tree, HNSW and inverted indexes are three
implementations of it, and a `MemIndexRegistry` on the writer config
carries the set a writer uses -- the built-ins by default, plus or instead
of anything a caller registers.

Everything resolves by capability rather than by type. A query finds its
index by asking each index on the column whether it can answer, so a
replacement plugin is found exactly as the built-in it replaces. The flush
is one loop over the indexes, each returning training rows, a file it
wrote, or nothing. The primary-key index is a capability an index opts
into; rewrite tracking runs whenever a primary key exists, full-text
granularity is discovered by asking the indexes, and point lookups go
through the primary key whatever maintains it. The type-keyed accessors
left on the store exist for tests only.

Maintained sets resolve through the registry too. Under
`maintain_all_indexes` an index no plugin claims is skipped with a
warning; a named set is validated against the plugins the writer will
open with, which `validate_maintained_indexes_with`,
`update_mem_wal_maintained_indexes_with` and the builder's
`mem_index_registry` accept. A refreshed set is compared with the one in
force through `MemIndexParams`, which every `PartialEq` settings type gets
for free, so a writer tells a changed index from an unchanged one without
knowing any plugin's settings.
@xuanyu-z
xuanyu-z force-pushed the memwal-index-plugins branch from 2da8fb8 to 4ccb69b Compare October 9, 2026 16:12
@hamersaw
hamersaw merged commit 352d509 into lance-format:main Oct 9, 2026
westonpace added a commit that referenced this pull request Oct 9, 2026
…vening changes

Rebasing this branch onto the 78 commits main gained in the meantime
surfaced test and fixture code that assumed BTree still trains from
row ids -- true when that code was written on main, but no longer
true once this branch's migration lands on top of it. None of these
were textual merge conflicts; they only showed up as test failures.

- `BTreeMemIndexPlugin::training_criteria()` (added by #9803's
  pluggable-mem-wal-index refactor) declared `.with_row_id()`, but
  `to_training_batches()` already emits `_rowaddr`. The new
  declared-vs-actual validation `build_scalar_index` gained (also from
  #9803) now catches that mismatch. Same root cause, two test
  fixtures: `index::create::tests::test_range_based_btree_index_create`
  and `index::frag_reuse_reader::tests::fixture_with_index` fed
  BTree a row-id-declared stream via the generic `preprocessed_data()`
  helper despite already scanning row addresses; both now call
  `preprocessed_stream` with the correct criteria directly.

- `test_row_id_index_creation_racing_defer_index_remap` (added by
  #9514, which allows FRI with stable row ids) exercised a row-id-domain
  BTree index racing a concurrently-committed FRI -- exactly the danger
  this migration exists to close. BTree can no longer illustrate that
  race on a stable-row-id dataset, so the test now uses Bitmap, which
  still stores row ids directly on this branch.

- `test_merge_insert_key_only_concurrent_write`'s compaction case
  updated its expectations: compaction physically rewrites a fragment,
  and an address-domain index can no longer cover the result (the same
  invariant `test_addr_domain_index_does_not_cover_rewritten_update_fragment`
  already covers for ZoneMap/BloomFilter/FM). The in-place patch that
  used to write zero files now correctly falls back to a real rewrite
  to keep the "id" BTree index's coverage consistent, which the test
  now asserts instead of the stale zero-file expectation.

Verified with a side-by-side worktree on plain origin/main: every test
touched here passes there unmodified, confirming the failures were
purely this rebase's interaction with main's intervening work, not
pre-existing breakage.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
jackye1995 pushed a commit that referenced this pull request Oct 10, 2026
… pass (#9804)

## Why

The memtable has its own predicate vocabulary and a hand-written match
over `Expr` that recognises `=`, `<`, `>=` and `IN` on one column. Any
other filter reads every memtable row, so `<=`, `>`, `IS NULL`, `LIKE
'prefix%'` and `AND` across two indexed columns never use an index.

## How a filter reaches an index

```mermaid
flowchart TB
    subgraph before["Before: a match written for the memtable"]
        f1["filter Expr"] --> m1{"one column, compared by<br/>equals, less than, at least,<br/>IN, or an OR of equals?"}
        m1 -- yes --> b1["that column's B-tree<br/>(BTreeIndexExec)"]
        m1 -- no --> s1["read every memtable row<br/>and apply the filter"]
    end
    subgraph after["After: the pass the base table's scan uses"]
        f2["filter Expr"] --> p2["apply_scalar_indices<br/>with each index's ScalarQueryParser<br/>(MemIndexPlugin::query_parser)"]
        p2 --> t2["tree of index searches<br/>AND / OR across indexes<br/>+ leftover expression"]
        t2 --> e2["ScalarMemIndexExec: evaluate the tree,<br/>clamp to visible rows"]
        e2 --> r2{"answered exactly?"}
        r2 -- yes --> o2["rows"]
        r2 -- no --> c2["re-check the whole filter<br/>on the narrowed rows"] --> o2
        p2 -- "nothing claimed, or NOT" --> s2["read every memtable row<br/>and apply the filter"]
        e2 -- "an index over its match budget declines" --> s2
    end
```

A memtable index then claims exactly the expressions its on-disk
counterpart claims, and a single-column plugin kind is reachable from a
filter by giving its parser, with no change to the memtable's planner.

## What changes

**Filters go through `apply_scalar_indices`**, the pass the base table's
scan uses, with a provider built from the memtable's indexes. A plugin
supplies the query parser its on-disk counterpart uses
(`MemIndexPlugin::query_parser`), so both claim the same expressions.
The result is a tree of per-index queries and a leftover expression. The
tree goes through `ScalarIndexExpr::optimize`, as on the base table, so
bounds on one column split by another conjunct are searched as one
range. `ScalarMemIndexExec` evaluates the tree and applies the whole
filter to the rows it narrowed to unless the indexes answered all of it
exactly. `ScalarPredicate` and `BTreeIndexExec` are removed. A list
column compared with a list literal is cast because of nested field ids;
the split looks through a cast that changes no value.

**A broad answer is not listed.** Only a batch's candidate rows are
read, and the filter is re-checked on those rows alone. The scan offers
an index a match budget (`SearchContext::match_budget`: a sixteenth of
the visible rows, never under 4,096); an index that would list more may
decline, and every visible row is read with the filter. The built-in
B-tree honours it. A failed search is an error, not a read of every row.
On 100,000 rows with B-trees on an integer and a string column (`main`
reads every row for the shapes marked *):

| Filter | Read every row | `main` | This PR |
|---|---|---|---|
| `id = 54321` | 134 µs | 60 µs | 58 µs |
| `id >= 10000 AND id < 11000` (1%) | 135 µs | 139 µs* | 73 µs |
| `id >= 10000 AND id < 20000` (10%) | 137 µs | 140 µs* | 122 µs |
| `id >= 0 AND id < 50000` (50%) | 146 µs | 152 µs* | 137 µs |
| `id >= 0` (every row) | 129 µs | 4,892 µs | 131 µs |
| `name LIKE 'k05%'` (10%) | 265 µs | 269 µs* | 209 µs |

**The memtable's own key index answers filters too.** With no maintained
index on a single-column key, the B-tree the memtable keeps for its key
is in the catalog, under a name no base-table index can carry, so `id =
4`, `id IN (...)` and key ranges still use an index, as before.

**B-tree ranges honour each bound.** An inclusive upper bound adds its
key's rows and an exclusive lower bound removes them, the latter by a
binary search over that key's sorted rows; a range whose bounds cross
matches nothing.

## Breaking changes

- `ScalarPredicate` and `BTreeIndexExec` are removed;
`ScalarMemIndexExec` answers a filter from any filter index.
- `SearchContext` gains a public `match_budget` field;
`SearchContext::new` leaves it unset.
- `MemIndexSpec` gains a public `index_details` field (the base-table
index's details message), so building one with a struct literal must set
it.

## Known limitations

- `NOT` is not evaluated from indexes: complementing a result needs each
index's null rows, which indexes do not report yet. A filter with a
`NOT`-shaped part (`<>`, `NOT IN`, `IS NOT NULL`) reads every row.

## Testing

- Compared with \`main\`: one seeded workload (puts with overwrites and
nulls, deletes, seals, flushes, crash-and-reopen and close-and-reopen;
single and composite keys) ran against both builds, reading after every
step through filtered and projected scans with limits and offsets,
vector and full-text search, key lookups, and filters on the memtable
alone. Over 200 seeds every result matches except \`x IN (1, NULL)\`,
where \`main\` returned null rows (fixed by #9803). Routing changed as
intended: \`>\`, \`<=\`, \`IS NULL\` and \`AND\` across indexed columns
now use an index where \`main\` read every row.
- A key filter with no maintained index on the key column uses the
memtable's own key index, and that index answers it exactly.
- A differential test runs 65 filters over integers, floats, strings,
booleans and dates holding nulls, NaN, both zeros, the infinities, the
integer extremes, and empty and non-ASCII text, with indexes on all or
some of the columns, and once with an index that declines every filter
inside `AND` and `OR`, and requires the index route to return exactly
the rows a full read returns; with every column indexed, a filter on
each type is checked to take the index route.
- Planning: every shape the on-disk B-tree parser claims reaches the
memtable index; an index over several columns answers no filter;
positions an index offers past the visible rows are cut; `AND`/`OR`
across two indexes compose; an unindexed conjunct comes back as the
leftover; `NOT` is scanned; a list comparison is claimed through the
cast.
- A filter index that declines leaves the rows to the filter, which
returns the filter's rows; on the index route the filter is applied
before projection, so a leftover on a dropped column still holds, and
row addresses are kept; one whose search fails makes the scan fail.
- Each B-tree backend declines a search past its budget and answers one
within it, `IS NULL` included; split bounds on one column are merged so
neither declines alone; a search with no filter to fall back on is never
declined; exclusive and inverted ranges on each backend, over a key held
by thousands of rows; a declined answer reads exactly the filter's rows
and row ids; candidates that fill a batch and candidates that are a few
of its rows are both re-checked and keep their own row ids.
- `cargo nextest run -p lance` passes (5,337 tests); `cargo clippy -p
lance --tests --benches -- -D warnings`, `cargo doc -p lance --no-deps`
with `-D warnings` and `cargo fmt --all -- --check` are clean.

---------

Co-authored-by: XYZhan <[email protected]>
xuanyu-z added a commit to lancedb/lancedb that referenced this pull request Oct 12, 2026
## Why

lance-format/lance#9803 makes the MemWAL's memtable index kinds
pluggable: a `MemIndexRegistry` on the writer config decides which
base-table index kinds are maintained in memory, so a kind Lance does
not build in can be added by registering a plugin. LanceDB opens the
MemWAL writer itself for `merge_insert`, and checks a named maintained
set itself, both against Lance's built-ins only. So a kind registered
outside Lance could not be named in
`LsmWriteSpec::with_maintained_indexes`, and under "maintain every
index" it was skipped.

## What changes

- `NativeTable::set_mem_index_registry(registry)` sets the memtable
index kinds a table maintains. The default is Lance's built-ins, so
nothing changes unless a caller sets one. The registry checks a named
maintained set (`validate_maintained_indexes_with`), is recorded on
`initialize_mem_wal`, and goes on the writer config `merge_insert`
opens. `lancedb::table` re-exports `MemIndexRegistry` and Lance's plugin
traits (`mem_index`), so a caller needs no direct `lance` dependency.
- The LSM vector read no longer checks resident memtables at all, and
the `carries_vector_index` helper goes with it. Lance already compares
every row of a memtable whose index can't answer the search, so no rows
are missed. It still requires the base vector index to be maintained.

## Limits

- The registry belongs to the table handle. Clones of a handle and its
branch handles share it; a handle opened separately starts from the
built-ins. Set it before the handle's first LSM write: a writer already
open keeps the kinds it opened with.
- The maintained set is stored with the table but the registry is not.
Once a spec names an index only a registered plugin maintains, an LSM
write from a handle without that registry is refused with Lance's "no
registered plugin maintains" error rather than skipping the index. That
includes the Python and Node bindings, which have no way to set a
registry yet.
- Rust only. A registry holds Rust plugin objects, which the Python,
TypeScript and Java bindings cannot construct, so they get no setter;
their documented behaviour (built-in kinds only) is unchanged.
- Per-index plugin settings (`ShardWriterConfig::index_overrides`, from
lance-format/lance#9805) are not exposed; writers use each plugin's
defaults.

## Open decision

Whether the registry should also be settable on the connection, so every
table a connection opens carries it. This PR keeps it per table; a
connection-level option would sit on top of `set_mem_index_registry`
without changing it.

## Depends on

Lance v14.0.0-beta.13, which `main` already uses. It includes
lance-format/lance#9803 and #9805 (pluggable memtable index kinds) and
#9857 (flushed generations keep the table's field ids).

## Testing

- `lsm_maintains_an_index_kind_from_the_tables_registry`: a stand-in
plugin maintains the base table's bitmap index as a B-tree. Naming the
index is refused without the registry and accepted with it; a separately
opened handle without the registry is refused an LSM write. Rows written
through `merge_insert` are found by id before and after the flush. Each
generation the shard manifests publish carries a bitmap index on
`region`, and a filter on it is answered through that index.
- `lsm_default_set_maintains_a_registry_kind_created_while_writing`:
under "maintain every index", a bitmap index created after the writer
opened is picked up by that writer and flushed. A clone of the table
handle shares the registry.
- `lsm_vector_search_compares_every_row_when_no_resident_index_answers`:
with a vector plugin that answers no search, LSM vector search still
returns the right rows, including a second page.
- `cargo test -p lancedb --features remote --lib` passes; `cargo clippy
-p lancedb --features remote --tests -- -D warnings` and `cargo fmt
--all -- --check` are clean.

---------

Co-authored-by: XYZhan <[email protected]>
westonpace added a commit that referenced this pull request Oct 14, 2026
…vening changes

Rebasing this branch onto the 78 commits main gained in the meantime
surfaced test and fixture code that assumed BTree still trains from
row ids -- true when that code was written on main, but no longer
true once this branch's migration lands on top of it. None of these
were textual merge conflicts; they only showed up as test failures.

- `BTreeMemIndexPlugin::training_criteria()` (added by #9803's
  pluggable-mem-wal-index refactor) declared `.with_row_id()`, but
  `to_training_batches()` already emits `_rowaddr`. The new
  declared-vs-actual validation `build_scalar_index` gained (also from
  #9803) now catches that mismatch. Same root cause, two test
  fixtures: `index::create::tests::test_range_based_btree_index_create`
  and `index::frag_reuse_reader::tests::fixture_with_index` fed
  BTree a row-id-declared stream via the generic `preprocessed_data()`
  helper despite already scanning row addresses; both now call
  `preprocessed_stream` with the correct criteria directly.

- `test_row_id_index_creation_racing_defer_index_remap` (added by
  #9514, which allows FRI with stable row ids) exercised a row-id-domain
  BTree index racing a concurrently-committed FRI -- exactly the danger
  this migration exists to close. BTree can no longer illustrate that
  race on a stable-row-id dataset, so the test now uses Bitmap, which
  still stores row ids directly on this branch.

- `test_merge_insert_key_only_concurrent_write`'s compaction case
  updated its expectations: compaction physically rewrites a fragment,
  and an address-domain index can no longer cover the result (the same
  invariant `test_addr_domain_index_does_not_cover_rewritten_update_fragment`
  already covers for ZoneMap/BloomFilter/FM). The in-place patch that
  used to write zero files now correctly falls back to a real rewrite
  to keep the "id" BTree index's coverage consistent, which the test
  now asserts instead of the stale zero-file expectation.

Verified with a side-by-side worktree on plain origin/main: every test
touched here passes there unmodified, confirming the failures were
purely this rebase's interaction with main's intervening work, not
pre-existing breakage.

Co-Authored-By: Claude Sonnet 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants