Documentation
¶
Overview ¶
Package yaad provides a graph-native persistent memory engine for AI coding agents. It stores, indexes, and retrieves contextual memories using a DAG with typed nodes and edges, a 4-signal hybrid search (BM25 + vector + graph + temporal) fused via reciprocal-rank fusion, and tiered spatial memory (hot/warm/cold) with promotion thresholds and token budgets.
Spatial memory management (this file) divides entries into three access tiers, promotes entries based on recent hit counts, demotes idle entries, and enforces per-tier token budgets by evicting the least-recently accessed entries first. The system is safe for concurrent use.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ImportMemory ¶
func ImportMemory(sm *SpatialMemory, export *MemoryExport) (int, error)
ImportMemory copies the entries from export into sm, overwriting any existing entries that share the same ID. Each imported entry retains its original tier, access count, and timestamps so the restored state matches the exported state. Entries with an empty ID or an unrecognized tier are skipped. It returns the number of entries successfully imported.
Types ¶
type ExportConfig ¶
type ExportConfig struct {
// IncludeColdTier includes cold-tier (rarely accessed) entries when true.
// When false, cold entries are omitted, reducing export size.
IncludeColdTier bool
// MaxEntries caps the number of entries in the export. Entries are sorted
// by LastAccessed descending before truncation, so the most recently
// accessed entries are retained. Zero or negative means unlimited.
MaxEntries int
// Format declares the intended serialization format: "json" (default) or
// "gzipped". ExportMemory validates this value; the actual compression is
// the caller's responsibility (e.g. wrapping the writer in gzip.NewWriter).
Format string
}
ExportConfig controls what ExportMemory includes in a MemoryExport and in which on-wire format the export is intended to be written.
type MemoryEntry ¶
type MemoryEntry struct {
ID string
Content string
Tier TierType
AccessCount int
LastAccessed time.Time
CreatedAt time.Time
TokenCount int
}
MemoryEntry is a single memory unit tracked by the spatial memory system.
type MemoryExport ¶
type MemoryExport struct {
Version string `json:"version"`
ExportedAt time.Time `json:"exported_at"`
Entries []MemoryEntry `json:"entries"`
Stats TierStatsMap `json:"stats"`
}
MemoryExport is a serializable snapshot of a SpatialMemory's entries and tier statistics. It is produced by ExportMemory and consumed by ImportMemory to back up and restore spatial memory state.
func ExportMemory ¶
func ExportMemory(sm *SpatialMemory, config ExportConfig) (*MemoryExport, error)
ExportMemory captures the current state of sm into a MemoryExport, shaped by config. The returned Stats describe only the entries that made it into the export (after tier filtering and MaxEntries truncation).
func ReadMemoryExport ¶
func ReadMemoryExport(r io.Reader) (*MemoryExport, error)
ReadMemoryExport decodes a MemoryExport from the JSON format produced by WriteTo.
func (*MemoryExport) Summary ¶
func (me *MemoryExport) Summary() string
Summary returns a one-line human-readable description of the export, including its version, timestamp, and per-tier entry breakdown.
type SpatialMemory ¶
type SpatialMemory struct {
// contains filtered or unexported fields
}
SpatialMemory manages a tiered set of memory entries with token budgets per tier. It is safe for concurrent use.
func NewSpatialMemory ¶
func NewSpatialMemory(hotBudget, warmBudget, coldBudget int) *SpatialMemory
NewSpatialMemory creates a SpatialMemory with the given token budgets per tier.
func (*SpatialMemory) Access ¶
func (sm *SpatialMemory) Access(id string) (MemoryEntry, bool)
Access records an access to the memory entry with the given id, updating its tier according to the promotion rules. Returns a copy of the entry, or false if the id was not found.
func (*SpatialMemory) Add ¶
func (sm *SpatialMemory) Add(entry MemoryEntry)
Add inserts a new memory entry. If the entry already exists it is overwritten. New entries always land in TierCold; LastAccessed defaults to now and CreatedAt fills in if zero.
func (*SpatialMemory) Compact ¶
func (sm *SpatialMemory) Compact()
Compact demotes entries that violate idle thresholds and enforces token budgets by demoting the least-recently-accessed entries first.
func (*SpatialMemory) Remove ¶
func (sm *SpatialMemory) Remove(id string) bool
Remove deletes the memory entry with the given id.
func (*SpatialMemory) TierStats ¶
func (sm *SpatialMemory) TierStats() map[TierType]struct{ Count, Tokens int }
TierStats returns the count of entries and total token usage for each tier. It snapshots entry pointers under the lock and computes stats outside it, reducing lock hold time for large entry sets.
type TierStatsMap ¶
TierStatsMap maps each TierType to its aggregate statistics.
Directories
¶
| Path | Synopsis |
|---|---|
|
benchmark
|
|
|
cmd/longmemreport
command
|
|
|
Package browse presents stored memories as a navigable virtual filesystem (directories per category, files per memory) for tree/search/get access.
|
Package browse presents stored memories as a navigable virtual filesystem (directories per category, files per memory) for tree/search/get access. |
|
Package compact implements memory compaction — auto-summarize when the graph exceeds a token budget.
|
Package compact implements memory compaction — auto-summarize when the graph exceeds a token budget. |
|
Package config loads, validates, and provides defaults for yaad's configuration (server, storage, embeddings, and related settings).
|
Package config loads, validates, and provides defaults for yaad's configuration (server, storage, embeddings, and related settings). |
|
Package conflict detects and resolves contradictory memories.
|
Package conflict detects and resolves contradictory memories. |
|
Package dedup implements rolling-window deduplication.
|
Package dedup implements rolling-window deduplication. |
|
Package embeddings provides a pluggable embedding provider interface.
|
Package embeddings provides a pluggable embedding provider interface. |
|
Package engine is the core of yaad: it ties storage, the typed graph, dedup, decay, conflict resolution, and hybrid recall together behind the Engine type, the main entry point for remember/recall/forget operations.
|
Package engine is the core of yaad: it ties storage, the typed graph, dedup, decay, conflict resolution, and hybrid recall together behind the Engine type, the main entry point for remember/recall/forget operations. |
|
cognitive
Package cognitive implements yaad's higher-level memory subsystems — epistemic state, curiosity, boundary detection, reconsolidation, and related processes layered on top of the core engine.
|
Package cognitive implements yaad's higher-level memory subsystems — epistemic state, curiosity, boundary detection, reconsolidation, and related processes layered on top of the core engine. |
|
Package exportimport handles JSON round-trip, Markdown, and Obsidian vault export.
|
Package exportimport handles JSON round-trip, Markdown, and Obsidian vault export. |
|
Package git provides git-awareness for memory staleness: it watches the working tree and HEAD so memories tied to changed files can be flagged or decayed.
|
Package git provides git-awareness for memory staleness: it watches the working tree and HEAD so memories tied to changed files can be flagged or decayed. |
|
Package graph implements yaad's typed, acyclic memory graph: nodes connected by typed edges, with cycle-checked insertion and traversal helpers used by recall and link suggestion.
|
Package graph implements yaad's typed, acyclic memory graph: nodes connected by typed edges, with cycle-checked insertion and traversal helpers used by recall and link suggestion. |
|
Package hooks implements auto-capture hooks for lifecycle events.
|
Package hooks implements auto-capture hooks for lifecycle events. |
|
Package ingest - semantic code chunker.
|
Package ingest - semantic code chunker. |
|
Package intent classifies query intent to route graph traversal.
|
Package intent classifies query intent to route graph traversal. |
|
internal
|
|
|
bench
Package bench implements a LongMemEval-style evaluation harness for Yaad.
|
Package bench implements a LongMemEval-style evaluation harness for Yaad. |
|
daemon
Package daemon manages yaad's background server lifecycle: PID file tracking, health checks, and auto-start logic.
|
Package daemon manages yaad's background server lifecycle: PID file tracking, health checks, and auto-start logic. |
|
proactive
Package proactive implements proactive context preloading for yaad.
|
Package proactive implements proactive context preloading for yaad. |
|
search
Package search provides intent-aware retrieval routing for yaad's graph.
|
Package search provides intent-aware retrieval routing for yaad's graph. |
|
server
Package server exposes yaad over the network: the REST API, the MCP server, and the browser dashboard, all backed by the same engine.
|
Package server exposes yaad over the network: the REST API, the MCP server, and the browser dashboard, all backed by the same engine. |
|
telemetry
Package telemetry provides OpenTelemetry metric instruments for yaad.
|
Package telemetry provides OpenTelemetry metric instruments for yaad. |
|
temporal
Package temporal provides bi-temporal validity windows for memory nodes.
|
Package temporal provides bi-temporal validity windows for memory nodes. |
|
tls
Package tls builds the server's TLS configuration, generating and auto-renewing a self-signed localhost certificate when none is supplied.
|
Package tls builds the server's TLS configuration, generating and auto-renewing a self-signed localhost certificate when none is supplied. |
|
tui
Package tui implements the Yaad terminal UI using Bubbletea.
|
Package tui implements the Yaad terminal UI using Bubbletea. |
|
version
Package version provides the canonical version string for yaad.
|
Package version provides the canonical version string for yaad. |
|
Package mental implements auto-generated project mental models.
|
Package mental implements auto-generated project mental models. |
|
Package privacy strips secrets and sensitive material from memory content before storage, via pattern matching, entropy heuristics, and <private> tag removal.
|
Package privacy strips secrets and sensitive material from memory content before storage, via pattern matching, entropy heuristics, and <private> tag removal. |
|
Package profile implements auto-maintained user/project profiles.
|
Package profile implements auto-maintained user/project profiles. |
|
Package skill implements procedural memory — reusable step sequences.
|
Package skill implements procedural memory — reusable step sequences. |
|
Package storage is yaad's persistence layer: a CGO-free SQLite store with FTS5 search, prepared-statement caching, and busy-retry, plus the Storage interface the rest of the system depends on.
|
Package storage is yaad's persistence layer: a CGO-free SQLite store with FTS5 search, prepared-statement caching, and busy-retry, plus the Storage interface the rest of the system depends on. |
|
Package temporal implements an immutable temporal backbone.
|
Package temporal implements an immutable temporal backbone. |
|
Package utils holds small, dependency-free helpers shared across yaad.
|
Package utils holds small, dependency-free helpers shared across yaad. |