Repository navigation
feat: infer maintained indexes when an LsmWriteSpec omits them - #3748
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
`LsmWriteSpec::maintained_indexes` becomes `Option<Vec<String>>`. `None` — now the default for a freshly constructed spec — maintains every index the MemWAL supports, resolved when the spec is installed. `Some([])` maintains none, and an explicit list is still taken verbatim. Resolution filters on `IndexConfig::is_memwal_maintainable`, which delegates to lance's `is_maintainable_index_type`. Sweeping up an index the memtable cannot build (a bitmap, say) would fail every memtable claim and leave the table unwritable, so the inferred set excludes them and an explicit list naming one is now rejected up front rather than at claim time. The resolved set is a snapshot, not a subscription: an index created after the spec is installed is not maintained until the spec is unset and set again. That is why the default flipped from "maintain nothing" — an unwanted maintained index costs memory, while a silently unmaintained one degrades FTS to an unscored scan. Note this needs a lance release carrying `is_maintainable_index_type` before it builds against the pinned tag. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Three cleanups to the LsmWriteSpec surface, all removing something: `with_no_maintained_indexes` is gone. `with_maintained_indexes` now takes `impl Into<Option<Vec<String>>>`, so `None` asks for every supported index, a list pins an exact set, and an empty list maintains none — one method covering what two did, and the argument reads the same as the field it sets. `IndexConfig::is_memwal_maintainable` is gone. What a memtable can build is lance's to say, and lance already says it via `is_maintainable_index_type`; mirroring that onto a lancedb type only added a place for the two to drift. `resolve_maintained_indexes` is now public and takes `&[IndexConfig]` rather than a table. It was already the whole of the resolution rules — infer from the committed set, or validate a named one — and a server installing specs on a caller's behalf needs exactly those rules. Sharing it means sophon no longer keeps a second copy that could disagree about what an absent list means, and the error now names the table's indexes so a rejected call says what was actually available. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Same content, fewer words. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
b1dafda to
225b8ee
Compare
|
@claude review once |
There was a problem hiding this comment.
Not approving — one of the inline findings is a real compile-time bug (two .with_maintained_indexes([..]) call sites in rust/lancedb/src/table/merge.rs were not updated for the new signature and won't compile), so cargo test --features remote --tests is broken as-is.
Extended reasoning...
Overview
This PR reworks LsmWriteSpec::maintained_indexes from a plain Vec<String> to Option<Vec<String>>, changing the default from "maintain nothing" to "infer every maintainable index at install time." It touches the Rust core (rust/lancedb/src/table.rs, rust/lancedb/src/table/merge/lsm.rs, rust/lancedb/src/remote/table.rs) plus the Python and Node.js bindings and their tests, keeping the wire/remote and both bindings in sync with the new semantics.
Security risks
None. This is an internal index-maintenance-configuration feature; no new user input surfaces are added, and the resolution logic only reads index metadata that's already accessible via list_indices.
Level of scrutiny
This warrants a normal-to-high level of scrutiny: it's a behavior-changing default (not just additive) on a cross-language public API, and it changes a widely-used helper's signature (with_maintained_indexes). I verified one of the two reported inline findings directly by grepping rust/lancedb/src/table/merge.rs: it still contains .with_maintained_indexes([fts_index]) and .with_maintained_indexes([vec_index]) at lines 1095 and 1188, both passing a [String; 1] array literal to a parameter now typed impl Into<Option<Vec<String>>>. That conversion isn't satisfied (no direct From<[String;1]> for Option<Vec<String>>, and Rust doesn't chain two Into conversions), so these are genuine compile failures in the crate's own test suite — this file is not among the PR's changed files, so it was simply missed when every other call site was updated to vec[...].
Other factors
Because a reported bug is a real, verifiable compilation break (not a nit), this PR is not safe to land until fixed, and I'm deferring rather than approving. The second inline nit (stale getter doc comments describing the old mirror-the-setter behavior) is minor and non-blocking on its own, but doesn't change the overall verdict here.
There was a problem hiding this comment.
❌ Gate recommendation: request changes.
The install-time tri-state design addresses the real configuration hazard. Keep that contract, but complete the integration so the repository type-checks and every published/readback API describes the resolved effective list rather than claiming an exact input round-trip.
Please mark this PR with the breaking-change label.
Two review findings on #3748. `with_maintained_indexes` now takes `impl Into<Option<Vec<String>>>`, but two test call sites in `table/merge.rs` still passed `[String; 1]` array literals. `Into` does not chain, so `[String; 1]` has no path to `Option<Vec<String>>` and the crate's test build failed to compile. Both now pass `vec![..]`, matching every other call site. The `get_lsm_write_spec` docs in all three bindings claimed the returned spec mirrors the setter input. Inference made that false: an omitted maintained set resolves to a concrete list at install time, so `None` never round-trips. Reworded in Rust, Python, and TypeScript, and applied by hand to the checked-in typedoc output, which had picked up none of this branch's TS doc changes — `pnpm run docs` needs a native build that the current lance pin cannot produce. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
❌ Gate recommendation: request changes.
The install-time tri-state remains the right contract, and this revision fixes the prior call-site and documentation issues. The implementation must still compile against the repository-pinned dependencies before it can land.
Keep the tri-state design, but either update the Lance pin and lockfile to a release that supplies the maintainability predicate or implement the filtering against the currently pinned API.
There was a problem hiding this comment.
❌ Gate recommendation: request changes.
The Lance update restores compilation, and the cross-language tri-state contract remains worthwhile. The current capability check can still commit an inferred maintained set that the MemWAL writer cannot open.
Resolve and validate each selected index against the full schema-aware writer contract before committing the spec; sharing that validation with shard-writer initialization keeps inference and explicit selection from drifting.
Inferring the maintained set filtered on Lance's `is_maintainable_index_type`, which reads only an index's protobuf type url. That is not enough to decide: every vector sub-type maps to the memtable's HNSW, which needs a `FixedSizeList<Float32>` column. An IVF-PQ index over `FixedSizeList<Float64>` was therefore inferred into the maintained set, committed, and then failed every shard-writer open — leaving the table unwritable through the LSM path. Delegate to Lance's `validate_maintained_indexes`, which resolves each index against the dataset schema and applies the rules its shard writer applies, so a spec that installs is one the MemWAL can open. Both the inferred and the explicit selection go through it, and the type-url filtering here is gone. Inference is now all-or-nothing: an index the MemWAL cannot maintain fails `set_lsm_write_spec` instead of being dropped from the set. Dropping it silently left the caller believing an index was maintained that the writer never touched. The error names the offending index and says to set `maintained_indexes` explicitly to install anyway. `resolve_maintained_indexes` is no longer public: it needs a `lance::Dataset` now, and a server sharing these rules should call Lance's function directly. Requires lance-format/lance#8360. BREAKING CHANGE: `set_lsm_write_spec` with an inferred maintained set now fails on a table carrying an index the MemWAL cannot maintain (bitmap, labelList, FM, or a vector index on an incompatible column) instead of silently maintaining a subset. Pass `maintained_indexes` explicitly to choose the set. `lancedb::table::resolve_maintained_indexes` is no longer exported. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The maintained-index validation this branch calls does not exist in v11.0.0-beta.2, so the workspace does not build against the released pin. Point the lance deps at the head of lance-format/lance#8360 to get CI compiling and produce test signal on the behavior change. The rev is reachable as refs/pull/8360/head on the public upstream repo, so cargo resolves it without a fork — the git URL stays lance-format/lance. This pin is temporary and must move to a release tag before merge; the manifest says so above the dependency block. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
❌ Gate recommendation: request changes.
The tri-state API is worthwhile, but this revision no longer provides its useful default and does not keep the resolved set stable through commit. Omitted input should snapshot every compatible index, while explicit lists stay all-or-nothing.
Put automatic resolution, schema-aware validation, and installation behind one authoritative Lance transaction shared by local and remote paths, and consume it from a released Lance revision.
| requested: Option<&[String]>, | ||
| ) -> Result<Vec<String>> { | ||
| let Some(requested) = requested else { | ||
| let all: Vec<String> = indices.iter().map(|index| index.name.clone()).collect(); |
There was a problem hiding this comment.
None now copies every table index into all and rejects the whole installation when any one is unsupported. A table with a BTree plus a Bitmap therefore has to name the BTree manually—the bookkeeping this change is meant to remove—and this contradicts the stated/public contract that omission means every supported index. Automatic selection should retain only indexes that pass the schema-aware MemWAL validator; explicit nonempty lists should remain all-or-nothing so caller mistakes still fail.
Reproducer
Executed on this head:
CARGO_HOME=/home/agent/tmp/pr3748-schemafix.zU6kVp/cargo-home CARGO_TARGET_DIR=/home/agent/tmp/pr3748-schemafix.zU6kVp/target cargo test --quiet --locked --features remote -p lancedb table::tests::test_set_lsm_write_spec_infers_maintained_indexes --lib -- --exact --nocapture
Observed: 1 passed; the test creates id_btree plus tag_bitmap and asserts that default installation returns InvalidInput naming tag_bitmap, with no spec installed. Expected for the inferred-default contract: installation succeeds with the concrete set ["id_btree"].
| # `validate_maintained_indexes`. The rev is reachable as refs/pull/8360/head on | ||
| # the public upstream repo, so this resolves in CI without a fork. | ||
| # Revert to a release tag once #8360 lands. Do not merge with this pin. | ||
| lance = { "version" = "=11.0.0-beta.2", default-features = false, "rev" = "f0652582625d4e8874e8d381047f57f2746c5a6e", "git" = "https://github.com/lance-format/lance.git" } |
There was a problem hiding this comment.
This pinned validator runs before the CreateIndex commit, so the selected set is not atomic with index state. A concurrent drop of a selected index can commit first and the MemWAL creation can rebase, persisting a missing name; a concurrent create can likewise be omitted from “every index at install.” The former leaves writer opening broken and the latter violates the snapshot contract. This manifest already says not to merge the pin. Use a released Lance revision where automatic resolution and validation rerun against the rebased manifest, or where changes to selected indexes/schema force a retry, then cover concurrent create/drop.
Reproducer
Executed against the exact pinned Lance revision:
CARGO_HOME=/home/agent/tmp/pr3748-schemafix.zU6kVp/cargo-home CARGO_TARGET_DIR=/home/agent/tmp/pr3748-schemafix.zU6kVp/target cargo test -p lance --lib test_create_index_conflicts_only_on_same_name -- --nocapture
Observed: 1 passed; the test asserts that same-name CreateIndex conflicts but a differently named CreateIndex is accepted for rebase. The pinned drop_index path is also a CreateIndex with no new names and the removed index in removed_indices, so it takes this accepted branch. Expected for MemWAL initialization: changes to the names/schema used by the selected set conflict or trigger re-resolution before commit.
`test_lsm_read_fts_unmaintained_index_errors` and its vector counterpart build a spec with `LsmWriteSpec.unsharded()` and comment that it maintains no indexes. That held when the default was "maintain nothing", but this branch made the default resolve to every index on the table, so both tests were maintaining the very index they meant to leave unmaintained and the guard they assert on no longer fired. Say `[]` explicitly, which is what each test means: reading through an index the MemWAL does not maintain must error rather than silently drop un-compacted rows. Both were stale from the first inference commit and only surfaced now that the branch compiles again. Also regenerate `docs/src/js/classes/Table.md` for the `setLsmWriteSpec` doc change, which `npm run docs` had not been run for. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
❌ Gate recommendation: request changes.
This revision fixes stale tests and generated documentation, but both acceptance contracts remain unchanged: omitted input still rejects mixed index sets instead of snapshotting compatible ones, and the selected set is still not stable through commit.
Keep the tri-state API, but put compatible-index resolution, schema-aware validation, and installation behind one authoritative released Lance transaction shared by local and remote paths.
| requested: Option<&[String]>, | ||
| ) -> Result<Vec<String>> { | ||
| let Some(requested) = requested else { | ||
| let all: Vec<String> = indices.iter().map(|index| index.name.clone()).collect(); |
There was a problem hiding this comment.
None copies every table index into all and validates the whole vector, so one incompatible index rejects automatic inference instead of selecting the compatible subset. A table with a BTree plus a Bitmap must name the BTree manually, defeating the bookkeeping-free default this change promises. For omitted input, retain only indexes that pass the schema-aware MemWAL validator; keep explicit nonempty lists all-or-nothing so caller mistakes still fail.
Reproducer
Executed on this head from /home/repo with CARGO_HOME=/home/agent/tmp/delta-verify.B0mCU4/cargo-home, CARGO_TARGET_DIR=/home/agent/tmp/delta-verify.B0mCU4/target, and CARGO_TERM_COLOR=never:
cargo test -p lancedb --lib table::tests::test_set_lsm_write_spec_infers_maintained_indexes --features remote -- --exact
Observed: 1 passed; 815 filtered. The test creates id_btree plus tag_bitmap and asserts that default installation returns InvalidInput with no spec installed. Expected for the inferred-default contract: installation succeeds with the concrete set ["id_btree"].
There was a problem hiding this comment.
I think this is the correct behavior. If a user provides None they expect all indexes to be created. If we are not maintaining all indexes in WAL we should fail with an actionable message and require explicit index configuration so there is no transparent loss.
| # `validate_maintained_indexes`. The rev is reachable as refs/pull/8360/head on | ||
| # the public upstream repo, so this resolves in CI without a fork. | ||
| # Revert to a release tag once #8360 lands. Do not merge with this pin. | ||
| lance = { "version" = "=11.0.0-beta.2", default-features = false, "rev" = "f0652582625d4e8874e8d381047f57f2746c5a6e", "git" = "https://github.com/lance-format/lance.git" } |
There was a problem hiding this comment.
This pinned validator runs before the CreateIndex commit, so the selected set is not atomic with index state. A concurrent drop of a selected index can commit first and MemWAL creation can rebase, persisting a missing name; a concurrent create can likewise be omitted from “every compatible index at install.” The former breaks writer opening and the latter breaks the snapshot contract. Use a released Lance revision where automatic resolution and validation rerun against the rebased manifest, or where changes to selected indexes or schema force a retry, then cover concurrent create and drop.
Reproducer
Executed against the exact pinned Lance revision from /home/repo with CARGO_HOME=/home/agent/tmp/delta-verify.B0mCU4/cargo-home, CARGO_TARGET_DIR=/home/agent/tmp/delta-verify.B0mCU4/target, and CARGO_TERM_COLOR=never:
cargo test --manifest-path /home/agent/tmp/delta-verify.B0mCU4/cargo-home/git/checkouts/lance-8ddea23c38163eda/f065258/rust/lance/Cargo.toml -p lance --lib test_create_index_conflicts_only_on_same_name
Observed: 1 passed; 2784 filtered. The test asserts that same-name CreateIndex conflicts but a differently named CreateIndex is accepted for rebase. The pinned drop_index path is also a CreateIndex operation with no new names and the removed index in removed_indices, so it takes this accepted branch. Expected for MemWAL initialization: changes to the names or schema used by the selected set conflict or trigger re-resolution before commit.
There was a problem hiding this comment.
Similar to the lance-format/lance#8360. We does not currently refresh or validate schema changes that occur after enabling WAL. This will be addressed as a follow up ticket.
|
Is this change ready for another review? saw a bunch of new gatekeeper comments |
3 similar comments
|
Is this change ready for another review? saw a bunch of new gatekeeper comments |
|
Is this change ready for another review? saw a bunch of new gatekeeper comments |
|
Is this change ready for another review? saw a bunch of new gatekeeper comments |
@xuanyu-z yeah, I think it's ready for another pass. Gatekeeper seems to caught up on the lance-side + this PR about ensuring indexes can not change structure after they are enabled. I think it makes sense, but it should be addressed as a follow up. |
…#8360) ## Problem `is_maintainable_index_type` inspects only an index's protobuf type url, which cannot decide whether the MemWAL can maintain that index. Every vector index sub-type carries `VectorIndexDetails` and so maps to `MemIndexKind::Hnsw`, but the memtable's HNSW requires a `FixedSizeList<Float32>` column. A caller that filters a maintained set on the type url alone can therefore commit an index that every shard-writer open then rejects, leaving the table unwritable. Concretely: an IVF-PQ index over `FixedSizeList<Float64>` is admitted by `is_maintainable_index_type`, gets committed into `maintained_indexes`, and then the first `merge_insert` fails opening the shard writer with `HNSW index requires a FixedSizeList<Float32> column`. The rules that actually decide this already exist in `validate_index_configs` — they just only run at `ShardWriter::open`, far from the call that chose the set. `is_maintainable_index_type`'s own doc comment made this reachable by advising callers to "filter on this before committing a maintained set". ## Change * Extract the index-config building loop out of `mem_wal_writer` into `build_index_configs`. * Add `validate_maintained_indexes(dataset, index_names)`, which builds the same configs and runs `validate_index_configs` against the same shard schema (base + `_tombstone`) with the same derived PK columns. * Both `mem_wal_writer` and the new entry point go through that one path, so a set that validates is a set the writer can open, and the two cannot drift as more index kinds become maintainable. * Correct the `is_maintainable_index_type` docs to say it is necessary but not sufficient, and point at the new function. The check is all-or-nothing by design: it reports the first index it cannot maintain rather than returning a usable subset. A caller inferring a set surfaces that error rather than silently dropping an index the caller believes is maintained and the writer never touches. ## Motivation lancedb is adding an inferred default for `maintained_indexes` (lancedb/lancedb#3748). Inference needs to ask "can the MemWAL maintain this index?" and there is currently no API that answers it correctly. Keeping the rule here, next to the code that enforces it, means every future widening of what the MemWAL can maintain reaches callers for free instead of being re-derived downstream. ## Testing Four new tests in `mem_wal::api`: * `test_validate_maintained_indexes_rejects_non_f32_vector_column` — asserts both halves of the bug: `is_maintainable_index_type` admits an IVF index over `FixedSizeList<Float64>`, and `validate_maintained_indexes` rejects it. * `test_validate_maintained_indexes_accepts_f32_vector_column` * `test_validate_maintained_indexes_accepts_btree` — guards the shard-schema plumbing (field ids resolve against base + `_tombstone`). * `test_validate_maintained_indexes_rejects_unknown_name` Full `dataset::mem_wal` suite: 582 passed, 1 ignored, 0 failed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
…icies Picks up lance v11.0.0-beta.3 (#3896), which released the `validate_maintained_indexes` API this branch calls. Resolves the Cargo.toml/Cargo.lock conflict in favor of main: the temporary `rev = "f0652582..."` pin at lance-format/lance#8360 from ea2af18 is gone, along with the "do not merge with this pin" comment that guarded it. beta.3 carries the function at rust/lance/src/dataset/mem_wal/api.rs, so the pin has served its purpose. Took main's Cargo.lock wholesale — the only differences from this branch's lock were the lance version bumps and main's own futures feature change (#3800), as the branch added no other dependency. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
What
LsmWriteSpec::maintained_indexesbecomesOption<Vec<String>>:None(new default)Some([])Some([..])with_maintained_indexeskeeps its signature;with_no_maintained_indexes()is new. Surfaced through the remote path (null on the wire), Python, and Node.Why
Callers had to state the maintained set by hand every time, which is both tedious and easy to get wrong — the common case is "maintain what I already built."
Resolution filters on
IndexConfig::is_memwal_maintainable, delegating to lance'sis_maintainable_index_type. This is load-bearing rather than cosmetic: lance does not skip an index type its memtable cannot build, it errors when the shard writer opens, so sweeping up a bitmap index would fail every memtable claim and leave the table unwritable. The inferred set excludes those, and an explicit list naming one is now rejected at spec time instead of at claim time.Behavior change
A freshly constructed spec used to maintain nothing; it now maintains everything supported. This flipped because napi collapses
undefinedandnulltoNone, so TypeScript cannot express "absent means nothing, null means all" — any other choice makes the bindings disagree with the wire. The error direction also favors it: an unwanted maintained index costs memory, while a silently unmaintained one degrades FTS to an unscored scan.Three existing tests encoded the old default and are updated rather than worked around.
Caveat
The resolved set is a snapshot, not a subscription. An index created after the spec is installed is not maintained until the spec is unset and set again.
get_lsm_write_spectherefore always reports a concrete list —Nonenever round-trips.Dependency
Needs a lance release carrying
is_maintainable_index_type(lance-format/lance#8095) before this builds against the pinned tag. Draft until then.Testing
38 Rust LSM tests and 10 Python tests pass against a local lance build, including new coverage that a bitmap index is excluded from inference and rejected when named, and that
[]stays distinguishable from null on the wire.🤖 Generated with Claude Code