コレクションフィールドの変更
コレクションフィールドのプロパティを変更して、カラム制約を変更したり、より厳格なデータ整合性ルールを適用したりできます。
各コレクションにはプライマリフィールドが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"
}
}"
ARRAYフィールドの変更
ARRAYフィールドには element_type および max_capacity の2つのプロパティがあります。前者は配列内の要素のデータ型を決定し、後者は配列内の要素数の上限を制限します。変更できるのは max_capacity プロパティのみです。
以下の例では、コレクションに array という名前の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"
}
}"
Alter field-level 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
}
}"