Skip to main content

VECTOR_SEARCH

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.

note

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 INSERT messages).
  • Execution mode: This function currently runs only in stream mode.

Syntax

VECTOR_SEARCH(
TABLE search_table,
DESCRIPTOR(column_to_search),
column_to_query,
top_k[,
config]
)

Input Parameters

ParameterData typeDescription
TABLE search_tableTABLEThe name of the vector table (e.g., a Milvus table).
DESCRIPTOR(column_to_search)DESCThe indexed vector column within the vector table used for similarity comparison.
column_to_queryARRAY<FLOAT> / ARRAY<DOUBLE>The vector feature column from the input data (e.g., an embedding).
top_kINTThe maximum number of similar entries to return.
configMAP<STRING, STRING>Optional runtime 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

ParameterData typeDefaultDescription
asyncBooleanNoneEnables asynchronous mode. Note: Currently not supported by the Milvus provider in VERA.
max-concurrent-operationsInteger10Maximum number of concurrent requests in asynchronous mode.
output-modeEnumORDEREDOutput mode for asynchronous operations: ORDERED or ALLOW_UNORDERED.
timeoutDuration3 minTimeout for an asynchronous operation.

Example

The following example demonstrates how to perform a vector search against a Milvus table containing user data.

note

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

CREATE TEMPORARY TABLE MilvusPeople (
id BIGINT NOT NULL,
name STRING,
age INT,
vec ARRAY<FLOAT>,
PRIMARY KEY (id) NOT ENFORCED
) WITH (
'connector' = 'milvus',
'endpoint' = '54.247.193.222',
'port' = '19530',
'databaseName' = 'default',
'collectionName' = 'people_demo',
'userName' = 'user',
'password' = 'password',
'search.metric' = 'L2'
);

2. Define the Query View

CREATE TEMPORARY VIEW QueryVectors AS
SELECT *
FROM (VALUES
(1, 'q_ada' , ARRAY[CAST(0.11 AS FLOAT), CAST(0.19 AS FLOAT), CAST(0.31 AS FLOAT)]),
(2, 'q_lin' , ARRAY[CAST(0.39 AS FLOAT), CAST(0.52 AS FLOAT), CAST(0.61 AS FLOAT)]),
(3, 'q_nils', ARRAY[CAST(0.71 AS FLOAT), CAST(0.79 AS FLOAT), CAST(0.88 AS FLOAT)])
) AS t(qid, label, qvec);
SELECT
q.qid,
q.label,
r.id AS match_id,
r.name AS match_name,
r.age AS match_age,
r.score
FROM QueryVectors AS q
CROSS JOIN LATERAL TABLE(
VECTOR_SEARCH(
TABLE => TABLE MilvusPeople,
COLUMN_TO_SEARCH => DESCRIPTOR(vec),
COLUMN_TO_QUERY => q.qvec,
TOP_K => 2,
MAP['async', 'false']
)
) AS r(id, name, age, vec, score);