跳到主要内容

添加 Collection 字段 (V2)

本操作可以在不重建 Collection 的情况下添加字段。

POST/v2/vectordb/collections/fields/add
连接端点

该 API 的 Base URL 格式如下:

https://${CLUSTER_ENDPOINT}

📘说明
  • 你需要填入您的 Zilliz Cloud 集群的 ${CLUSTER_ENDPOINT}
  • 您可以使用 查看集群详情 V2 来获取集群的 Endpoint.
shell
export CLUSTER_ENDPOINT=""
参数
Authorizationstringheader必填项

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

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

The name of the database which the collection belongs to. Setting this to a non-existing database results in an error. If not specified, the default database applies.

collectionNamestring必填项

The name of the target collection. Setting this to a non-existing collection results in an error.

schemaobject必填项

A field schema object.

fieldNamestring必填项

目标 Collection 中待创建的字段名称。

dataTypestring必填项

字段值的数据类型。

elementDataTypestring

数组字段中各元素的数据类型。若当前字段为数组类型,则该参数为必填项。

nullableboolean

字段是否可以为 null。如果设置为 true,则该字段可以包含 null 值。

defaultValuestring

字段的默认值。若当前字段为 VarChar 类型,则该参数为必填项。

isPrimaryboolean

当前字段是否为主键字段。将该参数设置为 True 则当前字段将成为主键字段。此时,还需要确定 autoID 参数的取值。

isPartitionKeyboolean

当前字段是否为 Partition Key。将该参数设置为 True 则当前字段将作为 Partition Key。在这种情况下, 会管理当前 Collection 中的所有 Partition。

elementTypeParamsobject

字段附加参数。

max_lengthinteger

如果当前字段的数据类型为 VarChar,则该参数为必填项,用于设置该字段值的最大长度。

diminteger

如果当前字段的数据类型为 FloatVector 或 BinaryVector,则该参数为必填项,用于设置向量维度。

max_capacityinteger

如果当前字段的数据类型为 Array,则该参数为必填项,用于设置该字段值的最大元素数量。

externalFieldstring

外部数据源中对应列的名称。创建外部集合时必填。

bash
export TOKEN="db_admin:xxxxxxxxxxxxx"

curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/fields/add" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Request-Timeout: 5" \
--header "Content-Type: application/json" \
-d '{
"dbName": "test_db",
"collectionName": "test_collection",
"schema": {
"fieldName": "new_field",
"dataType": "VARCHAR",
"nullable": true,
"defaultValue": "default_value",
"elementTypeParams": {
"max_length": 255
}
}
}'
响应

返回空对象。

codeinteger

响应码。

dataobject

Returns an error message.

codeinteger

响应码。

messagestring

错误描述。

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