milvus-logo
LFAI
< Docs
  • Python

search()

This method conducts a vector similarity search.

Invocation

search(data, anns_field, param, limit, expr=None, partition_names=None, output_fields=None, timeout=None, round_decimal=-1, **kwargs)

Parameters

ParameterDescriptionTypeRequired
dataData to search with.list[list[Float]]True
anns_fieldName of the vector field to search on.StringTrue
paramSpecific search parameter(s) of the index on the vector field.DictTrue
limitNumber of the nearest records to return.IntegerTrue
exprBoolean expression to filter the data.StringFalse
partition_namesList of names of the partitions to search on.
All partitions will be searched if it is left empty.
list[String]False
output_fieldsList of names of fields to output.list[String]False
timeoutAn optional duration of time in seconds to allow for the RPC. If it is set to None, the client keeps waiting until the server responds or error occurs.FloatFalse
round_decimalNumber of the decimal places of the returned distance.IntegerFalse
kwargs: _asyncBoolean value to indicate if to invoke this method asynchronously.BoolFalse
kwargs: _callbackFunction that will be invoked after server responds successfully. It takes effect only if _async is set to True.FunctionFalse
kwargs: consistency_levelConsistency level used in the search.String/IntegerFalse
kwargs: guarantee_timestampMilvus searches on the data view before this timestamp when it is provided. Otherwise, Milvus searches on the most updated data view. This parameter can only be used in the Customized level of consistency.IntegerFalse
kwargs: graceful_timeMilvus will use current timestamp minus the graceful_time as the guarantee_timestamp for search. This parameter can only be used in the Bounded level of consistency.IntegerFalse
kwargs: travel_timestampTimestamp that is used for Time Travel. Users can specify a timestamp in a search to get results based on a data view at a specified point in time.IntegerFalse

Return

A SearchResult object, an iterable, 2d-array-like class whose first dimension is the number of vectors to query (nq), and the second dimension is the number of limit (topk).

Raises

  • RpcError: error if gRPC encounter an error.
  • ParamError: error if the parameters are invalid.
  • DataTypeNotMatchException: error if wrong type of data is passed to server.
  • BaseException: error if the return result from server is not ok.

Example

search_params = {"metric_type": "L2", "params": {"nprobe": 10}}
from pymilvus import Collection
collection = Collection("book")      # Get an existing collection.
results = collection.search(
    data=[[0.1, 0.2]], 
    anns_field="book_intro", 
    param=search_params, 
    limit=10, 
    expr=None,
    consistency_level="Strong"
)
results[0].ids
results[0].distances
Feedback

Was this page helpful?