创建、删除集合

本页提供创建或删除集合的示例代码。

参考 示例程序 获取更详细的使用方式。
参考 示例程序 获取更详细的使用方式。

创建集合

  1. 准备创建集合所需参数:
# 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. 创建集合名为 demo_films 的集合:
# Create a collection.
>>> client.create_collection('demo_films', collection_param)
client.createCollection(collectionMapping);

删除集合

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

常见问题

建立集合后,segment_row_limitmetric_type 还支持修改吗? 不支持。
Milvus 对集合和分区的总数有限制吗? 有。二者之和不能超过 4,096。
编辑
© 2019 - 2020 Milvus. All rights reserved.