milvus-logo
LFAI
< Docs

load_state()

This method gets the loading status of a collection or a partition.

Invocation

load_state(collection_name, partition_names=None, using="default", timeout=None)

Parameters

ParameterDescriptionTypeRequired
collection_nameName of a collectionStringTrue
partition_nameName of a partitionStringFalse
usingAlias of the Milvus connection to be attached toStringFalse
timeoutTimeout duration of this operationfloatFalse

Return

Returns a LoadState enumerate object.

StateCodeDescription
NotExist0Indicates that the specified collection or partition does not exist.
NotLoad1Indicates that the specified collection or partition is not loaded.
Loading2Indicates that Milvus is loading the specified collection or partition.
Loaded3Indicates that Milvus finishes loading the specified collection or partition and it is ready for searches.

Example

from pymilvus import Collection, connections, FieldSchema, CollectionSchema, DataType, utility

# Check the load status before the collecction exists. 
# It should return 0, indicating that the collection does not exist yet.
print(utility.load_state("films"))

connections.connect()

fields = [
    FieldSchema("film_id", DataType.INT64, is_primary=True),
    FieldSchema("films", DataType.FLOAT_VECTOR, dim=8)
]

schema = CollectionSchema(fields)
collection = Collection("films", schema)
data = pd.DataFrame({
    "film_id" : pd.Series(data=list(range(10, 20)), index=list(range(10))),
    "films": [[random.random() for _ in range(8)] for _ in range (10)],
}) 

collection.insert(data)
collection.create_index("films", {"index_type": "IVF_FLAT", "params": {"nlist": 8}, "metric_type": "L2"})

# Check the load status of the collection before Milvus loads the collection to the query nodes. 
# It should return 1, indicating that the collection is not loaded yet.
print(utility.load_state("films"))

collection.load(_async=True)

# Run immediately after calling the load method.
# It should return 2, indicating that Milvus is loading the collection to the query nodes. 
print(utility.load_state("films"))

# Wait until the loading progress ends
utility.wait_for_loading_complete("films")

# This should return 3, indicating that the collection is ready for searches.
print(utility.load_state("films"))
Feedback

Was this page helpful?