This method conducts a vector query.


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


exprBoolean expression to filter the data.StringTrue
partition_namesList of names of the partitions to search on.
All partition will be searched if it is left empty.
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
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 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


A list that contains all results.


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


from pymilvus import Collection
collection = Collection("book")      # Get an existing collection.
res = collection.query(
  expr = "book_id in [2,4,6,8]", 
  output_fields = ["book_id", "book_intro"],
sorted_res = sorted(res, key=lambda k: k['book_id'])