Partitions の管理
partition は collection のサブセットです。各 partition は親 collection と同じデータ構造を共有しますが、collection 内のデータの一部のみを含みます。このページでは、partition の管理方法について説明します。
この機能は managed collections にのみ適用されます。
概要
collection を作成すると、Zilliz Cloud はその collection 内に _default という名前の partition も作成します。他の partition を追加しない場合、collection に挿入されたすべてのエンティティは default partition に入り、すべての検索とクエリも default partition 内で実行されます。
さらに partition を追加し、特定の条件に基づいてエンティティをそれらに挿入できます。その後、検索とクエリを特定の partition 内に制限することで、検索パフォーマンスを向上させることができます。
1 つの collection には最大 1,024 個の partition を作成できます。
Partition Key 機能は partition に基づく検索最適化であり、特定の scalar field の値に基づいて Zilliz Cloud がエンティティを異なる partition に分散できるようにします。この機能は、partition 指向のマルチテナンシーを実装し、検索パフォーマンスを向上させるのに役立ちます。
この機能については、このページでは説明しません。詳細については、Partition Key を使用するを参照してください。
Partitions の一覧表示
collection を作成すると、Zilliz Cloud はその collection 内に _default という名前の partition も作成します。collection 内の partition は次のように一覧表示できます。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
from pymilvus import MilvusClient
client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)
res = client.list_partitions(
collection_name="my_collection"
)
print(res)
# Output
#
# ["_default"]
import io.milvus.v2.service.partition.request.ListPartitionsReq;
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import java.util.*;
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);
ListPartitionsReq listPartitionsReq = ListPartitionsReq.builder()
.collectionName("my_collection")
.build();
List<String> partitionNames = client.listPartitions(listPartitionsReq);
System.out.println(partitionNames);
// Output:
// [_default]
import { MilvusClient, DataType } from "@zilliz/milvus2-sdk-node";
const address = "YOUR_CLUSTER_ENDPOINT";
const token = "YOUR_CLUSTER_TOKEN";
const client = new MilvusClient({address, token});
let res = await client.listPartitions({
collection_name: "my_collection"
})
console.log(res);
// Output
// ["_default"]
import (
"context"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)
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)
partitionNames, err := client.ListPartitions(ctx, milvusclient.NewListPartitionOption("my_collection"))
if err != nil {
fmt.Println(err.Error())
// handle error
}
fmt.Println(partitionNames)
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/list" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"collectionName": "my_collection"
}'
# {
# "code": 0,
# "data": [
# "_default"
# ]
# }
#include "milvus/MilvusClientV2.h"
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;
}
milvus::ListPartitionsResponse response;
status = client->ListPartitions(milvus::ListPartitionsRequest()
.WithCollectionName("my_collection"),
response);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
for (auto& info : response.PartitionInfos()) {
std::cout << "\t" << info.Name() << std::endl;
}
Partition の作成
collection にさらに partition を追加し、特定の条件に基づいてこれらの partition にエンティティを挿入できます。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
client.create_partition(
collection_name="my_collection",
partition_name="partitionA"
)
res = client.list_partitions(
collection_name="my_collection"
)
print(res)
# Output
#
# ["_default", "partitionA"]
import io.milvus.v2.service.partition.request.CreatePartitionReq;
CreatePartitionReq createPartitionReq = CreatePartitionReq.builder()
.collectionName("my_collection")
.partitionName("partitionA")
.build();
client.createPartition(createPartitionReq);
ListPartitionsReq listPartitionsReq = ListPartitionsReq.builder()
.collectionName("my_collection")
.build();
List<String> partitionNames = client.listPartitions(listPartitionsReq);
System.out.println(partitionNames);
// Output:
// [_default, partitionA]
await client.createPartition({
collection_name: "my_collection",
partition_name: "partitionA"
})
res = await client.listPartitions({
collection_name: "my_collection"
})
console.log(res)
// Output
// ["_default", "partitionA"]
import (
"fmt"
client "github.com/milvus-io/milvus/client/v2/milvusclient"
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err = client.CreatePartition(ctx, milvusclient.NewCreatePartitionOption("my_collection", "partitionA"))
if err != nil {
fmt.Println(err.Error())
// handle error
}
partitionNames, err := client.ListPartitions(ctx, milvusclient.NewListPartitionOption("my_collection"))
if err != nil {
fmt.Println(err.Error())
// handle error
}
fmt.Println(partitionNames)
// Output
// ["_default", "partitionA"]
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/create" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"collectionName": "my_collection",
"partitionName": "partitionA"
}'
# {
# "code": 0,
# "data": {}
# }
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/list" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"collectionName": "my_collection"
}'
# {
# "code": 0,
# "data": [
# "_default",
# "partitionA"
# ]
# }
auto status = client->CreatePartition(milvus::CreatePartitionRequest()
.WithCollectionName("my_collection")
.WithPartitionName("partitionA"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
milvus::ListPartitionsResponse response;
status = client->ListPartitions(milvus::ListPartitionsRequest().WithCollectionName("my_collection"), response);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
for (auto& info : response.PartitionInfos()) {
std::cout << "\t" << info.Name() << std::endl;
}
特定の Partition の確認
次のコードスニペットは、特定の collection に partition が存在するかどうかを確認する方法を示しています。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
res = client.has_partition(
collection_name="my_collection",
partition_name="partitionA"
)
print(res)
# Output
#
# True
import io.milvus.v2.service.partition.request.HasPartitionReq;
HasPartitionReq hasPartitionReq = HasPartitionReq.builder()
.collectionName("my_collection")
.partitionName("partitionA")
.build();
Boolean hasPartitionRes = client.hasPartition(hasPartitionReq);
System.out.println(hasPartitionRes);
// Output:
// true
res = await client.hasPartition({
collection_name: "my_collection",
partition_name: "partitionA"
})
console.log(res.value)
// Output
// true
result, err := client.HasPartition(ctx, milvusclient.NewHasPartitionOption("my_collection", "partitionA"))
if err != nil {
fmt.Println(err.Error())
// handle error
}
fmt.Println(result)
// Output:
// true
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/has" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"collectionName": "my_collection",
"partitionName": "partitionA"
}'
# {
# "code": 0,
# "data": {
# "has": true
# }
# }
milvus::HasPartitionResponse response;
auto status = client->HasPartition(milvus::HasPartitionRequest()
.WithCollectionName("my_collection")
.WithPartitionName("partitionA"),
response);
std::cout << response.Has() << std::endl;
Partitions の読み込みと解放
1 つまたは特定の partition を個別に読み込んだり解放したりできます。
Partitions の読み込み
collection 内の特定の partition を個別に読み込むことができます。collection 内に読み込まれていない partition がある場合、collection の読み込み状態は unloaded のままになる点に注意してください。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
client.load_partitions(
collection_name="my_collection",
partition_names=["partitionA"]
)
res = client.get_load_state(
collection_name="my_collection",
partition_name="partitionA"
)
print(res)
# Output
#
# {
# "state": "<LoadState: Loaded>"
# }
import io.milvus.v2.service.partition.request.LoadPartitionsReq;
import io.milvus.v2.service.collection.request.GetLoadStateReq;
LoadPartitionsReq loadPartitionsReq = LoadPartitionsReq.builder()
.collectionName("my_collection")
.partitionNames(Collections.singletonList("partitionA"))
.build();
client.loadPartitions(loadPartitionsReq);
GetLoadStateReq getLoadStateReq = GetLoadStateReq.builder()
.collectionName("my_collection")
.partitionName("partitionA")
.build();
Boolean getLoadStateRes = client.getLoadState(getLoadStateReq);
System.out.println(getLoadStateRes);
// True
await client.loadPartitions({
collection_name: "my_collection",
partition_names: ["partitionA"]
})
res = await client.getLoadState({
collection_name: "my_collection",
partition_name: "partitionA"
})
console.log(res)
// Output
//
// LoadStateLoaded
//
task, err := client.LoadPartitions(ctx, milvusclient.NewLoadPartitionsOption("my_collection", "partitionA"))
if err != nil {
fmt.Println(err.Error())
// handle error
}
// sync wait collection to be loaded
err = task.Await(ctx)
if err != nil {
fmt.Println(err.Error())
// handle error
}
state, err := client.GetLoadState(ctx, milvusclient.NewGetLoadStateOption("my_collection", "partitionA"))
if err != nil {
fmt.Println(err.Error())
// handle error
}
fmt.Println(state)
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/load" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"collectionName": "my_collection",
"partitionNames": ["partitionA"]
}'
# {
# "code": 0,
# "data": {}
# }
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/get_load_state" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"collectionName": "my_collection",
"partitionNames": ["partitionA"]
}'
# {
# "code": 0,
# "data": {
# "loadProgress": 100,
# "loadState": "LoadStateLoaded",
# "message": ""
# }
# }
auto status = client->LoadPartitions(milvus::LoadPartitionsRequest()
.WithCollectionName("my_collection")
.AddPartitionName("partitionA"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
milvus::GetLoadStateResponse response;
status = client->GetLoadState(milvus::GetLoadStateRequest()
.WithCollectionName("my_collection")
.AddPartitionName("partitionA"),
response);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
std::cout << std::to_string(response.State()) << std::endl;
Partitions の解放
特定の partition を解放することもできます。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
client.release_partitions(
collection_name="my_collection",
partition_names=["partitionA"]
)
res = client.get_load_state(
collection_name="my_collection",
partition_name="partitionA"
)
print(res)
# Output
#
# {
# "state": "<LoadState: NotLoaded>"
# }
import io.milvus.v2.service.partition.request.ReleasePartitionsReq;
ReleasePartitionsReq releasePartitionsReq = ReleasePartitionsReq.builder()
.collectionName("my_collection")
.partitionNames(Collections.singletonList("partitionA"))
.build();
client.releasePartitions(releasePartitionsReq);
GetLoadStateReq getLoadStateReq = GetLoadStateReq.builder()
.collectionName("my_collection")
.partitionName("partitionA")
.build();
Boolean getLoadStateRes = client.getLoadState(getLoadStateReq);
System.out.println(getLoadStateRes);
// False
await client.releasePartitions({
collection_name: "my_collection",
partition_names: ["partitionA"]
})
res = await client.getLoadState({
collection_name: "my_collection",
partition_name: "partitionA"
})
console.log(res)
// Output
//
// LoadStateNotLoaded
//
err = client.ReleasePartitions(ctx, milvusclient.NewReleasePartitionsOptions("my_collection", "partitionA"))
if err != nil {
fmt.Println(err.Error())
// handle error
}
state, err := client.GetLoadState(ctx, milvusclient.NewGetLoadStateOption("my_collection", "partitionA"))
if err != nil {
fmt.Println(err.Error())
// handle error
}
fmt.Println(state)
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/release" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"collectionName": "my_collection",
"partitionNames": ["partitionA"]
}'
# {
# "code": 0,
# "data": {}
# }
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/get_load_state" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"collectionName": "my_collection",
"partitionNames": ["partitionA"]
}'
# {
# "code": 0,
# "data": {
# "loadProgress": 0,
# "loadState": "LoadStateNotLoaded",
# "message": ""
# }
# }
auto status = client->ReleasePartitions(milvus::ReleasePartitionsRequest()
.WithCollectionName("my_collection")
.AddPartitionName("partitionA"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
milvus::GetLoadStateResponse response;
status = client->GetLoadState(milvus::GetLoadStateRequest()
.WithCollectionName("my_collection")
.AddPartitionName("partitionA"),
response);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
std::cout << std::to_string(response.State()) << std::endl;
Partitions 内のデータ操作
エンティティの挿入と削除
特定の partition で insert、upsert、delete 操作を実行できます。詳細については、以下を参照してください。
検索とクエリ
特定の partition 内で検索とクエリを実行できます。詳細については、以下を参照してください。
Partition の削除
不要になった partition を削除できます。partition を削除する前に、partition が解放されていることを確認してください。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
client.release_partitions(
collection_name="my_collection",
partition_names=["partitionA"]
)
client.drop_partition(
collection_name="my_collection",
partition_name="partitionA"
)
res = client.list_partitions(
collection_name="my_collection"
)
print(res)
# ["_default"]
import io.milvus.v2.service.partition.request.DropPartitionReq;
import io.milvus.v2.service.partition.request.ReleasePartitionsReq;
import io.milvus.v2.service.partition.request.ListPartitionsReq;
ReleasePartitionsReq releasePartitionsReq = ReleasePartitionsReq.builder()
.collectionName("my_collection")
.partitionNames(Collections.singletonList("partitionA"))
.build();
client.releasePartitions(releasePartitionsReq);
DropPartitionReq dropPartitionReq = DropPartitionReq.builder()
.collectionName("my_collection")
.partitionName("partitionA")
.build();
client.dropPartition(dropPartitionReq);
ListPartitionsReq listPartitionsReq = ListPartitionsReq.builder()
.collectionName("my_collection")
.build();
List<String> partitionNames = client.listPartitions(listPartitionsReq);
System.out.println(partitionNames);
// Output:
// [_default]
await client.releasePartitions({
collection_name: "my_collection",
partition_names: ["partitionA"]
})
await client.dropPartition({
collection_name: "my_collection",
partition_name: "partitionA"
})
res = await client.listPartitions({
collection_name: "my_collection"
})
console.log(res)
// Output
// ["_default"]
err = client.ReleasePartitions(ctx, milvusclient.NewReleasePartitionsOptions("my_collection", "partitionA"))
if err != nil {
fmt.Println(err.Error())
// handle error
}
err = client.DropPartition(ctx, milvusclient.NewDropPartitionOption("my_collection", "partitionA"))
if err != nil {
fmt.Println(err.Error())
// handle error
}
partitionNames, err := client.ListPartitions(ctx, milvusclient.NewListPartitionOption("my_collection"))
if err != nil {
fmt.Println(err.Error())
// handle error
}
fmt.Println(partitionNames)
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/release" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"collectionName": "my_collection",
"partitionNames": ["partitionA"]
}'
# {
# "code": 0,
# "data": {}
# }
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/drop" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"collectionName": "my_collection",
"partitionName": "partitionA"
}'
# {
# "code": 0,
# "data": {}
# }
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/list" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"collectionName": "my_collection"
}'
# {
# "code": 0,
# "data": [
# "_default"
# ]
# }
auto status = client->ReleasePartitions(milvus::ReleasePartitionsRequest()
.WithCollectionName("my_collection")
.AddPartitionName("partitionA"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
status = client->DropPartition(milvus::DropPartitionRequest()
.WithCollectionName("my_collection")
.WithPartitionName("partitionA"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
milvus::ListPartitionsResponse response;
status = client->ListPartitions(milvus::ListPartitionsRequest()
.WithCollectionName("my_collection"),
response);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
for (auto& info : response.PartitionInfos()) {
std::cout << "\t" << info.Name() << std::endl;
}