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.collectionManager.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();
compact -c book
curl -X 'POST' \
  'http://localhost:9091/api/v1/compaction' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "collectionID": 434262071120432449
  }'
Output:
{"status":{},"compactionID":434262132129005569}
Parameter Description
collection_name Name of the collection to compact data.
Parameter Description
CollectionName Name of the collection to compact data.
Option Description
-c 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.collectionManager.getCompactionState({
    compactionID
});
// This function is under active development on the GO client.
milvusClient.getCompactionState(GetCompactionStateParam.newBuilder()
  .withCompactionID(compactionID)
  .build()
);
show compaction_state -c book
curl -X 'GET' \
  'http://localhost:9091/api/v1/compaction/state' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "compactionID": 434262132129005569
  }'
Output:
{"status":{},"state":2}

What's next

Is this page helpful?
On this page