Free self-study · No account needed · Progress stays in this browser. Back it up before clearing site data or changing devices.

← Week 8: Persistent Memory

Week 08 / Lesson 1

Designing memory records

Choose what belongs in working state, event history, and reusable facts.

Section 1.1 1 of 7

Overview

Focus

Choose what belongs in working state, event history, and reusable facts.

Your route through the lesson

  • 1.2 Working, episodic, and semantic memory
  • 1.3 Durable records and cross-session loading
  • 1.4 Provenance, identity, and scope
  • 1.5 Put it into practice
  • 1.6 Guided comparison
  • 1.7 A preference scoped to one message

All required teaching is included here. Review selections are saved. Choose a correct answer for every question to continue; retries are unlimited. Study time and personal notes are optional.

Section 1.2 2 of 7

Working, episodic, and semantic memory

Focus

Distinguish temporary task state, remembered events, and reusable facts.

Memory is information retained for later use. Working memory is the current task’s short-lived state: the selected document, an unfinished calculation, or the next step. Episodic memory records an event, such as “On Tuesday, Lee asked for a concise incident summary.” Semantic memory stores a reusable fact or preference, such as “For project Atlas, Lee prefers timestamps in coordinated universal time.” These categories describe intended use, not three magical model abilities.

Consider an assistant drafting a single outage message. Its working state contains the current draft. Its event history can record that Lee requested a short version for that message. It should not automatically convert that event into the universal preference “Always omit detail.” An event demonstrates what happened in a situation; a reusable preference needs sufficient explicit scope.

Memory can be implemented with ordinary records rather than changing model weights. The application retrieves selected records into context when needed. This makes persistence, correction, and deletion inspectable. The model’s limited context and the durable record store are different systems: a long conversation is not by itself a reliable database.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A draft assistant remembers the next paragraph only while editing the current message. What kind of state is this?
2. A record says “Lee requested a short summary for incident 8.” What does that record directly establish?
3. An application stores a user preference in a database and later retrieves it into a prompt. What changed?

Section 1.3 3 of 7

Durable records and cross-session loading

Focus

Explain how durable storage preserves selected records across process restarts.

A Python variable disappears when its process exits. Durable storage survives that restart. A simple file can work for a single writer, but a database provides transactions, indexes, and constraints that make structured changes easier to reason about. A transaction groups related changes so either all commit or none do. Python includes sqlite3, a library for a local SQLite database, without an additional installation.

Suppose a preference record has identifier pref-7, owner lee, project atlas, value concise, and version 1. A create operation inserts it; a read selects it; an update replaces its value while increasing its version; a delete removes or marks it unavailable. These four operations form the basic record lifecycle. Closing the connection and opening another to the same file demonstrates restart continuity.

Continuity must be selective. Loading every historical record into every new conversation would disclose irrelevant information and turn old instructions into present authority. The application first identifies the caller and task, filters records by owner and scope, and then selects useful ones. Restart survival proves durability; it does not prove correct identity, relevance, or permission handling.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A preference is kept only in a Python dictionary. The process restarts. What should be expected?
2. Two database changes must either both happen or neither happen. Which mechanism expresses that requirement?
3. A database record survives reopening. What has this test established?

Section 1.4 4 of 7

Provenance, identity, and scope

Focus

Attach identity, scope, and provenance to each reusable memory record.

Provenance describes where information came from: who supplied it, when, in what context, and whether it was explicitly confirmed or inferred. Scope describes where it applies. A useful memory record includes owner, tenant or organization, project, record kind, value, source event, creation time, and version. Sensitive records may also require an expiry time and a permitted purpose.

Imagine two users named Sam in different organizations. Using the display name as the only key can mix their preferences. Instead, the trusted application supplies an internal owner identifier and organization identifier. A model may propose the value “use metric units,” but it cannot choose an owner identifier that grants access to someone else’s memory.

Now distinguish “Use metric units for this diagram” from “Remember that I prefer metric units for all my engineering diagrams.” The first applies to a single task; the second explicitly supports a broader, still bounded preference. A completed memory write records that distinction rather than stripping away the qualifying words. During retrieval, scope matching happens before relevance ranking, so a highly similar record from another organization remains ineligible.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Two organizations each have a user named Sam. Which key best prevents accidental memory mixing?
2. A user says “Use metric units for this diagram.” Which stored scope is justified?
3. A model proposes a memory write with owner = another-user. What should the executor do?

