Skip to content

Add index rebuild options - #74

Open
yuvalif wants to merge 7 commits into
lancedb:mainfrom
yuvalif:add-index-rebuild-options
Open

yuvalif wants to merge 7 commits into
lancedb:mainfrom
yuvalif:add-index-rebuild-options

Conversation

@yuvalif

@yuvalif yuvalif commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

this work should enable better control over the reindexing process:

  • expose all index optimization options and modes
  • allow storing user parameters atomically with the re-indexing operations
  • expose optional callback for index progression indication

yuvalif and others added 3 commits November 10, 2026 13:49
Signed-off-by: Yuval Lifshitz <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
run each optimization type on its own, on a table with two unindexed
fragments, and verify its effect on the number of fragments and on
the number of unindexed rows.

note: pruning only removes versions older
than a week, so it is verified to keep the recent versions.

Signed-off-by: Yuval Lifshitz <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
add the IVF_SQ, IVF_RQ and IVF_HNSW_FLAT vector index types and the
FM scalar index type, so that every index type supported by LanceDB
can be created through the C API.

Signed-off-by: Yuval Lifshitz <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
@yuvalif

yuvalif commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

@galsalomon66 would appriciate your feedback!

Copilot AI 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.

🟡 Changes recommended

The expanded statistics structure can overwrite memory for existing C callers, while unvalidated mode values at the FFI boundary can cause undefined behavior.

3 open issues
What changed in this PR

This PR expands the LanceDB C bindings to give callers more control over index maintenance and visibility into rebuild progress.

Changes:

  • Adds reindex modes, index selection, atomic transaction properties, and progress callbacks.
  • Extends index statistics and supports additional vector and scalar index types.
  • Adds tests, documentation, and an example of the reindexing workflow.
File Description
valgrind.supp Refines thread-allocation suppressions and adds Rayon coverage.
tests/​test_vector_index.cpp Tests vector index types, reindex modes, options, and statistics.
tests/​test_index.cpp Tests scalar reindexing, transaction properties, and progress reporting.
tests/​test_common.h Adds a thread-safe progress recorder for tests.
src/​table.rs Adds transaction-property retrieval and shared output-array handling.
src/​index.rs Implements reindex options, callbacks, new index types, and extended statistics.
include/​lancedb.h Exposes and documents the new C APIs and types.
examples/​full.cpp Demonstrates selective reindexing and transaction-property retrieval.
examples/​external_provider/​Cargo.lock Records new binding dependencies for the example.
docs/​index.rst Documents reindex modes, progress reporting, and maintenance guidance.
Cargo.toml Adds JSON parsing and asynchronous trait dependencies.
Cargo.lock Records the new direct dependencies.

Review effort: Balanced

Comment thread src/index.rs Resolved
Comment thread src/index.rs Resolved
Comment thread src/index.rs Resolved
@yuvalif yuvalif added abi-change ABI change will break code that was compiled against older versions of the library enhancement New feature or request labels Nov 15, 2026
yuvalif and others added 4 commits November 15, 2026 12:30
lancedb_table_index_stats() now also reports:
- the index type
- the number of fragments covered and not covered by the index
- the number of rows deleted from the indexed fragments
- the number of partitions of a vector index
- the table version the newest index segment was built against

Signed-off-by: Yuval Lifshitz <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
add lancedb_table_optimize_indices(), which brings the indices of a
table up to date with explicit options:
- the reindex mode: let lance decide (default), append a delta
  segment, merge segments, or retrain
- the number of segments to merge
- the names of the indices to optimize
- transaction properties to store with the commit

Signed-off-by: Yuval Lifshitz <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
add lancedb_table_get_transaction_properties(), which returns the
key-value pairs that were stored with the commit of a table version,
for example by lancedb_table_optimize_indices(). this allows finding
which job made a commit.

Signed-off-by: Yuval Lifshitz <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
add an optional callback to the options of
lancedb_table_optimize_indices(), which is called when a stage of
building an index starts, advances and completes. this allows
following a reindex of a large table.

Signed-off-by: Yuval Lifshitz <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>

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

Expanding LanceDBIndexStats in place under lancedb_table_index_stats is fine. Please add a short note to the PR description or docs that existing C/C++ callers must recompile against the new header before using the updated library, since the structure layout and size change under the same symbol.

Comment thread src/index.rs
LanceDBReindexMode::Retrain => OptimizeOptions::retrain(),
};

if opts.num_index_names > 0 {

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.

With a non-NULL index_names and num_index_names == 0, this branch is skipped and OptimizeOptions keeps index_names = None, which Lance interprets as every index. A caller that computes a selection and ends with zero names therefore gets the full set: RETRAIN retrains all vector indices, and other modes can merge or append across every index, commit a new table version, and store the transaction properties. The SDK treats Some(empty) as an empty selection and returns before the commit, and the header only defines NULL as "all indices"; this combination is currently accepted without an error.

@Xuanwo

Xuanwo commented Nov 21, 2026

Copy link
Copy Markdown
Member

#86 landed on main at 809e2fb, so the enum validation from #75 is now available for this PR’s conflict resolution.

Please preserve the raw integer inputs and checked conversions when merging src/index.rs. Extend LanceDBIndexType::from_c_int for the new creatable values 9–12 and keep UNKNOWN (99) as a statistics result. Pass the checked distance value into apply_ivf_config!. The new reindex mode lives in its own options struct, so it needs the same integer-first conversion before building the SDK options. The C17 helper in tests/test_c_enum_inputs.c provides a pattern for testing rejected values.

The public header also conflicts around the index declarations. Please retain the read-only index listing API from #90 alongside the rebuild statistics changes here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

abi-change ABI change will break code that was compiled against older versions of the library enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants