Collection Field の変更
collection フィールドのプロパティを変更して、列の制約を変更したり、より厳格なデータ整合性ルールを適用したりできます。
このページではフィールドプロパティの変更について説明します。フィールドの追加や削除のようなスキーマ形状の変更については扱いません。既存の collection に scalar フィールドを追加したり、フィールドを削除したりするには、Collection Schema の変更を参照してください。
-
各 collection は 1 つの primary field のみで構成されます。collection 作成時に設定すると、その後 primary field を変更したり、そのプロパティを変更したりすることはできません。
-
各 collection には 1 つの partition key のみを設定できます。collection 作成時に設定すると、その後 partition key を変更することはできません。
VarChar フィールドの変更
VarChar フィールドには max_length というプロパティがあり、フィールド値に含められる最大文字数を制限します。max_length プロパティは変更できます。
次の例では、collection に varchar という名前の VarChar フィールドが存在することを前提として、その max_length プロパティを設定します。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
from pymilvus import MilvusClient
client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)
client.alter_collection_field(
collection_name="my_collection",
field_name="varchar",
field_params={
"max_length": 1024
}
)
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.service.collection.request.*;
ConnectConfig config = ConnectConfig.builder()
.uri("YOUR_CLUSTER_ENDPOINT")
.token("YOUR_CLUSTER_TOKEN")
.build();
MilvusClientV2 client = new MilvusClientV2(config);
client.alterCollectionField(AlterCollectionFieldReq.builder()
.collectionName("my_collection")
.fieldName("varchar")
.property("max_length", "1024")
.build());
await client.alterCollectionFieldProperties({
collection_name: LOAD_COLLECTION_NAME,
field_name: 'varchar',
properties: { max_length: 1024 },
});
import (
"context"
"fmt"
"github.com/milvus-io/milvus/client/v2/entity"
"github.com/milvus-io/milvus/client/v2/milvusclient"
"github.com/milvus-io/milvus/pkg/v2/common"
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
milvusAddr := "YOUR_CLUSTER_ENDPOINT"
client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: milvusAddr,
})
if err != nil {
fmt.Println(err.Error())
// handle error
}
defer client.Close(ctx)
err = client.AlterCollectionFieldProperty(ctx, milvusclient.NewAlterCollectionFieldPropertiesOption(
"my_collection", "varchar").WithProperty(common.MaxLengthKey, 1024))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/collections/fields/alter_properties" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
--data '{
"collectionName": "my_collection",
"field_name": "varchar",
"properties": {
"max_length": "1024"
}
}'
#include "milvus/MilvusClientV2.h"
auto client = milvus::MilvusClientV2::Create();
milvus::ConnectParam connect_param{"YOUR_CLUSTER_ENDPOINT", "YOUR_CLUSTER_TOKEN"};
auto status = client->Connect(connect_param);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
status = client->AlterCollectionFieldProperties(milvus::AlterCollectionFieldPropertiesRequest()
.WithCollectionName("my_collection")
.WithFieldName("varchar")
.AddProperty("max_length", "1024"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
ARRAY フィールドの変更
array フィールドには element_type と max_capacity の 2 つのプロパティがあります。前者は array 内の要素のデータ型を決定し、後者は array に含められる要素の最大数を制限します。変更できるのは max_capacity プロパティのみです。
次の例では、collection に array という名前の array フィールドが存在することを前提として、その max_capacity プロパティを設定します。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
client.alter_collection_field(
collection_name="my_collection",
field_name="array",
field_params={
"max_capacity": 64
}
)
client.alterCollectionField(AlterCollectionFieldReq.builder()
.collectionName("my_collection")
.fieldName("array")
.property("max_capacity", "64")
.build());
await client.alterCollectionFieldProperties({
collection_name: "my_collection",
field_name: 'array',
properties: {
max_capacity: 64
}
});
err = client.AlterCollectionFieldProperty(ctx, milvusclient.NewAlterCollectionFieldPropertiesOption(
"my_collection", "array").WithProperty(common.MaxCapacityKey, 64))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/collections/fields/alter_properties" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
--data '{
"collectionName": "my_collection",
"field_name": "array",
"properties": {
"max_capacity": "64"
}
}'
auto status = client->AlterCollectionFieldProperties(milvus::AlterCollectionFieldPropertiesRequest()
.WithCollectionName("my_collection")
.WithFieldName("array")
.AddProperty("max_capacity", "64"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
フィールドレベルの mmap 設定の変更
メモリマッピング(Mmap)により、ディスク上の大きなファイルへ直接メモリアクセスできるようになり、Zilliz Cloud は index とデータをメモリとハードドライブの両方に保存できます。このアプローチは、アクセス頻度に基づいてデータ配置ポリシーを最適化し、検索パフォーマンスに影響を与えることなく collection のストレージ容量を拡張するのに役立ちます。
次の例では、collection に doc_chunk という名前のフィールドが存在することを前提として、その mmap_enabled プロパティを設定します。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
client.alter_collection_field(
collection="my_collection",
field_name="doc_chunk",
properties={"mmap.enabled": True}
)
client.alterCollectionField(AlterCollectionFieldReq.builder()
.collectionName("my_collection")
.fieldName("doc_chunk")
.property("mmap.enabled", "True")
.build());
await client.alterCollectionProperties({
collection_name: "my_collection",
field_name: 'doc_chunk',
properties: {
'mmap.enabled': true,
}
});
err = client.AlterCollectionFieldProperty(ctx, milvusclient.NewAlterCollectionFieldPropertiesOption(
"my_collection", "doc_chunk").WithProperty(common.MmapEnabledKey, true))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/collections/fields/alter_properties" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
--data '{
"collectionName": "my_collection",
"field_name": "doc_chunk",
"properties": {
"mmap.enabled": True
}
}'
auto status = client->AlterCollectionFieldProperties(milvus::AlterCollectionFieldPropertiesRequest()
.WithCollectionName("my_collection")
.WithFieldName("doc_chunk")
.AddProperty("mmap.enabled", "true"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}