Skip to main content

Search (V2)

Milvus version compatibility
Server-side sorting, grouping, and search aggregation parameters (orderByFields, groupByFields, searchAggregation) take effect only on clusters compatible with Milvus v3.0.x or later. On Zilliz Cloud, serverless clusters are compatible with Milvus v3.0.x, while Dedicated clusters are compatible with Milvus v2.6.x unless upgraded to the v3.0.x Public Preview.

This operation conducts a vector similarity search with an optional scalar filtering expression.

POST/v2/vectordb/entities/search
Connection Endpoint

The base URL for this API is in the following format:

https://{cluster-id}.{region}.vectordb.zillizcloud.com:19530

📘Notes
  • Use the cluster endpoint if you are using serving clusters.
    • Free & Serverless

      https://{cluster-id}.serverless.{region}.vectordb.zillizcloud.com

    • Dedicated

      https://{cluster-id}.{region}.vectordb.zillizcloud.com:19530

  • You need to fill in ${CLUSTER_ENDPOINT} with that of your Zilliz Cloud cluster.
  • To get the endpoint, use the Describe Cluster V2 API to extract the values from the responses.
shell
export CLUSTER_ENDPOINT="https://{cluster-id}.{region}.vectordb.zillizcloud.com:19530"
Parameters
Authorizationstringheaderrequired

The authentication token should be an API key with appropriate privileges or a pair of colon-joined username and password, like username:password. If you are using a project endpoint, only a valid API key with sufficient permissions applies.

Example Value: Bearer {{TOKEN}}
Request Body
dbNamestring

The name of the database.

collectionNamestringrequired

The name of the collection to which this operation applies.

dataarrayrequired

A list of vector embeddings.
Zilliz Cloud searches for the most similar vector embeddings to the specified ones.
This parameter is mutually exclusive with ids.

[]dataarray

A vector embedding

idsarray

A list of primary keys.
Zilliz Cloud searches for the most similar vector embeddings to those in the specified entities.
This parameter is mutually exclusive with data.

annsFieldstring

The name of the vector field.

filterstring

The filter used to find matches for the search.

groupingFieldstring

Groups search results by a specified field to ensure diversity and avoid returning multiple results from the same group.

groupSizeinteger

The number of entities to return for each group. This parameter is only valid when groupingField is specified.

strictGroupSizeboolean

Whether to return only the top k entities for each group. This parameter is only valid when groupingField is specified.

limitinteger

The total number of entities to return. You can use this parameter in combination with offset in param to enable pagination. The sum of this value and offset in param should be less than 16,384.

offsetinteger

The number of records to skip in the search result. You can use this parameter in combination with limit to enable pagination. The sum of this value and limit should be less than 16,384.

outputFieldsarray

An array of fields to return along with the search results.

[]outputFieldsstring

A field name

searchParamsobject

The parameter settings specific to this operation.

metricTypestring

The name of the metric type that applies to the current search. The value should be the same as the metric type of the target collection.

paramsobject

Extra search parameters.

radiusnumber<float64>

Determines the threshold of least similarity. When setting metric_type to L2, ensure that this value is greater than that of range_filter. Otherwise, this value should be lower than that of range_filter.

range_filternumber<float64>

Refines the search to vectors within a specific similarity range. When setting metric_type to IP or COSINE, ensure that this value is greater than that of radius. Otherwise, this value should be lower than that of radius.

partitionNamesarray

The name of the partitions to which this operation applies. Setting this parameter indicates that the search is within the specified partitions. Otherwise, the search is across all partitions in the collection.

[]partitionNamesstring

A partition name.

consistencyLevelstring

The consistency level of the search operation. The value should be the same as the consistency level of the target collection.

exprParamsobject

A set of key-value pairs that can be filled back in to the filter parameter to enable filtering templating. For details, refer to Filter Templating.

functionScoreobject

Function settings for the current search request.

functionsarray

The functions applied when function-based scoring is used in the search request, listed in an array.

[]functionsobject

A single function definition, identified by name and type and bound to its input and output fields through inputFieldNames and outputFieldNames.

descriptionstring

The description of the function to apply.

inputFieldNamesarrayrequired

