Utility

Methods

API

Description

loading_progress()

Drop the collection, as well as its corresponding index files.

wait_for_loading_complete()

Load the collection from disk to memory.

index_building_progress()

Release the collection from memory.

wait_for_index_building_complete()

Insert data into collection.

has_collection()

Return the number of entities.

has_partition()

Return the partition corresponding to name.

list_collections()

Checks if a specified partition exists.

APIs References

pymilvus_orm.utility.loading_progress(collection_name, partition_names=None, using='default')

Show #loaded entities vs #total entities.

Parameters
  • collection_name (str) -- The name of collection is loading

  • partition_names (str list) -- The names of partitions is loading

Return dict

Loading progress is a dict contains num of loaded entities and num of total entities. {'num_loaded_entities':loaded_segments_nums, 'num_total_entities': total_segments_nums}

Raises

PartitionNotExistException -- If partition doesn't exist.

Example
>>> from pymilvus_orm.collection import Collection
>>> from pymilvus_orm.schema import FieldSchema, CollectionSchema
>>> from pymilvus_orm.types import DataType
>>> from pymilvus_orm import connections
>>> from pymilvus_orm import utility
>>> connections.create_connection(alias="default")
>>> field = FieldSchema("int64", DataType.INT64, descrition="int64", is_parimary=False)
>>> schema = CollectionSchema(fields=[field], description="get collection entities num")
>>> collection = Collection(name="test_collection", schema=schema)
>>> import pandas as pd
>>> int64_series = pd.Series(data=list(range(10, 20)), index=list(range(10)))
>>> data = pd.DataFrame(data={"int64" : int64_series})
>>> collection.insert(data)
>>> collection.load() # load collection to memory
>>> utility.loading_progress("test_collection")
pymilvus_orm.utility.wait_for_loading_complete(collection_name, partition_names=None, timeout=None, using='default')

Block until loading is done or Raise Exception after timeout.

Parameters
  • collection_name (str) -- The name of collection to wait for loading complete

  • partition_names (str list) -- The names of partitions to wait for loading complete

  • timeout (int) -- The timeout for this method, unit: second

Raises
  • CollectionNotExistException -- If collection doesn't exist.

  • PartitionNotExistException -- If partition doesn't exist.

Example
>>> from pymilvus_orm.collection import Collection
>>> from pymilvus_orm.schema import FieldSchema, CollectionSchema
>>> from pymilvus_orm.types import DataType
>>> from pymilvus_orm import connections
>>> from pymilvus_orm import utility
>>> connections.create_connection(alias="default")
>>> field = FieldSchema("int64", DataType.INT64, descrition="int64", is_parimary=False)
>>> schema = CollectionSchema(fields=[field], description="get collection entities num")
>>> collection = Collection(name="test_collection", schema=schema)
>>> import pandas as pd
>>> int64_series = pd.Series(data=list(range(10, 20)), index=list(range(10)))
>>> data = pd.DataFrame(data={"int64" : int64_series})
>>> collection.insert(data)
>>> collection.load() # load collection to memory
>>> utility.wait_for_loading_complete("test_collection")
pymilvus_orm.utility.index_building_progress(collection_name, index_name='', using='default')

Show # indexed entities vs. # total entities.

Parameters
  • collection_name (str) -- The name of collection is building index

  • index_name (str) -- The name of index is building. Default index_name is to be used if index_name is not specific.

Return dict

Index building progress is a dict contains num of indexed entities and num of total entities. {'total_rows':total_rows,'indexed_rows':indexed_rows}

Raises
  • CollectionNotExistException -- If collection doesn't exist.

  • IndexNotExistException -- If index doesn't exist.

Example
>>> from pymilvus_orm.collection import Collection
>>> from pymilvus_orm.schema import FieldSchema, CollectionSchema
>>> from pymilvus_orm.types import DataType
>>> from pymilvus_orm import connections
>>> from pymilvus_orm import utility
>>> connections.create_connection(alias="default")
>>> _DIM = 128
>>> field = FieldSchema("float_vector", DataType.FLOAT_VECTOR, is_parimary=False, dim=_DIM)
>>> schema = CollectionSchema(fields=[field], description="test")
>>> collection = Collection(name="test_collection", schema=schema)
>>> import random
>>> import numpy as np
>>> vectors = [[random.random() for _ in range(_DIM)] for _ in range(5000)]
>>> collection.insert([vectors])
>>> collection.load() # load collection to memory
>>> index_param = {
>>>    "metric_type": "L2",
>>>    "index_type": "IVF_FLAT",
>>>    "params": {"nlist": 1024}
>>> }
>>> collection.create_index("float_vector", index_param)
>>> utility.wait_for_index_building_complete("test_collection", "")
>>> utility.loading_progress("test_collection")
pymilvus_orm.utility.wait_for_index_building_complete(collection_name, index_name='', timeout=None, using='default')

Block until building is done or Raise Exception after timeout.

Parameters
  • collection_name (str) -- The name of collection to wait

  • index_name (str) -- The name of index to wait

  • timeout (int) -- The timeout for this method, unit: second

Raises
  • CollectionNotExistException -- If collection doesn't exist.

  • IndexNotExistException -- If index doesn't exist.

Example
>>> from pymilvus_orm.collection import Collection
>>> from pymilvus_orm.schema import FieldSchema, CollectionSchema
>>> from pymilvus_orm.types import DataType
>>> from pymilvus_orm import connections
>>> from pymilvus_orm import utility
>>> connections.create_connection(alias="default")
>>> _DIM = 128
>>> field = FieldSchema("float_vector", DataType.FLOAT_VECTOR, is_parimary=False, dim=_DIM)
>>> schema = CollectionSchema(fields=[field], description="test")
>>> collection = Collection(name="test_collection", schema=schema)
>>> import random
>>> import numpy as np
>>> vectors = [[random.random() for _ in range(_DIM)] for _ in range(5000)]
>>> collection.insert([vectors])
>>> collection.load() # load collection to memory
>>> index_param = {
>>>    "metric_type": "L2",
>>>    "index_type": "IVF_FLAT",
>>>    "params": {"nlist": 1024}
>>> }
>>> collection.create_index("float_vector", index_param)
>>> utility.wait_for_index_building_complete("test_collection", "")
>>> utility.loading_progress("test_collection")
pymilvus_orm.utility.has_collection(collection_name, using='default')

Checks whether a specified collection exists.

Parameters

collection_name (str) -- The name of collection to check.

Return bool

Whether the collection exists.

Example
>>> from pymilvus_orm.collection import Collection
>>> from pymilvus_orm.schema import FieldSchema, CollectionSchema
>>> from pymilvus_orm.types import DataType
>>> from pymilvus_orm import connections
>>> from pymilvus_orm import utility
>>> connections.create_connection(alias="default")
>>> field = FieldSchema("int64", DataType.INT64, descrition="int64", is_parimary=False)
>>> schema = CollectionSchema(fields=[field], description="get collection entities num")
>>> collection = Collection(name="test_collection", schema=schema)
>>> utility.has_collection("test_collection")
pymilvus_orm.utility.has_partition(collection_name, partition_name, using='default')

Checks if a specified partition exists in a collection.

Parameters
  • collection_name (str) -- The collection name of partition to check

  • partition_name (str) -- The name of partition to check.

Return bool

Whether the partition exist.

Example
>>> from pymilvus_orm.collection import Collection
>>> from pymilvus_orm.schema import FieldSchema, CollectionSchema
>>> from pymilvus_orm.types import DataType
>>> from pymilvus_orm import connections
>>> from pymilvus_orm import utility
>>> connections.create_connection(alias="default")
>>> field = FieldSchema("int64", DataType.INT64, descrition="int64", is_parimary=False)
>>> schema = CollectionSchema(fields=[field], description="get collection entities num")
>>> collection = Collection(name="test_collection", schema=schema)
>>> utility.has_partition("_default")
pymilvus_orm.utility.list_collections(timeout=None, using='default') → list

Returns a list of all collection names.

Parameters

timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server response or error occur.

Return list[str]

List of collection names, return when operation is successful

Example
>>> from pymilvus_orm.collection import Collection
>>> from pymilvus_orm.schema import FieldSchema, CollectionSchema
>>> from pymilvus_orm.types import DataType
>>> from pymilvus_orm import connections
>>> from pymilvus_orm import utility
>>> connections.create_connection(alias="default")
>>> field = FieldSchema("int64", DataType.INT64, descrition="int64", is_parimary=False)
>>> schema = CollectionSchema(fields=[field], description="get collection entities num")
>>> collection = Collection(name="test_collection", schema=schema)
>>> utility.list_collections()