This topic describes how to use the k-nearest neighbor (KNN) vector query feature to query data in the Tablestore console or by using Tablestore SDKs.
API operation
You can call the Search operation and set the query type to KnnVectorQuery to use the KNN vector query feature.
Parameters
Parameter | Required | Description |
fieldName | Yes | The name of the vector field. |
topK | Yes | The top K query results that have the highest similarity as the vector that you want to query. For information about the maximum value of the topK parameter, see Search index limits. Important
|
float32QueryVector | Yes | The vector for which you want to query the similarity. |
filter | No | The filter. You can use a combination of query conditions that are not KNN vector query conditions. |
Methods
If an exception occurs when you use the KNN vector query feature, submit a ticket.
You can use the Tablestore console or Tablestore SDKs to use the KNN vector query feature. Before you use the KNN vector query feature to query data, make sure that the following requirements are met:
A Resource Access Management (RAM) user is created and permissions to perform operations on Tablestore are granted to the RAM user. For more information, see Use the AccessKey pair of a RAM user to access Tablestore.
A data table is created. For more information, see Operations on a data table.
A Vector field is specified when you create a search index. For more information, see Create a search index.
NoteIf a search index is created, you can dynamically modify the schema of the search index. For more information, see Dynamically modify the schema of a search index.
FAQ
How do I optimize the performance of Tablestore KNN vector query?
References
When you use a search index to query data, you can use the following query methods: term query, terms query, match all query, match query, match phrase query, prefix query, range query, wildcard query, fuzzy query, Boolean query, geo query, nested query, KNN vector query, and exists query. You can select query methods based on your business requirements to query data from multiple dimensions.
You can sort or paginate rows that meet the query conditions by using the sorting and paging features. For more information, see Perform sorting and paging.
You can use the collapse (distinct) feature to collapse the result set based on a specific column. This way, data of the specified type appears only once in the query results. For more information, see Collapse (distinct).
If you want to analyze data in a data table, you can use the aggregation feature of the Search operation or execute SQL statements. For example, you can obtain the minimum and maximum values, sum, and total number of rows. For more information, see Aggregation and SQL query.
If you want to obtain all rows that meet the query conditions without the need to sort the rows, you can call the ParallelScan and ComputeSplits operations to use the parallel scan feature. For more information, see Parallel scan.