This topic explains how to use k-nearest neighbor (KNN) vector queries in the Tablestore console or with Tablestore SDKs.
API
To perform a KNN vector query, call the Search operation and set the query type to KnnVectorQuery.
Parameters
|
Parameter |
Required |
Description |
|
fieldName |
Yes |
The name of the vector field. |
|
topK |
Yes |
The number of nearest neighbors to return. For the maximum value, see Search index limits. Important
A larger K value increases recall but also increases query latency and cost. |
|
float32QueryVector |
Yes |
The query vector used for the similarity search. |
|
minScore |
No |
The minimum score threshold. Only rows with a score greater than this value are returned. The value must be greater than or equal to 0. Default: 0. |
|
filter |
No |
A filter that supports any combination of non-vector query conditions. |
Procedure
If you encounter issues with KNN vector queries, submit a ticket or join DingTalk group 36165029092 (Tablestore Technical Discussion Group - 3) for assistance.
You can perform a KNN vector query in the Tablestore console or by using an SDK. Before you begin, complete the following tasks:
-
Create a RAM user and grant it permissions to perform operations on Tablestore. For more information, see Use the AccessKey pair of a RAM user to access Tablestore.
-
Create a data table. For more information, see Operations on a data table.
-
Configure a vector field when you create the search index. For more information, see Create a search index.
NoteIf a search index is already created, you can modify its schema. For more information, see Dynamically modify the schema of a search index.
FAQ
How do I optimize the performance of a KNN vector query in Tablestore?
Related documents
Search Index supports various query types for multi-dimensional data queries, including term query, terms query, match all query, match query, phrase match query, range query, prefix query, suffix query, wildcard query, token-based wildcard query, boolean query, geo query, nested query, vector search, and exists query.
When you query data, you can sort and paginate the result set or perform collapsing (deduplication).
For data analysis, such as finding the maximum or minimum value, calculating a sum, or counting rows, you can use the statistical aggregation or SQL query features.
To quickly export data regardless of the result set order, you can use the Parallel Scan feature.