pub struct CompactionTree {
pub line_threshold: usize,
}Expand description
Compaction tree manager.
Manages the 5-level compression hierarchy. Dream calls compact() to
promote entries up the tree when they exceed size thresholds.
§Usage
let tree = CompactionTree::default_tree();
// Check if content should be promoted
if tree.should_promote("long content...", CompactionLevel::Raw) {
let compacted = tree.compact_to_level("long content...", CompactionLevel::Raw, CompactionLevel::Daily);
}
// Promote several entries at once
let entries = vec!["entry 1".to_string(), "entry 2".to_string()];
let daily_summary = tree.promote(&entries, CompactionLevel::Raw);Fields§
§line_threshold: usizeLine count threshold for triggering compaction.
Implementations§
Source§impl CompactionTree
impl CompactionTree
Sourcepub fn new(line_threshold: usize) -> CompactionTree
pub fn new(line_threshold: usize) -> CompactionTree
Create a new compaction tree with the given line threshold.
Sourcepub fn default_tree() -> CompactionTree
pub fn default_tree() -> CompactionTree
Create with default threshold (200 lines).
Sourcepub fn should_compact(&self, content: &str) -> bool
pub fn should_compact(&self, content: &str) -> bool
Check if content should be compacted based on line count.
Uses the tree’s configured line_threshold.
Sourcepub fn should_promote(
&self,
content: &str,
current_level: CompactionLevel,
) -> bool
pub fn should_promote( &self, content: &str, current_level: CompactionLevel, ) -> bool
Check if content at a given level should be promoted to the next level.
Promotion is indicated when the content exceeds the threshold for its current compaction level.
Sourcepub fn compact_to_level(
&self,
content: &str,
from: CompactionLevel,
to: CompactionLevel,
) -> String
pub fn compact_to_level( &self, content: &str, from: CompactionLevel, to: CompactionLevel, ) -> String
Compact content from one level to another.
This applies rule-based compression appropriate for the target level.
If to is not strictly higher than from, the content is returned
unchanged.
§Multi-level compaction
When compacting across multiple levels (e.g., Raw → Weekly), the compression is applied progressively through each intermediate level for better quality.
Sourcepub fn promote(&self, entries: &[String], level: CompactionLevel) -> String
pub fn promote(&self, entries: &[String], level: CompactionLevel) -> String
Promote multiple entries from a given level into a single summary at the next level.
This is used by the dream process to consolidate several entries (e.g., multiple daily summaries) into one higher-level summary (e.g., a weekly summary).
§Returns
A compacted summary string combining all entries.
Sourcepub fn rule_based_compact(&self, content: &str) -> String
pub fn rule_based_compact(&self, content: &str) -> String
Simple rule-based compaction: preserve first/last sentences of each paragraph, discard middle.
This is the fallback when LLM compaction is not available.