mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-16 07:36:50 +00:00
105 lines
3.4 KiB
Plaintext
105 lines
3.4 KiB
Plaintext
---
|
|
title: "Index"
|
|
sidebarTitle: "Index"
|
|
description: "CREATE INDEX and DROP INDEX: one column, with the algorithm chosen by USING."
|
|
icon: bolt
|
|
keywords: ["create index", "drop index", "sql"]
|
|
availability:
|
|
embedded: unavailable
|
|
enterprise: available
|
|
---
|
|
|
|
## CREATE INDEX {#create}
|
|
|
|
<CodeGroup>
|
|
```sql SQL icon="database"
|
|
CREATE INDEX ON documents USING btree (title)
|
|
CREATE INDEX text_search ON documents USING fts (text)
|
|
```
|
|
</CodeGroup>
|
|
|
|
`USING` is required: it names the algorithm. The scalar algorithms are `btree`,
|
|
`bitmap` and `label_list`; `fts` builds a full-text index; and the vector
|
|
algorithms are `ivf_pq`, `ivf_rq`, `ivf_flat`, `ivf_hnsw_sq` and `ivf_hnsw_pq`,
|
|
where the deployment supports them. Index options go in a `WITH (...)` clause.
|
|
|
|
<Note>
|
|
In LanceDB Enterprise, SQL `CREATE INDEX` covers **one column**. A name between
|
|
`INDEX` and `ON` names the index, where the deployment's configuration allows
|
|
it; without one, the server names it after the column, as in `title_idx`. For a
|
|
multi-column index, use the SDK's [`create_index`](/indexing).
|
|
</Note>
|
|
|
|
<Note>
|
|
**Enterprise job type:** `reindex_` followed by the algorithm, such as
|
|
`reindex_btree` or `reindex_ivf_pq`; the name says which algorithm is building,
|
|
not a different feature. An SDK build that must not replace an existing index
|
|
runs as `create_` followed by the algorithm instead. See
|
|
[Incremental Indexing](/indexing/incremental-indexing).
|
|
</Note>
|
|
|
|
{/* Draft for the index exist_ok release.
|
|
|
|
```sql
|
|
CREATE INDEX IF NOT EXISTS text_search ON documents USING fts (text)
|
|
```
|
|
|
|
Use `IF NOT EXISTS` to preserve the existing index with the same name. Without an
|
|
explicit name, the name is derived from the column (`title_idx`, or
|
|
`title_list_element_idx` for list-element FTS). Existing definitions and builds
|
|
are kept, even when the new request specifies different settings.
|
|
|
|
The Python SDK exposes the same behavior through `exist_ok=True` on
|
|
`create_index` and `create_index_async`, including scalar and FTS wrappers.
|
|
This option takes precedence over `replace`, whose default behavior is unchanged.
|
|
|
|
```python
|
|
from lancedb.index import BTree
|
|
|
|
table.create_index("title", config=BTree(), name="title_idx", exist_ok=True)
|
|
```
|
|
|
|
```rust
|
|
use lancedb::index::Index;
|
|
|
|
table.create_index(&["title"], Index::BTree(Default::default()))
|
|
.name("title_idx".to_string())
|
|
.exist_ok(true)
|
|
.execute()
|
|
.await?;
|
|
```
|
|
|
|
The SDK option is available in Python and Rust. TypeScript support is a separate
|
|
follow-up. Remote use requires a server that supports the option.
|
|
|
|
An existing background build continues running. A completed submission handle
|
|
for a skipped creation does not wait for that build; use `wait_for_index` when
|
|
its completion is required.
|
|
|
|
*/}
|
|
|
|
## DROP INDEX {#drop}
|
|
|
|
<CodeGroup>
|
|
```sql SQL icon="database"
|
|
DROP INDEX documents.title_idx
|
|
```
|
|
</CodeGroup>
|
|
|
|
Takes the qualified `table.index` name. Find it with the SDK's
|
|
[`list_indices`](/indexing) if you created the index without
|
|
naming it yourself. A deployment builds the index in the background after
|
|
`CREATE INDEX` returns; until that build finishes, the index is not listed and
|
|
`DROP INDEX` reports it as not found.
|
|
|
|
## What to read next {#next}
|
|
|
|
<CardGroup cols={2}>
|
|
<Card title="Indexing" icon="bolt" href="/indexing">
|
|
Choosing an index type from the SDK.
|
|
</Card>
|
|
<Card title="Incremental Indexing" icon="refresh" href="/indexing/incremental-indexing">
|
|
Keeping an index current as data arrives.
|
|
</Card>
|
|
</CardGroup>
|