milvus-logo
LFAI
< Docs
  • Python

load()

This operation loads the data of the current collection into memory.

Request Syntax

load(
    partition_names: list[str] | None, 
    replica_number: int, 
    timeout: float | None, 
)

notes

This operation is non-blocking. You can call utility.wait_for_loading_complete() to block the current process.

PARAMETERS:

  • partition_names (list(str) | None) -

    The partitions of the current collection to load. If left unspecified, all partitions are to be loaded.

  • replica_number (int) -

    The number of replicas to create. The value defaults to 1 and ranges from 1 to the number of query nodes available. Setting this to 1 indicates that segments in the current collection or any specified partitions are to be loaded onto one query node.

    what are the differences between partitions and replicas?

    Partitioning allows you to further split a collection into multiple partitions, store different data in them, and load or release each of them individually. A collection can have up to 64 partitions.

    Replication is a mechanism for Milvus to load the same segments on multiple query nodes. It is very useful if you have a relatively small dataset but want to increase read-throughput with extra hardware resources.

  • timeout (float | None) -

    The timeout duration for this operation. Setting this to None indicates that this operation timeouts when any response arrives or any error occurs.

  • kwargs -

    • _resource_groups (list) -

      A specific set of resource groups into which the current collection is to be loaded.

      If left unspecified, the default resource group applies.

      what is a resource group?

      A resource group can hold several or all of the query nodes in a Milvus instance.

      Setting this parameter for this operation makes Milvus loads the current collection to the query nodes in the specified resource groups.

RETURN TYPE:

NoneType

RETURNS:

None

EXCEPTIONS:

  • MilvusException

    This exception is to be raised when any error occurs during this operation.

warning

If you try to load a collection that is not indexed, you will receive a MilvusException.

Examples

from pymilvus import Collection, CollectionSchema, FieldSchema, DataType

schema = CollectionSchema([
    FieldSchema("id", DataType.INT64, is_primary=True),
    FieldSchema("vector", DataType.FLOAT_VECTOR, dim=5)
])

# Create a collection
collection = Collection(
    name="test_collection",
    schema=schema
)

# Set the index parameters
index_params = {
    "index_type": "AUTOINDEX",
    "metric_type": "COSINE",
    "params": {
        "nprobe": 10
    }
}

# Create an index on the vector field
collection.create_index(
    field_name="vector", 
    index_params=index_params, 
    timeout=None
)

# Load the entire collection with one replica of the collection data
collection.load()

# Load the entire collection with two replicas of the collection data
collection.load(
    replica_number=2
)

# Load a specific partition with two replicas of the partition data
collection.load(
    partition_names=["partitionA"],
    replica_number=2
)
Feedback

Was this page helpful?