Creating partitions

Milvus allows you to partition vector data into a few partitions. Searches and other operations can be constrained to a single partition to improve performance.

A collection consists of one or more partitions. When creating a new collection, Milvus will create a default partition _default.

The following example establishes a partition named novel in the collection book.

from pymilvus import Collection
collection = Collection("book")      # Obtain an existing collection
collection.create_partition("novel")
Parameter Description
partition_name The name of the partition to create.
description (optional) Description of the partition to create.

Limitations

Feature Maximum Limit
Number of partitions in a collection 4,096

Verifying the existence of a partition

Verify if a specific partition exists in the specified collection.

from pymilvus import Collection
collection = Collection("book")      # Obtain an existing collection
collection.has_partition("novel")

Listing all partitions

from pymilvus import Collection
collection = Collection("book")      # Obtain an existing collection
collection.partitions

Deleting a partition

from pymilvus import Collection
collection.drop_partition("novel")

Loading a partition

Loading a partition into memory instead of loading the entire collection can significantly reduce memory usage. All search and query operations in Milvus are executed in memory.

Starting from version 2.3.0, Milvus has enhanced its partition operations and supports cascading loading and releasing operations. This means you can perform any combination of the following operations:

  • Load a loaded collection.
  • Load a collection, then load specific partition(s) in the collection.
  • Load a partition, then load the collection to which the partition belongs.
  • Load a partition and reload it before releasing.

Milvus allows users to load partitions as multiple replicas to leverage the CPU and memory resources of additional query nodes. This feature is supported in the current version through PyMilvus.

from pymilvus import Collection
collection = Collection("book")      # Obtain an existing collection
collection.load(["novel"], replica_number=2)

from pymilvus import Partition
partition = Partition("novel")       # Obtain an existing partition
partition.load(replica_number=2)

Getting replica information

You can view information about the loaded replicas.

from pymilvus import Partition
partition = Partition("novel")       # Obtain an existing partition
partition.load(replica_number=2)     # Load the partition with 2 replicas
result = partition.get_replicas()
print(result)

Releasing a partition

How to release a partition from memory after a search or query to reduce memory usage.

Starting from version 2.3.0, Milvus has enhanced its partition operations and supports cascading loading and releasing operations. This means you can perform any combination of the following operations:

  • Release a loaded collection.
  • Release specific partition(s) in a loaded collection.
  • Release a loaded partition.
  • Release partially loaded partitions in a collection.
from pymilvus import Partition
partition = Partition("novel")       # Obtain an existing partition
partition.release()