milvus-logo
LFAI
< Docs
  • Python
    • MilvusClient

search()

This method performs Approximate Nearest Neighbor (ANN) searches based on one or more vectors in a collection.

Invocation

search(
    collection_name,
    data,
    filter,
    limit,
    output_fields,
    search_params,
    timeout
)

Parameters

ParameterDescriptionTypeRequired
collection_nameName of the collection to search.StringTrue
dataVector data to search.list[]True
limitNumber of results to return per search. Default value: 10.IntegerFalse
filterFilter used to search.StringFalse
output_fieldsA list of fields to return.list[String]False
search_paramsParameters used to search.DictionaryFalse
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

Return

A list of dictionaries, excluding vector embeddings.

Raises

ValueError: Error if the collection being searched does not exist.

Example

  • Search with a single vector:

    from pymilvus import MilvusClient
    
    client = MilvusClient(uri, token)
    
    client.search(
        collection_name='medium_articles',
        data = [[-0.008266705,-0.009836753,0.04397694,-0.00025456678, ..., -0.016839132]],
        limit=5,
        output_fields=["title", "link"]
    )
    
  • Perform a bulk search with multiple vectors:

    from pymilvus import MilvusClient
    
    client = MilvusClient(uri, token)
    
    client.search(
        collection_name='medium_articles',
        data=[
                [-0.008266705,-0.009836753,0.04397694,-0.00025456678, ..., -0.016839132],
                [0.041732933, 0.013779674, -0.027564144, -0.013061441, ..., 0.030096486]
            ],
        limit=5,
        output_fields=["title", "link"]
    )
    
  • Search with filter expressions in a fixed schema:

    from pymilvus import MilvusClient
    
    client = MilvusClient(uri, token)
    
    client.search(
        collection_name='medium_articles',
        data = [[0.041732933, 0.013779674, -0.027564144, -0.013061441, ..., 0.030096486]],
        limit=5,
        filter="10 < reading_time < 15", # Filter articles with reading_time greater than 10 and less than 15.
        output_fields=["title", "link"]
    )
    
  • Search with filter expressions in a dynamic schema:

    from pymilvus import MilvusClient
    
    client = MilvusClient(uri, token)
    
    client.search(
        collection_name='medium_articles',
        data = [[0.041732933, 0.013779674, -0.027564144, -0.013061441, ..., 0.030096486]],
        limit=5,
        filter='$meta["claps"] > 30 and responses < 10',
        output_fields=['title', 'claps', 'responses']
    )
    

    The preceding code block shows how to access fields claps and responses that are not defined in the schema.

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Was this page helpful?