Create and Drop a Collection

This article provides Python sample codes for creating or dropping collections.

See example program for more detailed usage.
See example program for more detailed usage.

Create a collection

  1. Prepare the parameters needed to create the collection:
# Create a collection of 4 fields, where fields A, B, and C are int type fields
# and Vec is a 128-dimension float vector field.
# The default value of segment_row_limit is 524288 if not specified.
# If you set auto_id to True, you have Milvus create entity IDs. 
>>> collection_param = {
...    "fields": [
...        {"name": "A", "type": DataType.INT32},
...        {"name": "B", "type": DataType.INT32},
...        {"name": "C", "type": DataType.INT64},
...        {"name": "Vec", "type": DataType.FLOAT_VECTOR, "params": {"dim": 128}}
...    ],
...    "segment_row_limit": 100000,
...    "auto_id": True
... }
   // Basic create collection:
   // We will create a collection with three fields: film  duration, release_year and an
   // embedding which is essentially a float vector.
   // CollectionMapping will be used to create a collection. When adding vector fields, the
   // dimension must be specified. `auto_id` is set to false so we can provide custom ids.
    final int dimension = 8;
    final String collectionName = "demo_films";
    CollectionMapping collectionMapping = CollectionMapping
        .create(collectionName)
        .addField("duration", DataType.INT32)
        .addField("release_year", DataType.INT64)
        .addVectorField("embedding", DataType.VECTOR_FLOAT, dimension)
        .setParamsInJson("{\"segment_row_limit\": 4096, \"auto_id\": false}");
  1. Create a collection with a name test01.
# Create a collection.
>>> client.create_collection('test01', collection_param)
client.createCollection(collectionMapping);

Drop a collection

# Drop a collection.
>>> client.drop_collection('test01')
client.dropCollection(collectionName);

FAQ

Can I update segment_row_limit and metric_type after creating a collection? No, you cannot.
Is there a limit on the total number of collections and partitions? Yes. The total number of collections and partitions must not exceed 4,096.
Edit
© 2019 - 2020 Milvus. All rights reserved.