Skip to content
AgenticAIWiki
  1. Learn
  2. Part 10
  3. 54. The memory types map
  4. 54.3

Lesson 54.3 · 3 of 5 · 4 min read · Reviewed 24 Nov 2026

Semantic memory: facts

By the end, you can

  • Describe semantic memory for agents.
  • Keep facts accurate and up to date.

Semantic memory answers: what is true?

Kinds of facts

Fact Where it should live
“Prefers short answers” Memory store (learned from conversations)
“Team uses pnpm, not npm” Project memory file such as CLAUDE.md
“Account plan: Business” System of record; look it up
“Our refund window is 30 days” Policy document; retrieve it (Part 4)

A simple rule: if a real system already owns the fact, look it up. Memory is for things no system records, like preferences and conventions learned along the way.

Storing facts well

  • One fact per entry. “Prefers metric units” and “Lives in Berlin” as separate entries, so one can change without the other.
  • Source and date. “Said in chat on 2026-10-12” lets you judge freshness.
  • Scope. Is this about the user, the team, or the project?
  • Confidence. Stated directly or guessed? Guessed facts deserve more caution.

Conflicts

When a new fact contradicts an old one (“I’ve moved to Munich”), update or replace the old entry rather than adding a second. Lesson 57.3 covers consolidation.

Key points

  • Semantic memory holds facts: user preferences, account details, project conventions, domain knowledge.
  • Store facts as small, separate entries with a source and date, so they can be updated or removed.
  • Facts from a system of record (like a database) should be looked up fresh, not copied into memory.
Hands-on labRuns in the Playground

Keep facts as small dated entries

Build a semantic memory that stores one fact per entry with source and date, updates on conflict, and refuses facts a system of record owns.

You will have: A fact store with an upsert function and a printout of the final facts and the rejected writes.

Steps

  1. Write upsert(owner, key, value, source, date) that keeps one entry per owner and key.
  2. When a newer value arrives for the same key, replace it and keep the old value in a history list.
  3. Reject keys that a system of record owns (plan, balance, address) with a message to look them up instead.
  4. Feed in the sample writes and print the store and the rejected writes.

Done when

  • lives_in ends as Munich with Berlin in its history.
  • The plan write is rejected as a system-of-record fact.
  • Each stored fact has a source and a date.

Open in the Playground No API key needed.

Starter code (Python)
SYSTEM_OF_RECORD = {"plan", "balance", "address"}
WRITES = [
    ("C-2201", "lives_in", "Berlin", "chat", "2025-04-01"),
    ("C-2201", "units", "metric", "chat", "2025-06-12"),
    ("C-2201", "plan", "Business", "chat", "2026-01-05"),
    ("C-2201", "lives_in", "Munich", "chat", "2026-02-11"),
]
STORE = {}
REJECTED = []

def upsert(owner, key, value, source, date):
    # TODO: reject system-of-record keys; otherwise add or update one entry per (owner, key),
    # keeping older values in a "history" list
    pass

for w in WRITES:
    upsert(*w)
for (owner, key), e in STORE.items():
    print(owner, key, "=", e)
print("rejected:", REJECTED)
Show a solution
SYSTEM_OF_RECORD = {"plan", "balance", "address"}
WRITES = [
    ("C-2201", "lives_in", "Berlin", "chat", "2025-04-01"),
    ("C-2201", "units", "metric", "chat", "2025-06-12"),
    ("C-2201", "plan", "Business", "chat", "2026-01-05"),
    ("C-2201", "lives_in", "Munich", "chat", "2026-02-11"),
]
STORE = {}
REJECTED = []

def upsert(owner, key, value, source, date):
    if key in SYSTEM_OF_RECORD:
        REJECTED.append(key + " (system of record: look it up)")
        return
    old = STORE.get((owner, key))
    entry = {"value": value, "source": source, "date": date, "history": []}
    if old:
        if old["date"] > date:
            return
        entry["history"] = old["history"] + [(old["value"], old["date"])]
    STORE[(owner, key)] = entry

for w in WRITES:
    upsert(*w)
for (owner, key), e in STORE.items():
    print(owner, key, "=", e["value"], "| source", e["source"], e["date"], "| history", e["history"])
print("rejected:", REJECTED)
Quick checkWhere should an agent get a customer's current shipping address?
How sure are you?
Pick an answer and how sure you are