mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 20:44:00 +00:00
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:
co-authored by
Claude Opus 5.5
parent
ef59dcfe80
commit
5f87e18541
@@ -261,6 +261,49 @@ using an underlying bitmap index.
|
||||
|
||||
***
|
||||
|
||||
### plugin()
|
||||
|
||||
```ts
|
||||
static plugin(indexType, params?): Index
|
||||
```
|
||||
|
||||
Create a scalar index of a type recognized by a registered database plugin.
|
||||
|
||||
Use this for index types without a dedicated factory on `Index`.
|
||||
Prefer a dedicated factory when one is available.
|
||||
|
||||
An unknown plugin name or invalid parameters cause `createIndex` to fail.
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **indexType**: `string`
|
||||
The index type, case-insensitive.
|
||||
Surrounding whitespace is ignored. Must not be empty.
|
||||
|
||||
* **params?**: `string` \| `Record`<`string`, `unknown`>
|
||||
The index parameters, as an object or as a string
|
||||
holding a JSON object. They are passed as given. Each plugin defines
|
||||
its parameters and defaults; refer to the plugin's documentation
|
||||
for guidance.
|
||||
|
||||
#### Returns
|
||||
|
||||
[`Index`](Index.md)
|
||||
|
||||
#### Throws
|
||||
|
||||
If `indexType` is empty, or `params` is not a JSON object.
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
await table.createIndex("id", {
|
||||
config: Index.plugin("bloomfilter", { number_of_items: 4096 }),
|
||||
});
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### rtree()
|
||||
|
||||
```ts
|
||||
|
||||
Reference in New Issue
Block a user