milvus-logo
LFAI
< Docs
  • Python

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 collection.StringTrue
schemaSchema of the collection to create. A schema specifies the properties of a collection and the fields within. See Schema for more information.class schema.CollectionSchemaFalse
usingMilvus connection used to create the collection.StringFalse
shards_numShard number of the collection to create.
It corresponds to the number of data nodes used to insert data.
INT32False
kwargs: consistency_levelConsistency level used to create the collection.String/IntegerFalse

Return

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

Properties

PropertyDescriptionType
nameName of the collection.String
schemaSchema of the collection.class schema.CollectionSchema
descriptionDescription of the collection.String
is_emptyBoolean value to indicate if the collection is empty.Bool
num_entitiesNumber of entities in the collection.Integer
primary_fieldSchema of the primary field in the collection.class schema.FieldSchema
partitionsList of all partitions in the collection.list[String]
indexesList of all indexes in the collection.list[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
  }
Feedback

Was this page helpful?