Docs Home
Viewing docs for
BYOCSelf-Managed

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.

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

SQL
1VECTOR_SEARCH(
2  TABLE search_table,
3  DESCRIPTOR(column_to_search),
4  column_to_query,
5  top_k[,
6  config]
7)

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.

1. Create the Milvus Table

SQL
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

SQL
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);
SQL
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);
Was this helpful?