コレクションフィールドの変更
コレクションフィールドのプロパティを変更して、列制約を変更したり、データ整合性ルールをより厳格に適用できます。
各コレクションは1つの主フィールドのみで構成されます。コレクション作成時に設定すると、主フィールドを変更したり、そのプロパティを変更することはできません。
各コレクションは1つのパーティションキーのみを持つことができます。コレクション作成時に設定すると、パーティションキーを変更することはできません。
VarCharフィールドの変更
VarCharフィールドにはmax_lengthというプロパティがあり、フィールド値に含めることができる最大文字数を制約します。max_lengthプロパティを変更できます。
次の例では、コレクションにvarcharという名前のVarCharフィールドがあり、そのmax_lengthプロパティを設定することを前提としています。
- Python
- Java
- NodeJS
- Go
- cURL
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" \
--data "{
\"collectionName\": \"my_collection\",
\"field_name\": \"varchar\",
\"properties\": {
\"max_length\": \"1024\"
}
}"
配列フィールドの変更
配列フィールドにはelement_typeとmax_capacityの2つのプロパティがあります。前者は配列内の要素のデータ型を決定し、後者は配列内の最大要素数を制約します。max_capacityプロパティのみを変更できます。
次の例では、コレクションにarrayという名前の配列フィールドがあり、そのmax_capacityプロパティを設定することを前提としています。
- Python
- Java
- NodeJS
- Go
- cURL
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" \
--data "{
\"collectionName\": \"my_collection\",
\"field_name\": \"array\",
\"properties\": {
\"max_capacity\": \"64\"
}
}"
フィールドレベルのmmap設定の変更
メモリマッピング(mmap)により、ディスク上の大きなファイルへの直接メモリアクセスが可能になり、Zilliz Cloudがインデックスとデータをメモリとハードドライブの両方に保存できるようになります。このアプローチにより、アクセス頻度に基づいたデータ配置ポリシーを最適化し、検索パフォーマンスに影響を与えずにコレクションのストレージ容量を拡大できます。
次の例では、コレクションにdoc_chunkという名前のフィールドがあり、そのmmap_enabledプロパティを設定することを前提としています。
- Python
- Java
- NodeJS
- Go
- cURL
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" \
--data "{
\"collectionName\": \"my_collection\",
\"field_name\": \"doc_chunk\",
\"properties\": {
\"mmap.enabled\": True
}
}"