@@ -34,13 +34,17 @@ struct Config {
3434
3535 // Compaction configuration (inspired by Qdrant and Milvus best practices)
3636 std::atomic<bool > AutoCompaction{true }; // Enable automatic compaction (default: true)
37- std::atomic<double > CompactionThreshold{0.2 }; // Trigger compaction when 20 % deleted (default: 0.2 )
37+ std::atomic<double > CompactionThreshold{0.3 }; // Trigger compaction when 30 % deleted (default: 0.3 )
3838 std::atomic<int > CompactionInterval{3600 }; // Check interval in seconds (default: 1 hour)
3939 std::atomic<int > MinVectorsForCompaction{1000 }; // Minimum vectors to trigger compaction (default: 1000)
4040 std::atomic<int > CompactionMaxDuration{1800 }; // Maximum compaction duration in seconds (default: 30 min)
4141
4242 // Memory management configuration
4343 std::atomic<int > InitialTableCapacity{1000 }; // Initial table capacity (default: 1000, was 150000)
44+
45+ // Eager compaction configuration: run Table::Compact() immediately after large soft-deletes
46+ std::atomic<bool > EagerCompactionOnDelete{true }; // Default: true
47+ // std::atomic<bool> EagerCompactionOnDelete{false}; --- IGNORE
4448
4549 // Constructor to initialize thread counts based on hardware
4650 Config () {
@@ -127,6 +131,16 @@ struct Config {
127131 }
128132 }
129133
134+ // Eager compaction toggle after delete (optional)
135+ const char * env_eager_delete_compact = std::getenv (" EAGER_DELETE_COMPACT" );
136+ if (env_eager_delete_compact != nullptr ) {
137+ std::string env_value (env_eager_delete_compact);
138+ std::transform (env_value.begin (), env_value.end (), env_value.begin (), ::tolower);
139+ bool eager = (env_value == " true" || env_value == " 1" || env_value == " yes" );
140+ EagerCompactionOnDelete.store (eager, std::memory_order_release);
141+ printf (" [Config] Using EAGER_DELETE_COMPACT=%s from environment\n " , eager ? " true" : " false" );
142+ }
143+
130144 // Check environment variable for initial table capacity
131145 const char * env_initial_capacity = std::getenv (" INITIAL_TABLE_CAPACITY" );
132146 if (env_initial_capacity != nullptr ) {
@@ -218,6 +232,9 @@ struct Config {
218232 InitialTableCapacity.store (capacity, std::memory_order_release);
219233 }
220234 }
235+ if (json.HasMember (" EagerCompactionOnDelete" )) {
236+ EagerCompactionOnDelete.store (json.GetBool (" EagerCompactionOnDelete" ), std::memory_order_release);
237+ }
221238 }
222239
223240 // Setter method for SoftDelete mode
@@ -245,6 +262,7 @@ struct Config {
245262 config.SetInt (" MinVectorsForCompaction" , MinVectorsForCompaction.load (std::memory_order_acquire));
246263 config.SetInt (" CompactionMaxDuration" , CompactionMaxDuration.load (std::memory_order_acquire));
247264 config.SetInt (" InitialTableCapacity" , InitialTableCapacity.load (std::memory_order_acquire));
265+ config.SetBool (" EagerCompactionOnDelete" , EagerCompactionOnDelete.load (std::memory_order_acquire));
248266 return config;
249267 }
250268};
0 commit comments