Select Statements
When vector-distance operators appear within aSELECT statement, the following behavior applies:
When the operator is not combined with ORDER BY and LIMIT, an exact match is applied. That implies full table (or index) scan.
Examples:
ORDER_BY and LIMIT , the following rules apply:
- If there is no vector index for that distance metric, exact match is applied. That implies full table (or index) scan.
- If there is one vector index for that distance metric, approximate match is applied.
- If there is more than one vector index for that distance metric, the query must specify which vector index to use using the
index_typeparam described below.
Query Parameters
The Supported query parameters
The following are query parameters specific to vector index searches.search_type = { EXACT | IVEFLAT } Specifies whether the approximate or exact search should be done. Note that this can be used to override the rules defined above. In particular, it can be used to force an exact search where otherwise an approximate search would be performed.
Index_type = { HNSW | IVFFLAT } Specifies which index type to use. This is required when there are two vector indexes for the same column and the same distance metric.
hnsw_ef_search = number This parameter is relevant to search using HNSW index. It specifies the size of the dynamic candidate list for searching the graph. Valid values are integers from 1 to 65535 inclusive. If not specified, it defaults to 64.
ivfflat_probes = number This parameter is relevant to search using IVFFLAT index. Specifies the number of clusters to search in. Valid values are integers from 1 to the number of clusters (which was determined in creation). If not specified, it defaults to 1.
modules = (module_name [, ...]) By default, a vector index search is performed on all the modules that have a complete vector index. You may specify specific module(s) and limit the query to those modules.
Examples
In the following examples, assume all vector columns have vector indexes.Limitations for Approximate Search Queries
The following limitations apply to approximate search queries:OFFSETis not supported with approximate search queries.LIMITis limited to 65535 with approximate search queries. If a higher number is specified, exact search is performed. Specifying aLIMIThigher than 65535 and parametersearch_type = APPROXis not allowed.- It is not allowed to include a vector distance expressions in a hierarchical
ORDER BYwithLIMITusing approximate search.
All those queries can be performed with exact search by omitting the
PARAMS (search_type = APPROX) clause.ORDER BY clause. Such query cannot use approximate search.
Approximate search is not allowed on intermediate results such as join queries, only on table queries. For example: