milvus-logo
LFAI
< Docs
  • Python
    • MilvusClient

get()

This method grabs entities by primary keys. If output_fields is specified, this operation returns the specified field value only.

Invocation

get(
    collection_name,
    ids,
    output_fields,
    timeout
)

Parameters

ParameterDescriptionTypeRequired
collection_nameName of the collection where data is to grab.StringTrue
idsPrimary keys of the vectors to grab.Union[list, str, int]True
output_fieldsFields that are specified to return.String or INT64False
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 with primary keys and vector fields.

Raises

ValueError: Error if failed to grab vectors.

Example

  • Grab an entity by a primary key of a string:

    from pymilvus import MilvusClient
    
    client = MilvusClient(uri, token)
    
    client.get(
        collection_name='my-collection1',
        ids='pk1'
    )
    
  • Grab an entity by a primary key of an integer:

    from pymilvus import MilvusClient
    
    client = MilvusClient(uri, token)
    
    client.get(
        collection_name='my-collection2',
        ids=256
    )
    
  • Grab multiple entities and return specified fields:

    from pymilvus import MilvusClient
    
    client = MilvusClient(uri, token)
    
    client.get(
        collection_name='my-collection3',
        ids=['pk-1', 'pk-2'],
        output_fields=['claps','reading_time']
    )
    
Feedback

Was this page helpful?