Skip to main content

CompactionTree

Struct CompactionTree 

Source
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: usize

Line count threshold for triggering compaction.

Implementations§

Source§

impl CompactionTree

Source

pub fn new(line_threshold: usize) -> Self

Create a new compaction tree with the given line threshold.

Source

pub fn default_tree() -> Self

Create with default threshold (200 lines).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more