Manage Partitions
A partition is a subset of a collection. Each partition shares the same data structure with its parent collection but contains only a subset of the data in the collection. This page helps you understand how to manage partitions.
Overview
When creating a collection, Milvus also creates a partition named _default in the collection. If you are not going to add any other partitions, all entities inserted into the collection go into the default partition, and all searches and queries are also carried out within the default partition.
You can add more partitions and insert entities into them based on certain criteria. Then you can restrict your searches and queries within certain partitions, improving search performance.
A collection can have a maximum of 1,024 partitions.
The Partition Key feature is a search optimization based on partitions and allows Milvus to distribute entities into different partitions based on the values in a specific scalar field. This feature helps implement partition-oriented multi-tenancy and improves search performance.
This feature will not be discussed on this page. To find more, refer to Use Partition Key.
List Partitions
When creating a collection, Milvus also creates a partition named _default in the collection. You can list the partitions in a collection as follows.
from pymilvus import MilvusClient
client = MilvusClient(
uri="http://localhost:19530",
token="root:Milvus"
)
res = client.list_partitions(
collection_name="quick_setup"
)
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 = "http://localhost:19530";
String TOKEN = "root:Milvus";
// 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("quick_setup")
.build();
List<String> partitionNames = client.listPartitions(listPartitionsReq);
System.out.println(partitionNames);
// Output:
// [_default]
import { MilvusClient, DataType } from "@zilliz/milvus2-sdk-node";
const address = "http://localhost:19530";
const token = "root:Milvus";
const client = new MilvusClient({address, token});
let res = await client.listPartitions({
collection_name: "quick_setup"
})
console.log(res);
// Output
// ["_default"]
import (
"context"
client "github.com/milvus-io/milvus/client/v2/milvucclient"
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
milvusAddr := "127.0.0.1:19530"
token := "root:Milvus"
cli, err := client.New(ctx, &client.ClientConfig{
Address: milvusAddr,
APIKey: token,
})
if err != nil {
// handle error
}
defer cli.Close(ctx)
partitionNames, err := cli.ListPartitions(ctx, client.NewListPartitionOption("quick_setup"))
if err != nil {
// handle error
}
fmt.Println(partitionNames)
export CLUSTER_ENDPOINT="http://localhost:19530"
export TOKEN="root:Milvus"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/list" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "quick_setup"
}'
# {
# "code": 0,
# "data": [
# "_default"
# ]
# }
Create Partition
You can add more partitions to the collection and insert entities into these partitions based on certain criteria.
client.create_partition(
collection_name="quick_setup",
partition_name="partitionA"
)
res = client.list_partitions(
collection_name="quick_setup"
)
print(res)
# Output
#
# ["_default", "partitionA"]
import io.milvus.v2.service.partition.request.CreatePartitionReq;
CreatePartitionReq createPartitionReq = CreatePartitionReq.builder()
.collectionName("quick_setup")
.partitionName("partitionA")
.build();
client.createPartition(createPartitionReq);
ListPartitionsReq listPartitionsReq = ListPartitionsReq.builder()
.collectionName("quick_setup")
.build();
List<String> partitionNames = client.listPartitions(listPartitionsReq);
System.out.println(partitionNames);
// Output:
// [_default, partitionA]
await client.createPartition({
collection_name: "quick_setup",
partition_name: "partitionA"
})
res = await client.listPartitions({
collection_name: "quick_setup"
})
console.log(res)
// Output
// ["_default", "partitionA"]
import (
"fmt"
client "github.com/milvus-io/milvus/client/v2/milvusclient"
)
err = cli.CreatePartition(ctx, client.NewCreatePartitionOption("quick_setup", "partitionA"))
if err != nil {
// handle error
}
partitionNames, err := cli.ListPartitions(ctx, client.NewListPartitionOption("quick_setup"))
if err != nil {
// handle error
}
fmt.Println(partitionNames)
// Output
// ["_default", "partitionA"]
export CLUSTER_ENDPOINT="http://localhost:19530"
export TOKEN="root:Milvus"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/create" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "quick_setup",
"partitionName": "partitionA"
}'
# {
# "code": 0,
# "data": {}
# }
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/list" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "quick_setup"
}'
# {
# "code": 0,
# "data": [
# "_default",
# "partitionA"
# ]
# }
Check for a Specific Partition
The following code snippets demonstrate how to check whether a partition exists in a specific collection.
res = client.has_partition(
collection_name="quick_setup",
partition_name="partitionA"
)
print(res)
# Output
#
# True
import io.milvus.v2.service.partition.request.HasPartitionReq;
HasPartitionReq hasPartitionReq = HasPartitionReq.builder()
.collectionName("quick_setup")
.partitionName("partitionA")
.build();
Boolean hasPartitionRes = client.hasPartition(hasPartitionReq);
System.out.println(hasPartitionRes);
// Output:
// true
res = await client.hasPartition({
collection_name: "quick_setup",
partition_name: "partitionA"
})
console.log(res.value)
// Output
// true
import (
"fmt"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)
result, err := cli.HasPartition(ctx, milvusclient.NewHasPartitionOption("quick_setup", "partitionA"))
if err != nil {
// handle error
}
fmt.Println(result)
// Output:
// true
export CLUSTER_ENDPOINT="http://localhost:19530"
export TOKEN="root:Milvus"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/has" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "quick_setup",
"partitionName": "partitionA"
}'
# {
# "code": 0,
# "data": {
# "has": true
# }
# }
Load and Release Partitions
You can separately load or release one or certain partitions.
Load Partitions
You can separately load specific partitions in a collection. It is worth noting that the load status of a collection stays unloaded if there is an unloaded partition in the collection.
client.load_partitions(
collection_name="quick_setup",
partition_names=["partitionA"]
)
res = client.get_load_state(
collection_name="quick_setup",
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("quick_setup")
.partitionNames(Collections.singletonList("partitionA"))
.build();
client.loadPartitions(loadPartitionsReq);
GetLoadStateReq getLoadStateReq = GetLoadStateReq.builder()
.collectionName("quick_setup")
.partitionName("partitionA")
.build();
Boolean getLoadStateRes = client.getLoadState(getLoadStateReq);
System.out.println(getLoadStateRes);
// True
await client.loadPartitions({
collection_name: "quick_setup",
partition_names: ["partitionA"]
})
res = await client.getLoadState({
collection_name: "quick_setup",
partition_name: "partitionA"
})
console.log(res)
// Output
//
// LoadStateLoaded
//
// Go 缺失
export CLUSTER_ENDPOINT="http://localhost:19530"
export TOKEN="root:Milvus"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/load" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "quick_setup",
"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" \
-d '{
"collectionName": "quick_setup",
"partitionNames": ["partitionA"]
}'
# {
# "code": 0,
# "data": {
# "loadProgress": 100,
# "loadState": "LoadStateLoaded",
# "message": ""
# }
# }
Release Partitions
You can also release specific partitions.
client.release_partitions(
collection_name="quick_setup",
partition_names=["partitionA"]
)
res = client.get_load_state(
collection_name="quick_setup",
partition_name="partitionA"
)
print(res)
# Output
#
# {
# "state": "<LoadState: NotLoaded>"
# }
import io.milvus.v2.service.partition.request.ReleasePartitionsReq;
ReleasePartitionsReq releasePartitionsReq = ReleasePartitionsReq.builder()
.collectionName("quick_setup")
.partitionNames(Collections.singletonList("partitionA"))
.build();
client.releasePartitions(releasePartitionsReq);
GetLoadStateReq getLoadStateReq = GetLoadStateReq.builder()
.collectionName("quick_setup")
.partitionName("partitionA")
.build();
Boolean getLoadStateRes = client.getLoadState(getLoadStateReq);
System.out.println(getLoadStateRes);
// False
await client.releasePartitions({
collection_name: "quick_setup",
partition_names: ["partitionA"]
})
res = await client.getLoadState({
collection_name: "quick_setup",
partition_name: "partitionA"
})
console.log(res)
// Output
//
// LoadStateNotLoaded
//
// Go 缺失
export CLUSTER_ENDPOINT="http://localhost:19530"
export TOKEN="root:Milvus"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/release" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "quick_setup",
"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" \
-d '{
"collectionName": "quick_setup",
"partitionNames": ["partitionA"]
}'
# {
# "code": 0,
# "data": {
# "loadProgress": 0,
# "loadState": "LoadStateNotLoaded",
# "message": ""
# }
# }
Data Operations Within Partitions
Insert and Delete Entities
You can perform insert, upsert, and delete operations in specific operations. For details, refer to
Search and Query
You can conduct searches and queries within specific partitions. For details, refer to
Drop Partition
You can drop partitions that are no longer needed. Before dropping a partition, ensure that the partition has been released.
client.release_partitions(
collection_name="quick_setup",
partition_names=["partitionA"]
)
client.drop_partition(
collection_name="quick_setup",
partition_name="partitionA"
)
res = client.list_partitions(
collection_name="quick_setup"
)
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("quick_setup")
.partitionNames(Collections.singletonList("partitionA"))
.build();
client.releasePartitions(releasePartitionsReq);
DropPartitionReq dropPartitionReq = DropPartitionReq.builder()
.collectionName("quick_setup")
.partitionName("partitionA")
.build();
client.dropPartition(dropPartitionReq);
ListPartitionsReq listPartitionsReq = ListPartitionsReq.builder()
.collectionName("quick_setup")
.build();
List<String> partitionNames = client.listPartitions(listPartitionsReq);
System.out.println(partitionNames);
// Output:
// [_default]
await client.releasePartitions({
collection_name: "quick_setup",
partition_names: ["partitionA"]
})
await client.dropPartition({
collection_name: "quick_setup",
partition_name: "partitionA"
})
res = await client.listPartitions({
collection_name: "quick_setup"
})
console.log(res)
// Output
// ["_default"]
// Go 缺失
export CLUSTER_ENDPOINT="http://localhost:19530"
export TOKEN="root:Milvus"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/release" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "quick_setup",
"partitionNames": ["partitionA"]
}'
# {
# "code": 0,
# "data": {}
# }
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/drop" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "quick_setup",
"partitionName": "partitionA"
}'
# {
# "code": 0,
# "data": {}
# }
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/partitions/list" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "quick_setup"
}'
# {
# "code": 0,
# "data": [
# "_default"
# ]
# }