feat: add compaction ratio setting to control partial context compaction

Allow users to configure what percentage of older messages to compact,
keeping the most recent portion intact. Default ratio is 80%, meaning
the oldest 80% of uncompacted messages are summarized while the newest
20% remain as-is for full-fidelity context.
This commit is contained in:
Acbox
2026-03-29 19:14:43 +08:00
parent fc1ef4ddb3
commit 0e646625bf
23 changed files with 181 additions and 37 deletions
+1
View File
@@ -174,6 +174,7 @@ CREATE TABLE IF NOT EXISTS bots (
heartbeat_model_id UUID REFERENCES models(id) ON DELETE SET NULL,
compaction_enabled BOOLEAN NOT NULL DEFAULT false,
compaction_threshold INTEGER NOT NULL DEFAULT 100000,
compaction_ratio INTEGER NOT NULL DEFAULT 80,
compaction_model_id UUID REFERENCES models(id) ON DELETE SET NULL,
title_model_id UUID REFERENCES models(id) ON DELETE SET NULL,
tts_model_id UUID REFERENCES tts_models(id) ON DELETE SET NULL,
@@ -0,0 +1,4 @@
-- 0052_compaction_ratio (rollback)
-- Remove compaction_ratio column from bots table.
ALTER TABLE bots DROP COLUMN IF EXISTS compaction_ratio;
@@ -0,0 +1,4 @@
-- 0052_compaction_ratio
-- Add compaction_ratio column to bots table for controlling what percentage of messages to compact.
ALTER TABLE bots ADD COLUMN IF NOT EXISTS compaction_ratio INTEGER NOT NULL DEFAULT 80;