Partition

A partition is a group of entities in one collection with the same label. Entities inserted without a label will be tagged a default label by milvus.

Partition is managable, which means managing a group of entities with the same label in one collection.

Constructor

Constructor

Description

Partition()

Milvus partition.

Attributes

API

Description

description

Return the description text.

name

Return the partition name.

is_empty

Return whether the Partition is empty.

num_entities

Return the number of entities.

Methods

API

Description

drop()

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

load()

Load the Partition from disk to memory.

release()

Release the Partition from memory.

insert()

Insert data into partition.

search()

Vector similarity search with an optional boolean expression as filters

API Refereences

class pymilvus_orm.Partition(collection, name, description='', **kwargs)
property description

Return the description text.

Return str

Partition description text, return when operation is successful

Example

>>> from pymilvus_orm.collection import Collection
>>> from pymilvus_orm.partition import Partition
>>> from pymilvus_orm.schema import FieldSchema, CollectionSchema
>>> from pymilvus_orm.types import DataType
>>> from pymilvus_orm import connections
>>> connections.create_connection(alias="default")
<milvus.client.stub.Milvus object at 0x7f9a190ca898>
>>> field = FieldSchema("int64", DataType.INT64, "int64", is_parimary=False)
>>> schema = CollectionSchema(fields=[field], description="collection description")
>>> collection = Collection(name="test_collection", schema=schema, alias="default")
>>> partition = Partition(collection, "test_partition", "test partition desc")
>>> partition.description
'test partition desc'
property name

Return the partition name.

Return str

Partition name, return when operation is successful

Example

>>> from pymilvus_orm.collection import Collection
>>> from pymilvus_orm.partition import Partition
>>> from pymilvus_orm.schema import FieldSchema, CollectionSchema
>>> from pymilvus_orm.types import DataType
>>> from pymilvus_orm import connections
>>> connections.create_connection(alias="default")
<milvus.client.stub.Milvus object at 0x7f9a190ca898>
>>> field = FieldSchema("int64", DataType.INT64, descrition="int64", is_parimary=False)
>>> schema = CollectionSchema(fields=[field], description="collection description")
>>> collection = Collection(name="test_collection", schema=schema, alias="default")
>>> partition = Partition(collection, "test_partition", "test partition desc")
>>> partition.name
'test_partition'
property is_empty

Return whether the partition is empty

Return bool

Whether the partition is empty

Example

>>> from pymilvus_orm.collection import Collection
>>> from pymilvus_orm.partition import Partition
>>> from pymilvus_orm.schema import FieldSchema, CollectionSchema
>>> from pymilvus_orm.types import DataType
>>> from pymilvus_orm import connections
>>> connections.create_connection(alias="default")
<milvus.client.stub.Milvus object at 0x7f9a190ca898>
>>> field = FieldSchema("int64", DataType.INT64, "int64", is_parimary=False)
>>> schema = CollectionSchema(fields=[field], description="collection description")
>>> collection = Collection(name="test_collection", schema=schema, alias="default")
>>> partition = Partition(collection, "test_partition", "test partition desc")
>>> partition.is_empty
True
property num_entities

Return the number of entities.

Return int

Number of entities in this partition.

Example

>>> from pymilvus_orm.collection import Collection
>>> from pymilvus_orm.schema import FieldSchema, CollectionSchema
>>> from pymilvus_orm import connections
>>> from pymilvus_orm.types import DataType
>>> connections.create_connection()
<milvus.client.stub.Milvus object at 0x7f4d59da0be0>
>>> field = FieldSchema("int64", DataType.INT64, is_primary=False, description="int64")
>>> schema = CollectionSchema([field], description="collection schema has a int64 field")
>>> collection = Collection(name="test_collection", schema=schema)
>>> from pymilvus_orm.partition import Partition
>>> partition = Partition(collection, "test_partition")
>>> import random
>>> data = [[random.randint(1,100) for _ in range(10)]]
>>> partition.insert(data)
>>> partition.num_entities
10
drop(**kwargs)

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

Raises

PartitionNotExistException -- When partitoin does not exist

load(field_names=None, index_names=None, **kwargs)

Load the partition from disk to memory.

Parameters
  • field_names (list[str]) -- The specified fields to load.

  • index_names (list[str]) -- The specified indexes to load.

Raises

InvalidArgumentException -- If argument is not valid

release(**kwargs)

Release the partition from memory.

Raises

PartitionNotExistException -- When partitoin does not exist

insert(data, **kwargs)

Insert data into partition.

Parameters
  • data (list-like(list, tuple) object or pandas.DataFrame) -- The specified data to insert, the dimension of data needs to align with column number

  • kwargs --

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

Raises

PartitionNotExistException -- When partitoin does not exist

search(data, anns_field, params, limit, expr=None, output_fields=None, timeout=None, **kwargs)

Vector similarity search with an optional boolean expression as filters.

Parameters
  • data (list[list[float]]) -- The vectors of search data, the length of data is number of query (nq), the dim of every vector in data must be equal to vector field's of collection.

  • anns_field (str) -- The vector field used to search of collection.

  • params (dict) -- The parameters of search, such as nprobe, etc.

  • limit (int) -- The max number of returned record, we also called this parameter as topk.

  • expr (str) -- The boolean expression used to filter attribute.

  • output_fields (list[str]) -- The fields to return in the search result, not supported now.

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

  • kwargs --

    • _async (bool) -- Indicate if invoke asynchronously. When value is true, method returns a SearchResultFuture object; otherwise, method returns results from server directly.

    • _callback (function) -- The callback function which is invoked after server response successfully. It only takes effect when _async is set to True.

Returns

SearchResult: SearchResult is iterable and is a 2d-array-like class, the first dimension is the number of vectors to query (nq), the second dimension is the number of limit(topk).

Return type

SearchResult

Raises
  • RpcError -- If gRPC encounter an error.

  • ParamError -- If parameters are invalid.

  • BaseException -- If the return result from server is not ok.