Skip to main content

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.

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

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
)

The following operations are related to load():