Building a Memory Layer¶
The write path is the part the tutorials skip.
84 lessons across 21 modules and 3 levels. Every lesson carries a lifecycle stage, a prerequisite list, a runnable lab, and a piece of the capstone.
Where the mass sits¶
A RAG tutorial spends ~85% of its length on retrieve. This course does not, and the table below is the argument:
| Stage | Lessons | Share | |
|---|---|---|---|
orientation |
framing the problem | 4 | ██ 5% |
extract |
turns into facts | 6 | ███ 7% |
store |
where facts live | 17 | ████████ 20% |
retrieve |
getting them back | 9 | ████ 11% |
evolve |
keeping them true | 20 | ██████████ 24% |
assemble |
fitting the budget | 7 | ███ 8% |
govern |
privacy, eval, ops | 21 | ██████████ 25% |
The three levels¶
The Loop · How does a system remember at all?¶
A CLI assistant that survives process restart, builds its own corpus from conversation, and is visibly broken in seven documented ways.
13 lessons · 4 modules
The Write Path in Earnest · How does memory stay correct as it grows?¶
memlab v0.2: typed memories, entity resolution, deterministic belief updating, salience-driven decay, and budgeted context assembly.
31 lessons · 8 modules
Time, Scale, Multiplicity, Trust · How does it survive time, scale, multiplicity, and scrutiny?¶
memlab v0.3: bi-temporal, multi-agent, governed, benchmarked, with cascade deletion that provably reaches derived data.
40 lessons · 9 modules
Contents¶
The Loop¶
Why Memory Is Not RAG
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 1 | Memory Is Not RAG | orientation |
Separate the read path over a given corpus from the write path that authors its own. |
| 2 | The Taxonomy That Actually Routes | orientation |
Treat working/episodic/semantic/procedural as engineering categories with distinct lifecycles. |
| 3 | Context Is Not Memory | orientation |
Explain why a larger context window is not a memory layer: no selection, persistence, or mutation. |
| 4 | Anatomy of a Memory Layer | orientation |
Name every component the rest of the course builds. The reference diagram. |
The Write Path, Naively
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 5 | Designing the Memory Record | store |
Choose the fields now that Intermediate will depend on: scope, provenance, event time, confidence. |
| 6 | Naive Extraction | extract |
Pull durable facts from a turn with structured output, and cause your first over-extraction disaster. |
| 7 | Writing Memories Down | store |
Append-only JSONL with stable ids and idempotent writes; meet the duplicate problem it creates. |
The Read Path, Honestly
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 8 | Embedding Recall | retrieve |
Build minimum-viable vector search, framed as one strategy among several. |
| 9 | Retrieval Is Not Enough | retrieve |
Scope by owner before ranking; meet semantically-close-but-wrong and confidently-stale. |
| 10 | Getting Memories Into the Prompt | assemble |
Inject recalled beliefs with attribution, and mark them as beliefs rather than ground truth. |
The Loop Closes
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 11 | Session Memory vs Long-Term Memory | evolve |
Decide what dies at end of session and what gets promoted. |
| 12 | Your First Memory Layer | assemble |
Ship memlab v0.1: an assistant that survives restart. |
| 13 | Watching It Fail | govern |
Catalogue the seven failures you now have; each one names the Intermediate module that fixes it. |
The Write Path in Earnest¶
Typed Memory & Extraction Pipelines
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 14 | The Typed Memory Model | store |
Give each memory type its own schema, lifecycle, and update rule. |
| 15 | Extraction Pipelines | extract |
Stage candidate generation, salience filtering, schema validation, and type routing. |
| 16 | Precision and Recall on the Write Path | extract |
Measure extraction quality and price the compounding cost of over-extraction. |
| 17 | Atomic Memories | extract |
Size a memory so it can be updated later; recognise one that is too big to revise. |
Identity & Entity Resolution
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 18 | Entities and Aliases | store |
Collapse 'my wife', 'Sarah', and 'S.' into one canonical node. |
| 19 | Entity Resolution | store |
Block, score, merge, and un-merge; handle the split problem. |
| 20 | Scopes and Namespaces | store |
Key memory by user, agent, org, and session — the multi-tenancy substrate. |
Consolidation
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 21 | Deduplication | evolve |
Detect exact, near, and semantic duplicates; choose write-time vs read-time dedupe. |
| 22 | Summarization and Compaction | evolve |
Build rolling summaries and hierarchical digests without losing the originals. |
| 23 | Semantic Drift | evolve |
Bound degradation by re-deriving from anchored originals, never summarizing summaries. |
| 24 | From Episode to Belief | evolve |
Promote 'on Tuesday she said X' to 'she prefers X' — and know when that is wrong. |
Conflict Resolution & Belief Updating
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 25 | Contradiction Detection | evolve |
Separate a genuine contradiction from a legitimate change over time. |
| 26 | ADD, UPDATE, DELETE, NOOP | evolve |
See why a free-form LLM UPDATE decision is the largest source of silent memory corruption. |
| 27 | Deterministic Arbitration | evolve |
Confine the model to detection and let rules decide, using recency, authority, and explicitness. |
| 28 | Supersede, Never Destroy | evolve |
Keep the audit trail that makes bi-temporal modeling possible later. |
Forgetting
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 29 | Why Forgetting Is a Feature | evolve |
Justify forgetting on cost, latency, precision, privacy, and coherence. |
| 30 | Salience Scoring | evolve |
Combine recency, reinforcement, explicit markers, and retrieval-hit feedback. |
| 31 | Decay and Memory Tiers | evolve |
Move memories across scratchpad, working, and long-term tiers under decay and reinforcement. |
| 32 | Forgetting Under a Budget | evolve |
Evict, archive, or quarantine within a bounded store, and tune without losing the user. |
Retrieval Done Properly
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 33 | Scope, Then Rank | retrieve |
Apply hard filters on owner, type, and validity before any similarity is computed. |
| 34 | Hybrid Ranking | retrieve |
Fuse semantic, lexical, recency, and salience signals; add diversity. |
| 35 | The Query Is Not the Last Message | retrieve |
Rewrite and expand queries; condition retrieval on intent. |
| 36 | Should I Even Look? | retrieve |
Choose between always-on retrieval and memory as a tool call. |
Stores
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 37 | Vector Stores for Data That Changes | store |
Handle reindexing, tombstones, and embedding staleness after an UPDATE. |
| 38 | The Underrated Default | store |
Use SQLite with FTS as a genuinely good memory store. |
| 39 | Graph Stores | store |
Model entities and relations; traverse for multi-hop recall. |
| 40 | Hybrid Architecture | store |
Pick a store per memory type and keep them consistent under write fan-out. |
Context Assembly Under Budget
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 41 | The Packing Problem | assemble |
Treat the token budget as constrained selection, not truncation. |
| 42 | Ordering and Formatting | assemble |
Price the line format, and check whether ordering by score costs anything. |
| 43 | What Must Never Be Dropped | assemble |
Make coverage an invariant of the packer, derived from the question rather than a topic list. |
| 44 | Does This Earn Its Tokens? | assemble |
Price every element of the context, including the ones that are not memories. |
Time, Scale, Multiplicity, Trust¶
Temporal Reasoning & Bi-Temporal Modeling
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 45 | Two Clocks | store |
Audit which of the two clocks is actually running; four instants, not two. |
| 46 | Validity Intervals | store |
Separate when a fact was true from when it was believed, and query both. |
| 47 | Three Temporal Questions | retrieve |
Route the three temporal questions, and release every filter that assumed now. |
| 48 | Resolving 'Last Week' | extract |
Four classes of relative reference, and the one you must not resolve. |
| 49 | Temporal Knowledge Graphs | store |
Cascade invalidation through the derivation graph -- the one that actually has edges. |
Offline Consolidation
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 50 | Sleep-Time Compute | evolve |
The window is the cost, not the compute -- and the gate that closes it is already computed. |
| 51 | Background Job Mechanics | evolve |
Write back only what the job read -- absence means two opposite things. |
| 52 | Reflection and Insight | evolve |
Derive higher-order beliefs, and measure that storing them makes the answer worse. |
| 53 | Promotion as a Release | evolve |
Measure a consolidation before applying it, and be able to take it back. |
Multi-Agent & Shared Memory
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 54 | Memory Topologies | store |
Price each shape by what a reader loses -- and by what it leaks. |
| 55 | Provenance and Trust | govern |
Trust the claim, not the claimant -- and flag what cannot be assessed. |
| 56 | Cross-Agent Write Conflicts | evolve |
The precedence rule is a threshold -- and above it, recency decides. |
| 57 | Memory Access Control | govern |
Say no to a write, and assert the filter that says no to a read. |
Personalization & User Modeling
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 58 | From Facts to a User Model | evolve |
Key the model on attributes, and keep what does not fit. |
| 59 | Behaviour as Memory | extract |
A correction is a labelled negative example, and it always arrives late. |
| 60 | Personalization Without Creepiness | assemble |
Split the model by how each attribute is used, and report what was withheld. |
| 61 | Cold Start and Shared Accounts | retrieve |
Coverage is not knowledge, and one field stands between two people. |
Procedural Memory & Learning From Experience
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 62 | Procedural Memory | store |
Order survives by exception, and a comment about a workflow parses as one. |
| 63 | Learning From Outcomes | evolve |
The conclusion survives and the evidence does not -- measured from the transcript. |
| 64 | Retrieving Procedures | retrieve |
A workflow loses to a comment about it, and no ranker tuning fixes that. |
Privacy, PII, Deletion & Right to Be Forgotten
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 65 | PII on the Write Path | govern |
Label personal data without deciding at the gate -- the strict policy breaks the exam. |
| 66 | Redaction and Minimization | govern |
Coarsen per kind, and measure what each level costs the answer. |
| 67 | Deletion That Actually Deletes | govern |
Resolve the request by label, then reach every structure -- and report the zeroes. |
| 68 | Proving You Forgot | govern |
Prove a deletion using the content-addressed id, and keep none of the content. |
| 69 | Memory Attacks | govern |
Three defences exist, all accidental, and the fourth attack has none. |
Evaluating Memory Systems
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 70 | Why Memory Eval Is Hard | govern |
Count what can be scored at all, before scoring anything. |
| 71 | Component Metrics | govern |
Score the stages -- and debug the metric before believing it about the system. |
| 72 | Build Your Own Harness | govern |
One battery across every profile -- and name what it cannot see. |
| 73 | Regression Testing a Stateful System | govern |
Half the tests pin a measured number -- and a frozen corpus is what makes that affordable. |
| 74 | LLM as Judge, and Its Failure Modes | govern |
One judgement of three model calls -- and arbitration is never one of them. |
| 75 | Reading Benchmark Claims Critically | govern |
Four questions for any score -- applied to your own claim first. |
Cost, Latency & Scale
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 76 | The Write Path Dominates | govern |
Count the calls: the read path makes none, and the write path makes two per turn. |
| 77 | The Latency Budget | govern |
Half the per-turn cost blocks -- and the other half is a model call in a stage called deferrable. |
| 78 | Caching, Batching, Routing | govern |
Two of six tactics do not apply, and routing has two targets rather than one. |
| 79 | Scaling the Store | store |
Replicate and measure -- retrieval grows linearly, consolidation grows 104x. |
Production Failure Modes & Governance
| # | Lesson | Stage | You will be able to |
|---|---|---|---|
| 80 | The Failure Field Guide | govern |
Five of seven symptoms are ambiguous, so the useful column is the tell. |
| 81 | Memory Observability | govern |
Six answers from the record with no logging, and three that need a read-time write. |
| 82 | Invariants and Drift Detection | govern |
Collect the invariants, label the kind, and stop an outlier moving its own reference. |
| 83 | Migrating Live Memory | store |
The id hashes identity, not state -- which is why this migration was one phase. |
| 84 | Hardening Pass | govern |
Ship v0.3 with its six open items -- the section that makes the rest checkable. |