milvus-logo
Star
0
Forks
0
Get Started

search()

This method conducts a vector similarity search in a specified partition.

Invocation

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

Parameters

ParameterDescriptionTypeRequired
dataData to search withlist[list[Float]]True
anns_fieldName of the vector field to search onStringTrue
paramSpecific search parameter(s) of the index on the vector fieldDictTrue
limitNumber of nearest records to returnIntegerTrue
exprBoolean expression to filter the dataStringFalse
output_fieldsList of names of fields to outputlist[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 distanceIntegerFalse
kwargs
  • _async
  • _callback
  • consistency_level
  • guarantee_timestamp
  • graceful_time
  • travel_timestamp

  • Boolean value to indicate if to invoke asynchronously
  • Function that will be invoked after server responds successfully. It takes effect only if _async is set to True.
  • Consistency level used in the search
  • Milvus searches on the data view before this timestamp when it is provided. Otherwise, it searches the most updated data view. It can be only used in Customized level of consistency.
  • PyMilvus will use current timestamp minus the graceful_time as the guarantee_timestamp for search. It can be only used in Bounded level of consistency.
  • Timestamp 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.

  • Bool
  • Function
  • String/Integer
  • Integer
  • Integer
  • Integer
False

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.
  • BaseException: error if the return result from server is not ok.

Example

search_params = {"metric_type": "L2", "params": {"nprobe": 10}}
from pymilvus import Partition
partition = Partition("novel")
results = partition.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