Local persistence

Give it memory

Use SQLite to store selected facts locally and add them back to the model context on later conversations.

Chapter 06/10Time 20–30 minCost $0 software

Memory is software, not magic

The model does not permanently absorb your conversations. We will store selected facts ourselves and put relevant memory back into the prompt when needed.

Start with SQLite

SQLite is built into Python and stores the database in a local file.

CREATE TABLE memories
(
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    category TEXT NOT NULL,
    content TEXT NOT NULL
);
import sqlite3

connection = sqlite3.connect("jarvis.db")
connection.execute("""
CREATE TABLE IF NOT EXISTS memories
(
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    category TEXT NOT NULL,
    content TEXT NOT NULL
)
""")
connection.execute(
    "INSERT INTO memories(category, content) VALUES (?, ?)",
    ("preference", "Keep technical answers concise")
)
connection.commit()

Keep memory intentional

A simple first version can have the user explicitly save memory rather than automatically retaining everything. For example:

/remember preference | Use Celsius for temperatures
/remember project | My home server is named atlas

The downloadable starter implements this pattern and retrieves the most recent memories before each model call.

Privacy still matters locally

A local database can contain sensitive information. Treat jarvis.db like any other personal data file: protect your account, backups, and disk encryption, and avoid saving secrets such as passwords or API keys.

Later: semantic retrieval

Once basic memory works, you can add embeddings and vector search so the controller retrieves memories and documents by meaning rather than only recency. Do that after the simple system is stable.

Checkpoint

You can save a fact, restart the Python process, and retrieve that fact from the SQLite file.

Finished this chapter?
Your progress is stored only in this browser.