For clusters in proxy mode, TairVector provides a global index (TairVectorGlobalIndex) built on the data index (TairVectorIndex).
Overview
Once associated with data indexes, a global index automatically handles load balancing. When you write data to the global index, Tair evenly distributes the data to the data indexes across different shards in the cluster. During a query, the global index also aggregates the results from each data index and returns the final, combined result. The data structure of a global index is as follows:
After you create a global index, you can use the TVS.EXPANDINDEXGLOBAL command to directly create the corresponding data indexes. Alternatively, you can use the TVS.IMPORTINDEXGLOBAL command to associate existing data indexes with the global index. These data indexes must be created with the TVS.CREATEINDEX command, and their metadata must match that of the global index. Once associated, you only need to work with the global index.
You can also disassociate a data index from a global index.
Prerequisites
-
The instance is DRAM-based (compatible with Redis 6.0 and later).
-
The instance must be a cluster instance in proxy mode, with a proxy version of 7.0.10 or later.
-
The TairVector global index feature must be enabled. To enable this feature, set the globalvectorindex_enabled instance parameter to 1. For more information, see Set parameters.
Precautions
-
A global index is typically available immediately after you run the TVS.CREATEINDEXGLOBAL, TVS.EXPANDINDEXGLOBAL, or TVS.IMPORTINDEXGLOBAL commands. However, network latency and background synchronization can cause a brief delay of up to 30 seconds.
-
Do not delete a data index before disassociating it from the global index. Otherwise, the system will return the
ERR there are vector indexes that don't exist, please check and retryerror.
Commands
Table 1. TairVector global index commands
|
Type |
Command |
Syntax |
Description |
|
Index operation |
|
Creates a global index and specifies the algorithm and distance function for index building and querying. |
|
|
|
Creates data indexes in a global index. |
||
|
|
Binds an existing data index to a global index. The metadata of the existing data index must match that of the global index. |
||
|
|
Lists information about one or more global indexes. |
||
|
|
Disassociates a global index from one or more data indexes. If you do not specify any data indexes, this command deletes the global index and disassociates all related data indexes. |
||
|
Vector data operation |
|
Inserts a data record (identified by a key) into a global index. Tair automatically writes the key to an appropriate data index to ensure data balancing. |
|
|
|
Returns all attributes and values of the record for a specified key in a global index. |
||
|
|
Returns the values of one or more specified attribute_keys for a key in a global index. |
||
|
|
Deletes the data record specified by the key from the full index. |
||
|
|
Deletes the specified attribute_key and its value from the data record (key) in the full index. |
||
|
|
In the global index, scan for data records that meet the specified condition (key). |
||
|
Vector nearest-neighbor query |
|
Performs a nearest neighbor query for a specified vector in a global index and returns up to topN results. |
|
|
|
Searches for the nearest neighbors of a specified vector in a global index. The search logic is the same as for TVS.KNNSEARCHGLOBAL, but this command can also return tag attributes. |
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
|
Category |
Description |
|
Syntax |
|
|
Time complexity |
O(1) |
|
Command description |
Creates a global index and specifies the algorithm and distance function for index building and querying. A global index can be deleted only with the TVS.DELINDEXGLOBAL command. |
|
Options |
|
|
Return value |
|
|
Examples |
Command examples:
All examples return the following:
|
TVS.EXPANDINDEXGLOBAL
|
Item |
Description |
|
Syntax |
|
|
Time complexity |
O(1) |
|
Command description |
Creates data indexes in a global index. When you specify the number of new data indexes to create, Tair automatically creates and names them, distributing them evenly across shards. The metadata of a data index is identical to that of the global index. Data indexes are associated with the global index but are stored independently in Tair. Note
We recommend matching the number of data indexes in a global index with the number of shards in the instance. For example, if a Tair instance has three shards and you create three data indexes, Tair creates one data index in each shard to achieve automatic load balancing. |
|
Parameter |
|
|
Return value |
|
|
Example |
Example command:
Example output:
|
TVS.IMPORTINDEXGLOBAL
|
Item |
Description |
|
Syntax |
|
|
Time complexity |
O(1) |
|
Command description |
Binds an existing data index to a global index. The metadata of the existing data index must match that of the global index. |
|
Parameter |
|
|
Output |
|
|
Example |
Example command:
Example output:
|
TVS.LISTINDEXGLOBAL
|
Category |
Description |
|
Syntax |
|
|
Time complexity |
O(1) |
|
Command description |
Lists information about one or more global indexes. |
|
Parameter |
|
|
Return value |
|
|
Example |
Command:
Output:
|
TVS.DELINDEXGLOBAL
|
Item |
Description |
|
Syntax |
|
|
Time complexity |
O(1) |
|
Command description |
Disassociates a global index from one or more data indexes. If you do not specify any data indexes, this command deletes the global index and disassociates all related data indexes. Note
This command does not delete data indexes. To delete a data index, run the TVS.DELINDEX command. |
|
Parameter |
|
|
Return value |
|
|
Example |
Command example:
Example output:
|
TVS.HSETGLOBAL
|
Category |
Description |
|
Syntax |
|
|
Time complexity |
The time complexity is O(1) if no vector is created or updated. Otherwise, the time complexity is O(log(N)), where N is the number of keys in the vector index. |
|
Command description |
Inserts a data record (identified by a key) into a global index. Tair automatically writes the key to an appropriate data index to ensure data balancing. If the record already exists, it is overwritten. |
|
Parameters |
|
|
Output |
|
|
Example |
Example command:
Example output:
|
TVS.HGETALLGLOBAL
|
Item |
Description |
|
Syntax |
|
|
Time complexity |
O(1) * M, where M is the number of data indexes. |
|
Command description |
Returns all attributes and values of the record for a specified key in a global index. |
|
Parameter |
|
|
Output |
|
|
Example |
Example command:
Example output:
|
TVS.HMGETGLOBAL
|
Item |
Description |
|
Syntax |
|
|
Time complexity |
O(1) * M, where M is the number of attribute keys. |
|
Command description |
Returns the values of one or more specified attribute_keys for a key in a global index. |
|
Parameters |
|
|
Output |
|
|
Example |
Sample command:
Sample output:
|
TVS.DELGLOBAL
|
Item |
Description |
|
Syntax |
|
|
Time complexity |
O(1) |
|
Command description |
Deletes the data record specified by the key from the full index. |
|
Parameters |
|
|
Return value |
|
|
Example |
Example command:
Example output:
|
TVS.HDELGLOBAL
|
Category |
Description |
|
Syntax |
|
|
Time complexity |
O(1) |
|
Command description |
Deletes the specified attribute_key and its value from the data record (key) in the full index. |
|
Parameters |
|
|
Output |
|
|
Example |
Example command:
Example output:
|
TVS.SCANGLOBAL
|
Item |
Description |
|
Syntax |
|
|
Time complexity |
O(N), where N is the number of keys in the global index. |
|
Command description |
In the global index, scan for data records that meet the specified condition (key). In a single scan, Tair returns results from only one data shard. |
|
Parameter |
|
|
Return value |
|
|
Example |
Command example:
Return example:
|
TVS.KNNSEARCHGLOBAL
|
Category |
Description |
|
Syntax |
|
|
Time complexity |
N is the number of keys in each data index, and M is the number of data indexes. |
|
Command description |
Performs a nearest neighbor query for a specified vector in a global index and returns up to topN results. For example, if you want to query for the topN results, Tair first retrieves topN results from each data index. At this point, there can be a maximum of |
|
Options |
|
|
Return value |
|
|
Example |
Run the following commands first:
Sample command 1:
Sample output 1:
Sample command 2:
Sample output 2:
|
TVS.KNNSEARCHFIELDGLOBAL
|
Item |
Description |
|
Syntax |
|
|
Time complexity |
N is the number of keys in a data index, and M is the number of data indexes. |
|
Command description |
Searches for the nearest neighbors of a specified vector in a global index. The search logic is the same as for TVS.KNNSEARCHGLOBAL, but this command can also return tag attributes. |
|
Options |
|
|
Return value |
|
|
Example |
Run the following commands first:
Example command:
Example output:
|