🚀 Try Zilliz Cloud, the fully managed Milvus, for free—experience 10x faster performance! Try Now>>

milvus-logo
LFAI
< Docs
  • Python

compact()

This operation compacts the collection by merging small segments into larger ones. It is recommended to call this operation after inserting a large amount of data into a collection.

Request Syntax

compact(
    self,
    collection_name: str,
    is_clustering: Optional[bool] = False,
    timeout: Optional[float] = None,
    **kwargs,
) -> int

PARAMETERS:

  • collection_name (str) -

    The name of the target collection.

  • is_clustering (bool) -

    Whether to perform a clustering compaction. For details, refer to Clustering Compaction.

  • timeout (Optional[float]) -

    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:

int

RETURNS:

A compaction job ID, which can be used to get the compaction status.

EXCEPTIONS:

  • MilvusException

    This exception will be raised when any error occurs during this operation, especially when the specified alias does not exist.

Example

from pymilvus import MilvusClient

# 1. Create a milvus client
client = MilvusClient(
    uri="http://localhost:19530",
    token="root:Milvus"
)

client.compact(
    collection_name="collection_name"
)

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Was this page helpful?