Create Vector Index
Syntax
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 Name | Optional Values | Default Value | Remarks |
|---|---|---|---|
| distance.function | l2_distancecosine_distancenegative_dot_productjaccard_distancehamming_distance | cosine_distance | For convenience, please use negative_dot_product for dot product scenarios |
| scalar.type | f32, f16, i8, b1 | f32 | The type of vector elements in the vector index, which can be different from the vector column |
| m | Recommended not to exceed 1000 | 16 | Maximum number of neighbors in the HNSW algorithm |
| ef.construction | Recommended not to exceed 5000 | 128 | Size of the candidate set when constructing the index in the HNSW algorithm |
| reuse.vector.column | false/true | false | Whether to reuse the data of the vector column to save storage space |
| compress.codec | uncompressed/zstd/lz4 | uncompressed | Compression algorithm for the vector index; not effective when reusing the column |
| compress.level | fatest/default/best | default | Compression algorithm level |
| compress.byte.stream.split | false/true | true | Rearrange float bits before compression |
| compress.block.size | Integer greater than 1M | 16777216 | Compression block size |
| conversion.rule | default/as_bits | default | When 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 Type | Supported Vector Element Types | Remarks |
| b1 | tinyint, int, float | When "conversion.rule" = "as_bits", each bit in vector(tinyint, N) is treated as an element in the vector. When "conversion.rule" = "default", the vector is binarized. |
| i8 | tinyint, int, float | When the vector element type is inconsistent with the index, cast is performed (note that overflow may occur). |
| f16 | int, float | When the vector element type is inconsistent with the index, cast is performed. |
| f32 | int, float | When the vector element type is inconsistent with the index, cast is performed. |
Examples
Reference Documentation
User Guide
Add Vector Index to Existing Table
Syntax
VECTOR: Index type, vector index
index_name: Index name, located under the schema of the target table. Index names cannot be duplicated within the same schema. The index must be in the same schema as the target table.
PROPERTIES: Specify parameters for INDEX
Description
Executing CREATE INDEX is only effective for new data. Existing data requires BUILD INDEX to build the vector index.
The index must be in the same schema as the target table; creating an index across schemas will result in an error.
Example
