TairVector provides global indexes (TairVectorGlobalIndex) based on data indexes (TairVectorIndex) for cluster instances in proxy mode.
Overview
After a global index is associated with data indexes, the global index can automatically implement load balancing. After you write data to a global index, Tair evenly distributes the data among the data indexes across different shards in the cluster instance. During a query, the global index also automatically aggregates the query results from each data index and returns the final result. The following figure shows the data structure of a global index.
After you create a global index, you can use the TVS.EXPANDINDEXGLOBAL command to create associated data indexes. Alternatively, you can use the TVS.IMPORTINDEXGLOBAL command to associate existing data indexes with the global index. These existing data indexes are created by using the TVS.CREATEINDEX command and share the same metadata as the global index. After data indexes are associated with the global index, you need to only perform operations on the global index.
You can also disassociate data indexes from global indexes.
Prerequisites
The instance is a Tair DRAM-based instance that is compatible with Redis 6.0 or later. For more information, see DRAM-based instances.
The instance is a cluster instance in proxy mode and the version of the proxy nodes is 7.0.10 or later.
The TairVector global index feature is enabled by setting the globalvectorindex_enabled parameter of the instance to 1. For more information, see Configure instance parameters.
Precautions
In most cases, a global index takes effect immediately after the TVS.CREATEINDEXGLOBAL, TVS.EXPANDINDEXGLOBAL, and TVS.IMPORTINDEXGLOBAL commands are run. However, the global index may not take effect immediately due to factors such as network latency and background synchronization. The maximum time for the global index to take effect does not exceed 30 seconds.
Do not directly delete a data index before it is disassociated from a global index. Otherwise, the
ERR there are vector indexes that don't exist, please check and retry
error is returned.
Supported commands
Table 1. TairVectorGlobalIndex commands
Type | Command | Syntax | Description |
Index operations |
| Creates a global index. This command allows you to specify the specific algorithm that is used to create the index and perform queries as well as the distance function. | |
| Creates data indexes in a global index. | ||
| Associates an existing data index with a global index. The metadata of the existing data index must be the same as that of the global index. | ||
| Queries the information about global indexes. | ||
| Disassociates a global index from its associated data indexes. If no data index is specified, the global index is deleted and all related data indexes are disassociated from the global index. | ||
Vector data operation |
| Inserts keys into a global index. After keys are inserted, Tair automatically writes the keys to the appropriate data indexes to ensure that data is evenly balanced across all data indexes. | |
| Queries all data records of a key in a global index. | ||
| Queries the values of attribute keys in the specified key of the specified vector index. | ||
| Deletes specific keys from a global index. | ||
| Deletes the specified attribute key and its value from the specified key of a global index. | ||
| Scans the keys that meet specific criteria in a global index. | ||
Vector nearest-neighbor queries |
| Queries the nearest-neighbor vectors of the specified vector in a global index. Up to 10,000 vectors can be returned. | |
| Queries the nearest-neighbor vectors of the specified vector in a global index. The search logic of this command is the same as that of TVS.KNNSEARCHGLOBAL, with the additional capability to return tag attributes along with the search results. |
The following list describes the conventions for the command syntax used in this topic:
Uppercase keyword
: indicates the command keyword.Italic text
: indicates variables.[options]
: indicates that the enclosed parameters are optional. Parameters that are not enclosed by brackets must be specified.A|B
: indicates that the parameters separated by the vertical bars (|) are mutually exclusive. Only one of the parameters can be specified....
: indicates that the parameter preceding this symbol can be repeatedly specified.
TVS.CREATEINDEXGLOBAL
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Creates a global index. This command allows you to specify the specific algorithm that is used to create the index and perform queries as well as the distance function. The global index can be deleted only by using the TVS.DELINDEXGLOBAL command. |
Parameter |
|
Output |
|
Example | Sample commands:
Sample output:
|
TVS.EXPANDINDEXGLOBAL
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Creates data indexes in a global index. When you specify the number of data indexes that you want to create and run this command, Tair automatically and evenly distributes these data indexes across different shards and assigns names to the data indexes. The metadata of the data indexes is the same as that of the global index. Although the data indexes are associated with the global index, they are stored independently in Tair. Note We recommend that you keep the number of data indexes in each global index equal to the number of shards in the instance. For example, if the Tair instance contains three shards and you use this command to create three data indexes, Tair creates a data index in each shard to implement load balancing. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
TVS.IMPORTINDEXGLOBAL
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Associates an existing data index with a global index. The metadata of the existing data index must be the same as that of the global index. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
TVS.LISTINDEXGLOBAL
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Queries the information about global indexes. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
TVS.DELINDEXGLOBAL
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Disassociates a global index from its associated data indexes. If no data index is specified, the global index is deleted and all related data indexes are disassociated from the global index. Note This command does not delete data indexes. To delete data indexes, use the TVS.DELINDEX command. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
TVS.HSETGLOBAL
Item | Description |
Syntax |
|
Time complexity | If the operation of inserting or updating data does not involve the creation or update of a vector value, the time complexity is O(1). Otherwise, the time complexity is O(log(N)), where N indicates the number of keys in the vector index. |
Command description | Inserts keys into a global index. After keys are inserted, Tair automatically writes the keys to the appropriate data indexes to ensure that data is evenly balanced across all data indexes. If a key already exists, its value is updated with the new value. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
TVS.HGETALLGLOBAL
Item | Description |
Syntax |
|
Time complexity | O(1)*M, where M indicates the number of data indexes. |
Command description | Queries all data records of a key in a global index. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
TVS.HMGETGLOBAL
Item | Description |
Syntax |
|
Time complexity | O(1)*M, where M indicates the number of data indexes. |
Command description | Queries the values of attribute keys in the specified key of the specified vector index. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
TVS.DELGLOBAL
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Deletes specific keys from a global index. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
TVS.HDELGLOBAL
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Deletes the specified attribute key and its value from the specified key of a global index. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
TVS.SCANGLOBAL
Item | Description |
Syntax |
|
Time complexity | O(N), where N indicates the number of keys in a data index. |
Command description | Scans the keys that meet specific criteria in a global index. Tair returns the results of only one data shard in each scan. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
TVS.KNNSEARCHGLOBAL
Item | Description |
Syntax |
|
Time complexity |
N indicates the number of keys in a data index, and M indicates the number of data indexes. |
Command description | Queries the nearest-neighbor vectors of the specified vector in a global index. Up to 10,000 vectors can be returned. For example, if you want to query the topN value, Tair retrieves the top N vectors from each data index. In this case, the maximum number of vectors is the |
Parameter |
|
Output |
|
Example | Run the following commands in advance:
Sample command 1:
Sample output 1:
Sample command 2:
Sample output 2:
|
TVS.KNNSEARCHFIELDGLOBAL
Item | Description |
Syntax |
|
Time complexity |
N indicates the number of keys in a data index, and M indicates the number of data indexes. |
Command description | Queries the nearest-neighbor vectors of the specified vector in a global index. The search logic of this command is the same as that of TVS.KNNSEARCHGLOBAL, with the additional capability to return tag attributes along with the search results. |
Parameter |
|
Output |
|
Example | Run the following commands in advance:
Sample command:
Sample output:
|