feat: create any registered Lance scalar index plugin by name (#5004)

Closes #4933

Adds a generic configuration for creating a scalar index of any type
recognized by a registered database plugin, using its type name and
optional JSON parameters. Index types without a dedicated SDK
configuration can use the same API.

- **Rust:** `Index::Plugin(PluginIndexBuilder)`, with JSON-object
parameters through `.params(...)` or `.params_json(...)`.
- **Python:** `ScalarPlugin(index_type, params=None)`, accepting a dict
or JSON-object string.
- **TypeScript:** `Index.plugin(indexType, params?)`, accepting an
object or JSON-object string.
- Type names are case-insensitive and surrounding whitespace is ignored.
Empty names and non-object parameters are rejected.
- Native index introspection preserves existing built-in types and
exposes other registered plugin types through `Custom`.

The guide and SDK references describe index creation, parameter
ownership, and errors consistently. They recommend a dedicated
configuration when one exists and refer readers to the plugin’s
documentation for parameter names and defaults. The TypeScript reference
is regenerated from its source JSDoc.

## Remote request format

Generic requests use `index_type: "PLUGIN"` and a separate upper-cased
`plugin_type`. Arbitrary parameters stay nested under `params`,
preserving omitted parameters versus an explicit empty object. This
separates the generic path from built-in handling and prevents
parameters from overwriting request fields.

## Validation

- 52 targeted tests passed: 15 Rust, 22 Python, and 15 TypeScript.
- Two Rust plugin doctests passed.
- Rust Clippy, the Node build and lint, changed-file Python lint,
TypeDoc generation, Vale, and the MkDocs SDK-reference build passed.
- Request tests cover Python sync/async calls, object and JSON-string
inputs, normalization, omitted and empty parameters, and collisions with
request metadata.
- Repository-wide Ruff reports existing findings in untouched
documentation examples. Strict Mintlify validation reports four missing
snippet-export warnings, also reproduced on the unmodified commit.

## Follow-ups

- Replace the built-in examples with a widely available custom plugin
when one is available, as discussed in review.
- Remote `list_indices()` and `index_stats()` still parse a fixed set of
type names; accepting unrecognized plugin types through a `Custom`
fallback remains separate.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sarwar Bhuiyan
2026-11-24 07:00:47 -08:00
committed by GitHub
co-authored by Claude Opus 5.5
parent ef59dcfe80
commit 5f87e18541
18 changed files with 1097 additions and 13 deletions
+13 -1
View File
@@ -5,7 +5,7 @@ use std::sync::Mutex;
use lancedb::index::Index as LanceDbIndex;
use lancedb::index::scalar::{
BTreeIndexBuilder, FmIndexBuilder, FtsIndexBuilder, RTreeIndexBuilder,
BTreeIndexBuilder, FmIndexBuilder, FtsIndexBuilder, PluginIndexBuilder, RTreeIndexBuilder,
};
use lancedb::index::vector::{
IvfFlatIndexBuilder, IvfHnswPqIndexBuilder, IvfHnswSqIndexBuilder, IvfPqIndexBuilder,
@@ -228,6 +228,18 @@ impl Index {
}
}
/// `params_json`, if set, must be a string holding a JSON object.
#[napi(factory)]
pub fn plugin(index_type: String, params_json: Option<String>) -> napi::Result<Self> {
let mut builder = PluginIndexBuilder::new(index_type).default_error()?;
if let Some(params_json) = params_json {
builder = builder.params_json(params_json).default_error()?;
}
Ok(Self {
inner: Mutex::new(Some(LanceDbIndex::Plugin(builder))),
})
}
#[napi(factory)]
pub fn rtree(page_size: Option<u32>) -> napi::Result<Self> {
let mut builder = RTreeIndexBuilder::default();
+6 -1
View File
@@ -1314,7 +1314,12 @@ pub struct IndexConfig {
impl From<lancedb::index::IndexConfig> for IndexConfig {
fn from(value: lancedb::index::IndexConfig) -> Self {
let index_type = format!("{:?}", value.index_type);
// A registered plugin's type is its display name, such as "MinHashLsh",
// which `Debug` would render as `Custom("MinHashLsh")`.
let index_type = match value.index_type {
lancedb::index::IndexType::Custom(name) => name,
index_type => format!("{index_type:?}"),
};
Self {
index_type,
columns: value.columns,