compact

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package compact implements memory compaction — auto-summarize when the graph exceeds a token budget. Based on Engram and Letta approaches.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Compactor

type Compactor struct {
	// contains filtered or unexported fields
}

Compactor summarizes old, low-confidence memories to keep the graph lean.

func New

func New(store storage.Storage, maxTokens int) *Compactor

func (*Compactor) Compact

func (c *Compactor) Compact(ctx context.Context, project string) (int, error)

Compact merges low-confidence, old memories of the same type into summary nodes. Returns the number of nodes compacted.

func (*Compactor) NeedsCompaction

func (c *Compactor) NeedsCompaction(ctx context.Context, project string) (bool, int)

NeedsCompaction returns true if total content exceeds the token budget.

func (*Compactor) WithSummarizer

func (c *Compactor) WithSummarizer(s Summarizer) *Compactor

WithSummarizer sets a custom summarizer (e.g., LLM-backed).

type DefaultSummarizer

type DefaultSummarizer struct{}

DefaultSummarizer is the built-in, no-LLM summarizer.

func (DefaultSummarizer) Summarize

func (DefaultSummarizer) Summarize(_ context.Context, typ string, contents []string) (string, error)

type Summarizer

type Summarizer interface {
	Summarize(ctx context.Context, typ string, contents []string) (string, error)
}

Summarizer generates a summary from a list of content strings. Default: naive list. Consumers (e.g., Hawk) can inject an LLM-backed implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL