📦 Moved to new directory. Last updated 12.2.2026. New location: claude-config/library/03-memory-state/deep-dives/state-02-long-term-vector-store.html

Deep dive 2 of 27: Three-Tier Memory: Long-Term (Vector Store)

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

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 Context and State Management (Intro) · All 27 solutions · ← Three-Tier Memory: Short-Term (Context Window) · Three-Tier Memory: Episodic (Experience Log) →

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

Long-term memory is knowledge kept outside the model that the AI can search when it needs it: help articles, past facts about a user, notes from earlier sessions. A vector store (a database that finds text by meaning, using embeddings) finds items by meaning, so "my VPN says 809" can find an article titled "Error 809".

In plain terms: a library with a librarian who understands what you mean, not just the exact title.

The problem it solves

No external state (nothing saved outside the model, so everything is lost when the program stops) and The context window: finite, expensive, volatile (the window is limited, paid per token, and gone after each call): anything only in the window is gone after the call, and you can't fit a whole knowledge base (a library of help articles; in ServiceApps, a named group of KB articles) into it.

The standard approach (in my words): keep a long-term tier (the AI's suggestion: likely approve, needs review or likely deny) in a vector store (a database that finds text by meaning, using embeddings) and pull relevant items into the window only when a question needs them.

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 should remember KB articles (one help-center article in a knowledge base, with a number like KB0010234) and a few saved preferences per employee, and recall the right one for a new question.

Steps.

  1. Turn each item (KB (knowledge base: a library of help articles) section, saved preference) into a vector (text turned into a list of numbers so similar meanings sit close together) with an embedding (text turned into numbers so similar meanings sit close together) model.
  2. Store the vector (text turned into a list of numbers so similar meanings sit close together) with its text and labels (kind, user, KB (knowledge base: a library of help articles), permissions).
  3. At question time, embed the question and return the closest items, filtered by labels.
  4. Put only the top results into the window.

The code (Python):

import math, re
from collections import Counter

def embed(text):                 # stand-in for a real embedding model: word counts
    return Counter(re.findall(r"[a-z0-9]+", text.lower()))

def cosine(a, b):
    dot = sum(a[w] * b[w] for w in a)
    na, nb = math.sqrt(sum(v * v for v in a.values())), math.sqrt(sum(v * v for v in b.values()))
    return dot / (na * nb) if na and nb else 0.0

store = []                       # long-term memory: (vector, text, labels)
def remember(text, **labels): store.append((embed(text), text, labels))
def recall(question, k=1, **where):
    q = embed(question)
    hits = [(cosine(q, v), t) for v, t, lab in store if all(lab.get(x) == y for x, y in where.items())]
    return sorted(hits, key=lambda h: -h[0])[:k]

remember("KB0010234: VPN error 809 means the client can't reach the server; avoid guest Wi-Fi.", kind="kb")
remember("KB0020311: Working abroad is allowed up to 10 working days a year.", kind="kb")
remember("User prefers answers in short bullet points.", kind="preference", user="u42")

for q, where in [("why does my vpn say error 809", {"kind": "kb"}), ("how should answers be formatted", {"user": "u42"})]:
    score, text = recall(q, **where)[0]
    print(f"{q!r} -> {score:.2f} {text}")

Output (from running the code above):

'why does my vpn say error 809' -> 0.27 KB0010234: VPN error 809 means the client can't reach the server; avoid guest Wi-Fi.
'how should answers be formatted' -> 0.17 User prefers answers in short bullet points.

What to watch for.

In plain terms: every saved note gets a meaning-based shelf location, and the assistant borrows only the one or two books it needs.

In NurseOps Now

Built for documents. Policy (the health plan's written rules for when a test is covered) PDFs (a fixed-layout document file) and the AI Assist (the app's chat helper for staff questions) user guide are chunked, embedded (turned into numbers (a vector) so similar meanings sit close together) with all-MiniLM-L6-v2 (a small, free open model that turns text into 384 numbers) and stored in Chroma (the database that stores the policy vectors) (backend/app/rag/index.py), always filtered by CPT code (a standard code for a medical procedure). Chat itself is kept in checkpoints (saved copies of a conversation's state) and case facts in SQL, not in the vector store (a database that finds text by meaning, using embeddings). See the ingestion deep dive.

Trade-offs

Interview answer

"For long-term memory I use a vector store (a database that finds text by meaning, using embeddings) for knowledge that's searched by meaning, like KB articles (one help-center article in a knowledge base, with a number like KB0010234), with labels for user and permissions applied before ranking. Exact facts go to SQL instead, because a similarity search can return a near match when you needed the exact record."

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.

AI Assist
The app's chat helper for staff questions.Used in: In NurseOps Now↩ Back to where you were
all-MiniLM-L6-v2
A small, free open model that turns text into 384 numbers.Used in: In NurseOps Now↩ Back to where you were
checkpoints
Saved copies of a conversation's state.Used in: In NurseOps Now↩ Back to where you were
Chroma
The database that stores the policy vectors.Used in: In NurseOps Now↩ Back to where you were
CPT code
A standard code for a medical procedure.Used in: In NurseOps Now↩ Back to where you were
embedded
Turned into numbers (a vector) so similar meanings sit close together.Used in: In NurseOps Now↩ Back to where you were
embedding
Text turned into numbers so similar meanings sit close together.Used in: How to implement it (ServiceApps), Trade-offs↩ 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
KB article
One help-center article in a knowledge base, with a number like KB0010234.Used in: How to implement it (ServiceApps), Interview answer↩ Back to where you were
knowledge base
A library of help articles; in ServiceApps, a named group of KB articles.Used in: The problem it solves↩ Back to where you were
no external state
Nothing saved outside the model, so everything is lost when the program stops.Used in: The problem it solves↩ Back to where you were
PDF
A fixed-layout document file.Used in: In NurseOps Now↩ Back to where you were
policy
The health plan's written rules for when a test is covered.Used in: In NurseOps Now↩ 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
the context window: finite, expensive, volatile
The window is limited, paid per token, and gone after each call.Used in: The problem it solves↩ Back to where you were
tier
The AI's suggestion: likely approve, needs review or likely deny.Used in: The problem it solves↩ Back to where you were
vector
Text turned into a list of numbers so similar meanings sit close together.Used in: How to implement it (ServiceApps)↩ Back to where you were
vector store
A database that finds text by meaning, using embeddings.Used in: In plain words, The problem it solves, How to implement it (ServiceApps), In NurseOps Now, Interview answer↩ Back to where you were