Load a Partition
This topic describes how to load a partition to memory. Loading partitions instead of the whole collection to memory can significantly reduce the memory usage. All search and query operations within Milvus are executed in memory.
Since version 2.3.0, Milvus has enhanced its partition operations and now supports cascading load and release operations. This means that you can perform any combination of the following operations:
- Load a collection that has already been loaded.
- Load a collection, and then load a specific partition in the collection.
- Load a partition, and then load the collection to which it belongs.
- Load a partition, and reload it before release.
Milvus allows users to load a partition as multiple replicas to utilize the CPU and memory resources of extra query nodes. This feature boosts the overall QPS and throughput with extra hardware. It is supported on PyMilvus in current release.
- In current release, volume of the data to load must be under 90% of the total memory resources of all query nodes to reserve memory resources for execution engine.
- In current release, all on-line query nodes will be divided into multiple replica groups according to the replica number specified by user. All replica groups shall have minimal memory resources to load one replica of the provided collection. Otherwise, an error will be returned.
When interacting with Milvus using Python code, you have the flexibility to choose between PyMilvus and MilvusClient (new). For more information, refer to Python SDK.
from pymilvus import Collection
collection = Collection("book") # Get an existing collection.
collection.load(["novel"], replica_number=2)
# Or you can load a partition with the partition as an object
from pymilvus import Partition
partition = Partition("novel") # Get an existing partition.
partition.load(replica_number=2)
await milvusClient.loadPartitions({
collection_name: "book",
partition_names: ["novel"],
});
err := milvusClient.LoadPartitions(
context.Background(), // ctx
"book", // CollectionName
[]string{"novel"}, // partitionNames
false, // async
)
if err != nil {
log.Fatal("failed to load partitions:", err.Error())
}
milvusClient.loadPartitions(
LoadPartitionsParam.newBuilder()
.withCollectionName("book")
.withPartitionNames(["novel"])
.build()
);
Parameter | Description |
---|---|
partition_name |
Name of the partition. |
replica_number (optional) |
Number of the replica to load. |
Parameter | Description |
---|---|
collection_name |
Name of the collection to load partitions from. |
partition_names |
List of names of the partitions to load. |
Parameter | Description |
---|---|
ctx |
Context to control API invocation process. |
CollectionName |
Name of the collection to load partitions from. |
partitionNames |
List of names of the partitions to load. |
async |
Switch to control sync/async behavior. The deadline of context is not applied in sync load. |
Parameter | Description |
---|---|
CollectionName |
Name of the collection to load partitions from. |
PartitionNames |
List of names of the partitions to load. |
Get replica information
You can check the information of the loaded replicas.
from pymilvus import Partition
partition = Partition("novel") # Get an existing partition.
partition.load(replica_number=2) # Load partition as 2 replicas
result = partition.get_replicas()
print(result)
What’s next
- Learn more basic operations of Milvus: