Help Center/ AI DataLake/ devg/ Lance Development Guide/ Lance on Aura/ Using Indexes for Lance Tables
Updated on 2026-11-06 GMT+08:00

Using Indexes for Lance Tables

Creating an Index

You can create an index for a vector column in a Lance table. The vector column must be declared as a fixed-size list. For details, see Creating a Lance Table.

Supported vector index types include: ivfflat, ivfpq, ivfrq, ivfsq, hnsw, hnswpq, and hnswsq. For details about how to create an index, see CREATE INDEX.

Distributed creation of vector indexes is supported. The generated index can be either a global index, or multiple local sub-indexes. Each sub-index corresponds to a partition of the table and indexes non-overlapping data. You can control the number of table partitions using the fq_query_vdn parameter. During index creation, if merge_segment is set to 1, a global index is generated. Otherwise, multiple sub-indexes are generated. Using multiple sub-indexes accelerates queries.

Table 1 Vector index algorithms and their respective use cases

Index Type

Description

Build Overhead

Compression Rate

Query Latency (Small topK)

Recall

Memory Usage

Use Cases

Tuning Parameters

ivfflat

Clustering and bucketing (partitioning). Stores original vectors. During query, it traverses bucket centers and scans only a subset of buckets to measure the exact distance between the query vector and candidate vectors.

Low

N/A

Medium

Extremely high

High

Small to medium tables; high precision requirements; sufficient memory

Build: nlists, sample_rate, max_iters

Query: minimum_nprobes, maximum_nprobes, refine_factor

ivfpq

Clustering and bucketing. Stores product quantization (PQ) codebook and vector quantization results. Index scans use approximate distances based on quantization. The exact distances can be computed and re-ranked using the refinement process.

Medium

High

Moderately low

Medium

Low

100M+ records; low precision requirements; memory-constrained; large topK; hybrid scalar-vector queries. Increasing refine_factor can improve recall, but values greater than 2 will affect performance.

Build: nlists, sample_rate, max_iters, num_sub_vectors

Query: minimum_nprobes, maximum_nprobes, refine_factor

ivfrq

Clustering and bucketing. Stores residuals using RaBitQ (1-bit quantization). Index scans use approximate distances, and the refinement process enables precise re-ranking.

Moderately high

Moderately high

Medium

High

Low to medium

100M+ records; medium precision requirements; memory-constrained; large topK; hybrid scalar-vector queries. Lower refine_factor values yield high recall.

Build: nlists, sample_rate, max_iters, num_bits (currently only 1-bit supported)

Query: minimum_nprobes, maximum_nprobes, refine_factor

ivfsq

Clustering and bucketing. Stores scalar quantization (8-bit) values. Index scans use approximate distances, and the refinement process enables precise re-ranking.

Medium

Medium

Medium

High

Medium

100M+ records; high precision requirements; sufficient memory; large topK; hybrid scalar-vector queries.

Build: nlists, sample_rate, max_iters, num_bits

Query: minimum_nprobes, maximum_nprobes, refine_factor

hnsw

Clustering generates a multi-layer directed graph. Stores original vectors. During a query, it navigates the graph to access a subset of bucket centers; and scans only selected buckets using exact distance computation.

High

N/A

Low

Extremely high

High

(>ivfflat)

100M+ records; low-latency requirement; small topK; high precision; hybrid queries with low scalar filter selectivity.

Build: nlists, sample_rate, max_iters, m, ef

Query: ef, refine_factor, minimum_nprobes, maximum_nprobes

hnswpq

Clustering generates a multi-layer directed graph. Stores product quantization (PQ) codebook and vector quantization results. Index scans use approximate distances based on quantization. Exact distances can be computed and re-ranked using the refinement process.

Extremely high

High

Low

Medium

Medium

100M+ records; low-latency requirement; small topK; low precision; hybrid queries with low scalar filter selectivity. Increasing refine_factor can improve recall.

Build: nlists, sample_rate, max_iters, m, ef, num_sub_vectors

Query: ef, refine_factor, minimum_nprobes, maximum_nprobes

hnswsq

Clustering generates a multi-layer directed graph. Stores scalar quantization (8-bit) values. Index scans use approximate distances, and the refinement process enables precise re-ranking.

