memory

package
v0.0.0-...-c11f1c7 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category string
const (
	CategoryCore         Category = "core"
	CategoryDaily        Category = "daily"
	CategoryConversation Category = "conversation"
	CategoryCustom       Category = "custom"
	CategoryLesson       Category = "lesson"
	CategoryCorrection   Category = "correction"
)

type Consolidator

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

Consolidator merges old memories into concise summaries.

func NewConsolidator

func NewConsolidator(store *Store, summarize SummarizeFunc) *Consolidator

NewConsolidator creates a memory consolidator. summarize is called to produce a summary of a group of memories. If nil, a simple concatenation is used as fallback.

func (*Consolidator) Consolidate

func (c *Consolidator) Consolidate(ctx context.Context) (int, error)

Consolidate finds old daily/conversation memories, groups by tags, summarizes, and replaces.

type Entry

type Entry struct {
	ID          int64
	Category    Category
	Content     string
	Tags        string
	Importance  float64
	AccessCount int
	CreatedAt   time.Time
	AccessedAt  time.Time
}

type Store

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

func NewStore

func NewStore(dbPath string) (*Store, error)

func (*Store) BuildContextFromMemory

func (s *Store) BuildContextFromMemory(ctx context.Context, query string) string

BuildContextFromMemory retrieves relevant memories for the current query and formats them for the system prompt. Core memories are ALWAYS included. Additional memories are keyword-matched from the query.

func (*Store) ClearHistory

func (s *Store) ClearHistory(_ context.Context, sessionID string) error

ClearHistory deletes all history for a session.

func (*Store) Close

func (s *Store) Close() error

Close closes the database connection.

func (*Store) Consolidate

func (s *Store) Consolidate(_ context.Context) (int64, error)

Consolidate removes old, low-importance memories that haven't been accessed recently. Keeps core, lesson, and correction memories. Removes daily/conversation/custom memories older than 30 days with low access counts and importance.

func (*Store) Count

func (s *Store) Count(_ context.Context) (int, error)

Count returns the total number of memories.

func (*Store) DB

func (s *Store) DB() *sql.DB

DB returns the underlying database connection for shared use.

func (*Store) Forget

func (s *Store) Forget(_ context.Context, id int64) error

Forget deletes a memory by ID.

func (*Store) Get

func (s *Store) Get(_ context.Context, id int64) (*Entry, error)

Get retrieves a single memory by ID.

func (*Store) GetHistory

func (s *Store) GetHistory(_ context.Context, sessionID string, limit int) ([]map[string]string, error)

GetHistory returns conversation history for a session.

func (*Store) GetLatestSessionID

func (s *Store) GetLatestSessionID() (string, error)

GetLatestSessionID returns the most recent session ID from conversation history.

func (*Store) List

func (s *Store) List(_ context.Context, category Category, limit int) ([]Entry, error)

List returns memories filtered by category.

func (*Store) ListOlderThan

func (s *Store) ListOlderThan(ctx context.Context, olderThan time.Time, limit int) ([]Entry, error)

ListOlderThan returns daily/conversation memories older than the given time.

func (*Store) MemStore

func (s *Store) MemStore(_ context.Context, category Category, content, tags string, importance float64) (int64, error)

MemStore stores a memory entry with an importance score. Importance ranges from 0.0 to 1.0 (default 0.5).

func (*Store) Recall

func (s *Store) Recall(_ context.Context, query string, limit int) ([]Entry, error)

Recall searches memories using FTS5 keyword search with composite relevance scoring. Score = fts5_rank * 0.4 + decay_score * 0.3 + importance * 0.3 where decay_score = exp(-0.05 * days_since_access) * (1 + 0.02 * access_count)

func (*Store) SaveHistory

func (s *Store) SaveHistory(_ context.Context, sessionID, role, content string) error

SaveHistory saves a conversation turn.

type SummarizeFunc

type SummarizeFunc func(ctx context.Context, memories []Entry) (string, error)

SummarizeFunc takes a batch of memories and returns a consolidated summary.

Jump to

Keyboard shortcuts

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