VECTOR_SEARCH_AGG

Updated at:

VECTOR_SEARCH_AGG searches a Milvus vector table for the top-K most similar records and returns all matches as a single array. Unlike VECTOR_SEARCH, VECTOR_SEARCH_AGG returns one row per input record, with all matches packed into an ARRAY<ROW> column named search_results.

Limitations

  • Stream mode is supported from VVR 11.3, and batch mode is supported from VVR 11.4.

  • The OUTPUT_COLUMNS parameter is supported from VVR 11.9 and later.

  • Only Milvus is supported as the vector table for searches.

  • Only append-only streams are supported. An append-only stream contains only INSERT messages.

Syntax

VECTOR_SEARCH_AGG(
  SEARCH_TABLE => TABLE <SEARCH_TABLE>,
  COLUMN_TO_SEARCH => DESCRIPTOR(<COLUMN_TO_SEARCH>),
  COLUMN_TO_QUERY => <COLUMN_TO_QUERY>,
  TOP_K => <TOP_K>
  [, CONFIG => <CONFIG>]
  [, OUTPUT_COLUMNS => DESCRIPTOR(<OUTPUT_COLUMN>[, ...])]
)

Input parameters

Parameter

Data type

Description

TABLE <SEARCH_TABLE>

TABLE

The name of the vector table.

DESCRIPTOR(<COLUMN_TO_SEARCH>)

DESC

The indexed vector column in the vector table. Input data is compared with the specified vector column to compute similarity.

COLUMN_TO_QUERY

ARRAY<FLOAT>/ARRAY<DOUBLE>

The vector feature column in the input, such as the embedding of an uploaded image or text, which is matched against the indexed vector column by similarity.

TOP_K

INT

The maximum number of similar records to return.

CONFIG

MAP<STRING,STRING>

Configurable Runtime parameters.

OUTPUT_COLUMNS

DESC

Optional. The vector search result fields to return in each array element. You can select the top-level fields of the vector table and the score similarity field generated by the engine. The field order matches the declaration order in DESCRIPTOR. If you don't specify this parameter, all fields of the vector table and score are returned.

Return value

VECTOR_SEARCH_AGG returns a table that contains a single record, with the schema ROW<ARRAY>.

The array column is named search_results. If OUTPUT_COLUMNS is not specified, each ROW contains all columns of the vector table and an extra score field, which matches the behavior of earlier versions. If OUTPUT_COLUMNS is specified, each ROW contains only the specified fields, ordered as declared in DESCRIPTOR.

The score field is of the DOUBLE type and describes the similarity between the input and a search result. You can also select or prune it through OUTPUT_COLUMNS. If the vector table already has a column named score, the engine picks a unique name for the generated similarity field, such as score0. In this case, use the actual field name in OUTPUT_COLUMNS.

OUTPUT_COLUMNS can't be empty, doesn't support nested fields, and can't contain duplicate fields.

Runtime parameters

Parameter

Data type

Default value

Description

async

Boolean

(none)

Whether async mode is enabled. If the connector of the vector table doesn't support the specified mode, the engine reports an error.

By default, the engine chooses the execution mode based on the modes the connector supports. If both asynchronous and synchronous modes are supported, the engine prefers asynchronous mode for higher overall throughput.

max-concurrent-operations

Integer

10

The maximum number of concurrent requests in async mode.

output-mode

Enum

ORDERED

The output mode of asynchronous operations.

Valid values:

  • ORDERED

  • ALLOW_UNORDERED

For the meaning of the two values, see Async I/O.

timeout

Duration

3min

The timeout from the first call until the asynchronous operation completes. The period can cover multiple retries and is reset on failover.

Example

Sample data

Assume that the vector table vector_table contains the following data:

id

topic

vector_index

1

'BigData'

[1, 1, 0]

2

'Streaming'

[-5, -12, -13]

3

'Batch'

[5, 12, 13]

Assume that the query table query_table contains the following data:

id

user_keyword

embedding

1

'Spark'

[5, 12, 13]

2

'Flink'

[-5, -12, -13]

Sample statements

For each row in query_table, the following SQL searches vector_table and returns the two most similar records.

SELECT user_keyword, search_results
FROM
  query_table,
  LATERAL TABLE (VECTOR_SEARCH_AGG(
    SEARCH_TABLE => TABLE vector_table,
    COLUMN_TO_SEARCH => DESCRIPTOR(vector_index),
    COLUMN_TO_QUERY => query_table.embedding,
    TOP_K => 2,
    CONFIG => MAP['async', 'false'], -- Enable synchronous mode
    OUTPUT_COLUMNS => DESCRIPTOR(topic, score)
    ))

Sample output

user_keyword

search_results

'Spark'

[('Batch', 1.0), ('BigData', 0.6538461538461539)]

'Flink'

[('Streaming', 1.0), ('BigData', -0.6538461538461539)]