compact()
Adds target_size/target_size_unit and positive-size validation. Async variant shares the sync method contract.
Request Syntax
compact(
collection_name: str,
is_clustering: Optional[bool] = False,
is_l0: Optional[bool] = False,
target_size: Optional[int] = None,
target_size_unit: str = "mb",
timeout: Optional[float] = None,
**kwargs,
) -> int
PARAMETERS:
-
collection_name (str) - [REQUIRED] The name of the collection to compact.
-
is_clustering (Optional[bool]) - Default:
FalseThe flag that requests a clustering compaction. -
is_l0 (Optional[bool]) - Default:
FalseThe flag that requests a level-zero compaction. -
target_size (Optional[int]) - Default:
NoneThe desired segment size after compaction. The value must be a positive integer; the server default is used when omitted. -
target_size_unit (str) - Default:
"mb"The unit fortarget_size. Supported values areb,kb,mb,gb,tb, andpb; the default ismb. -
timeout (Optional[float]) - Default:
NoneThe maximum time, in seconds, to wait for the RPC. When omitted, the client waits until the server responds or an error occurs. -
kwargs (Any) - The additional request context options.
RETURN TYPE:
int
RETURNS:
Compaction job identifier returned by Milvus.
EXCEPTIONS:
- MilvusException Raised when the server rejects the request or the RPC fails. Inspect the server error message for exact failure details.
Examples
Demonstrates compact usage.
from pymilvus import MilvusClient
client = MilvusClient(uri="http://localhost:19530")
job_id = client.compact(collection_name="book_chunks", target_size=512, target_size_unit="mb")
print(job_id)