コレクションフィールドの変更
カラム制約を変更したり、より厳格なデータ整合性ルールを適用するために、コレクションフィールドのプロパティを変更できます。
各コレクションは1つの主キーのみを持ちます。コレクション作成時に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
}
}"