Creating Partitions
This topic describes how to create partitions in Milvus.
Milvus allows the majority of the vector data to be divided into a small number of partitions. This enables search and other operations to be restricted to within a single partition, improving performance.
A collection consists of one or more partitions. When creating a new collection, Milvus will create a default partition, _default
. For more information, refer to the Glossary - Partition.
The following example creates a partition named novel
in the collection book
.
err := milvusClient.CreatePartition(
context.Background(), // ctx
"book", // CollectionName
"novel" // partitionName
)
if err != nil {
log.Fatal("Failed to create partition: ", err.Error())
}
Parameter | Description |
---|---|
ctx |
Context for controlling the API call process. |
CollectionName |
Name of the collection in which to create a partition. |
partitionName |
Name of the partition to be created. |
Limits
Feature | Maximum Limit |
---|---|
Number of partitions in a single collection | 4,096 |
Verifying the Existence of a Partition
Verify whether a specified partition exists in a collection.
hasPar, err := milvusClient.HasPartition(
context.Background(), // ctx
"book", // CollectionName
"novel", // partitionName
)
if err != nil {
log.Fatal("Failed to check partition: ", err.Error())
}
log.Println(hasPar)
Listing All Partitions
listPar, err := milvusClient.ShowPartitions(
context.Background(), // ctx
"book", // CollectionName
)
if err != nil {
log.Fatal("Failed to list partitions: ", err.Error())
}
log.Println(listPar)
Deleting a Partition
err := milvusClient.DropPartition(
context.Background(), // ctx
"book", // CollectionName
"novel", // partitionName
)
if err != nil {
log.Fatal("Failed to delete partition: ", err.Error())
}
Loading a Partition
Milvus allows users to load partitions as multiple replicas to leverage the CPU and memory resources of additional query nodes, improving overall QPS and throughput.
err := milvusClient.LoadPartitions(
context.Background(), // ctx
"book", // CollectionName
[]string{"novel"}, // partitionNames
false // async
)
if err != nil {
log.Fatal("Failed to load partitions: ", err.Error())
}
Releasing a Partition
err := milvusClient.ReleasePartitions(
context.Background(), // ctx
"book", // CollectionName
[]string{"novel"} // partitionNames
)
if err != nil {
log.Fatal("Failed to release partitions: ", err.Error())
}