Updated on 2026-11-06 GMT+08:00

CREATE INDEX

Function

CREATE INDEX can be used to create indexes for one or more columns of a foreign table.

An index is an object that creates a record for each value in the index column for quickly locating one or more rows in the foreign table.

Currently, Aura supports vector indexes for Lance foreign tables.

Constraints

  • Currently, only vector indexes for Lance foreign tables are supported.
  • The vector index algorithm can be any of {ivfflat, ivfpq, ivfrq, ivfsq, hnsw, hnswpq, hnswsq}. The supported distance functions include vector_l2_ops and vector_cosine_ops.
  • Only one type of distance index can be created for each vector column, for example, vector_l2_ops|vector_cosine_ops. If an incorrect distance function is used, the query recall may be affected.
  • You cannot create indexes with the same index name (index_name). To rebuild an index, use the ALTER INDEX ... REBUILD statement. To modify parameters, you need to delete the index (using DROP INDEX) and then use the new parameters to create an index (using CREATE INDEX). IF NOT EXISTS is recommended for preventing errors caused by the creation of indexes with the same name.
  • NULL vectors and vectors with NULL values will not be indexed.
  • The double type is not supported. You need to use a floating-point vector with a specified precision (array<float4> or array<float8>) and use TBLPROPERTIES to specify the dimension of the vector when creating a table, for example, TBLPROPERTIES ('arrow.fixed-size-list.size.{nameOfThisVectorColumn}' = '128'). This prevents other DDL operations (ALTER COLUMN) during index creation. float4/8 corresponds to float32/64.

Syntax

1
2
3
4
CREATE INDEX [ IF NOT EXISTS ] [index_name] ON table_name 
[ USING access_method ]
( col_name opt_opclass [, ...] )
[ WITH ( option_key = option_value [, ... ] ) ];

Parameter Description

  • index_name: index name
  • table_name: name of the table for which an index is to be created
  • access_method: index building algorithm, for example, IVFPQ for vector indexes

  • col_name: name of the column for which an index is to be created
  • opt_opclass: index column operator class. For example, if the cosine distance is used to create an index, the value is vector_cosine_ops.
  • option_key: index parameter variable. For details, see the method of setting index parameters.
  • option_value: index parameter value. For details, see the method of setting index parameters.
Table 1 Method of setting index parameters

Index Type

Parameter (option_key)

Description

Usage

Reference Value (option_value)

ivfflat

nlists, lists, or num_partitions

Number of clustering buckets

with (nlists=?)

num_rows // 4,096 or a value set using sqrt(num_rows) for large tables

sample_rate

Number of vectors sampled for each center

with (sample_rate=?)

256, 1024, ... The table must contain at least sample_rate data records (a clustering bucket).

max_iters

Number of iterations during k-means clustering

with (max_iters=?)

25, 50, ...

ivfpq

nlists, lists, or num_partitions

Number of clusters generated from the entire high-dimensional vector space

with (nlists=?)

num_rows // 4,096 or a value set using sqrt(num_rows) for large tables. In addition, the lists/num_sub_vectors % 8 =0 constraint is recommended for more efficient SIMD execution.

num_sub_vectors

Number of sub-vectors a vector is split into during product quantization

with (num_sub_vectors=?)

dimension // 8, rounded to the nearest integer, for example, {4, 8, 16}. The hard constraint is as follows: num_sub_vectors < dim (number of column dimensions). When the value of dimension is less than or equal to 256, PQ is recommended.

sample_rate

Number of vectors sampled during the calculation of the number of global clusters and quantization subvector cluster centers

with (sample_rate=?)

256, 1024, ...;

Constraint: num_rows ≥ nlists x sample_rate^2

max_iters

Number of iterations during the calculation of the number of global clusters and quantization subvector cluster centers

with (max_iters=?)

25, 50, ...

ivfrq

nlists, lists, or num_partitions

Number of clustering buckets

with (nlists=?)

num_rows // 4,096 or a value set using sqrt(num_rows) for large tables

num_bits

Number of quantization bits

with (bits=?)

Currently, only 1 bit is supported.

sample_rate

Number of vectors sampled for each center

with (sample_rate=?)

256, 1024, ... The table must contain at least sample_rate data records (a clustering bucket).

max_iters

Number of iterations during k-means clustering

with (max_iters=?)

25, 50, ...

ivfsq

nlists, lists, or num_partitions

Number of clustering buckets

with (nlists=?)

num_rows // 4,096 or a value set using sqrt(num_rows) for large tables

num_bits

Number of quantization bits

with (bits=?)

{4, 8 (default)}

sample_rate

Number of vectors sampled for each center

with (sample_rate=?)

256, 1024, ... The table must contain at least sample_rate data records (a clustering bucket).

max_iters

Number of iterations during k-means clustering

with (max_iters=?)

25, 50, ...

hnsw/hnswflat

nlists, lists, or num_partitions

Number of clustering buckets

with (nlists=?)

num_rows // 1,048,576 or a value set using sqrt(num_rows) for large tables

m

Number of edges of each node in an HNSW graph

with (m=?)

default 20

ef or ef_construction

Search breadth for graph creation

with (ef=?)

>=150

sample_rate

Number of vectors sampled for each center

with (sample_rate=?)

256, 1024, ... The table must contain at least sample_rate data records (a clustering bucket).

max_iters

Number of iterations during k-means clustering

with (max_iters=?)

25, 50, ...

hnswpq

nlists, lists, or num_partitions

Number of clustering buckets

with (nlists=?)

num_rows // 1,048,576 or a value set using sqrt(num_rows) for large tables

m

Number of edges of each node in an HNSW graph

with (m=?)

default 20

ef or ef_construction

Search breadth for graph creation

with (ef=?)

>=150

num_sub_vectors

Number of sub-vectors a vector is split into during product quantization

with (num_sub_vectors=?)

dimension // 8, rounded to the nearest integer, for example, {4, 8, 16}

Hard constraint: num_sub_vectors < dim (number of column dimensions)

sample_rate

Number of vectors sampled during the calculation of the number of global clusters and quantization subvector cluster centers

with (sample_rate=?)

256, 1024, ...;

Constraint: num_rows ≥ nlists x sample_rate^2

max_iters

Number of iterations during the calculation of the number of global clusters and quantization subvector cluster centers

with (max_iters=?)

25, 50, ...

hnswsq

nlists, lists, or num_partitions

Number of clustering buckets

with (nlists=?)

num_rows // 1,048,576 or a value set using sqrt(num_rows) for large tables

m

Number of edges of each node in an HNSW graph

with (m=?)

default 20

ef or ef_construction

Search breadth for graph creation

with (ef=?)

>=150

num_bits

Number of quantization bits

with (bits=?)

{4, 8 (default)}

sample_rate

Number of vectors sampled during the calculation of the number of global clusters and quantization subvector cluster centers

with (sample_rate=?)

256, 1024, ...;

Constraint: num_rows ≥ nlists x sample_rate^2

max_iters

Number of iterations during the calculation of the number of global clusters and quantization subvector cluster centers

with (max_iters=?)

25, 50, ...

Example

Create an index for the vector column of the lance_vector table using IVFPQ.

1
2
create table lance_vector (vector array<float4>) TABLEPROPERTIES ('arrow.fixed-size-list.vector' = '16') store as lance;
CREATE INDEX ix ON lance_vector USING ivfpq (vector vector_cosine_ops) WITH (nlists=2, num_sub_vectors=2);