📦 Moved to new directory. Last updated 12.2.2026. New location: claude-config/library/03-memory-state/deep-dives/state-16-structured-storage-sql-postgres.html

Deep dive 16 of 27: Structured Storage (SQL/Postgres)

Nov 19, 2026 · Michael Chang · Status in NurseOps Now: ✅ built (SQLite)

Show definitions in ( ) · hover a highlighted word for its meaning, click it for details · open with ?defs=1 to show definitions

Part of: Remembering the right things: state management in NurseOps Now, section Implementing Long-Term Memory: External Persistence Architecture (7.3) · All 27 solutions · ← The Hot/Cold State Architecture · Semantic Storage (Vector DB like Pinecone, Weaviate, or Chroma) →

Read in this order

  1. In plain words: what it is, without jargon
  2. The problem it solves: the problem, and the standard approach in my words
  3. How to implement it (ServiceApps): scenario, steps, code and real output
  4. In NurseOps Now: built or not, and where
  5. Trade-offs and Interview answer

In plain words

Structured storage (a database with fixed tables for exact facts, like SQL) keeps exact facts in database tables: ticket numbers, statuses, dates, approvals. You ask it precise questions and always get the exact answer, which a meaning-based search can't guarantee.

In plain terms: a spreadsheet with fixed columns: you look up row INC0012345 and get exactly that row.

The problem it solves

Summarization solves volume, not time (a summary shrinks memory but doesn't survive a crash or restart): exact facts need durable storage, and a vector (text turned into a list of numbers so similar meanings sit close together) search might return the wrong but similar ticket number.

The standard approach (in my words): use SQL for strict facts that need exact retrieval (finding the right section of the right policy), with deterministic queries.

How to implement it (ServiceApps)

Illustrative example: no ServiceApps (a company platform for IT tickets, HR requests and help-center articles) instance is connected, so the scenario and data are made up. The code is a self-contained sketch; it was run on that made-up data on Nov 19, 2026, and the output below is from that run.

The setting. ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist, an AI helper inside a company's ServiceApps (a company platform for IT tickets, HR requests and help-center articles) portal. Employees ask it IT and HR questions; it answers from knowledge-base (KB (knowledge base: a library of help articles)) articles, looks up the employee's own tickets (incidents (a ServiceApps ticket for something broken) like INC0012345) and requests, and keeps one conversation per employee and ticket.

The scenario. ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist answers "Which of my tickets are still open, and were any approved?"

Steps.

  1. Model the facts as tables (tickets, approvals).
  2. Let the AI call a tool (a function the AI can call, such as policy search) that runs a fixed, parameterized query, not free-form SQL.
  3. Return exact rows to the model.
  4. Use Postgres in production; the same SQL works.

The code (Python):

import sqlite3
db = sqlite3.connect(":memory:")                 # stand-in for Postgres
db.executescript("""
create table tickets(number text primary key, user text, status text, opened date, priority int);
create table approvals(ticket text references tickets(number), approver text, decision text, at date);
insert into tickets values ('INC0012345','u42','In Progress','2026-11-18',2),
                           ('INC0012346','u42','Resolved','2026-11-02',3),
                           ('INC0012400','u77','New','2026-11-19',1);
insert into approvals values ('INC0012345','mgr9','approved','2026-11-18');
""")
OPEN_TICKETS = """select t.number, t.status, t.opened, a.decision
                  from tickets t left join approvals a on a.ticket = t.number
                  where t.user = ? and t.status != 'Resolved' order by t.opened"""
for row in db.execute(OPEN_TICKETS, ("u42",)):
    print(row)
print(db.execute("select count(*) from tickets where opened >= '2026-11-15'").fetchone()[0], "tickets opened since Nov 15")

Output (from running the code above):

('INC0012345', 'In Progress', '2026-11-18', 'approved')
2 tickets opened since Nov 15

What to watch for.

In plain terms: the assistant looks up your ticket by its exact number, like a librarian using a catalog number, not a guess.

In NurseOps Now

Built on SQLite (Postgres planned for production, per the project's CLAUDE (Anthropic's AI model that this app uses).md): tables cases, ai_reviews, decisions, audit_log, llm_calls. The AI reads them only through tools (a function the AI can call, such as policy search) like get_case. See Step 4.

Trade-offs

Interview answer

"Exact facts like ticket status and approvals go in SQL, and the agent (an AI that chooses which tools to use to answer) reads them through fixed, parameterized query tools (a function the AI can call, such as policy search) filtered by the user. A vector (text turned into a list of numbers so similar meanings sit close together) search might return a similar ticket; SQL returns the right one."

All data in this post is made up. No real people, tickets or patient data.

← Back to all 27 solutions in the state management blog

Key terms

Every highlighted word in this post links here. Click ↩ Back to return to the spot you came from.

agent
An AI that chooses which tools to use to answer.Used in: Interview answer↩ Back to where you were
audit row
One line in the log of who did what, when.Used in: How to implement it (ServiceApps)↩ Back to where you were
Claude
Anthropic's AI model that this app uses.Used in: In NurseOps Now↩ Back to where you were
incident
A ServiceApps ticket for something broken.Used in: How to implement it (ServiceApps)↩ Back to where you were
KB
Knowledge base: a library of help articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
retrieval
Finding the right section of the right policy.Used in: The problem it solves↩ Back to where you were
schema
A fixed form the AI's answer must fit.Used in: Trade-offs↩ Back to where you were
ServiceApps
A company platform for IT tickets, HR requests and help-center articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
structured storage
A database with fixed tables for exact facts, like SQL.Used in: In plain words↩ Back to where you were
summarization solves volume, not time
A summary shrinks memory but doesn't survive a crash or restart.Used in: The problem it solves↩ Back to where you were
tool
A function the AI can call, such as policy search.Used in: How to implement it (ServiceApps), In NurseOps Now, Interview answer↩ Back to where you were
vector
Text turned into a list of numbers so similar meanings sit close together.Used in: The problem it solves, Interview answer↩ Back to where you were