Create Vector Index

Syntax

CREATE TABLE table_name(
  columns_difinition,
  INDEX index_name (column_name) USING VECTOR  PROPERTIES(
      "property1" = "value1",
      "property2" = "value2"
  )
);

columns_difinition: Define the field information of the table, the last field must be separated by a comma

INDEX: Keyword

index_name: Custom name for the index

column_name: The name of the field that needs to be indexed

VECTOR: Keyword, indicating vector index

COMMENT: Specify the description information of the index

PROPERTIES: Specify the parameters of the vector INDEX

Parameter NameOptional ValuesDefault ValueRemarks
distance.functionl2_distancecosine_distancenegative_dot_productjaccard_distancehamming_distancecosine_distanceFor convenience, please use negative_dot_product for dot product scenarios
scalar.typef32, f16, i8, b1f32The type of vector elements in the vector index, which can be different from the vector column
mRecommended not to exceed 100016Maximum number of neighbors in the HNSW algorithm
ef.constructionRecommended not to exceed 5000128Size of the candidate set when constructing the index in the HNSW algorithm
reuse.vector.columnfalse/truefalseWhether to reuse the data of the vector column to save storage space
compress.codecuncompressed/zstd/lz4uncompressedCompression algorithm for the vector index; not effective when reusing the column
compress.levelfatest/default/bestdefaultCompression algorithm level
compress.byte.stream.splitfalse/truetrueRearrange float bits before compression
compress.block.sizeInteger greater than 1M16777216Compression block size
conversion.ruledefault/as_bitsdefaultWhen indexing vector(tinyint, N) type by bits, use as_bits

Vector Index Scalar Type and Column Type

Index element type refers to the type specified by scalar.type in properties; when the types are inconsistent, certain conversion rules (mostly cast) will be applied, except when using type b1.

Index Element TypeSupported Vector Element TypesRemarks
b1tinyint, int, floatWhen "conversion.rule" = "bits", each bit in vector(tinyint, N) is treated as an element in the vector. When "conversion.rule" = "default", the vector is binarized.
i8tinyint, int, floatWhen the vector element type is inconsistent with the index, cast is performed (note that overflow may occur).
f16int, floatWhen the vector element type is inconsistent with the index, cast is performed.
f32int, floatWhen the vector element type is inconsistent with the index, cast is performed.

Examples

CREATE TABLE test_vector1 (
    vec vector(float, 4),
    id int,
    index test_vector1_vec_idx  (vec) using vector properties (
        "scalar.type" = "f32",
        "distance.function" = "l2_distance"
    )
)

Reference Documentation

User Guide

Vector Index User Guide

Add Vector Index to Existing Table

Syntax

CREATE  VECTOR INDEX [IF NOT EXISTS] index_name ON TABLE 
[schema].table_name(col_name) PROPERTIES(
    "property1" = "value1",
    "property2" = "value2"
)

VECTOR: Index type, vector index

index_name: Table name, located under schema, index name under schema must be unique

PROPERTIES: Specify parameters for INDEX

Description

Executing CREATE INDEX is only effective for new data

Example

CREATE TABLE test_vector2 (
    vec vector(float, 512),
    id int
) ;

 CREATE vector INDEX test_vector2_vec_idx on (vec) properties (
        "scalar.type" = "f32",
        "distance.function" = "l2_distance"
 );