Section 1.5 5 of 7

Put it into practice

Focus

Create scoped records and verify continuity through a reopened database.

Save week08.py in your exercise folder and run python week08.py --lesson 1. The lab uses only the standard library and creates its database inside a temporary directory. It needs no credentials or network and takes seconds on a processor. The temporary directory is removed after checks, so the test is repeatable without leaving a personal-data store behind.

sqlite3.connect(path) opens a database file. A with block commits successful changes and rolls back an exception. Question marks bind values separately from command text, preventing a value from becoming part of the database command:

import sqlite3
db = sqlite3.connect(":memory:")
db.execute("CREATE TABLE memory (owner TEXT, value TEXT)")
with db:
    db.execute("INSERT INTO memory VALUES (?, ?)", ("lee", "metric"))
assert db.execute("SELECT value FROM memory WHERE owner = ?", ("lee",)).fetchone()[0] == "metric"
db.close()

The one-item tuple ("lee",) needs its comma. The weekly lab uses a real temporary file rather than :memory: so it can close and reopen it. PASS means owner filtering, record operations, and restart continuity matched assertions, not that an unrestricted assistant has been evaluated.

Download this week’s Python lab ↓

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Why does the query use a question mark and a separate tuple for a stored value?
2. Why does a restart-continuity test use a file database instead of :memory:?
3. What does ("lee",) mean in a Python parameter call?

Section 1.6 6 of 7

Guided comparison

Focus

Follow a memory lifecycle and separate persistence from instruction promotion.

The completed lab creates two records: a project preference for owner Lee and a task-only instruction for the current draft. The project preference is eligible in a later Atlas session. The draft instruction is not, because the later session has a different task identifier. Both can remain in the database while only one is selected for context.

An update changes Lee’s project preference from concise to detailed and increments its version. Reading again returns detailed. A delete then removes that active preference. A separate owner’s record remains intact. These checks distinguish correct targeting from merely emptying the entire database.

Finally, the connection closes and another opens the same file. A retained event is still present, proving file-backed continuity. The test deliberately reads by trusted owner and scope again after reopening; it does not assume that a successful earlier read grants all future access. If the lab instead loaded every row, it might still pass a crude “something survived” test while failing the actual product requirement. A useful acceptance check therefore combines a positive eligible read with negative reads for another owner and a different task.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A task-only instruction remains stored but is excluded from another task. Is that consistent?
2. Deleting Lee’s preference also deletes another owner’s unrelated fact. Which property failed?
3. A restart test checks an eligible read and a forbidden cross-owner read. Why use both?

Section 1.7 7 of 7

A preference scoped to one message

Focus

Keep a one-message formatting request from becoming a permanent preference.

An incident commander says, “For this executive update, omit internal hostnames.” The assistant should comply while drafting that update. It may retain the event for a permitted audit purpose, but the phrase “for this executive update” limits the instruction. A later troubleshooting session may need those hostnames and may have an authorized technical audience.

A completed memory representation stores kind event, task executive-update-12, source commander-message-5, and the exact scoped request. It does not write the semantic preference “Never include hostnames.” When the later troubleshooting task begins, scope filtering excludes the task-only instruction. Existing access rules still determine which hostnames the technical audience may see.

This case also distinguishes forgetting from non-use. Excluding a record because it does not apply does not necessarily delete it. Deleting it requires a retention decision, taught next. Clear scope lets the application be helpful across sessions without turning every temporary request into permanent policy. If a user later explicitly requests a lasting preference, that new request becomes a separate source with its own scope and version rather than an invisible reinterpretation of the original event.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. “For this executive update, omit hostnames” is stored as “Never include hostnames.” What went wrong?
2. A later troubleshooting session excludes a task-scoped event. Does exclusion necessarily delete it?
3. A user later explicitly requests a lasting preference. What should record provenance preserve?

Your personal notes

Optional, ungraded, and saved only in this browser. Export a backup from the Academy homepage to keep them.

References and further reading
Ask your own AI assistant

Copy this prompt into an assistant you already use. Nothing is sent automatically, and your personal notes are not included.

Next lesson: Correcting and forgetting stored information →