Skip to main content
Status: Stable — The four-tier memory system, hybrid search, and wiki compilation are production-ready. P2P Sync is experimental.

Memory System

FERAL’s memory is a four-tier architecture stored in a single SQLite database (~/.feral/memory.db). Each tier serves a different retention and retrieval pattern. On top of the tiers sit hybrid search, diversity reranking, session compaction, wiki compilation, and P2P sync.

Four Memory Tiers

Working Memory

In-RAM context for the current session. Holds the conversation history, tool results, and scratch state. Cleared when the session ends.
Working memory is capped at a configurable token budget. When it overflows, the oldest messages are compacted into an episode (see Session Compaction).

Episodic Memory

Auto-generated summaries of past conversations. Each episode captures the key facts, decisions, and outcomes from a session.
Episodes are created automatically when a session ends or when working memory overflows.

Semantic Memory / Knowledge Graph

Persistent facts stored as subject-predicate-object triples. Extracted automatically from conversations or added explicitly via “remember X” commands.

Execution Log

An append-only log of every tool invocation, including arguments, results, latency, and success/failure status.
Useful for debugging, skill auto-generation, and auditing what the agent actually did. Memory retrieval combines SQLite FTS5 (keyword) and vector similarity (semantic) to get the best of both worlds.
How hybrid scoring works:
  1. FTS5 returns top-N by BM25 score, normalized to [0, 1].
  2. Vector search returns top-N by cosine similarity, already in [0, 1].
  3. Scores are combined: final = alpha * vector_score + (1 - alpha) * fts_score.
  4. Results are merged and deduplicated by ID.
Vector embeddings use all-MiniLM-L6-v2 (384 dimensions) by default, computed locally via sentence-transformers. For larger deployments, swap in OpenAI text-embedding-3-small via config.

MMR Diversity Reranking

After hybrid search, Maximal Marginal Relevance reranks results to reduce redundancy. Without MMR, the top-5 results might all describe the same event from different angles.
The algorithm iteratively selects the result that maximizes lambda * relevance - (1 - lambda) * max_similarity_to_already_selected.

Session Compaction

When working memory exceeds its token budget, the compactor summarizes older messages into an episode and evicts them from the active context.
The compaction flow:
  1. Select messages beyond the budget.
  2. Prompt the LLM to summarize them into a structured episode.
  3. Insert the episode into episodes table with embedding.
  4. Replace the compacted messages with a system note: [Session compacted — N messages summarized].

Wiki Compilation

The Memory Wiki compiles episodes, notes, and knowledge graph entries into durable, human-readable wiki pages organized by topic. Compilation runs automatically on a schedule. To trigger a manual compile or browse pages, use the HTTP API or the WebUI Memory → Wiki tab:
Wiki pages are stored in ~/.feral/wiki/ as Markdown files with YAML frontmatter tracking provenance:
Compilation runs automatically on a schedule or on-demand. New facts merge into existing pages; conflicts are flagged for user review.

P2P Sync

For multi-device setups (laptop + phone + home server), FERAL supports peer-to-peer memory synchronization over the /sync WebSocket endpoint.
Sync uses HLC (Hybrid Logical Clock) timestamps with last-write-wins conflict resolution at the row level. Each peer maintains a write-ahead log (WAL) and exchanges deltas since the peer’s last-seen HLC; clock drift between peers is tolerated up to a configurable skew window. There is no CRDT merge — earlier docs incorrectly described the model as CRDT-based; the implementation is HLC + LWW + WAL replication, which is simpler and matches the data-loss profile the user signs up for (“the latest write wins”).

API Reference