High

Medium

Low

High

Moderately high

100M+ records; low-latency requirement; small topK; moderately high precision; hybrid queries with low scalar filter selectivity.

Build: nlists, sample_rate, max_iters, m, ef, num_bits

Query: ef, refine_factor, minimum_nprobes, maximum_nprobes

Example:

Create an index named lance_index_01 on the Lance table lance_tbl using the IVF-PQ algorithm with L2 (Euclidean) distance. The IVF index partitions the vector space into 2 clusters. Each vector is split into 4 sub-vectors, and multiple sub-indexes will be generated.

1
CREATE INDEX IF NOT EXISTS lance_index_01 ON lance_tbl USING ivfpq (vector_column vector_l2_ops) WITH (nlists=2, num_subvectors=4, merge_segment=0);
Table 2 Scalar index algorithms and their respective use cases

Index Type

Description

Use Cases

Supported Data Types

Parameters

btree

Sorts data by value and organizes it into pages. Stores min/max values per page in memory to build a B-tree index. During a query, it prunes irrelevant pages via the B-tree and scans only a few candidate pages to return exact results.

Range queries, equality queries, IN queries, exact filtering on large datasets

Integer: tinyint, smallint, int, integer, bigint, long

Floating-point: real, float, double precision, double

Boolean: boolean

String: varchar(n), char(n), string, text

Time: date, timestamp

Decimal: decimal(p,s), numeric(p,s)

N/A

Example:

Create an index named lance_idx on the column_name column of the Lance table lance_tbl, using the B-tree algorithm.

1
CREATE INDEX IF NOT EXISTS lance_idx ON lance_tbl USING btree (column_name);
Table 3 Full-text index algorithms and their respective use cases

Index Type

Description

Use Cases

Supported Data Types

Parameters

inverted

Tokenizes source text into individual terms. During a query, it looks up these terms in the inverted index and returns matching records.

Word matching, phrase matching

  • text
  • varchar
  • bpchar
  • text[]
  • varchar[]
  • bpchar[]

base_tokenizer, with_position, and max_token_length. For details about the parameters, see Table 5.

In Aura, scalar indexes in Lance format support only the B-tree type, and full-text indexes support only the inverted type.

Example:

Create an index named lance_fts on the column_name column of the Lance table lance_tbl, using the full-text (inverted) index algorithm. The tokenizer is set to ngram (which supports Chinese text), position tracking is enabled (for phrase queries), and the maximum token length is set to 20 (tokens exceeding this length will be truncated).

1
CREATE INDEX IF NOT EXISTS lance_fts ON lance_tbl USING inverted (column_name) WITH (base_tokenizer = 'ngram', with_position = true, max_token_length = 20);
Table 4 Available tokenizers for full-text indexes

Tokenizer Value

Description

Feature Dependency

simple

Tokenization by whitespace and punctuation (default)

Always available

whitespace

Tokenization by whitespace only

Always available

raw

No tokenization. The entire text is treated as a single token.

Always available

ngram

N-gram tokenization (overlapping character sequences), which must be used together with min_ngram_length and max_ngram_length.

Always available

icu

ICU dictionary-based Unicode tokenization

Always available

lindera/<model>

Lindera Japanese morphological analysis (e.g., lindera/ipadic)

You need to manually download the dictionary.

jieba or jieba/<model>

Jieba Chinese word segmentation (jieba is equivalent to jieba/default)

You need to manually download the dictionary.

Table 5 Parameters

Parameter

Type

Default Value

Recommended Value

Description

base_tokenizer

string

simple

  • Use simple for English.
  • Use jieba/ngram for Chinese.
  • Use lindera/ipadic for Japanese.
  • Use ngram for fuzzy prefix search.

Basic tokenizer, which determines how text is split into tokens. The options are as follows:

  • simple (tokenization by whitespace and punctuation)
  • whitespace (tokenization by whitespace only)
  • raw (no tokenization)
  • ngram (N-Gram overlapping character sequences)
  • icu (ICU Unicode tokenization)
  • lindera/<model> (Japanese morphological analysis)
  • jieba (Chinese word segmentation)

with_position

bool

