memory

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package memory defines memini's core domain types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeContent

func NormalizeContent(s string) string

NormalizeContent collapses whitespace and case so trivially-duplicated memories compare equal. Used by recall dedup and the fsck duplicate audit.

Types

type Memory

type Memory struct {
	ID        string `json:"id"`
	Namespace string `json:"namespace"`
	Tier      Tier   `json:"tier"`
	Content   string `json:"content"`
	Summary   string `json:"summary,omitempty"`

	// Metadata is arbitrary structured data, persisted as JSON.
	Metadata map[string]any `json:"metadata,omitempty"`
	// Tags are free-form labels used for keyword retrieval and filtering.
	Tags []string `json:"tags,omitempty"`

	// Importance biases decay and ranking; higher survives longer. Range [0,1].
	Importance float64 `json:"importance"`

	CreatedAt      time.Time  `json:"created_at"`
	UpdatedAt      time.Time  `json:"updated_at"`
	LastAccessedAt time.Time  `json:"last_accessed_at"`
	AccessCount    int        `json:"access_count"`
	ExpiresAt      *time.Time `json:"expires_at,omitempty"`

	// SupersededBy points at the memory that replaced this one during
	// contradiction resolution; non-nil means this record is tombstoned.
	SupersededBy *string `json:"superseded_by,omitempty"`

	// Embedding is the dense vector for similarity search. It is required when
	// writing to the store and is omitted from API responses.
	Embedding []float32 `json:"-"`
}

Memory is a single stored memory, scoped to a namespace (tenant/agent).

func (*Memory) Expired

func (m *Memory) Expired(now time.Time) bool

Expired reports whether the memory has passed its TTL as of now.

func (*Memory) Recency

func (m *Memory) Recency(now time.Time) float64

Recency returns an exponentially-decaying [0,1] factor for how recently the memory was accessed, halving every retentionHalfLife. Used by recall ranking.

func (*Memory) RetentionScore

func (m *Memory) RetentionScore(now time.Time) float64

RetentionScore ranks a memory for short-term eviction (higher = keep longer). It rewards importance and access frequency, and decays exponentially with time since last access. Used to bound short-term capacity.

type Term

type Term string

Term is the coarse memory horizon: short-term memories are transient and TTL'd; long-term memories are durable and curated.

const (
	ShortTerm Term = "short" // working, episodic — transient, decays
	LongTerm  Term = "long"  // semantic, procedural — durable, curated
)

type Tier

type Tier string

Tier classifies a memory by how consolidated it is: working → episodic → semantic, with procedural held separately for how-to knowledge.

const (
	// TierWorking holds raw, short-lived observations (typically session-scoped).
	TierWorking Tier = "working"
	// TierEpisodic holds summaries of what happened in a session.
	TierEpisodic Tier = "episodic"
	// TierSemantic holds durable extracted facts ("what I know").
	TierSemantic Tier = "semantic"
	// TierProcedural holds workflows and how-to knowledge.
	TierProcedural Tier = "procedural"
)

func (Tier) DefaultTTL

func (t Tier) DefaultTTL() time.Duration

DefaultTTL is the TTL for a tier; zero means never expires.

func (Tier) Term

func (t Tier) Term() Term

Term maps a tier to its memory horizon. Working/episodic are short-term; semantic/procedural are long-term.

func (Tier) Valid

func (t Tier) Valid() bool

Valid reports whether t is a known tier.

Jump to

Keyboard shortcuts

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