milvus-logo
LFAI
< Docs
  • Python

create_collection()

This method creates a collection.

Invocation

create_collection(
    collection_name,
    dimension,
    primary_field_name,
    id_type,
    vector_field_name,
    metric_type,
    auto_id,
    timeout
)

Parameters

ParameterDescriptionTypeRequired
collection_nameName of the collection to create.StringTrue
dimensionVector dimension.IntegerTrue
primary_field_nameName of the primary key. Default value: id.StringFalse
id_typeData type of the primary key. Valid values: int or string.StringFalse
vector_field_nameName of the vector field.StringFalse
metric_typeMetric type for the collection. Default value: IP.StringFalse
auto_idWhether to automatically generate a unique ID for each new vector inserted into the collection. Default value: False.BooleanFalse
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 new collection object.

Raises

None

Example

  • Create a collection with a dynamic schema:

    from pymilvus import MilvusClient
    
    client = MilvusClient(uri, token)
    
    client.create_collection(
        collection_name='medium_articles',
        dimension=768
    )
    
  • Create a collection with a custom schema:

    from pymilvus import MilvusClient
    
    client = MilvusClient(uri, token)
    
    client.create_collection(
        collection_name='medium_articles',
        dimension=768,
        primary_field_name='custom_id',
        vector_field_name='vector_title'
    )
    
Feedback

Was this page helpful?