false

  • Set this parameter to true if phrase query is required.
  • Retain the value false for keyword search.

Whether to store token location information in the inverted index. If this parameter is set to true, phrase query is supported, but the index size will increase significantly (by more than 10 times). This parameter is not available for the N-gram tokenizer.

max_token_length

uint32

40

  • Retain the default value 40 in common scenarios.
  • Set this parameter to None for languages without spaces, such as Chinese and Japanese.
  • Set this parameter to None if contains_tokens acceleration is required.

Maximum length of a token. Tokens whose length is greater than or equal to this value will be filtered out. The value None indicates no limit on the token length. If this parameter is set to a value other than None, index acceleration cannot be used for contains_tokens SQL queries.

Querying Using Indexes

On columns where indexes have already been created, you can perform query operations using those indexes. Currently, Aura supports the following index query types for Lance tables: vector index query, scalar index query, hybrid query of vectors and scalars, and full-text index query.

  • Vector index query

Example:

SELECT * FROM lance_vector ORDER BY vector_col::vector <-> '[-0.2,0.5,-3.3,0.0]'::vector LIMIT 10;

This query uses the index on the vector_col column in the lance_vector table to retrieve the top 10 nearest neighbors for the vector [-0.2,0.5,-3.3,0.0]. The ORDER BY ... LIMIT syntax triggers an Approximate Nearest Neighbor (ANN) query. The vector column involved in the ORDER BY clause must have an available index. The <-> operator is a distance operator. The following distance operators are currently supported in Aura.

Table 6

Operator

Description

<->

L2 distance

<#>

Inner product distance

<=>

Cosine distance

The vector column must contain an index that matches the distance operator used in the query. If no matching index exists, the query will fail. If multiple indexes with the same distance operator exist in the vector column, the most recently created index is selected.

  • Scalar index query

Example:

SELECT * FROM ext_type_cols WHERE big_val > 0 ORDER BY id;

Scalar index queries do not have a specific syntax. Actually, they are standard WHERE clause queries. If a scalar index exists in the big_val column, Aura pushes the WHERE predicate down to Lance. The Lance internal optimizer determines whether to use the index.

  • Hybrid query of vectors and scalars

Example:

SELECT count(1) FROM (
      SELECT id, name FROM lance_mixed_q
      WHERE id > 4000 AND age < 30
      ORDER BY vec::vector <-> '[1,2,...]'::vector LIMIT 1024
  ) t1;

The hybrid queries combine the syntax for vector index queries and scalar index queries. Aura employs a Post-filter policy: it first performs a vector index query to return the top-K results, and then filters these results based on the WHERE conditions.

  • Full-text index query

Example:

 SELECT * FROM fts_test WHERE content @@ 'Aura' ORDER BY id;
 SELECT * FROM fts_test WHERE content @@ 'lance' AND id < 5 ORDER BY id;

The operator for full-text index query is @@. It can be used together with scalar query filter conditions. However, hybrid queries combining full-text indexes and vector indexes are not supported.

Showing Existing Indexes

You can print all indexes of a Lance table or all Lance tables in the current database. For details, see SHOW INDEX.

Example:

1
2
SHOW INDEX;
SHOW INDEX lance_tbl;

Deleting an Existing Index

You can delete an existing index from a Lance table. For details, see DROP INDEX.

Example:

1
DROP INDEX lance_index_01 ON lance_tbl;

Rebuilding or Updating an Existing Index

Updating the data in a Lance index column can invalidate some index fragments or the entire index. Therefore, you need to periodically run the optimize command to incrementally rebuild the index.

You can rebuild an existing index. The rebuilt index retains the same name and parameters, but the index data is rebuilt from the latest full data of the indexed column. For details, see ALTER INDEX.

Example:

1
ALTER INDEX IF EXISTS lance_index_01 ON lance_tbl REBUILD;

You can update an existing index. When new data is inserted or deleted, existing indexes are not updated immediately. This means the latest data cannot be retrieved via the index, which may impact query performance (though query results may be correct).

To ensure that an existing index includes the latest data without performing a full rebuild, use the index optimization feature.

For details, see ALTER INDEX.

Example:

1
ALTER INDEX IF EXISTS lance_index_01 ON lance_tbl OPTIMIZE;