A list of scalar fields to use as input for the function.

[]inputFieldNamesstring

The name of a scalar field used as input to the function.

namestringrequired

The name of the function to apply.

outputFieldNamesarrayrequired

A list of vector fields to use as output for the function.

[]outputFieldNamesstring

The name of a vector field used as output for the function.

paramsobject

Extra parameters for the function in key-value pairs.

typestringrequired

The type of the function to apply.

paramsobject

Extra parameters for the function in key-value pairs.

paramsobject

Extra parameters for the search in key-value pairs.

functionChainsarray

Function chains applied during search reranking.

[]functionChainsobject

A function chain applied during search reranking.

namestringPublic Preview

The function-chain name.

stagestringrequiredPublic Preview

The execution stage of the function chain.

opsarrayrequired

The ordered operations in the function chain.

[]opsobjectrequired

An operation in a function chain.

opstringrequiredPublic Preview

The operation name.

exprobject

The optional expression evaluated by this operation.

namestringrequiredPublic Preview

The expression function name.

argsarray

The ordered expression arguments.

[]argsobject

An expression argument supplied as either a column or a literal.

columnstringPublic Preview

A column name. Exactly one of column and literal must be specified.

literalundefinedPublic Preview

A literal value. Exactly one of column and literal must be specified.

paramsobject

Expression parameters in key-value pairs.

inputsarray

Input column names.

[]inputsstringPublic Preview

An input column name.

outputsarray

Output column names.

[]outputsstringPublic Preview

An output column name.

paramsobject

Operation parameters in key-value pairs.

searchAggregationobject

Aggregation settings for the search results. This parameter cannot be combined with ids, offset, or grouping parameters.

fieldsarrayrequired

The non-empty scalar fields used to form aggregation buckets.

[]fieldsstringPublic Preview

A scalar field used to form aggregation buckets.

sizeintegerrequiredPublic Preview

The number of aggregation buckets to return.

Value Range: ≥ 1
searchSizeintegerPublic Preview

The number of buckets considered during search. When specified, it must be greater than or equal to size.

Value Range: ≥ 1
metricsobject

Named metric aggregations keyed by result name.

orderarray

Ordering rules for aggregation buckets.

[]orderobject

An ordering rule for aggregation buckets.

keystringrequiredPublic Preview

The bucket count or metric key used for ordering.

directionstringrequiredPublic Preview

The sort direction.

topHitsobject

Top-hit settings for each aggregation bucket.

sizeintegerrequiredPublic Preview

The number of top hits returned for each bucket.

Value Range: ≥ 1
sortarray

Sort rules for top hits.

[]sortobject

A sort rule for top hits.

fieldNamestringrequiredPublic Preview

The field used to sort top hits.

directionstringrequiredPublic Preview

The sort direction.

subAggregationobject

A nested aggregation applied within each bucket. A search aggregation may nest at most 3 levels of sub-aggregations beneath the top-level aggregation (4 levels in total; deeper requests are rejected).

fieldsarrayrequired

The non-empty scalar fields used to form aggregation buckets.

[]fieldsstringPublic Preview

A scalar field used to form aggregation buckets.

sizeintegerrequiredPublic Preview

The number of aggregation buckets to return.

Value Range: ≥ 1
searchSizeintegerPublic Preview

The number of buckets considered during search. When specified, it must be greater than or equal to size.

Value Range: ≥ 1
metricsobject

Named metric aggregations keyed by result name.

orderarray

Ordering rules for aggregation buckets.

[]orderobject

An ordering rule for aggregation buckets.

keystringrequiredPublic Preview

The bucket count or metric key used for ordering.

directionstringrequiredPublic Preview

The sort direction.

topHitsobject

Top-hit settings for each aggregation bucket.

sizeintegerrequiredPublic Preview

The number of top hits returned for each bucket.

Value Range: ≥ 1
sortarray

Sort rules for top hits.

[]sortobject

A sort rule for top hits.

fieldNamestringrequiredPublic Preview

The field used to sort top hits.

directionstringrequiredPublic Preview

The sort direction.

subAggregationobject (SearchAggregationRequest)

