Files
lancedb/rust
Lenin MookiahandLenin Mookiah 787ad381bf docs(rust): document and test num_threads for index optimization (#5359)
This PR fixes [issue
#4960](https://github.com/lancedb/lancedb/issues/4960).

Fixes #4960

The issue asks for a `num_threads` option on `OptimizeOptions`, like
`CompactionOptions::num_threads`, so index optimization can be held to a
CPU budget. LanceDB re-exports `OptimizeOptions` from `lance-index`, and
Lance added `OptimizeOptions::num_threads` / `with_num_threads` in
lance-format/lance#11154. The bump to Lance v16.0.0-beta.7 (#5352)
brought it in, and `OptimizeAction::Index(options)` already hands the
options through to `Dataset::optimize_indices` unchanged. So the Rust
option works today, but nothing in LanceDB says so or checks it.

This PR:

- documents the option on `OptimizeAction::Index`, with a
compile-checked example
(`OptimizeOptions::default().with_num_threads(2)`), what it limits
(compute stages of index optimization, not a process-wide thread cap),
that zero is rejected, and that index optimization runs on LanceDB
Embedded tables only;
- adds `test_optimize_index_with_num_threads`: on a table with 100
indexed and 100 unindexed rows, `with_num_threads(0)` returns an error
naming `num_threads` and leaves the index untouched, and
`with_num_threads(1)` then indexes all 200 rows.

No code paths change.

Possible SDK parity gap: the Python and TypeScript `optimize()`
convenience methods run the index step with default `OptimizeOptions`,
so they don't expose this limit yet. That would be a separate binding
change; I left it out of this PR.

## Testing

On macOS arm64, Rust 1.100.0 stable:

```
cargo test --profile ci -p lancedb --lib table::optimize::tests     # 24 passed, incl. test_optimize_index_with_num_threads
cargo test --profile ci -p lancedb --doc OptimizeAction             # 2 passed, incl. the new OptimizeAction::Index example
cargo fmt --all -- --check                                          # clean
```

As a check that the test exercises the pass-through, I temporarily made
`optimize_indices` ignore the caller's options and use
`OptimizeOptions::default()`; `test_optimize_index_with_num_threads`
then fails at the zero-value assertion. The test can't observe the
thread count itself, so the `with_num_threads(1)` case only shows a
limited run completes and indexes every row.

`cargo clippy -p lancedb --tests` on Rust 1.100 reports dead-code and
`if`-guard lints in other files (`job/profile.rs`, `table/add_data.rs`,
`table/write_progress.rs`, `table/query.rs`,
`table/computed_columns.rs`) with the default features; none in
`table/optimize.rs`.

Co-authored-by: Lenin Mookiah <2639584+leninworld@users.noreply.github.com>
2026-12-02 15:09:00 +00:00
..