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