milvus-logo

Collection()

This is the constructor method to create a collection with the specified schema or to get an existing collection with the name.

Invocation

Collection(name, schema=None, using='default', shards_num=2, **kwargs)

Parameters

ParameterDescriptionTypeRequired
nameName of the collectionStringTrue
schemaSchema of the collection to createclass schema.CollectionSchemaFalse
usingMilvus Connection used to create the collectionStringFalse
shards_numShard number of the collection to create.
It corresponds to the number of data nodes used to insert data.
INT32False
kwargs: consistency_level
String/IntegerFalse

A schema specifies the properties of a collection and the fields within. See Schema for more information.

Return

A new collection object created with the specified schema or an existing collection object by name.

Properties

PropertyDescriptionType
nameName of the collectionString
schemaSchema of the collectionclass schema.CollectionSchema
descriptionDescription of the collectionString
is_emptyBoolean value to indicate if the collection is emptyBool
num_entitiesNumber of entities in the collectionInteger
primary_fieldSchema of the primary field in the collectionclass schema.FieldSchema
partitionsList of all partitions in the collectionlist[String]
indexesList of all indexes in the collectionlist[String]

Raises

CollectionNotExistException: error if the collection does not exist.

Example

from pymilvus import CollectionSchema, FieldSchema, DataType, Collection
book_id = FieldSchema(
  name="book_id", 
  dtype=DataType.INT64, 
  is_primary=True, 
)
word_count = FieldSchema(
  name="word_count", 
  dtype=DataType.INT64,  
)
book_intro = FieldSchema(
  name="book_intro", 
  dtype=DataType.FLOAT_VECTOR, 
  dim=2
)
schema = CollectionSchema(
  fields=[book_id, word_count, book_intro], 
  description="Test book search"
)
collection_name = "book"
collection = Collection(
    name=collection_name, 
    schema=schema, 
    using='default', 
    shards_num=2,
    consistency_level="Strong"
)
collection.schema
{
  auto_id: False
  description: Test book search
  fields: [{
    name: book_id
    description: 
    type: 5
    is_primary: True
    auto_id: False
  }, {
    name: word_count
    description: 
    type: 5
  }, {
    name: book_intro
    description: 
    type: 101
    params: {'dim': 2}
  }]
}
collection.description
'Test book search'
collection.name
'book'
collection.is_empty
True
collection.primary_field
{
    name: book_id
    description: 
    type: 5
    is_primary: True
    auto_id: False
  }