Partitions の管理
partition は collection のサブセットです。各 partition は親 collection と同じデータ構造を共有しますが、collection 内のデータの一部のみを含みます。このページでは、partition を管理する方法について説明します。
概要
collection を作成すると、Zilliz Cloud はその collection 内に _default という名前の partition も作成します。ほかの partition を追加しない場合、collection に挿入されたすべての entity は default partition に入り、すべての検索およびクエリも default partition 内で実行されます。
特定の条件に基づいてさらに partition を追加し、それらに entity を挿入できます。その後、特定の partition 内に検索やクエリを制限することで、検索パフォーマンスを向上させることができます。
1 つの collection には最大 1,024 個の partition を持てます。
Partition Key 機能は partition に基づく検索最適化機能であり、特定の scalar フィールドの値に基づいて Zilliz Cloud が entity を異なる partition に分散できるようにします。この機能は、partition 指向のマルチテナンシーの実装と検索パフォーマンスの向上に役立ちます。
このページではこの機能については扱いません。詳細については、Use 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 に entity を挿入できます。
- 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;
Partition のロードとリリース
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;
Partition 内でのデータ操作
Entity の挿入と削除
特定の partition 内で insert、upsert、および delete 操作を実行できます。詳細については、以下を参照してください。
Search と Query
特定の partition 内で search および query を実行できます。詳細については、以下を参照してください。
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;
}