milvus-logo
LFAI
首页
  • 用户指南

管理 Collections

本指南将指导您使用所选的 SDK 创建和管理 Collections。

开始之前

概述

在 Milvus 中,您可以将向量嵌入存储在 Collections 中。一个 Collections 中的所有向量嵌入都具有相同的维度和距离度量相似性。

Milvus Collections 支持动态字段(即 Schema 中未预定义的字)和主键的自动递增。

为了适应不同的偏好,Milvus 提供了两种创建 Collections 的方法。其中一种提供快速设置,其他则允许对 Collections 模式和索引参数进行详细定制。

此外,你还可以在必要时查看、加载、释放和删除一个 Collection。

创建 Collections

您可以通过以下任一方式创建 Collections:

  • 快速设置

    在这种方式下,只需给集合命名并指定要存储在此集合中的向量嵌入的维数,即可创建集合。详情请参阅快速设置

  • 自定义设置

    与让 In Milvus 为你的 Collections 决定几乎所有事情不同,你可以自己决定 Collections 的Schema索引参数。详情请参阅自定义设置

快速设置

在人工智能行业大跃进的背景下,大多数开发人员只需要一个简单而又充满活力的 Collections 就可以开始使用了。Milvus 只需三个参数就能快速设置这样的 Collections:

  • 要创建的 Collections 名称、

  • 要插入的向量 Embeddings 的维度,以及

  • 用于衡量向量嵌入之间相似性的度量类型。

为了快速设置,请使用 create_collection()方法 MilvusClient类的方法创建一个具有指定名称和维度的 Collection。

如需快速设置,请使用 createCollection()方法创建一个具有指定名称和维度的集合。 MilvusClientV2类的方法创建一个具有指定名称和维度的 Collection。

快速设置时,使用 createCollection()方法创建一个具有指定名称和维度的集合。 MilvusClient类的方法创建一个具有指定名称和维度的 Collection。

如需快速设置,请使用 POST /v2/vectordb/collections/createAPI 端点创建具有指定名称和维度的 Collection。

from pymilvus import MilvusClient, DataType

# 1. Set up a Milvus client
client = MilvusClient(
uri="http://localhost:19530"
)

# 2. Create a collection in quick setup mode
client.create_collection(
collection_name="quick_setup",
dimension=5
)

res = client.get_load_state(
collection_name="quick_setup"
)

print(res)

# Output
#
# {
# "state": "<LoadState: Loaded>"
# }
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.service.collection.request.GetLoadStateReq;
import io.milvus.v2.service.collection.request.CreateCollectionReq;

String CLUSTER_ENDPOINT = "http://localhost:19530";

// 1. Connect to Milvus server
ConnectConfig connectConfig = ConnectConfig.builder()
    .uri(CLUSTER_ENDPOINT)
    .build();

MilvusClientV2 client = new MilvusClientV2(connectConfig);

// 2. Create a collection in quick setup mode
CreateCollectionReq quickSetupReq = CreateCollectionReq.builder()
    .collectionName("quick_setup")
    .dimension(5)
    .build();

client.createCollection(quickSetupReq);

// Thread.sleep(5000);

GetLoadStateReq quickSetupLoadStateReq = GetLoadStateReq.builder()
    .collectionName("quick_setup")
    .build();

Boolean res = client.getLoadState(quickSetupLoadStateReq);

System.out.println(res);

// Output:
// true
address = "http://localhost:19530"

// 1. Set up a Milvus Client
client = new MilvusClient({address});

// 2. Create a collection in quick setup mode
let res = await client.createCollection({
    collection_name: "quick_setup",
    dimension: 5,
});  

console.log(res.error_code)

// Output
// 
// Success
// 

res = await client.getLoadState({
    collection_name: "quick_setup"
})

console.log(res.state)

// Output
// 
// LoadStateLoaded
// 
$ export MILVUS_URI="localhost:19530"

$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/create" \
-H "Content-Type: application/json" \
-d '{
  "collectionName": "quick_setup",
  "dimension": 5
}'

# Output
#
# {
#     "code": 0,
#     "data": {},
# }

$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/get_load_state" \
-H "Content-Type: application/json" \
-d '{
  "collectionName": "quick_setup"
}'

# {
#     "code": 0,
#     "data": {
#         "loadProgress": 100,
#         "loadState": "LoadStateLoaded"
#     }
# }

上述代码生成的 Collections 只包含两个字段:id (作为主键)和vector (作为向量字段),默认情况下启用auto_idenable_dynamic_field 设置。

  • auto_id

    启用该设置可确保主键自动递增。数据插入时无需手动提供主键。

  • enable_dynamic_field

    启用后,待插入数据中除idvector 以外的所有字段都会被视为动态字段。这些附加字段以键值对的形式保存在一个名为$meta 的特殊字段中。此功能允许在插入数据时包含额外字段。

从提供的代码中自动索引和加载的 Collections 可以立即插入数据。

自定义设置

与其让 Milvus 为你的 Collections 决定几乎一切,你可以自己决定 Collections 的Schema索引参数

第一步:设置 Schema

Schema 定义了 Collections 的结构。在 Schema 中,您可以选择启用或禁用enable_dynamic_field 、添加预定义字段以及为每个字段设置属性。有关概念和可用数据类型的详细解释,请参阅Schema Explained

要设置模式,请使用 create_schema()创建模式对象,并使用 add_field()为模式添加字段。

要设置模式,使用 createSchema()创建模式对象,并使用 addField()为模式添加字段。

要设置模式,使用 createCollection().

要设置模式,您需要定义一个 JSON 对象,该对象应遵循模式格式,如 POST /v2/vectordb/collections/createAPI 端点参考页面上显示的模式格式定义一个 JSON 对象。

# 3. Create a collection in customized setup mode

# 3.1. Create schema
schema = MilvusClient.create_schema(
auto_id=False,
enable_dynamic_field=True,
)

# 3.2. Add fields to schema
schema.add_field(field_name="my_id", datatype=DataType.INT64, is_primary=True)
schema.add_field(field_name="my_vector", datatype=DataType.FLOAT_VECTOR, dim=5)
import io.milvus.v2.common.DataType;
import io.milvus.v2.service.collection.request.CreateCollectionReq;

// 3. Create a collection in customized setup mode

// 3.1 Create schema
CreateCollectionReq.CollectionSchema schema = client.createSchema();

// 3.2 Add fields to schema
schema.addField(AddFieldReq.builder()
    .fieldName("my_id")
    .dataType(DataType.Int64)
    .isPrimaryKey(true)
    .autoID(false)
    .build());

schema.addField(AddFieldReq.builder()
    .fieldName("my_vector")
    .dataType(DataType.FloatVector)
    .dimension(5)
    .build());
// 3. Create a collection in customized setup mode
// 3.1 Define fields
const fields = [
    {
        name: "my_id",
        data_type: DataType.Int64,
        is_primary_key: true,
        auto_id: false
    },
    {
        name: "my_vector",
        data_type: DataType.FloatVector,
        dim: 5
    },
]
export fields='[{ \
    "fieldName": "my_id", \
    "dataType": "Int64", \
    "isPrimary": true \
}, \
{ \
    "fieldName": "my_vector", \
    "dataType": "FloatVector", \
    "elementTypeParams": { \
        "dim": 5 \
    } \
}]'
参数 参数
auto_id 确定主字段是否自动递增。
设置为True 时,主字段将自动递增。在这种情况下,主字段不应包含在要插入的数据中,以免出错。自动生成的 ID 有固定长度,不能更改。
enable_dynamic_field 如果插入到目标 Collections 的数据包括未在 Collections 模式中定义的字段,则决定 Milvus 是否将未定义字段的值保存在动态字段中。
设置为"true "时,Milvus 将创建一个名为$meta的字段,用于保存插入数据中的任何未定义字段及其值。
field_name 字段的名称。
datatype 字段的数据类型。有关可用数据类型的列表,请参阅数据类型
is_primary 当前字段是否为集合中的主字段。
每个集合只有一个主字段。主字段应为DataType.INT64类型或DataType.VARCHAR类型。
dim 向量 Embeddings 的维数。
对于DataType.FLOAT_VECTORDataType .BINARY _ VECTORDataType. FLOAT16_VECTORDataType.BFLOAT16_VECTOR类型的字段,这是必填项。如果使用DataType.SPARSE_FLOAT_VECTOR,请省略此参数。
参数 说明
fieldName 字段的名称。
dataType 字段的数据类型。有关可用数据类型的列表,请参阅DataType
isPrimaryKey 当前字段是否为集合中的主字段。
每个集合只有一个主字段。主字段应为DataType.Int64类型或DataType.VarChar类型。
autoID 是否允许主字段自动递增。
设置为true 时,主字段将自动递增。在这种情况下,主字段不应包含在要插入的数据中,以免出错。
dimension 向量 Embeddings 的维数。
对于DataType.FloatVectorDataType .BinaryVectorDataType.Float16VectorDataType.BFloat16Vector类型的字段,此项为必填项。
参数 字段名称。
name 字段的名称。
data_type 字段的数据类型。有关所有可用数据类型的枚举,请参阅DataType
is_primary_key 当前字段是否为集合中的主字段。
每个集合只有一个主字段。主字段应为DataType.INT64类型或DataType.VARCHAR类型。
auto_id 主字段是否会在数据插入此 Collections 时自动递增。
默认值为 ""。设置为True 时,主字段将自动递增。如果需要使用自定义 Schema 设置 Collections,请跳过该参数。
dim 保存向量嵌入的 Collections 字段的维度。
该值应为大于 1 的整数,通常由用于生成向量嵌入的模型决定。
参数 描述
fieldName 要在目标 Collections 中创建的字段名称。
dataType 字段值的数据类型。
isPrimary 当前字段是否为主字段。将其设置为True 后,当前字段就是主字段。
elementTypeParams 额外字段参数。
dim FloatVector 或 BinaryVector 字段的可选参数,用于确定向量维度。

第二步:设置索引参数

索引参数决定了 Milvus 如何在 Collections 中组织数据。您可以通过调整metric_typeindex_type 来定制特定字段的索引过程。对于向量字段,您可以根据所处理的向量类型,灵活选择COSINE,L2,IP,HAMMINGJACCARD 作为metric_type 。更多信息,请参阅 "相似度指标"

要设置索引参数,请使用 prepare_index_params()准备索引参数,并使用 add_index()来添加索引。

要设置索引参数,请使用IndexParam

要设置索引参数,请使用 createIndex().

要设置索引参数,您需要定义一个 JSON 对象,该对象应遵循 API 端点参考页面上显示的索引参数格式。 POST /v2/vectordb/collections/createAPI 端点参考页面上显示的索引参数格式定义一个 JSON 对象。

# 3.3. Prepare index parameters
index_params = client.prepare_index_params()

# 3.4. Add indexes
index_params.add_index(
field_name="my_id",
index_type="STL_SORT"
)

index_params.add_index(
field_name="my_vector",
index_type="IVF_FLAT",
metric_type="IP",
params={ "nlist": 128 }
)
import io.milvus.v2.common.IndexParam;

// 3.3 Prepare index parameters
IndexParam indexParamForIdField = IndexParam.builder()
    .fieldName("my_id")
    .indexType(IndexParam.IndexType.STL_SORT)
    .build();

IndexParam indexParamForVectorField = IndexParam.builder()
    .fieldName("my_vector")
    .indexType(IndexParam.IndexType.IVF_FLAT)
    .metricType(IndexParam.MetricType.L2)
    .extraParams(Map.of("nlist", 1024))
    .build();

List<IndexParam> indexParams = new ArrayList<>();
indexParams.add(indexParamForIdField);
indexParams.add(indexParamForVectorField);
// 3.2 Prepare index parameters
const index_params = [{
    field_name: "my_id",
    index_type: "STL_SORT"
},{
    field_name: "my_vector",
    index_type: "IVF_FLAT",
    metric_type: "IP",
    params: { nlist: 1024}
}]
export indexParams='[{ \
    "fieldName": "my_id", \
    "indexName": "my_id", \
    "params": { \
        "index_type": "SLT_SORT" \
  } \
}, { \
    "fieldName": "my_vector", \
    "metricType": "COSINE", \
    "indexName": "my_vector", \
    "params": { \
        "index_type": "IVF_FLAT", \
        "nlist": 1024 \
  } \
}]'
参数 说明
field_name 应用此对象的目标文件名称。
index_type 用于在特定字段中排列数据的算法名称。有关适用算法,请参阅内存索引磁盘索引
metric_type 用于衡量向量间相似性的算法。可能的值有IPL2COSINEJACCARDHAMMING。只有当指定字段是向量字段时才可用。更多信息,请参阅Milvus 支持的索引
params 指定索引类型的微调参数。有关可能的键和值范围的详细信息,请参阅内存索引
参数 说明
fieldName 应用此 IndexParam 对象的目标字段的名称。
indexType 用于在特定字段中排列数据的算法名称。有关适用算法,请参阅内存索引磁盘索引
metricType 索引使用的距离度量。可能的值有IPL2COSINEJACCARDHAMMING
extraParams 额外的索引参数。有关详细信息,请参阅内存索引磁盘索引
参数 说明
field_name 要创建索引的目标字段的名称。
index_type 用于在特定字段中排列数据的算法名称。有关适用算法,请参阅内存索引磁盘索引
metric_type 用于衡量向量间相似性的算法。可能的值有IPL2COSINEJACCARDHAMMING。只有当指定字段是向量字段时才可用。更多信息,请参阅Milvus 支持的索引
params 指定索引类型的微调参数。有关可能的键和值范围的详细信息,请参阅内存索引
参数 说明
fieldName 要创建索引的目标字段的名称。
indexName 要创建的索引的名称。默认值为目标字段名称。
metricType 用于衡量向量间相似性的算法。可能的值有IPL2COSINEJACCARDHAMMING。只有当指定字段是向量字段时才可用。更多信息,请参阅Milvus 支持的索引
params 索引类型和相关设置。详情请参阅内存索引
params.index_type 要创建的索引类型。
params.nlist 群集单元数。这适用于与 IVF 相关的索引类型。

上面的代码片段演示了如何分别为向量场和标量场设置索引参数。对于向量场,同时设置度量类型和索引类型。对于标量字段,只需设置索引类型。建议为向量场和任何经常用于筛选的标量场创建索引。

第 3 步:创建 Collections

你可以选择分别创建 Collections 和索引文件,或者在创建 Collections 时同时加载索引。

使用create_collection()以指定的 Schema 和索引参数创建集合,并使用get_load_state()检查集合的加载状态。

使用createCollection()以指定的 Schema 和索引参数创建集合,并使用getLoadState()检查集合的加载状态。

