LoadCollection()

This operation loads collection data into the query node’s CPU and memory. If the request is in sync mode, this operation checks the collection’s loading progress and waits until the collection is completely loaded into the query node. Otherwise, it will return immediately.

Status LoadCollection(const LoadCollectionRequest& request)

Request Syntax

auto request = LoadCollectionRequest()
    .WithDatabaseName(db_name)
    .WithCollectionName(collection_name)
    .WithSync(sync)
    .WithReplicaNum(replica_num)
    .WithTimeoutMs(timeout_ms)
    .WithRefresh(refresh)
    .WithLoadFields(load_fields)
    .WithSkipDynamicField(skip_dynamic_field)
    .WithTargetResourceGroups(target_resource_groups);

REQUEST METHODS:

  • WithDatabaseName(const std::string& db_name)

    Sets the target database name. The default database applies if it is empty.

  • WithCollectionName(const std::string& collection_name)

    Sets the name of the target collection.

  • WithSync(bool sync)

    Sets the sync mode. The default value is True.

    • True: wait the collection to be fully loaded.

    • False: return immediately no matter the collection is fully loaded or not.

  • WithReplicaNum(int64_t replica_num)

    Sets the number of replicas.

  • WithTimeoutMs(int64_t timeout_ms)

    Sets the timeout in milliseconds. The default value is 60000 ms. This parameter only works when this operation works in sync mode.

    If WaitFlushedMs is set to 0, this operation repeatedly calls GetLoadingProgress() to check the loading state until the collection is fully loaded into memory. If WaitFlushedMs is greater than 0, this operation will break the loop after a specified period of time and return a status indicating a timeout.

  • WithRefresh(bool refresh)

    Sets the refresh option. The default value is False. This parameter takes effect when there are new segments generated by the bulk import interface.

    • True: Loads newly generated segments from the bulk import interface.

    • False: Ignores newly generated segments from the bulk import interface.

  • WithLoadFields(const std::set<std::string>& load_fields)

    Sets the load fields.

  • AddLoadField(const std::string& field_name)

    Adds a field to be loaded.

  • WithSkipDynamicField(bool skip_dynamic_field)

    Whether to skip loading the dynamic field. The default value is False.

  • WithTargetResourceGroups(const std::set<std::string>& target_resource_groups)

    Sets the target resource groups.

RETURNS:

Status

Check status.IsOk() to confirm success.

EXCEPTIONS:

  • StatusCode

    Check status.Code() and status.Message() for error details.

Example

#include "milvus/MilvusClientV2.h"
auto client = milvus::MilvusClientV2::Create();

milvus::ConnectParam connect_param{"http://localhost:19530", "root:Milvus"};
auto status = client->Connect(connect_param);
if (!status.IsOk()) {
    std::cout << status.Message() << std::endl;
}

status = client->LoadCollection(
    milvus::LoadCollectionRequest()
        .WithCollectionName(collection_name)
);
if (!status.IsOk()) {
    std::cout << status.Message() << std::endl;
}

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Was this page helpful?