コレクションの変更
コレクションの名前を変更したり、設定を変更したりできます。このページでは、コレクションを変更する方法について説明します。
コレクションの名前変更
以下のようにしてコレクションの名前を変更できます。
- Python
- Java
- NodeJS
- Go
- cURL
from pymilvus import MilvusClient
client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)
client.rename_collection(
old_name="my_collection",
new_name="my_new_collection"
)
import io.milvus.v2.service.collection.request.RenameCollectionReq;
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
String CLUSTER_ENDPOINT = "YOUR_CLUSTER_ENDPOINT";
String TOKEN = "YOUR_CLUSTER_TOKEN";
// 1. Connect to Milvus server
ConnectConfig connectConfig = ConnectConfig.builder()
.uri(CLUSTER_ENDPOINT)
.token(TOKEN)
.build();
MilvusClientV2 client = new MilvusClientV2(connectConfig);
RenameCollectionReq renameCollectionReq = RenameCollectionReq.builder()
.collectionName("my_collection")
.newCollectionName("my_new_collection")
.build();
client.renameCollection(renameCollectionReq);
import { MilvusClient, DataType } from "@zilliz/milvus2-sdk-node";
const address = "YOUR_CLUSTER_ENDPOINT";
const token = "YOUR_CLUSTER_TOKEN";
const client = new MilvusClient({address, token});
const res = await client.renameCollection({
oldName: "my_collection",
newName: "my_new_collection"
});
import (
"context"
"fmt"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
milvusAddr := "YOUR_CLUSTER_ENDPOINT"
token := "YOUR_CLUSTER_TOKEN"
client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: milvusAddr,
APIKey: token,
})
if err != nil {
fmt.Println(err.Error())
// handle error
}
defer client.Close(ctx)
err = client.RenameCollection(ctx, milvusclient.NewRenameCollectionOption("my_collection", "my_new_collection"))
if err != nil {
fmt.Println(err.Error())
// handle error
}
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/rename" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "my_collection",
"newCollectionName": "my_new_collection"
}'
Set Collection Properties
コレクション作成後も、コレクションレベルのプロパティを変更できます。
Supported properties
Property | Description |
|---|---|
| コレクションのデータを特定の期間後に削除する必要がある場合は、Time-To-Live (TTL) を秒単位で設定することを検討してください。TTL の期限が切れると、Zilliz Cloud はそのコレクションからすべてのエンティティを削除します。 削除は非同期で行われるため、削除が完了するまでは検索およびクエリが可能です。 詳細については、「Set Collection TTL」を参照してください。 |
| メモリマッピング(mmap)により、ディスク上の大規模ファイルに直接メモリアクセスできるようになり、Zilliz Cloud はインデックスとデータをメモリおよびハードドライブの両方に格納できます。このアプローチにより、アクセス頻度に基づいたデータ配置ポリシーを最適化し、検索パフォーマンスに影響を与えることなくコレクションのストレージ容量を拡張できます。 Zilliz Cloud はクラスターに対してグローバルな mmap 設定を実装しています。特定のフィールドまたはそのインデックスに対して設定を変更できます。 詳細については、「Use mmap」を参照してください。 |
| パーティションキー分離(パーティションキー Isolation)を有効にすると、Zilliz Cloud はパーティションキーの値に基づいてエンティティをグループ化し、各グループごとに個別のインデックスを作成します。検索リクエストを受信すると、Zilliz Cloud はフィルタリング条件で指定されたパーティションキーの値に基づいて対応するインデックスを特定し、そのインデックスに含まれるエンティティの範囲内でのみ検索を実行します。これにより、関係のないエンティティをスキャンせずに済み、検索パフォーマンスが大幅に向上します。 詳細については、「Use パーティションキー Isolation」を参照してください。 |
| 元々動的フィールド(dynamic field)を有効にしていなかったコレクションに対して、動的フィールドを有効化します。有効化後は、元のスキーマで定義されていないフィールドを持つエンティティを挿入できます。詳細については、「Dynamic Field」を参照してください。 |
| コレクションで AutoID が有効になっている場合に、ユーザー提供の主キー値を受け入れるかどうかを指定します。
|
| このコレクションにおけるタイムゾーン依存操作(特に |
Example 1: Set collection TTL
以下のコードスニペットは、コレクションの TTL を設定する方法を示しています。
- Python
- Java
- NodeJS
- Go
- cURL
from pymilvus import MilvusClient
client.alter_collection_properties(
collection_name="my_collection",
properties={"collection.ttl.seconds": 60}
)
import io.milvus.param.Constant;
import io.milvus.v2.service.collection.request.AlterCollectionPropertiesReq;
AlterCollectionPropertiesReq alterCollectionReq = AlterCollectionPropertiesReq.builder()
.collectionName("my_collection")
.property(Constant.TTL_SECONDS, "60")
.build();
client.alterCollectionProperties(alterCollectionReq);
res = await client.alterCollection({
collection_name: "my_collection",
properties: {
"collection.ttl.seconds": 60
}
})
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.CollectionTTLConfigKey, 60))
if err != nil {
fmt.Println(err.Error())
// handle error
}
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/alter_properties" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "my_collection",
"properties": {
"collection.ttl.seconds": 60
}
}'
例 2: mmap を有効にする
次のコードスニペットは、mmap を有効にする方法を示しています。
- Python
- Java
- NodeJS
- Go
- cURL
from pymilvus import MilvusClient
client.alter_collection_properties(
collection_name="my_collection",
properties={"mmap.enabled": True}
)
AlterCollectionPropertiesReq alterCollectionReq = AlterCollectionPropertiesReq.builder()
.collectionName("my_collection")
.property(Constant.MMAP_ENABLED, "True")
.build();
client.alterCollectionProperties(alterCollectionReq);
await client.alterCollectionProperties({
collection_name: "my_collection",
properties: {
"mmap.enabled": true
}
});
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.MmapEnabledKey, true))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl -X POST "YOUR_CLUSTER_ENDPOINT/v2/vectordb/collections/alter_properties" \
-H "Content-Type: application/json" \
-d '{
"collectionName": "my_collection",
"properties": {
"mmap.enabled": "true"
}
}'
例 3: パーティションキーの有効化
次のコードスニペットは、パーティションキーを有効にする方法を示しています。
- Python
- Java
- NodeJS
- Go
- cURL
from pymilvus import MilvusClient
client.alter_collection_properties(
collection_name="my_collection",
properties={"partitionkey.isolation": True}
)
AlterCollectionPropertiesReq alterCollectionReq = AlterCollectionPropertiesReq.builder()
.collectionName("my_collection")
.property("partitionkey.isolation", "True")
.build();
client.alterCollectionProperties(alterCollectionReq);
await client.alterCollectionProperties({
collection_name: "my_collection",
properties: {
"partitionkey.isolation": true
}
});
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.PartitionKeyIsolationKey, true))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl -X POST "YOUR_CLUSTER_ENDPOINT/v2/vectordb/collections/alter_properties" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"collectionName": "my_collection",
"properties": {
"partitionkey.isolation": "true"
}
}'
例4: 動的フィールドの有効化
以下のコードスニペットは、動的フィールドを有効にする方法を示しています。
- Python
- Java
- NodeJS
- Go
- cURL
from pymilvus import MilvusClient
client.alter_collection_properties(
collection_name="my_collection",
properties={"dynamicfield.enabled": True}
)
AlterCollectionPropertiesReq alterCollectionReq = AlterCollectionPropertiesReq.builder()
.collectionName("my_collection")
.property("dynamicfield.enabled", "True")
.build();
client.alterCollectionProperties(alterCollectionReq);
await client.alterCollectionProperties({
collection_name: "my_collection",
properties: {
"dynamicfield.enabled": true
}
});
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.EnableDynamicSchemaKey, true))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl -X POST "YOUR_CLUSTER_ENDPOINT/v2/vectordb/collections/alter_properties" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"collectionName": "my_collection",
"properties": {
"dynamicfield.enabled": "true"
}
}'
例5: allow_insert_auto_idを有効化する
allow_insert_auto_id プロパティを有効にすると、AutoIDが有効になっているコレクションに対して、insert、upsert、および一括インポート時にユーザーが主キー値を指定できるようになります。このプロパティを "true" に設定すると、Zilliz Cloudはユーザーが提供した主キー値が存在する場合はそれを利用し、存在しない場合は自動生成します。デフォルト値は "false" です。
以下の例では、allow_insert_auto_id を有効にする方法を示しています:
- Python
- Java
- NodeJS
- Go
- cURL
client.alter_collection_properties(
collection_name="my_collection",
properties={"allow_insert_auto_id": "true"}
)
# After enabling, inserts with a PK column will use that PK; otherwise Zilliz Cloud auto-generates.
AlterCollectionPropertiesReq alterCollectionReq = AlterCollectionPropertiesReq.builder()
.collectionName("my_collection")
.property("allow_insert_auto_id", "True")
.build();
client.alterCollectionProperties(alterCollectionReq);
await client.alterCollectionProperties({
collection_name: "my_collection",
properties: {
"allow_insert_auto_id": true
}
});
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.AllowInsertAutoIDKey, true))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl -X POST "YOUR_CLUSTER_ENDPOINT/v2/vectordb/collections/alter_properties" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"collectionName": "my_collection",
"properties": {
"allow_insert_auto_id": "true"
}
}'
例6: コレクションのタイムゾーンを設定する
timezone プロパティを使用して、コレクションのデフォルトタイムゾーンを設定できます。これにより、コレクション内のすべての操作(データ挿入、クエリ、結果表示など)において、時刻関連データの解釈および表示方法が決定されます。
timezone の値は、Asia/Shanghai、America/Chicago、UTC などの有効な IANA タイムゾーン識別子 でなければなりません。無効または非標準の値を使用すると、コレクションプロパティの変更時にエラーが発生します。
以下の例では、コレクションのタイムゾーンを Asia/Shanghai に設定する方法を示しています:
- Python
- Java
- NodeJS
- Go
- cURL
client.alter_collection_properties(
collection_name="my_collection",
properties={"timezone": "Asia/Shanghai"}
)
AlterCollectionPropertiesReq alterCollectionReq = AlterCollectionPropertiesReq.builder()
.collectionName("my_collection")
.property("timezone", "Asia/Shanghai")
.build();
client.alterCollectionProperties(alterCollectionReq);
// js
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.CollectionDefaultTimezone, true))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl -X POST "YOUR_CLUSTER_ENDPOINT/v2/vectordb/collections/alter_properties" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"collectionName": "my_collection",
"properties": {
"timezone": "Asia/Shanghai"
}
}'
コレクションプロパティの削除
以下のようにコレクションプロパティを削除することで、リセットすることもできます。
- Python
- Java
- NodeJS
- Go
- cURL
client.drop_collection_properties(
collection_name="my_collection",
property_keys=[
"collection.ttl.seconds"
]
)
client.dropCollectionProperties(DropCollectionPropertiesReq.builder()
.collectionName("my_collection")
.propertyKeys(Collections.singletonList("collection.ttl.seconds"))
.build());
client.dropCollectionProperties({
collection_name:"my_collection",
properties: ['collection.ttl.seconds'],
});
err = client.DropCollectionProperties(ctx, milvusclient.NewDropCollectionPropertiesOption("my_collection", common.CollectionTTLConfigKey))
if err != nil {
fmt.Println(err.Error())
// handle error
}
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/drop_properties" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "my_collection",
"propertyKeys": [
"collection.ttl.seconds"
]
}'