VECTOR_SEARCH
On this page
This topic explains how to use the VECTOR_SEARCH function to perform semantic searches. This function finds items that are semantically similar to a specified high-dimensional numerical vector.
While VECTOR_SEARCH is a generic function designed to work with any vector database, currently only Milvus is supported as a vector provider.
Limitations
- Version support:
- Supported in VERA Engine 4.3 or later.
- Vector database: Only Milvus is supported as the vector table.
- Stream type: Only non-updating streams are supported (containing only
INSERTmessages). - Execution mode: This function currently runs only in stream mode.
Syntax
1VECTOR_SEARCH(
2 TABLE search_table,
3 DESCRIPTOR(column_to_search),
4 column_to_query,
5 top_k[,
6 config]
7)Input Parameters
Return Value
The VECTOR_SEARCH function returns a table where each row contains all columns from the vector table and an additional score column (DOUBLE). The score indicates the similarity between the input data and the matched row.
Runtime Parameters
Example
The following example demonstrates how to perform a vector search against a Milvus table containing user data.
This example assumes you have a Milvus database populated with a table named people_demo. For details on setting up and populating a Milvus database, see the Milvus Connector documentation.
1. Create the Milvus Table
1CREATE TEMPORARY TABLE MilvusPeople (
2 id BIGINT NOT NULL,
3 name STRING,
4 age INT,
5 vec ARRAY<FLOAT>,
6 PRIMARY KEY (id) NOT ENFORCED
7) WITH (
8 'connector' = 'milvus',
9 'endpoint' = '54.247.193.222',
10 'port' = '19530',
11 'databaseName' = 'default',
12 'collectionName' = 'people_demo',
13 'userName' = 'user',
14 'password' = 'password',
15 'search.metric' = 'L2'
16);2. Define the Query View
1CREATE TEMPORARY VIEW QueryVectors AS
2SELECT *
3FROM (VALUES
4 (1, 'q_ada' , ARRAY[CAST(0.11 AS FLOAT), CAST(0.19 AS FLOAT), CAST(0.31 AS FLOAT)]),
5 (2, 'q_lin' , ARRAY[CAST(0.39 AS FLOAT), CAST(0.52 AS FLOAT), CAST(0.61 AS FLOAT)]),
6 (3, 'q_nils', ARRAY[CAST(0.71 AS FLOAT), CAST(0.79 AS FLOAT), CAST(0.88 AS FLOAT)])
7) AS t(qid, label, qvec);3. Execute Vector Search
1SELECT
2 q.qid,
3 q.label,
4 r.id AS match_id,
5 r.name AS match_name,
6 r.age AS match_age,
7 r.score
8FROM QueryVectors AS q
9CROSS JOIN LATERAL TABLE(
10 VECTOR_SEARCH(
11 TABLE => TABLE MilvusPeople,
12 COLUMN_TO_SEARCH => DESCRIPTOR(vec),
13 COLUMN_TO_QUERY => q.qvec,
14 TOP_K => 2,
15 MAP['async', 'false']
16 )
17) AS r(id, name, age, vec, score);