Deep dive 13 of 27: Vector Compression via RAG
Nov 19, 2026 · Michael Chang · Status in NurseOps Now: 🟡 documents only
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 Compression Strategies: Summarization and Entity Extraction (7.2) · All 27 solutions · ← Entity Extraction · The Engineering Trade-off: Fidelity vs. Capacity →
Read in this order
- In plain words: what it is, without jargon
- The problem it solves: the problem, and the standard approach in my words
- How to implement it (ServiceApps): scenario, steps, code and real output
- In NurseOps Now: built or not, and where
- Trade-offs and Interview answer
In plain words
Vector (text turned into a list of numbers so similar meanings sit close together) compression stores old conversation (or any long text) as embeddings (text turned into numbers so similar meanings sit close together) outside the window, and brings back only the few pieces relevant to the current question. The AI can "remember" a long history while only a few hundred tokens (pieces of words the AI reads and writes; cost is per token) are in the window.
In plain terms: instead of re-reading every old email, you search your mailbox and open the two that matter.
The problem it solves
History can't keep growing: summaries lose detail, and you can't keep all old turns in the window.
The standard approach (in my words): convert past text into embeddings (text turned into numbers so similar meanings sit close together) in a vector (text turned into a list of numbers so similar meanings sit close together) database, and retrieve only relevant segments just in time.
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. An employee had a long chat weeks ago with their laptop tag and contact preference. Today they ask about both.
Steps.
- When turns leave the window, embed and store them with user and thread (one saved conversation, here one per user and case) labels.
- On a new question, search only that user's stored turns.
- Insert the top few results, labeled as "from earlier conversations".
- Expire old memories (see TTL expiration (deleting saved data automatically after a set time)).
The code (Python):
import math, re
from collections import Counter
def embed(t): return Counter(re.findall(r"[a-z0-9]+", t.lower()))
def cos(a, b):
d = sum(a[w] * b[w] for w in a)
n = math.sqrt(sum(v * v for v in a.values())) * math.sqrt(sum(v * v for v in b.values()))
return d / n if n else 0.0
old_turns = ["user: my laptop asset tag is LT-4471", "user: I work from the Berlin office on Tuesdays",
"assistant: your VPN profile was reset on Monday", "user: I prefer email over phone calls"] + \
[f"user: small talk number {i}" for i in range(30)]
memory = [(embed(t), t) for t in old_turns] # stored outside the window
def recall(q, k=2):
qv = embed(q)
return [t for _, t in sorted(memory, key=lambda m: -cos(qv, m[0]))[:k]]
q = "what is my laptop asset tag and do I prefer email or phone"
print("old turns in memory:", len(memory), "| the window gets only:")
for t in recall(q):
print(" ", t)
Output (from running the code above):
old turns in memory: 34 | the window gets only: user: my laptop asset tag is LT-4471 user: I prefer email over phone calls
What to watch for.
- Search only the current user's memories.
- Old memories can be outdated; prefer recent ones and show their date.
- Retrieved turns are data, not instructions.
In plain terms: every old conversation goes into a searchable archive; each new question pulls out just the two lines it needs.
In NurseOps Now
Partly built: NurseOps Now uses vector (text turned into a list of numbers so similar meanings sit close together) search (Chroma (the database that stores the policy vectors)) for policy (the health plan's written rules for when a test is covered) text and the user guide, not for chat history. See the ingestion deep dive.
Trade-offs
- Keeps far more history than a summary, but search can miss or surface stale memories.
- Storage and embedding (text turned into numbers so similar meanings sit close together) costs grow with every conversation.
Interview answer
"Old turns don't have to be summarized or dropped: I embed them into a per-user vector store (a database that finds text by meaning, using embeddings) and retrieve only what the new question needs, labeled as earlier conversation. It scales to long histories with a few hundred tokens (pieces of words the AI reads and writes; cost is per token) of window."
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.
- Chroma
- The database that stores the policy vectors.Used in: In NurseOps Now↩ Back to where you were
- embedding
- Text turned into numbers so similar meanings sit close together.Used in: Trade-offs↩ Back to where you were
- embeddings
- Text turned into numbers so similar meanings sit close together.Used in: In plain words, The problem it solves↩ 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
- 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
- thread
- One saved conversation, here one per user and case.Used in: How to implement it (ServiceApps)↩ Back to where you were
- tokens
- Pieces of words the AI reads and writes; cost is per token.Used in: In plain words, Interview answer↩ Back to where you were
- TTL expiration
- Deleting saved data automatically after a set time.Used in: How to implement it (ServiceApps)↩ Back to where you were
- vector
- Text turned into a list of numbers so similar meanings sit close together.Used in: In plain words, The problem it solves, In NurseOps Now↩ Back to where you were
- vector store
- A database that finds text by meaning, using embeddings.Used in: Interview answer↩ Back to where you were