milvus-logo
LFAI
Home
  • User Guide

Load a Collection

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.
from pymilvus import Collection, utility

# Get an existing collection.
collection = Collection("book")      
collection.load(replica_number=2)

# Check the loading progress and loading status
utility.load_state("book")
# Output: <LoadState: Loaded>

utility.loading_progress("book")
# Output: {'loading_progress': 100%}
await milvusClient.loadCollection({
  collection_name: "book",
});
err := milvusClient.LoadCollection(
  context.Background(),   // ctx
  "book",                 // CollectionName
  false                   // 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 progress

var 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)
GetReplicasParam getReplicasParam = GetReplicasParam.newBuilder()
    .withCollectionName("book")
    .build();

client.getReplicas(getReplicasParam);
replicas, err = client.GetReplicas(context.Background(), "book")
let res = client.getReplicas({
    collectionID: '436777253933154305' // should be a collection id returned by a compact task.
})

Below is an example of the output.

Replica groups:
- Group: <group_id:435309823872729305>, <group_nodes:(21, 20)>, <shards:[Shard: <channel_name:milvus-zong-rootcoord-dml_27_435367661874184193v0>, <shard_leader:21>, <shard_nodes:[21]>, Shard: <channel_name:milvus-zong-rootcoord-dml_28_435367661874184193v1>, <shard_leader:20>, <shard_nodes:[20, 21]>]>
- Group: <group_id:435309823872729304>, <group_nodes:(25,)>, <shards:[Shard: <channel_name:milvus-zong-rootcoord-dml_28_435367661874184193v1>, <shard_leader:25>, <shard_nodes:[25]>, Shard: <channel_name:milvus-zong-rootcoord-dml_27_435367661874184193v0>, <shard_leader:25>, <shard_nodes:[25]>]>

Constraints

  • 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.

What’s next

Feedback

Was this page helpful?