Synopsis
Description
A vector index can be created on a vector column to provide appropriate searches for vectors that are “close” to a given vector according to one of the distance metrics described in the previous section. Regatta supports two types of vector indexes:HNSW and IVFFLAT.
Each index type supports all the distance metrics, but each index uses a single distance metric and supports approximate searches only for that metric. Multiple vector indexes can be created for the same vector column, as long as they differ in the combination of index type and distance metric.
An index vector is created for all the rows of a table, or only for rows residing in specific modules. Modules can be added to and removed from the index at any time using the ALTER VECTOR INDEX command (see Modify Vector Indexes). However, once the index was built for a specific module, it does not change – it is not updated when rows are inserted or updated. In order to update the index for the rows residing in a module, the module should be removed from the index and added back. This will result in rebuilding the index for the module’s rows.
The CREATE VECTOR INDEX command creates the index and initiates the build process. It returns once the index was created and the build process was initiated. Only after the build process is completed, the index becomes usable for approximate vector search. The SHOW VECTOR INDEXES command (see Show Vector Indexes) can be used to query the status of the index.
Parameters
index_name The name of the index. If not specified, RegattaDB generates a name.ON table_name
Specifies the table containing the vector column to be indexed.
USING { HNSW | IVFFLAT }
This parameter indicates that the index is a vector index that supports approximate search.
column_name
Specifies the column to be indexed. The column must be of type vector.
distance_metric
This parameter can be one of the following:
COSINE – Cosine similarity between vectors.
L2 – Euclidean distance.
IP – Inner product (also known as dot product)
WITH ( option [, ... ] )
Specifies various options for the index creation. The options are listed below. Some of them apply to any vector index type, and some are specific to a certain type.
General Options
parallelism = {FULL, HIGH, MEDIUM, LOW}
This is a hint for determining the number of CPU cores that participate in the construction of the index in each module. The default value is FULL, which is the highest level of parallelism. The actual number of cores participating in the index construction is determined by an internal RegattaDB algorithm and depends on the actual number of cores.
The higher the parallelism is set, the faster the index will be built. On the other hand, highly-parallel build can potentially impact transaction performance, especially when that processing is CPU-intensive. If you create a vector index while the system is running a high load of mission-critical transaction processing, consider using this parameter to lower the parallelism of the index build to avoid impact to the transactions performance.
Modules = ((module_name [, parallelism]), ...)
Specifies a list of modules for which the vector index should be built, out of the modules in which the table resides. The index will be built only for rows residing in those modules. If this option is not specified, the index is built for all the table rows.
When modules are specified, an optional parallelism parameter can be used for each specified module. This allows setting parallelism on a per-module basis, overriding the index-wide parameter.
Modules can be added and removed using the
ALTER VECTOR INDEX command (see Modify Vector Indexes)Options for the HNSW Index Type
Options for the IVFFLAT Index Type
There is currently one option that applies only toIVFFLAT Index type.
lists | num_clusters
This option is applied in each module according to the number of rows residing in the module. The following values can be specified:
FUNCTION SQRT [ (c) ]
The number of clusters is the square root of the number of the rows, multiplied by a constant c. The argument c is optional, the default for c is 1.
FUNCTION DIV(n)
The number of clusters is the number of rows divided by n.
FUNCTION MIN_DIV_SQRT(n [, c])
The number of clusters is the minimum between DIV(n) and SQRT(c)
This parameter is optional. The default is FUNCTION MIN_DIV_SQRT(1000)
Example: