跳到主要内容

创建 Collection (V2)

This operation creates a collection in a specified cluster.

POST/v2/vectordb/collections/create
连接端点

该 API 的 Base URL 格式如下:

https://{cluster-id}.{region}.vectordb.zillizcloud.com:19530

📘说明
  • 如果您使用的是服务集群,请使用集群端点。
    • Free 与 Serverless 版

      https://{cluster-id}.serverless.{region}.vectordb.zillizcloud.com

    • Dedicated 版

      https://{cluster-id}.{region}.vectordb.zillizcloud.com:19530

  • 你需要填入您的 Zilliz Cloud 集群的 ${CLUSTER_ENDPOINT}
  • 您可以使用 查看集群详情 V2 来获取集群的 Endpoint.
export CLUSTER_ENDPOINT="https://{cluster-id}.{region}.vectordb.zillizcloud.com:19530"
参数
Authorizationstringheaderrequired

认证令牌,应为具备适当权限的 API 密钥或用冒号分隔的用户名和密码,如 username:password。如果您使用的是项目端点,则仅具备足够权限的有效 API 密钥适用。

示例值:Bearer {{TOKEN}}
请求体application/json
dbNamestring

数据库名称。

collectionNamestring必填项

待创建 Collection 的名称。

dimensioninteger必填项

向量值的维度数。 若该字段的 idTypeDataType.FLOAT_VECTORDataType.Binary_VECTOR,则该字段为必填项。

metricTypestring

当前 Collection 的度量类型。

idTypestring

主键字段数据类型。该参数为快速创建 Collection 而设计,若您已定义 schema 字段,则该参数将被忽略。

autoIDboolean

主键是否自动增长。该参数为快速创建 Collection 而设计,若您已定义 schema 字段,则该参数将被忽略。

primaryFieldNamestring

主键字段名称。该参数为快速创建 Collection 而设计,若您已定义 schema 字段,则该参数将被忽略。

vectorFieldNamestring

向量字段名称。该参数为快速创建 Collection 而设计,若您已定义 schema 字段,则该参数将被忽略。

descriptionstring

当前 Collection 的描述信息。

paramsobject

创建 Collection 的附加参数。

max_lengthinteger

当前 Collection 允许的最大字节数。如果当前 Collection 的主键字段是字符串类型,则该参数可用。

enableDynamicFieldboolean

是否启用动态字段功能。

consistencyLevelstring

当前 Collection 的一致性级别。

ttlSecondsinteger

当前 Collection 的 TTL 时间。如果设置,则在 TTL 时间结束后,该 Collection 将被删除。

mmap.enabledboolean

是否为当前 Collection 启用内存映射功能。

ttlFieldstring

用于 TTL 过期策略的字段名称。

warmup.scalarFieldboolean

是否在加载时将标量字段数据预加载到内存中。

warmup.scalarIndexboolean

是否在加载时将标量索引数据预加载到内存中。

warmup.vectorFieldboolean

是否在加载时将向量字段数据预加载到内存中。

warmup.vectorIndexboolean

是否在加载时将向量索引数据预加载到内存中。

dbNamestring

数据库名称。

collectionNamestring

待创建 Collection 的名称。

schemaundefined

Schema 决定了 Collection 中数据的组织方式。一个有效的 Schema 应包含多个字段,其中必须包含主键字段、向量字段以及多个标量字段。设置本参数时,dimensionidTypeautoIDprimaryFieldNamevectorFieldName 等参数将被忽略。

indexParamsarray

索引构建所需相关参数。

[]indexParamsobject

一个索引 Schema 对象。

metricTypestring必填项

用于构建索引的相似度类型。更多详情,请参考相似度指标详解。

fieldNamestring必填项

要创建索引的目标字段名称。

indexNamestring必填项

要创建的索引名称。该值默认为目标字段名称。

paramsobject

索引类型及相关设置。对于 Zilliz Cloud 集群而言,请始终将 index_type 设置成 AUTOINDEX

index_typestring必填项

要创建的索引类型。对于 Zilliz Cloud 集群而言,请始终将 index_type 设置成 AUTOINDEX

paramsobject

创建 Collection 的附加参数。

consistencyLevelstring

当前 Collection 的一致性级别。

partitionsNuminteger

随当前 Collection 创建的 Partition 数量。如果当前 Collection 中有指定为 Partition Key 的字段,则该参数为必填项。

ttlSecondsinteger

当前 Collection 的 TTL 时间。如果设置,则在 TTL 时间结束后,该 Collection 将被删除。

partitionKeyIsolationboolean

是否为当前 Collection 启用 Partition Key 隔离功能。

mmap.enabledboolean

是否为当前 Collection 启用内存映射功能。

ttlFieldstring

用于 TTL 过期策略的字段名称。

warmup.scalarFieldboolean

是否在加载时将标量字段数据预加载到内存中。

warmup.scalarIndexboolean

是否在加载时将标量索引数据预加载到内存中。

warmup.vectorFieldboolean

是否在加载时将向量字段数据预加载到内存中。

warmup.vectorIndexboolean

是否在加载时将向量索引数据预加载到内存中。

descriptionstring

当前 Collection 的描述信息。

dbNamestring

数据库名称。

collectionNamestring

待创建 Collection 的名称。

schemaundefined

外部集合的 Schema。必须包含带有 externalField 映射的字段,以及 externalSource 和 externalSpec。

indexParamsarray

索引构建所需相关参数。

[]indexParamsobject

一个索引 Schema 对象。

metricTypestring必填项

用于构建索引的相似度类型。更多详情,请参考相似度指标详解。

fieldNamestring必填项

要创建索引的目标字段名称。

indexNamestring必填项

要创建的索引名称。该值默认为目标字段名称。

paramsobject

索引类型及相关设置。对于 Zilliz Cloud 集群而言,请始终将 index_type 设置成 AUTOINDEX

index_typestring必填项

要创建的索引类型。对于 Zilliz Cloud 集群而言,请始终将 index_type 设置成 AUTOINDEX

paramsobject

创建 Collection 的附加参数。

consistencyLevelstring

当前 Collection 的一致性级别。

partitionsNuminteger

随当前 Collection 创建的 Partition 数量。如果当前 Collection 中有指定为 Partition Key 的字段,则该参数为必填项。

ttlSecondsinteger

当前 Collection 的 TTL 时间。如果设置,则在 TTL 时间结束后,该 Collection 将被删除。

partitionKeyIsolationboolean

是否为当前 Collection 启用 Partition Key 隔离功能。

mmap.enabledboolean

是否为当前 Collection 启用内存映射功能。

ttlFieldstring

用于 TTL 过期策略的字段名称。

warmup.scalarFieldboolean

是否在加载时将标量字段数据预加载到内存中。

warmup.scalarIndexboolean

是否在加载时将标量索引数据预加载到内存中。

warmup.vectorFieldboolean

是否在加载时将向量字段数据预加载到内存中。

warmup.vectorIndexboolean

是否在加载时将向量索引数据预加载到内存中。

descriptionstring

当前 Collection 的描述信息。

export TOKEN="db_admin:xxxxxxxxxxxxx"

curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/create" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Request-Timeout: 5" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "test_collection",
"dimension": 5
}'
export TOKEN="db_admin:xxxxxxxxxxxxx"

curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/create" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Request-Timeout: 5" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "custom_quick_setup",
"dimension": 5,
"primaryFieldName": "my_id",
"idType": "VarChar",
"vectorFieldName": "my_vector",
"metric_type": "L2",
"autoId": true,
"params": {
"max_length": "512"
}
}'
响应200 - application/json
codeinteger

响应码。

dataobject

返回错误消息。

codeinteger

响应码。

messagestring

错误描述。

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