milvus-logo

Compact Data

This topic describes how to compact data in Milvus.

Milvus supports automatic data compaction by default. You can configure your Milvus to enable or disable compaction and automatic compaction.

If automatic compaction is disabled, you can still compact data manually.

To ensure accuracy of searches with Time Travel, Milvus retains the data operation log within the span specified in common.retentionDuration. Therefore, data operated within this period will not be compacted.

Compact data manually

Compaction requests are processed asynchronously because they are usually time-consuming.

from pymilvus import Collection
collection = Collection("book")      # Get an existing collection.
collection.compact()
const res = await milvusClient.compact({
  collection_name: "book",
});
const compactionID = res.compactionID;
// This function is under active development on the GO client.
R<ManualCompactionResponse> response = milvusClient.manualCompaction(
  ManualCompactionParam.newBuilder()
    .withCollectionName("book")
    .build()
);
long compactionID = response.getData().getCompactionID();
await milvusClient.GetCollection("book").CompactAsync();
Parameter Description
collection_name Name of the collection to compact data.
Parameter Description
CollectionName Name of the collection to compact data.

Check compaction status

You can check the compaction status with the compaction ID returned when the manual compaction is triggered.

collection.get_compaction_state()
const state = await milvusClient.getCompactionState({
    compactionID
});
// This function is under active development on the GO client.
milvusClient.getCompactionState(GetCompactionStateParam.newBuilder()
  .withCompactionID(compactionID)
  .build()
);

What's next

On this page