searchIterator()
This operation conducts a scalar filtering with a specified boolean expression.
queryIterator(data): Promise<any>
Request Syntax
milvusClient.query({
db_name: string,
collection_name: string,
partition_names?: string[];
anns_field?: string;
data?: SearchDataType;
output_fields?: string[];
limit?: number;
filter?: string;
exprValues?: keyValueObj;
params?: keyValueObj;
metric_type?: string;
consistency_level?: ConsistencyLevelEnum;
ignore_growing?: boolean;
group_by_field?: string;
group_size?: number;
strict_group_size?: boolean;
hints?: string;
round_decimal?: number;
transformers?: OutputTransformers;
batchSize: number;
external_filter_fn: (row: SearchResultData) => boolean;
})
PARAMETERS:
db_name (string) -
The name of the database to which the target collection belongs.
collection_name (string) -
[REQUIRED]
The name of the collection to search
partition_names (string[]) -
A list of the names of the partitions to search.
anns_field (string) -
The name of the target vector field for this operation. It is mandatory if you are searching in a collection with multiple vector fields.
data (number[] | number[][]) -
A list of vector embeddings.
Milvus searches for the most similar vector embeddings to the specified ones.
output_fields (string[]) -
A list of field names to include in each entity in return.
The value defaults to None. If left unspecified, only the primary field is included.
limit (number) -
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.
In a grouping search, however,
limitspecifies the maximum number of groups to return, rather than individual entities. Each group is formed based on the specifiedgroup_by_field.filter (string) -
A scalar filtering condition to filter matching entities.
The value defaults to an empty string, indicating that no condition applies.
You can set this parameter to an empty string to skip scalar filtering. To build a scalar filtering condition, refer to Boolean Expression Rules.
exprValues (keyValueObj) -
If you choose to use placeholders in
filteras stated in Filtering Templating, then you can specify the actual values for these placeholders as key-value pairs as the value of this parameter.params (KeyValueObj) -
The additional search parameters in key-value pairs.
radius (number) -
Determines the threshold of least similarity. When setting
metric_typetoL2, ensure that this value is greater than that of range_filter. Otherwise, this value should be lower than that of range_filter.range_filter (number) -
Refines the search to vectors within a specific similarity range. When setting
metric_typetoIPorCOSINE, ensure that this value is greater than that of radius. Otherwise, this value should be lower than that of radius.max_empty_result_buckets (number)
This param is only used for range search for IVF-serial indexes, including BIN_IVF_FLAT, IVF_FLAT, IVF_SQ8, IVF_PQ, and SCANN. The value defaults to 1 and ranges from 1 to 65536.
During range search, the search process terminates early if the number of buckets with no valid range search results reaches the specified value. Increasing this parameter improves range search recall.
metric_type (string) -
The metric type used to measure similarity between vectors. The value varies with the vector field type. The following table lists the mapping between vector field types and their supported metric types.
Field Type
Dimension Range
Supported Metric Types
Default Metric Type
FLOAT_VECTOR2-32,768
COSINE,L2,IPCOSINEFLOAT16_VECTOR2-32,768
COSINE,L2,IPCOSINEBFLOAT16_VECTOR2-32,768
COSINE,L2,IPCOSINEINT8_VECTOR2-32,768
COSINE,L2,IPCOSINESPARSE_FLOAT_VECTORNo need to specify the dimension.
IP,BM25(used only for full text search)IPBINARY_VECTOR8-32,768*8
HAMMING,JACCARD,MHJACCARDHAMMINGconsistency_level (ConsistencyLevelEnum) -
The consistency level of the target collection. The value defaults to Bounded (1) with options of Strong (0), Bounded (1), Session (2), and Eventually (3).
ignore_growing (boolean) -
A boolean value indicating whether to skip the search in growing segments.
group_by_field (string) -
Groups search results by a specified field to ensure diversity and avoid returning multiple results from the same group.
group_size (number) -
The target number of entities to return within each group in a grouping search. For example, setting
group_size=2instructs the system to return up to 2 of the most similar entities (e.g., document passages or vector representations) within each group. Without settinggroup_size, the system defaults to returning only 1 entity per group.strict_group_size (boolean) -
This Boolean parameter dictates whether
group_sizeshould be strictly enforced. Whengroup_size=true, the system will attempt to fill each group with exactlygroup_sizeresults, as long as sufficient data exists within each group. If there is an insufficient number of entities in a group, it will return only the available entities, ensuring that groups with adequate data meet the specifiedgroup_size.hints (string) -
A hints string to improve search performance.
round_decimal (number) -
The number of decimal places to keep in the final results.
transformers (OutputTransformers) -
A custom function to convert data for the following data types:
BFloat16Vector (
(bf16bytes: Uint8Array) => BFloat16Vector;)Float16Vector (
(f16: Uint8Array) => Float16Vector;)SparseFloatVector (
(sparse: SparseVectorDic) => SparseFloatVector;)
batchSize (number) -
The number of entities to return each iteration.
external_filter_fn ((row: SearchResultData) => boolean) -
An external filtering function that takes the search results as the argument and filters out the entities that evaluate to
falsein the function.timeout (number) -
The timeout duration for this operation. Setting this to None indicates that this operation timeouts when any response arrives or any error occurs.
RETURNS Promise<SearchResults>
This method returns a promise that resolves to a SearchResults object.
{
status: object,
results: list[string],
recalls: list[number]
}
PARAMETERS:
status (object) -
code (number) -
A code that indicates the operation result. It remains 0 if this operation succeeds.
error_code (string | number) -
An error code that indicates an occurred error. It remains Success if this operation succeeds.
reason (string) -
The reason that indicates the reason for the reported error. It remains an empty string if this operation succeeds.
results (list[object]) -
Each result object has the following keys:
id (string) -
The ID of the search result
score(number) -
The similarity score of the search result.
Plus output fields and their values.
recalls (list[number]) -
Each number indicates the recall rate of a search against a query vector.
Example
const queryData = {
collection_name: 'my_collection',
expr: 'age > 30',
limit: 100,
pageSize: 10
};
const iterator = await queryIterator(queryData);
for await (const batch of iterator) {
console.log(batch); // Process each batch of query results
}