CSE Roadmap

Core tier · about 8 hours · 15 parts

Part 3 of 15 · 2 min read

Facts replace, episodes append, procedures version

Three kinds of thing a user says behave so differently that storing them the same way guarantees two of the three come out wrong.

Think of three different drawers. One holds your current address, which you cross out and rewrite whenever you move. One holds a diary, which you never edit after the fact. One holds a recipe card, which you replace with an improved version but keep the old one filed behind it.

In plain words: semantic memory stores facts with one current value per key and uses a replace rule. Episodic memory stores events that are written once and never edited. Procedural memory stores how-to instructions that are versioned, so the newest is current but older ones stay as history. Using the wrong rule for a kind of memory produces a specific, predictable failure, not just a worse answer.

A worked example. When a fact is corrected ("Actually, I moved to Oslo"), set_fact demotes the old row and inserts a new one, so recall never shows both at once. When a decision is made ("Decision: the Lisbon offsite budget is B-4417"), add_episode writes it once and it is never touched again, because a decision made on Tuesday stays true even after a different decision on Friday. When a procedure changes, set_procedure increments a version number and the old steps remain in the table, demoted but not deleted, so a bad instruction can be rolled back.

The key lines. From code/mini-memory/store.py:

# from code/mini-memory/store.py
def set_fact(self, key: str, value: str, source: str, session: int) -> None:
    self.db.execute("UPDATE facts SET current = 0 WHERE key = ? AND current = 1", (key,))
    self.db.execute("INSERT INTO facts (key, value, source, session, current) VALUES (?,?,?,?,1)", (key, value, source, session))
    self.db.commit()

Read it as: the old row is demoted, never deleted, before the new row is inserted. A single key can only ever have one row with current = 1 at a time. That is the replace rule enforced structurally, rather than by hoping the caller remembers to check for an old value first.

Semantic, episodic and procedural memory

Semantic memory stores facts about the user or the world, each with a key and one current value, using a replace rule. Episodic memory stores events, written once and not changed. Procedural memory stores how-to knowledge, which can be rewritten as the agent learns a better way, using a version rule.

Example: asking "where do I live?" after a move only gets one clean answer because home_city is semantic and replaced -- if it had been stored the way an episode is stored, append-only, the agent would have two true-sounding answers and no rule for choosing between them.