A nested aggregation applied within each bucket. A search aggregation may nest at most 3 levels of sub-aggregations beneath the top-level aggregation (4 levels in total; deeper requests are rejected).

orderByFieldsarray

The scalar fields used to sort the search results. Each item can be a field name, fieldName:asc, or fieldName:desc; the default sort direction is ascending.

[]orderByFieldsstringPublic Preview

One sort specification for the search results, given as a field name (sorted ascending by default), fieldName:asc, or fieldName:desc.

bash
export TOKEN="db_admin:xxxxxxxxxxxxx"

curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/entities/search" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Request-Timeout: 5" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "quick_setup",
"data": [
[
0.3580376395471989,
-0.6023495712049978,
0.18414012509913835,
-0.26286205330961354,
0.9029438446296592
]
],
"annsField": "vector",
"limit": 3,
"outputFields": [
"color"
],
"functionChains": [
{
"name": "l2",
"stage": "FunctionChainStageL2Rerank",
"ops": [
{
"op": "map",
"outputs": [
"new_score"
],
"expr": {
"name": "num_combine",
"args": [
{
"column": "$score"
},
{
"literal": 2.5
}
],
"params": {
"mode": "weighted"
}
}
}
]
}
],
"searchAggregation": {
"fields": [
"color"
],
"size": 10,
"order": [
{
"key": "_count",
"direction": "desc"
}
]
}
}'
Responses

Returns the search results.

One form of the successful response body, carrying the search results together with the topks and recalls arrays that describe each returned result group.

codeinteger

Response code.

costinteger

Cost of this operation. This applies to free and serverless clusters only, indicating the vCU usage of the current request.

dataarray

A list of entity objects.

[]dataobject

An entity object.

idoneOf

The primary key value of the returned entity. Milvus primary keys are Int64 or VarChar depending on the collection schema, so the value may arrive as a number or a string.

integer
(To be added soon)
string
(To be added soon)
distancenumber

The similarity distance between the query vector and this returned entity.

grpstring

The group that this result belongs to, present when groupingField is specified.

bucketsarray

Aggregated search buckets, present when searchAggregation is specified.

[]bucketsobject
countnumberPublic Preview

The number of entities aggregated into this bucket.

hitsarray

The search results aggregated into this bucket.

[]hitsobject
keyarray

The key values that define this bucket.

[]keyobject
fieldIdintegerPublic Preview

The ID of the field that defines this bucket.

fieldNamestringPublic Preview

The name of the field that defines this bucket.

metricsobject

Aggregation metrics computed over the hits in this bucket.

avgnumberPublic Preview

The average distance of the hits in this bucket.

maxnumberPublic Preview

The maximum distance of the hits in this bucket.

minnumberPublic Preview

The minimum distance of the hits in this bucket.

nnumberPublic Preview

The number of hits aggregated into this bucket.

totalnumberPublic Preview

The total distance of the hits in this bucket.

subGroupsarray

Nested sub-groups of this bucket.

[]subGroupsobject
recallsarray

Recall values for each search result group.

[]recallsnumber

The recall value for one search result group.

topksarray

The number of top-K results returned for each query vector.

[]topksinteger

The number of top-K results returned for one query vector.

scanned_remote_bytesinteger

Returned when the deployment uses tiered storage with usage tracking enabled and the operation reads from remote/disk storage. Omitted when all data is served from local cache.

scanned_total_bytesinteger

Returned when the deployment uses tiered storage with usage tracking enabled and the operation reads from remote/disk storage. Omitted when all data is served from local cache.

cache_hit_rationumber

Returned when the deployment uses tiered storage with usage tracking enabled and the operation reads from remote/disk storage. Omitted when all data is served from local cache.

aggTopksarray

The top-k limits of the aggregated search branches, present when searchAggregation is specified.

[]aggTopksnumberPublic Preview
(To be added soon)

Returns an error message.

codeinteger

Response code.

messagestring

Error message.

Successjson
{
"code": 0,
"data": [
{
"color": "orange_6781",
"distance": 1,
"id": 448300048035776800
},
{
"color": "red_4794",
"distance": 0.9353201,
"id": 448300048035776800
},
{
"color": "grey_8510",
"distance": 0.7733054,
"id": 448300048035776800
}
]
}