コレクションの変更
コレクションの名前を変更したり、設定を変更することができます。このページでは、コレクションの変更方法について説明します。
コレクション名の変更
コレクションの名前は次のように変更できます。
- 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"
"log"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
milvusAddr := "YOUR_CLUSTER_ENDPOINT"
token := "YOUR_CLUSTER_TOKEN"
cli, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: milvusAddr,
APIKey: token,
})
if err != nil {
log.Fatal("failed to connect to milvus server: ", err.Error())
}
defer cli.Close(ctx)
err = cli.RenameCollection(ctx, milvusclient.NewRenameCollectionOption("my_collection", "my_new_collection"))
if err != nil {
// 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"
}'
コレクションのプロパティを設定
次のコードスニペットは、コレクション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.v2.service.collection.request.AlterCollectionReq;
import java.util.HashMap;
import java.util.Map;
Map<String, String> properties = new HashMap<>();
properties.put("collection.ttl.seconds", "60");
AlterCollectionReq alterCollectionReq = AlterCollectionReq.builder()
.collectionName("my_collection")
.properties(properties)
.build();
client.alterCollection(alterCollectionReq);
res = await client.alterCollection({
collection_name: "my_collection",
properties: {
"collection.ttl.seconds": 60
}
})
import (
"context"
"fmt"
"log"
"github.com/milvus-io/milvus/client/v2/milvusclient"
"github.com/milvus-io/milvus/pkg/common"
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
milvusAddr := "YOUR_CLUSTER_ENDPOINT"
cli, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: milvusAddr,
})
if err != nil {
log.Fatal("failed to connect to milvus server: ", err.Error())
}
defer cli.Close(ctx)
err = cli.AlterCollection(ctx, milvusclient.NewAlterCollectionOption("my_collection").WithProperty(common.CollectionTTLConfigKey, 60))
if err != nil {
// 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": "test_collection",
"properties": {
"collection.ttl.seconds": 60
}
}'
適用可能なコレクションプロパティは次のとおりです。
プロパティ | いつ使用するか |
---|---|
| コレクションのデータを特定の期間後に削除する必要がある場合は、Time-To-Live(TTL)を秒単位で設定することを検討してください。TTLがタイムアウトすると、Zilliz Cloudはコレクションからすべてのエンティティを削除します。 削除は非同期であり、削除が完了する前に検索とクエリが可能であることを示しています。 詳細はSet Collection TTLを参照してください。 |
| メモリマッピング(Mmap)により、ディスク上の大きなファイルに直接メモリアクセスできるため、Zilliz Cloudはインデックスとデータをメモリとハードドライブの両方に保存できます。このアプローチにより、アクセス頻度に基づいてデータ配置ポリシーを最適化し、検索パフォーマンスに影響を与えることなくコレクションのストレージ容量を拡張できます。 <ターゲットを含める="zilliz"> Zilliz Cloudは、クラスタのグローバルmmap設定を実装しています。特定のフィールドまたはインデックスの設定を変更できます。 </include> 詳しくはmmapを使うを参照してください。 |
| パーティションキーの分離を有効にすると、Zilliz Cloudはパーティションキーの値に基づいてエンティティをグループ化し、これらのグループごとに別々のインデックスを作成します。検索リクエストを受け取ると、Zilliz Cloudはフィルタリング条件で指定されたパーティションキーの値に基づいてインデックスを検索し、インデックスに含まれるエンティティ内で検索範囲を制限するため、検索中に関係のないエンティティをスキャンせず、検索パフォーマンスを大幅に向上させます。 詳細は、パーティションキー分離を使用するを参照してください。 |
ドロップコレクションのプロパティ
以下のようにコレクションプロパティをドロップすることでリセットすることもできます。
- 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'],
});
// TODO
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"
]
}'