milvus-logo
Star
0
Forks
0
Get Started

search()

This method conducts a vector query in a specified partition.

Invocation

query(expr, output_fields=None, timeout=None, **kwargs)

Parameters

ParameterDescriptionTypeRequired
exprBoolean expression to filter the dataStringTrue
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
kwargs
  • consistency_level
  • guarantee_timestamp
  • graceful_time
  • travel_timestamp

  • 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.

  • String/Integer
  • Integer
  • Integer
  • Integer
False

Return

A list that contains all results.

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

from pymilvus import Partition
partition = Partition("novel")
res = collection.query(
  expr = "book_id in [2,4,6,8]", 
  output_fields = ["book_id", "book_intro"],
  consistency_level="Strong"
)
sorted_res = sorted(res, key=lambda k: k['book_id'])
sorted_res