Skip to main content

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.

  • 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="https://inxx-xxxxxxxxxxxx.api.gcp-us-west1.zillizcloud.com:19530",
token="user:password"
)

client.compact(
collection_name="collection_name"
)