This topic describes how to load the collection to memory before a search or a query. All search and query operations within Milvus are executed in memory.
Milvus allows users to load a collection as multiple replicas to utilize the CPU and memory resources of extra query nodes. This feature boosts the overall QPS and throughput without extra hardware. Before loading a collection, ensure that you have already indexed it.
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.
err := milvusClient.LoadCollection(
context.Background(), // ctx"book", // CollectionNamefalse// async
)
if err != nil {
log.Fatal("failed to load collection:", err.Error())
}
// To get the load status
loadStatus, err := milvusClient.GetLoadState(
context.Background(), // ctx"book", // CollectionName
[]string{"Default partition"} // List of partitions
)
if err != nil {
log.Fatal("failed to get the load state", err.Error())
}
// To get the loading progress
percentage, err := milvusClient.GetLoadingProgress(
context.Background(), // ctx"book", // CollectionName
[]string{"Default partition"} // List of partitions
)
if err != nil {
log.Fatal("failed to get the loading progress", err.Error())
}
milvusClient.loadCollection(
LoadCollectionParam.newBuilder()
.withCollectionName("book")
.build()
);
// You can check the loading status
GetLoadStateParam param = GetLoadStateParam.newBuilder()
.withCollectionName(collectionName)
.build();
R<GetLoadStateResponse> response = client.getLoadState(param);
if (response.getStatus() != R.Status.Success.getCode()) {
System.out.println(response.getMessage());
}
System.out.println(response.getState());
// and loading progress as well
GetLoadingProgressParam param = GetLoadingProgressParam.newBuilder()
.withCollectionName(collectionName)
.build();
R<GetLoadingProgressResponse> response = client.getLoadingProgress(param);
if (response.getStatus() != R.Status.Success.getCode()) {
System.out.println(response.getMessage());
}
System.out.println(response.getProgress());
var collection = Client.GetCollection("book")
await collection.LoadAsync();
// You can check the loading progressvar progress = await collection.GetLoadingProgressAysnc();
Console.WriteLine(progress);
Parameter
Description
partition_name (optional)
Name of the partition to load.
replica_number (optional)
Number of the replica to load.
Parameter
Description
collection_name
Name of the collection to load.
Parameter
Description
ctx
Context to control API invocation process.
CollectionName
Name of the collection 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.
Option
Description
(Optional) replicaNumber
The name of the partition to load.
Get replica information
You can check the information of the loaded replicas.
from pymilvus import Collection
collection = Collection("book") # Get an existing collection.
collection.load(replica_number=2) # Load collection as 2 replicas
result = collection.get_replicas()
print(result)
Error will be returned at the attempt to load partition(s) when the parent collection is already loaded. Future releases will support releasing partitions from a loaded collection, and (if needed) then loading some other partition(s).
“Load successfully” will be returned at the attempt to load the collection that is already loaded.
Error will be returned at the attempt to load the collection when the child partition(s) is/are already loaded. Future releases will support loading the collection when some of its partitions are already loaded.
Loading different partitions in a same collection via separate RPCs is not allowed.