[**@lancedb/lancedb**](../README.md) • **Docs** *** [@lancedb/lancedb](../globals.md) / Index # Class: Index ## Methods ### bitmap() ```ts static bitmap(): Index ``` Create a bitmap index. A `Bitmap` index stores a bitmap for each distinct value in the column for every row. This index works best for low-cardinality columns, where the number of unique values is small (i.e., less than a few hundreds). #### Returns [`Index`](Index.md) *** ### bloomFilter() ```ts static bloomFilter(options?): Index ``` Create a Bloom filter index. Bloom filters accelerate equality and membership filters by skipping groups of rows that cannot match. Candidate rows are checked to remove false positives. This index uses less space than a btree or bitmap index, but does not accelerate range filters. Unset options use Lance's defaults. #### Parameters * **options?**: [`BloomFilterOptions`](../interfaces/BloomFilterOptions.md) #### Returns [`Index`](Index.md) #### Example Tuning a Bloom filter on an Embedded table: ```ts await table.createIndex("id", { config: Index.bloomFilter({ numberOfItems: 4096, probability: 0.01 }), }); ``` *** ### btree() ```ts static btree(): Index ``` Create a btree index A btree index is an index on a scalar columns. The index stores a copy of the column in sorted order. A header entry is created for each block of rows (currently the block size is fixed at 4096). These header entries are stored in a separate cacheable structure (a btree). To search for data the header is used to determine which blocks need to be read from disk. For example, a btree index in a table with 1Bi rows requires sizeof(Scalar) * 256Ki bytes of memory and will generally need to read sizeof(Scalar) * 4096 bytes to find the correct row ids. This index is good for scalar columns with mostly distinct values and does best when the query is highly selective. The btree index does not currently have any parameters though parameters such as the block size may be added in the future. #### Returns [`Index`](Index.md) *** ### fm() ```ts static fm(): Index ``` Create an FM-Index. An FM-Index is a scalar index on string or binary columns that accelerates substring search, i.e. `contains(col, 'needle')`. Unlike the tokenized full-text-search index, it matches arbitrary substrings of the raw bytes. #### Returns [`Index`](Index.md) *** ### fts() ```ts static fts(options?): Index ``` Create a full text search index A full text search index is an index on a string column, so that you can conduct full text searches on the column. The results of a full text search are ordered by relevance measured by BM25. You can combine filters with full text search. #### Parameters * **options?**: `Partial`<[`FtsOptions`](../interfaces/FtsOptions.md)> #### Returns [`Index`](Index.md) *** ### hnswPq() ```ts static hnswPq(options?): Index ``` Create a hnswPq index HNSW-PQ stands for Hierarchical Navigable Small World - Product Quantization. It is a variant of the HNSW algorithm that uses product quantization to compress the vectors. #### Parameters * **options?**: `Partial`<[`HnswPqOptions`](../interfaces/HnswPqOptions.md)> #### Returns [`Index`](Index.md) *** ### hnswSq() ```ts static hnswSq(options?): Index ``` Create a hnswSq index HNSW-SQ stands for Hierarchical Navigable Small World - Scalar Quantization. It is a variant of the HNSW algorithm that uses scalar quantization to compress the vectors. #### Parameters * **options?**: `Partial`<[`HnswSqOptions`](../interfaces/HnswSqOptions.md)> #### Returns [`Index`](Index.md) *** ### ivfFlat() ```ts static ivfFlat(options?): Index ``` Create an IvfFlat index This index groups vectors into partitions of similar vectors. Each partition keeps track of a centroid which is the average value of all vectors in the group. During a query the centroids are compared with the query vector to find the closest partitions. The vectors in these partitions are then searched to find the closest vectors. The partitioning process is called IVF and the `num_partitions` parameter controls how many groups to create. Note that training an IVF FLAT index on a large dataset is a slow operation and currently is also a memory intensive operation. #### Parameters * **options?**: `Partial`<[`IvfFlatOptions`](../interfaces/IvfFlatOptions.md)> #### Returns [`Index`](Index.md) *** ### ivfPq() ```ts static ivfPq(options?): Index ``` Create an IvfPq index This index stores a compressed (quantized) copy of every vector. These vectors are grouped into partitions of similar vectors. Each partition keeps track of a centroid which is the average value of all vectors in the group. During a query the centroids are compared with the query vector to find the closest partitions. The compressed vectors in these partitions are then searched to find the closest vectors. The compression scheme is called product quantization. Each vector is divided into subvectors and then each subvector is quantized into a small number of bits. the parameters `num_bits` and `num_subvectors` control this process, providing a tradeoff between index size (and thus search speed) and index accuracy. The partitioning process is called IVF and the `num_partitions` parameter controls how many groups to create. Note that training an IVF PQ index on a large dataset is a slow operation and currently is also a memory intensive operation. #### Parameters * **options?**: `Partial`<[`IvfPqOptions`](../interfaces/IvfPqOptions.md)> #### Returns [`Index`](Index.md) *** ### ivfRq() ```ts static ivfRq(options?): Index ``` Create an IvfRq index IVF-RQ (RabitQ Quantization) compresses vectors using RabitQ quantization and organizes them into IVF partitions. The compression scheme is called RabitQ quantization. Each dimension is quantized into a small number of bits. The parameters `num_bits` and `num_partitions` control this process, providing a tradeoff between index size (and thus search speed) and index accuracy. The partitioning process is called IVF and the `num_partitions` parameter controls how many groups to create. Note that training an IVF RQ index on a large dataset is a slow operation and currently is also a memory intensive operation. #### Parameters * **options?**: `Partial`<[`IvfRqOptions`](../interfaces/IvfRqOptions.md)> #### Returns [`Index`](Index.md) *** ### labelList() ```ts static labelList(): Index ``` Create a label list index. LabelList index is a scalar index that can be used on `List` columns to support queries with `array_has_all` and `array_has_any` using an underlying bitmap index. #### Returns [`Index`](Index.md) *** ### ngram() ```ts static ngram(): Index ``` Create an NGram index. An `NGram` index is a scalar index on a UTF-8 string column that accelerates substring filters such as `contains(col, 'needle')`, along with some `LIKE` and regular-expression predicates. It tokenizes values into overlapping character trigrams and narrows a scan to the rows that share the query's trigrams. The exact predicate is then evaluated on those candidates. Queries shorter than three characters fall back to a scan. #### Returns [`Index`](Index.md) #### Example ```ts await table.createIndex("text", { config: Index.ngram() }); const rows = await table.query().where("contains(text, 'needle')").toArray(); ``` *** ### 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 static rtree(options?): Index ``` Create an RTree index. An RTree index is a scalar index on a GeoArrow geometry column, that is, a column whose Arrow field metadata sets `ARROW:extension:name` to a GeoArrow type such as `geoarrow.point`, `geoarrow.polygon` or `geoarrow.wkb`. It stores the bounding box of each geometry and accelerates spatial filters. The index accelerates `ST_Intersects`, `ST_Contains`, `ST_Within`, `ST_Touches`, `ST_Crosses`, `ST_Overlaps`, `ST_Covers` and `ST_CoveredBy` between the indexed column and a constant geometry, in either argument order, for example `ST_Within(geom, ST_GeomFromText('POLYGON ((...))'))`, as well as `geom IS NULL`. These filters can be combined with other conditions using `AND`. See the R-tree section of https://docs.lancedb.com/indexing/scalar-index for storing geometry, the other spatial functions, and spatial filters on vector search. Remote tables send the `RTREE` index type to the server, which must support it. #### Parameters * **options?**: `Partial`<[`RTreeOptions`](../interfaces/RTreeOptions.md)> #### Returns [`Index`](Index.md) #### Example ```ts await table.createIndex("geom", { config: Index.rtree() }); await table .query() .where("ST_Intersects(geom, ST_GeomFromText('POLYGON ((0 0, 4 0, 0 4, 0 0))'))") .toArray(); ``` *** ### zoneMap() ```ts static zoneMap(): Index ``` Create a ZoneMap index. This index stores min/max summaries for ranges of rows and skips ranges that cannot match a filter. It works best for numeric or temporal columns whose values are correlated with row order, such as timestamps or sequential IDs. For strings, binary data, and supported types wider than eight bytes, this index uses per-fragment write seeds. By default, these use version 0 and do not activate the version 1 table capability. A commit that explicitly sets the table configuration key `lance.zone_write_seeds.version` to `"1"` activates a persistent reader and writer capability. Upgrade all readers and writers before opting in: clients that do not support this capability cannot access the resulting snapshots. Dropping the index or restoring an older version does not remove the capability from subsequent snapshots. #### Returns [`Index`](Index.md) #### Example ```ts await table.createIndex("timestamp", { config: Index.zoneMap() }); ```