Engineering

7-Layer Memory Architecture: How ZenBrain Remembers Like a Human Brain

Alexander Bering
Alexander Bering
March 20, 2026 · 5 min read

Why Conventional AI Memory Falls Short

Most AI systems treat memory as a flat vector store. Embed text, store vectors, retrieve by cosine similarity. It works — but it has fundamental limitations:

  • No temporal decay — A fact from 3 years ago has the same weight as yesterday's insight
  • No consolidation — Memories are never strengthened or reorganized
  • No active forgetting — Everything is stored forever, creating noise
  • No relational context — Facts exist in isolation, no connections between them

The human brain solves all of these. It actively forgets irrelevant information, strengthens important memories during sleep, and builds dense networks of associations. We wanted our AI to do the same.

The 7 Layers

ZenBrain's HiMeS (Hierarchical Memory System) architecture implements seven layers, each serving a distinct cognitive function:

Layer 1: Working Memory

Purpose: Active task focus — your mental scratchpad.

Working memory holds the current context. It's small (like human working memory, approximately 7 items), fast, and constantly refreshed. When you switch tasks, working memory clears and reloads.

Layer 2: Short-Term Memory

Purpose: Session context — what you remember from this conversation.

Short-term memory persists across a single session. It tracks the flow of conversation, maintains context, and provides continuity. It decays naturally when the session ends.

Layer 3: Episodic Memory

Purpose: Concrete experiences — "Last Tuesday, when we discussed the API redesign..."

Episodic memories are timestamped, contextual records of specific interactions. They capture not just what was said, but when, where (which context), and what emotional valence the interaction had. Most systems don't distinguish between facts and experiences — we do.

Layer 4: Semantic Memory

Purpose: Facts and concepts — "PostgreSQL supports pgvector for embeddings."

Semantic memory stores factual knowledge stripped of temporal context. These memories are built up from repeated episodic experiences — just like in the human brain, where individual episodes gradually crystallize into general knowledge.

Layer 5: Procedural Memory

Purpose: How-to knowledge — processes and workflows.

Procedural memory captures how to do things. "When the user asks for a code review, first check the diff, then analyze patterns, then provide feedback." These are learned from successful interactions and refined through feedback.

Layer 6: Prospective Memory

Purpose: Future planning — "Remember to follow up on Monday."

Prospective memory handles intentions and planned actions. It enables the AI to proactively remind you about things, track deadlines, and maintain awareness of future commitments.

Layer 7: Long-Term Memory

Purpose: Persistent knowledge — your life experience.

Long-term memory is the permanent store. Facts that have been consolidated, reinforced through repetition, and proven important over time live here. This layer uses Ebbinghaus-style decay curves — memories that aren't accessed gradually fade, but each retrieval strengthens them.

Sleep Consolidation: The Secret Weapon

In neuroscience, sleep consolidation is the process where the brain replays recent experiences during rest periods, strengthening important memories and pruning weak connections. Stickgold & Walker (2013) showed that memory consolidation during sleep is critical for learning.

We implemented the same mechanism. During idle periods, ZenBrain:

  1. Selects memories with high importance scores that haven't been consolidated yet
  2. Replays them — re-evaluates their importance in the context of everything else the system knows
  3. Strengthens connections between related memories using Hebbian learning ("neurons that fire together wire together")
  4. Prunes weak connections — memories that haven't been accessed and have low importance scores decay and eventually get forgotten

This is genuinely unique. We surveyed every major AI memory system — Mem0, Letta/MemGPT, Zep, LangChain's memory modules — and none implement sleep consolidation.

Spaced Repetition with FSRS

For knowledge that needs long-term retention, we use the FSRS (Free Spaced Repetition Scheduler) algorithm. Originally designed for flashcard apps like Anki, FSRS calculates optimal review intervals based on stability, difficulty, and elapsed time.

Each memory gets a retrievability score (0-1) predicting the probability of successful recall. When retrievability drops below a threshold, the memory gets flagged for review.

Hebbian Knowledge Graphs

Memories don't exist in isolation. The brain builds dense networks of associations. We do the same:

  • Co-activation: When two memories are accessed together, the connection strengthens
  • Decay: Connections that aren't reinforced gradually weaken
  • Normalization: Connection weights are normalized to prevent runaway activation

The system naturally builds topic clusters, recognizes related concepts, and traverses knowledge paths that the user never explicitly defined.

The Numbers

  • 276 tests for the memory algorithms alone (all passing)
  • 12 neuroscience algorithms in @zensation/algorithms
  • 7 memory layers in @zensation/core
  • Zero dependencies — pure TypeScript
  • 95% confidence intervals for all probabilistic outputs

Try It

The entire system is open source:

npm install @zensation/algorithms @zensation/core

GitHub: github.com/zensation-ai/zenbrain

This is part of the "Building an AI Brain" series. Next: how we use Contextual Retrieval (Anthropic method) for +67% retrieval accuracy.