使用createCollection()以指定的 Schema 和索引参数创建集合,并使用getLoadState()检查集合的加载状态。

  • 创建集合时同时加载索引。

    # 3.5. Create a collection with the index loaded simultaneously
    client.create_collection(
        collection_name="customized_setup_1",
        schema=schema,
        index_params=index_params
    )
    
    time.sleep(5)
    
    res = client.get_load_state(
    collection_name="customized_setup_1"
    )
    
    print(res)
    
    # Output
    #
    # {
    # "state": "<LoadState: Loaded>"
    # }
    
    import io.milvus.v2.service.collection.request.CreateCollectionReq;
    import io.milvus.v2.service.collection.request.GetLoadStateReq;
    
    // 3.4 Create a collection with schema and index parameters
    CreateCollectionReq customizedSetupReq1 = CreateCollectionReq.builder()
        .collectionName("customized_setup_1")
        .collectionSchema(schema)
        .indexParams(indexParams)
        .build();
    
    client.createCollection(customizedSetupReq1);
    
    // Thread.sleep(5000);
    
    // 3.5 Get load state of the collection
    GetLoadStateReq customSetupLoadStateReq1 = GetLoadStateReq.builder()
        .collectionName("customized_setup_1")
        .build();
    
    res = client.getLoadState(customSetupLoadStateReq1);
    
    System.out.println(res);
    
    // Output:
    // true
    
    // 3.3 Create a collection with fields and index parameters
    res = await client.createCollection({
        collection_name: "customized_setup_1",
        fields: fields,
        index_params: index_params,
    })
    
    console.log(res.error_code)  
    
    // Output
    // 
    // Success
    // 
    
    res = await client.getLoadState({
        collection_name: "customized_setup_1"
    })
    
    console.log(res.state)
    
    // Output
    // 
    // LoadStateLoaded
    //   
    
    $ curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/create" \
    -H "Content-Type: application/json" \
    -d '{
        "collectionName": "customized_setup_1",
        "schema": {
            "autoId": false,
            "enabledDynamicField": false,
            "fields": [
                {
                    "fieldName": "my_id",
                    "dataType": "Int64",
                    "isPrimary": true
                },
                {
                    "fieldName": "my_vector",
                    "dataType": "FloatVector",
                    "elementTypeParams": {
                        "dim": "5"
                    }
                }
            ]
        },
        "indexParams": [
            {
                "fieldName": "my_vector",
                "metricType": "COSINE",
                "indexName": "my_vector",
                "params": {
                    "index_type": "IVF_FLAT",
                    "nlist": "1024"
                }
            },
            {
                "fieldName": "my_id",
                "indexName": "my_id",
                "params": {
                    "index_type": "STL_SORT"
                }            
            }
        ]
    }'
    
    # Output
    #
    # {
    #     "code": 0,
    #     "data": {},
    # }
    
    $ curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/get_load_state" \
    -H "Content-Type: application/json" \
    -d '{
        "collectionName": "customized_setup_1"
    }'
    
    # {
    #     "code": 0,
    #     "data": {
    #         "loadProgress": 100,
    #         "loadState": "LoadStateLoaded"
    #     }
    # }
    

    上面创建的 Collection 会自动加载。要了解加载和释放集合的更多信息,请参阅加载释放集合

  • 分别创建 Collections 和索引文件。

    # 3.6. Create a collection and index it separately
    client.create_collection(
        collection_name="customized_setup_2",
        schema=schema,
    )
    
    res = client.get_load_state(
    collection_name="customized_setup_2"
    )
    
    print(res)
    
    # Output
    #
    # {
    # "state": "<LoadState: NotLoad>"
    # }
    
    // 3.6 Create a collection and index it separately
    CreateCollectionReq customizedSetupReq2 = CreateCollectionReq.builder()
        .collectionName("customized_setup_2")
        .collectionSchema(schema)
        .build();
    
    client.createCollection(customizedSetupReq2);
    
    // 3.4 Create a collection and index it seperately
    res = await client.createCollection({
        collection_name: "customized_setup_2",
        fields: fields,
    })
    
    console.log(res.error_code)
    
    // Output
    // 
    // Success
    // 
    
    res = await client.getLoadState({
        collection_name: "customized_setup_2"
    })
    
    console.log(res.state)
    
    // Output
    // 
    // LoadStateNotLoad
    // 
    
    $ curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/create" \
    -H "Content-Type: application/json" \
    -d '{
        "collectionName": "customized_setup_2",
        "schema": {
            "autoId": false,
            "enabledDynamicField": false,
            "fields": [
                {
                    "fieldName": "my_id",
                    "dataType": "Int64",
                    "isPrimary": true
                },
                {
                    "fieldName": "my_vector",
                    "dataType": "FloatVector",
                    "elementTypeParams": {
                        "dim": "5"
                    }
                }
            ]
            
        }
    }'
    
    # Output
    #
    # {
    #     "code": 0,
    #     "data": {},
    # }
    
    $ curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/get_load_state" \
    -H "Content-Type: application/json" \
    -d '{
        "collectionName": "customized_setup_2"
    }'
    
    # {
    #     "code": 0,
    #     "data": {
    #         "loadState": "LoadStateNotLoaded"
    #     }
    # }
    

    上面创建的 Collection 不会自动加载。您可以按如下方式为 Collections 创建索引。以单独的方式为 Collection 创建索引不会自动加载 Collection。有关详情,请参阅加载和释放 Collections

    参数 说明
    collection_name Collection 的名称。
    schema 此 Collection 的Schema
    设置为 "无 "表示将使用默认设置创建此 Collection。
    要使用自定义Schema设置 Collection,需要创建一个CollectionSchema对象并在此处引用它。在这种情况下,Milvus 会忽略请求中携带的所有其他 Schema 相关设置。
    index_params 在此 Collections 中建立向量字段索引的参数。要使用自定义 Schema 设置集合并自动将集合加载到内存中,需要创建一个 IndexParams 对象并在此处引用。
    至少应为此集合中的向量字段添加一个索引。如果希望稍后再设置索引参数,也可以跳过此参数。

    参数 说明
    collectionName Collections 的名称。
    collectionSchema 此 Collection 的 Schema。
    留空表示将以默认设置创建此 Collection。要使用自定义模式设置集合,需要创建一个CollectionSchema对象并在此处引用。
    indexParams 在此 Collection 中建立向量场索引的参数。要使用自定义Schema设置集合并自动将集合加载到内存中,需要创建一个包含IndexParam对象列表的IndexParams对象,并在此处引用该对象。

    参数 说明
    collection_name Collections 的名称。
    fields Collections 中的字段。
    index_params 要创建的 Collections 的索引参数。

    参数 说明
    collectionName Collections 的名称。
    schema Schema 负责组织目标 Collections 中的数据。一个有效的 Schema 应该有多个字段,其中必须包括一个主键、一个向量字段和几个标量字段。
    schema.autoID 是否允许主字段自动递增。设置为 True 时,主字段将自动递增。在这种情况下,主字段不应包含在要插入的数据中,以免出错。在 is_primary 设置为 True 的字段中设置此参数。
    schema.enableDynamicField 是否允许使用保留的 $meta 字段来保存键值对中的非 Schema 定义字段。
    fields 字段对象列表。
    fields.fieldName 要在目标 Collections 中创建的字段名称。
    fields.dataType 字段值的数据类型。
    fields.isPrimary 当前字段是否为主字段。将此设置为 True 时,当前字段就是主字段。
    fields.elementTypeParams 额外字段参数。
    fields.elementTypeParams.dim FloatVector 或 BinaryVector 字段的可选参数,用于确定向量维度。

    上面创建的 Collection 不会自动加载。你可以按以下方法为 Collections 创建索引。以单独方式为集合创建索引不会自动加载集合。有关详细信息,请参阅加载和释放集合

    # 3.6 Create index
    client.create_index(
        collection_name="customized_setup_2",
        index_params=index_params
    )
    
    res = client.get_load_state(
    collection_name="customized_setup_2"
    )
    
    print(res)
    
    # Output
    #
    # {
    # "state": "<LoadState: NotLoad>"
    # }
    
    CreateIndexReq  createIndexReq = CreateIndexReq.builder()
        .collectionName("customized_setup_2")
        .indexParams(indexParams)
        .build();
    
    client.createIndex(createIndexReq);
    
    // Thread.sleep(1000);
    
    // 3.7 Get load state of the collection
    GetLoadStateReq customSetupLoadStateReq2 = GetLoadStateReq.builder()
        .collectionName("customized_setup_2")
        .build();
    
    res = client.getLoadState(customSetupLoadStateReq2);
    
    System.out.println(res);
    
    // Output:
    // false
    
    // 3.5 Create index
    res = await client.createIndex({
        collection_name: "customized_setup_2",
        field_name: "my_vector",
        index_type: "IVF_FLAT",
        metric_type: "IP",
        params: { nlist: 1024}
    })
    
    res = await client.getLoadState({
        collection_name: "customized_setup_2"
    })
    
    console.log(res.state)
    
    // Output
    // 
    // LoadStateNotLoad
    //
    
    $ curl -X POST "http://${MILVUS_URI}/v2/vectordb/indexes/create" \
    -H "Content-Type: application/json" \
    -d '{
        "collectionName": "customized_setup_2",
        "indexParams": [
            {
                "metricType": "L2",
                "fieldName": "my_vector",
                "indexName": "my_vector",
                "indexConfig": {
                    "index_type": "IVF_FLAT",
                    "nlist": "1024"
                }
            }
        ]
    }'
    
    # Output
    #
    # {
    #     "code": 0,
    #     "data": {},
    # }
    
    $ curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/get_load_state" \
    -H "Content-Type: application/json" \
    -d '{
        "collectionName": "customized_setup_2"
    }'
    
    # {
    #     "code": 0,
    #     "data": {
    #         "loadState": "LoadStateNotLoaded"
    #     }
    # }
    
    参数 说明
    collection_name Collections 的名称。
    index_params IndexParams对象,包含一个IndexParam对象列表。
参数 说明
collectionName Collections 名称。
indexParams IndexParam对象列表。
参数 说明
collection_name Collections 的名称。
field_name 要创建索引的字段名称。
index_type 用于在特定字段中排列数据的算法名称。有关适用算法,请参阅内存索引磁盘索引
metric_type 用于衡量向量间相似性的算法。可能的值有IPL2COSINEJACCARDHAMMING。只有当指定字段是向量字段时才可用。更多信息,请参阅Milvus 支持的索引
params 指定索引类型的微调参数。有关可能的键和值范围的详细信息,请参阅内存索引
参数 说明
collectionName Collections 的名称。
indexParams 要创建的 Collection 的索引参数。
indexParams.metricType 用于建立索引的相似度度量类型。默认值为 COSINE。
indexParams.fieldName 要创建索引的目标字段的名称。
indexParams.indexName 要创建的索引的名称,值默认为目标字段名称。
indexParams.indexConfig.index_type 要创建的索引类型。
indexParams.indexConfig.nlist 群集单元数。这适用于与 IVF 相关的索引类型。

查看集合

要查看现有集合的详细信息,请使用describe_collection()

要查看现有集合的详细信息,请使用describeCollection()

要查看现有集合的详细信息,请使用describeCollection()

要查看 Collections 的定义,可以使用 POST /v2/vectordb/collections/describePOST /v2/vectordb/collections/listAPI 端点查看集合的定义。

# 5. View Collections
res = client.describe_collection(
    collection_name="customized_setup_2"
)

print(res)

# Output
#
# {
# "collection_name": "customized_setup_2",
# "auto_id": false,
# "num_shards": 1,
# "description": "",
# "fields": [
# {
# "field_id": 100,
# "name": "my_id",
# "description": "",
# "type": 5,
# "params": {},
# "element_type": 0,
# "is_primary": true
# },
# {
# "field_id": 101,
# "name": "my_vector",
# "description": "",
# "type": 101,
# "params": {
# "dim": 5
# },
# "element_type": 0
# }
# ],
# "aliases": [],
# "collection_id": 448143479230158446,
# "consistency_level": 2,
# "properties": {},
# "num_partitions": 1,
# "enable_dynamic_field": true
# }

import io.milvus.v2.service.collection.request.DescribeCollectionReq;
import io.milvus.v2.service.collection.response.DescribeCollectionResp;

// 4. View collections
DescribeCollectionReq describeCollectionReq = DescribeCollectionReq.builder()
    .collectionName("customized_setup_2")
    .build();

DescribeCollectionResp describeCollectionRes = client.describeCollection(describeCollectionReq);

System.out.println(JSONObject.toJSON(describeCollectionRes));

// Output:
// {
//     "createTime": 449005822816026627,
//     "collectionSchema": {"fieldSchemaList": [
//         {
//             "autoID": false,
//             "dataType": "Int64",
//             "name": "my_id",
//             "description": "",
//             "isPrimaryKey": true,
//             "maxLength": 65535,
//             "isPartitionKey": false
//         },
//         {
//             "autoID": false,
//             "dataType": "FloatVector",
//             "name": "my_vector",
//             "description": "",
//             "isPrimaryKey": false,
//             "dimension": 5,
//             "maxLength": 65535,
//             "isPartitionKey": false
//         }
//     ]},
//     "vectorFieldName": ["my_vector"],
//     "autoID": false,
//     "fieldNames": [
//         "my_id",
//         "my_vector"
//     ],
//     "description": "",
//     "numOfPartitions": 1,
//     "primaryFieldName": "my_id",
//     "enableDynamicField": true,
//     "collectionName": "customized_setup_2"
// }
// 5. View Collections
res = await client.describeCollection({
    collection_name: "customized_setup_2"
})

console.log(res)

// Output
// 
// {
//   virtual_channel_names: [ 'by-dev-rootcoord-dml_13_449007919953017716v0' ],
//   physical_channel_names: [ 'by-dev-rootcoord-dml_13' ],
//   aliases: [],
//   start_positions: [],
//   properties: [],
//   status: {
//     extra_info: {},
//     error_code: 'Success',
//     reason: '',
//     code: 0,
//     retriable: false,
//     detail: ''
//   },
//   schema: {
//     fields: [ [Object], [Object] ],
//     properties: [],
//     name: 'customized_setup_2',
//     description: '',
//     autoID: false,
//     enable_dynamic_field: false
//   },
//   collectionID: '449007919953017716',
//   created_timestamp: '449024569603784707',
//   created_utc_timestamp: '1712892797866',
//   shards_num: 1,
//   consistency_level: 'Bounded',
//   collection_name: 'customized_setup_2',
//   db_name: 'default',
//   num_partitions: '1'
// }
// 
curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/describe" \
-H "Content-Type: application/json" \
-d '{
    "dbName": "default",
    "collectionName": "test_collection"
}'

# {
#     "code": 0,
#     "data": {
#         "aliases": [],
#         "autoId": false,
#         "collectionID": 448707763883002014,
#         "collectionName": "test_collection",
#         "consistencyLevel": "Bounded",
#         "description": "",
#         "enableDynamicField": true,
#         "fields": [
#             {
#                 "autoId": false,
#                 "description": "",
#                 "id": 100,
#                 "name": "id",
#                 "partitionKey": false,
#                 "primaryKey": true,
#                 "type": "Int64"
#             },
#             {
#                 "autoId": false,
#                 "description": "",
#                 "id": 101,
#                 "name": "vector",
#                 "params": [
#                     {
#                         "key": "dim",
#                         "value": "5"
#                     }
#                 ],
#                 "partitionKey": false,
#                 "primaryKey": false,
#                 "type": "FloatVector"
#             }
#         ],
#         "indexes": [
#             {
#                 "fieldName": "vector",
#                 "indexName": "vector",
#                 "metricType": "COSINE"
#             }
#         ],
#         "load": "LoadStateLoaded",
#         "partitionsNum": 1,
#         "properties": [],
#         "shardsNum": 1
#     }
# }

要列出所有现有的 Collections,可以按以下方式操作:

# 6. List all collection names
res = client.list_collections()

print(res)

# Output
#
# [
# "customized_setup_2",
# "quick_setup",
# "customized_setup_1"
# ]
import io.milvus.v2.service.collection.response.ListCollectionsResp;

// 5. List all collection names
ListCollectionsResp listCollectionsRes = client.listCollections();

System.out.println(listCollectionsRes.getCollectionNames());

// Output:
// [
//     "customized_setup_2",
//     "quick_setup",
//     "customized_setup_1"
// ]
// 5. List all collection names
ListCollectionsResp listCollectionsRes = client.listCollections();

System.out.println(listCollectionsRes.getCollectionNames());

// Output:
// [
//     "customized_setup_1",
//     "quick_setup",
//     "customized_setup_2"
// ]
$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/list" \
-H "Content-Type: application/json" \
-d '{
    "dbName": "default"
}'

# {
#   "code": 0,
#   "data": [
#     "quick_setup",
#     "customized_setup_1",
#     "customized_setup_2"
#   ]
# }

加载和释放 Collections

在加载 Collection 的过程中,Milvus 会将 Collection 的索引文件加载到内存中。相反,在释放 Collections 时,Milvus 会从内存中卸载索引文件。在某个 Collection 中进行搜索之前,请确保该 Collection 已加载。

加载 Collections

要加载一个 Collection,请使用 load_collection()方法,指定 Collections 名称。还可以设置replica_number ,以确定加载 Collections 时在查询节点上创建多少个数据段内存副本。

  • Milvus Standalone:replica_number 的最大允许值为 1。
  • Milvus 群集:最大值不应超过 Milvus 配置中设置的queryNode.replicas 。有关其他详细信息,请参阅查询节点相关配置

要加载一个 Collection,请使用 loadCollection()方法,指定 Collections 名称。

要加载 Collections,请使用 loadCollection()方法,指定 Collections 名称。

要加载一个 Collection,可以使用 POST /v2/vectordb/collections/loadPOST /v2/vectordb/collections/get_load_stateAPI 端点。

# 7. Load the collection
client.load_collection(
    collection_name="customized_setup_2",
    replica_number=1 # Number of replicas to create on query nodes. Max value is 1 for Milvus Standalone, and no greater than `queryNode.replicas` for Milvus Cluster.
)

res = client.get_load_state(
collection_name="customized_setup_2"
)

print(res)

# Output
#
# {
# "state": "<LoadState: Loaded>"
# }
import io.milvus.v2.service.collection.request.LoadCollectionReq;

// 6. Load the collection
LoadCollectionReq loadCollectionReq = LoadCollectionReq.builder()
    .collectionName("customized_setup_2")
    .build();

client.loadCollection(loadCollectionReq);

// Thread.sleep(5000);

// 7. Get load state of the collection
GetLoadStateReq loadStateReq = GetLoadStateReq.builder()
    .collectionName("customized_setup_2")
    .build();

res = client.getLoadState(loadStateReq);

System.out.println(res);

// Output:
// true
// 7. Load the collection
res = await client.loadCollection({
    collection_name: "customized_setup_2"
})

console.log(res.error_code)

// Output
// 
// Success
// 

await sleep(3000)

res = await client.getLoadState({
    collection_name: "customized_setup_2"
})

console.log(res.state)

// Output
// 
// LoadStateLoaded
// 
$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/load" \
-H "Content-Type: application/json" \
-d '{
    "collectionName": "customized_setup_2"
}'

# Output
#
# {
#     "code": 0,
#     "data": {},
# }

$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/get_load_state" \
-H "Content-Type: application/json" \
-d '{
  "collectionName": "customized_setup_2"
}'

# {
#     "code": 0,
#     "data": {
#         "loadProgress": 100,
#         "loadState": "LoadStateLoaded"
#     }
# }

发布 Collections

要释放一个 Collections,请使用 release_collection()方法,并指定 Collections 名称。

要释放 Collections,请使用 releaseCollection()方法,指定 Collections 名称。

要释放一个 Collection,请使用 releaseCollection()方法,指定 Collections 名称。

要释放一个 Collection,可以使用 POST /v2/vectordb/collections/releasePOST /v2/vectordb/collections/get_load_stateAPI 端点。

# 8. Release the collection
client.release_collection(
    collection_name="customized_setup_2"
)

res = client.get_load_state(
collection_name="customized_setup_2"
)

print(res)

# Output
#
# {
# "state": "<LoadState: NotLoad>"
# }
import io.milvus.v2.service.collection.request.ReleaseCollectionReq;

// 8. Release the collection
ReleaseCollectionReq releaseCollectionReq = ReleaseCollectionReq.builder()
    .collectionName("customized_setup_2")
    .build();

client.releaseCollection(releaseCollectionReq);

// Thread.sleep(1000);

res = client.getLoadState(loadStateReq);

System.out.println(res);

// Output:
// false
// 8. Release the collection
res = await client.releaseCollection({
    collection_name: "customized_setup_2"
})

console.log(res.error_code)

// Output
// 
// Success
// 

res = await client.getLoadState({
    collection_name: "customized_setup_2"
})

console.log(res.state)

// Output
// 
// LoadStateNotLoad
// 
$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/release" \
-H "Content-Type: application/json" \
-d '{
    "collectionName": "customized_setup_2"
}'

# Output
#
# {
#     "code": 0,
#     "data": {},
# }


$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/get_load_state" \
-H "Content-Type: application/json" \
-d '{
  "collectionName": "customized_setup_2"
}'


# {
#     "code": 0,
#     "data": {
#         "loadState": "LoadStateNotLoad"
#     }
# }

设置别名

您可以为集合指定别名,使它们在特定上下文中更有意义。您可以为一个 Collection 指定多个别名,但多个 Collection 不能共享一个别名。

创建别名

要创建别名,请使用 create_alias()方法,指定 Collections 名称和别名。

要创建别名,请使用 createAlias()方法,指定 Collections 名称和别名。

要创建别名,请使用 createAlias()方法,指定 Collections 名称和别名。

要为 Collections 创建别名,可以使用 POST /v2/vectordb/aliases/createAPI 端点。

# 9.1. Create aliases
client.create_alias(
    collection_name="customized_setup_2",
    alias="bob"
)

client.create_alias(
collection_name="customized_setup_2",
alias="alice"
)
import io.milvus.v2.service.utility.request.CreateAliasReq;

// 9. Manage aliases

// 9.1 Create alias
CreateAliasReq createAliasReq = CreateAliasReq.builder()
    .collectionName("customized_setup_2")
    .alias("bob")
    .build();

client.createAlias(createAliasReq);

createAliasReq = CreateAliasReq.builder()
    .collectionName("customized_setup_2")
    .alias("alice")
    .build();

client.createAlias(createAliasReq);
// 9. Manage aliases
// 9.1 Create aliases
res = await client.createAlias({
    collection_name: "customized_setup_2",
    alias: "bob"
})

console.log(res.error_code)

// Output
// 
// Success
// 

res = await client.createAlias({
    collection_name: "customized_setup_2",
    alias: "alice"
})

console.log(res.error_code)

// Output
// 
// Success
// 
$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/aliases/create" \
-H "Content-Type: application/json" \
-d '{
    "collectionName": "customized_setup_2",
    "aliasName": "bob"
}'

# Output
#
# {
#     "code": 0,
#     "data": {}
# }

$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/aliases/create" \
-H "Content-Type: application/json" \
-d '{
    "collectionName": "customized_setup_2",
    "aliasName": "alice"
}'

# Output
#
# {
#     "code": 0,
#     "data": {}
# }
参数 说明
collection_name 要创建别名的 Collections 名称。
alias Collections 的别名。操作前,请确保别名不存在。如果已经存在,则会出现异常。
参数 参数
collectionName 要创建别名的 Collection 的名称。
alias Collections 的别名。在进行此操作前,请确保别名不存在。如果已经存在,则会出现异常。
参数 参数
collection_name 要创建别名的 Collection 的名称。
alias Collections 的别名。在进行此操作前,请确保别名不存在。如果已经存在,则会出现异常。
参数 参数
collectionName 要创建别名的 Collection 的名称。
aliasName Collections 的别名。在进行此操作前,请确保别名不存在。如果已经存在,则会出现异常。

列出别名

要列出别名,请使用 list_aliases()方法,并指定 Collections 名称。

要列出别名,请使用 listAliases()方法,并指定 Collection 名称。

要列出别名,请使用 listAliases()方法,并指定 Collections 名称。

要列出 Collections 的别名,可使用 POST /v2/vectordb/aliases/listAPI 端点。

# 9.2. List aliases
res = client.list_aliases(
    collection_name="customized_setup_2"
)

print(res)

# Output
#
# {
# "aliases": [
# "bob",
# "alice"
# ],
# "collection_name": "customized_setup_2",
# "db_name": "default"
# }
import io.milvus.v2.service.utility.request.ListAliasesReq;
import io.milvus.v2.service.utility.response.ListAliasResp;

// 9.2 List alises
ListAliasesReq listAliasesReq = ListAliasesReq.builder()
    .collectionName("customized_setup_2")
    .build();

ListAliasResp listAliasRes = client.listAliases(listAliasesReq);

System.out.println(listAliasRes.getAlias());

// Output:
// [
//     "bob",
//     "alice"
// ]
// 9.2 List aliases
res = await client.listAliases({
    collection_name: "customized_setup_2"
})

console.log(res.aliases)

// Output
// 
// [ 'bob', 'alice' ]
// 
$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/aliases/list" \
-H "Content-Type: application/json" \
-d '{
    "collectionName": "customized_setup_2"
}'

# {
#     "code": 0,
#     "data": [
#         "bob",
#         "alice"
#     ]
# }

描述别名

要描述别名,请使用 describe_alias()方法指定别名。

要描述别名,请使用 describeAlias()方法指定别名。

要描述别名,请使用 describeAlias()方法指定别名。

要描述 Collections 的别名,可以使用 POST /v2/vectordb/aliases/describeAPI 端点。

# 9.3. Describe aliases
res = client.describe_alias(
    alias="bob"
)

print(res)

# Output
#
# {
# "alias": "bob",
# "collection_name": "customized_setup_2",
# "db_name": "default"
# }
import io.milvus.v2.service.utility.request.DescribeAliasReq;
import io.milvus.v2.service.utility.response.DescribeAliasResp;

// 9.3 Describe alias
DescribeAliasReq describeAliasReq = DescribeAliasReq.builder()
    .alias("bob")
    .build();

DescribeAliasResp describeAliasRes = client.describeAlias(describeAliasReq);

System.out.println(JSONObject.toJSON(describeAliasRes));

// Output:
// {
//     "alias": "bob",
//     "collectionName": "customized_setup_2"
// }
// 9.3 Describe aliases
res = await client.describeAlias({
    collection_name: "customized_setup_2",
    alias: "bob"
})

console.log(res)

// Output
// 
// {
//   status: {
//     extra_info: {},
//     error_code: 'Success',
//     reason: '',
//     code: 0,
//     retriable: false,
//     detail: ''
//   },
//   db_name: 'default',
//   alias: 'bob',
//   collection: 'customized_setup_2'
// }
// 
$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/aliases/describe" \
-H "Content-Type: application/json" \
-d '{
    "aliasName": "bob"
}'

# {
#     "code": 0,
#     "data": {
#         "aliasName": "bob",
#         "collectionName": "quick_setup",
#         "dbName": "default"
#     }
# }

重新指定别名

要将别名重新分配给其他 Collections,请使用 alter_alias()方法,指定 Collections 名称和别名。

要将别名重新指定给其他 Collections,请使用 alterAlias()方法,指定集合名称和别名。

要将别名重新分配给其他 Collections,请使用 alterAlias()方法,指定 Collections 名称和别名。

要将别名重新指定给其他 Collections,可使用 POST /v2/vectordb/aliases/alterAPI 端点。

# 9.4 Reassign aliases to other collections
client.alter_alias(
    collection_name="customized_setup_1",
    alias="alice"
)

res = client.list_aliases(
collection_name="customized_setup_1"
)

print(res)

# Output
#
# {
# "aliases": [
# "alice"
# ],
# "collection_name": "customized_setup_1",
# "db_name": "default"
# }

res = client.list_aliases(
collection_name="customized_setup_2"
)

print(res)

# Output
#
# {
# "aliases": [
# "bob"
# ],
# "collection_name": "customized_setup_2",
# "db_name": "default"
# }
import io.milvus.v2.service.utility.request.AlterAliasReq;

// 9.4 Reassign alias to other collections
AlterAliasReq alterAliasReq = AlterAliasReq.builder()
    .collectionName("customized_setup_1")
    .alias("alice")
    .build();

client.alterAlias(alterAliasReq);

listAliasesReq = ListAliasesReq.builder()
    .collectionName("customized_setup_1")
    .build();

listAliasRes = client.listAliases(listAliasesReq);

System.out.println(listAliasRes.getAlias());

// Output:
// ["alice"]

listAliasesReq = ListAliasesReq.builder()
    .collectionName("customized_setup_2")
    .build();

listAliasRes = client.listAliases(listAliasesReq);

System.out.println(listAliasRes.getAlias());

// Output:
// ["bob"]
// 9.4 Reassign aliases to other collections
res = await client.alterAlias({
    collection_name: "customized_setup_1",
    alias: "alice"
})

console.log(res.error_code)

// Output
// 
// Success
// 

res = await client.listAliases({
    collection_name: "customized_setup_1"
})

console.log(res.aliases)

// Output
// 
// [ 'alice' ]
// 

res = await client.listAliases({
    collection_name: "customized_setup_2"
})

console.log(res.aliases)

// Output
// 
// [ 'bob' ]
// 
$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/aliases/alter" \
-H "Content-Type: application/json" \
-d '{
     "collectionName": "customized_setup_1",
     "aliasName": "alice"
}'

# {
#     "code": 0,
#     "data": {}
# }


$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/aliases/list" \
-H "Content-Type: application/json" \
-d '{
    "collectionName": "customized_setup_1"
}'


# {
#     "code": 0,
#     "data": [
#         "alice"
#     ]
# }


$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/aliases/list" \
-H "Content-Type: application/json" \
-d '{
    "collectionName": "customized_setup_2"
}'


# {
#     "code": 0,
#     "data": [
#         "bob"
#     ]
# }

删除别名

要删除别名,请使用 drop_alias()方法指定别名。

要删除别名,请使用 dropAlias()方法,指定别名。

要删除别名,请使用 dropAlias()方法,指定别名。

要为 Collections 删除别名,可使用 POST /v2/vectordb/aliases/dropAPI 端点。

# 9.5 Drop aliases
client.drop_alias(
    alias="bob"
)

client.drop_alias(
alias="alice"
)
import io.milvus.v2.service.utility.request.DropAliasReq;

// 9.5 Drop alias
DropAliasReq dropAliasReq = DropAliasReq.builder()
    .alias("bob")
    .build();

client.dropAlias(dropAliasReq);

dropAliasReq = DropAliasReq.builder()
    .alias("alice")
    .build();

client.dropAlias(dropAliasReq);
// 9.5 Drop aliases
res = await client.dropAlias({
    alias: "bob"
})

console.log(res.error_code)

// Output
// 
// Success
// 

res = await client.dropAlias({
    alias: "alice"
})

console.log(res.error_code)

// Output
// 
// Success
// 
$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/aliases/drop" \
-H "Content-Type: application/json" \
-d '{
    "aliasName": "bob"
}'

# {
#     "code": 0,
#     "data": {}
# }


$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/aliases/drop" \
-H "Content-Type: application/json" \
-d '{
    "aliasName": "alice"
}'


# {
#     "code": 0,
#     "data": {}
# }

设置属性

可以为 Collections 设置属性,如ttl.secondsmmap.enabled 。更多信息,请参阅set_properties()

本节中的代码片段使用PyMilvus ORM 模块与 Milvus 进行交互。使用新的MilvusClient SDK的代码片段即将发布。

设置 TTL

为 Collections 中的数据设置生存时间(TTL),指定数据在自动删除前应保留多长时间。

from pymilvus import Collection, connections

# Connect to Milvus server
connections.connect(host="localhost", port="19530") # Change to your Milvus server IP and port

# Get existing collection
collection = Collection("quick_setup")

# Set the TTL for the data in the collection
collection.set_properties(
properties={
"collection.ttl.seconds": 60
}
)

设置 MMAP

为 Collections 配置内存映射 (MMAP) 属性,该属性决定数据是否映射到内存中以提高查询性能。有关详细信息,请参阅配置内存映射 。

在设置 MMAP 属性之前,请先释放 Collection。否则会出错。

from pymilvus import Collection, connections

# Connect to Milvus server
connections.connect(host="localhost", port="19530") # Change to your Milvus server IP and port

# Get existing collection
collection = Collection("quick_setup")

# Before setting memory mapping property, we need to release the collection first.
collection.release()

# Set memory mapping property to True or Flase
collection.set_properties(
properties={
"mmap.enabled": True
}
)

放弃收藏

如果不再需要某个 Collection,您可以放弃该 Collection。

要删除一个 Collection,请使用 drop_collection()方法,并指定 Collections 名称。

要删除一个 Collection,请使用 dropCollection()方法,指定 Collections 名称。

要放弃一个 Collection,请使用 dropCollection()方法,指定 Collections 名称。

要删除一个 Collection,可以使用 POST /v2/vectordb/collections/dropAPI 端点。

# 10. Drop the collections
client.drop_collection(
    collection_name="quick_setup"
)

client.drop_collection(
collection_name="customized_setup_1"
)

client.drop_collection(
collection_name="customized_setup_2"
)
import io.milvus.v2.service.collection.request.DropCollectionReq;

// 10. Drop collections

DropCollectionReq dropQuickSetupParam = DropCollectionReq.builder()
    .collectionName("quick_setup")
    .build();

client.dropCollection(dropQuickSetupParam);

DropCollectionReq dropCustomizedSetupParam = DropCollectionReq.builder()
    .collectionName("customized_setup_1")
    .build();

client.dropCollection(dropCustomizedSetupParam);

dropCustomizedSetupParam = DropCollectionReq.builder()
    .collectionName("customized_setup_2")
    .build();

client.dropCollection(dropCustomizedSetupParam);
// 10. Drop the collection
res = await client.dropCollection({
    collection_name: "customized_setup_2"
})

console.log(res.error_code)

// Output
// 
// Success
// 

res = await client.dropCollection({
    collection_name: "customized_setup_1"
})

console.log(res.error_code)

// Output
// 
// Success
// 

res = await client.dropCollection({
    collection_name: "quick_setup"
})

console.log(res.error_code)

// Output
// 
// Success
// 
$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/drop" \
-H "Content-Type: application/json" \
-d '{
    "collectionName": "quick_setup"
}'

# {
#     "code": 0,
#     "data": {}
# }


$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/drop" \
-H "Content-Type: application/json" \
-d '{
    "collectionName": "customized_setup_1"
}'


# {
#     "code": 0,
#     "data": {}
# }


$ curl -X POST "http://${MILVUS_URI}/v2/vectordb/collections/drop" \
-H "Content-Type: application/json" \
-d '{
    "collectionName": "customized_setup_2"
}'


# {
#     "code": 0,
#     "data": {}
# }

翻译自DeepLogo

反馈

此页对您是否有帮助?