πŸ“¦ Moved to new directory. Last updated 12.2.2026. New location: claude-config/library/03-memory-state/deep-dives/fw-llamaindex.html

Framework deep dive: LlamaIndex memory and the 27 solutions

Nov 19, 2026 · Michael Chang · Status: ⬜ not used in NurseOps Now

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 Β· All 27 solutions Β· Other frameworks: LangGraph Β· AutoGen Β· CrewAI

Read in this order

  1. In plain words
  2. What it gives you for memory: from the current docs
  3. How to implement it (ServiceApps): code and output
  4. The 27 solutions with LlamaIndex: replace, complement or still yours
  5. Use both: what you still build
  6. In NurseOps Now, Trade-offs and Interview answer

In plain words

LlamaIndex is best known for RAG (retrieval-augmented generation: the AI looks things up before it answers) over documents, and its agents (an AI that chooses which tools to use to answer) get a Memory object per session: recent chat is kept up to a token (the unit the AI reads and is billed by, about three quarters of a word) limit, and older messages are flushed into long-term memory blocks (static text, extracted facts, or a vector store (a database that finds text by meaning, using embeddings)).

In plain terms: a notepad with a size limit; when it's full, the oldest notes are filed into labeled binders, and one sticky note (the rules) is always on top.

What it gives you for memory

From the official memory docs (LlamaIndex memory docs), checked on Nov 19, 2026:

How to implement it (ServiceApps)

Illustrative example: made-up data, no ServiceApps (a company platform for IT tickets, HR requests and help-center articles) instance. The code was run as shown; the model is a scripted stand-in, so no API key (a secret code that lets the app use a paid service) is needed.

The scenario. ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist with a 60-token memory and a pinned rules block: after seven messages, only the newest chat still fits next to the rules.

Steps.

  1. Create Memory.from_defaults(session_id=..., token_limit=...) per conversation.
  2. Add a StaticMemoryBlock with priority=0 for the rules (never truncated).
  3. Add a FactExtractionMemoryBlock or VectorMemoryBlock to keep what gets flushed.
  4. Point it at a real database (async_database_uri) in production.

The code (Python):

from llama_index.core.llms import ChatMessage
from llama_index.core.memory import Memory, StaticMemoryBlock

rules = StaticMemoryBlock(name="rules", static_content="You are ServiceApps Assist. Cite KB numbers.", priority=0)
memory = Memory.from_defaults(session_id="u42:INC0012345", token_limit=60,         # short-term limit (7.1)
                              chat_history_token_ratio=0.5, token_flush_size=20,
                              memory_blocks=[rules])                                # pinned rules (7.1)
turns = [("user", "My VPN keeps dropping on my laptop at the hotel"), ("assistant", "Which error code do you see?"),
         ("user", "Error 809 every time I connect"), ("assistant", "809 means the VPN can't reach the server."),
         ("user", "I'm on the hotel guest Wi-Fi right now"), ("assistant", "Avoid guest Wi-Fi; try your phone hotspot."),
         ("user", "Still failing on the hotspot too")]
for role, text in turns:
    memory.put(ChatMessage(role=role, content=text))
sent = memory.get()                                    # what the next model call receives
print("stored messages :", len(memory.get_all()))
print("sent next call  :", len(sent), "messages")
print("first one sent  :", sent[0].role.value, "->", str(sent[0].content)[:90])
print("oldest chat sent:", [m.content for m in sent if m.role.value == "user"][0])

Output (from running the code above on Nov 19, 2026):

stored messages : 7
sent next call  : 4 messages
first one sent  : system -> <memory>
<rules>
You are ServiceApps Assist. Cite KB numbers.
</rules>
</memory>
oldest chat sent: I'm on the hotel guest Wi-Fi right now

What to watch for.

The 27 solutions with LlamaIndex

πŸ” Replace = LlamaIndex does it, you configure it (13 of 27). 🀝 Complement = use both: LlamaIndex gives the mechanism, you add the rules (8). πŸ›  Still yours = build it yourself (6). † = not a memory feature, so from general knowledge rather than the memory docs; check the current docs.

Memory solutionWith LlamaIndexHowSolution
Three-Tier Memory: Short-Term (Context Window) (what the AI sees in the current call)πŸ” ReplaceMemory.from_defaults(session_id=..., token_limit=...) manages the chat historyDeep dive
Three-Tier Memory: Long-Term (Vector Store) (knowledge saved outside the model and searched when needed)πŸ” ReplaceVectorMemoryBlock on any vector store (a database that finds text by meaning, using embeddings)Deep dive
Three-Tier Memory: Episodic (Experience Log) (a record of what happened, step by step)🀝 ComplementThe chat store keeps messages per session; the audit log (a permanent record of who did what and when) is yoursDeep dive
Agentic Outcome: Token Budgets (keeping each call within a planned size)πŸ” Replacetoken_limit, chat_history_token_ratio and block priority decide what's keptDeep dive
Agentic Outcome: Hybrid Memory Systems (recent chat in the window plus long-term search)πŸ” ReplaceShort-term chat + memory blocks in one MemoryDeep dive
Agentic Outcome: Strict State Serialization (saving state so work can pause, crash and resume without loss)🀝 ComplementWorkflow (a fixed series of steps the app runs) ctx.to_dict() / Context.from_dict(); Memory is stored separatelyDeep dive
Token Counting Middleware (code that counts tokens before every AI call and acts when the window gets too full)πŸ” ReplaceCounts tokens (pieces of words the AI reads and writes; cost is per token) (tiktoken by default) and flushes old messages past the limitDeep dive
Dynamic Context Loading (giving the AI tools to fetch data only when it needs it, instead of putting everything in the prompt)πŸ” ReplaceTools (a function the AI can call, such as policy search) and query engines are standard †Deep dive
System Prompt Pinning (keeping the rules in a protected place that is sent on every call and never trimmed)πŸ” ReplaceStaticMemoryBlock with priority=0 is always inserted, never truncated †Deep dive
Textual Summarization (rewriting old conversation into short, dense notes)πŸ›  Still yoursThe summary buffer is deprecated; old messages are flushed to memory blocks insteadDeep dive
Rolling Summaries (a short running summary that replaces old conversation turns)🀝 ComplementPast chat_history_token_ratio, the oldest messages move to long-term blocksDeep dive
Entity Extraction (pulling key facts (names, dates, IDs) out of text into a structured record)πŸ” ReplaceFactExtractionMemoryBlock(max_facts=...)Deep dive
Vector Compression via RAG (storing text as vectors and pulling back only the parts that match)πŸ” ReplaceFlushed messages go into a VectorMemoryBlockDeep dive
The Engineering Trade-off: Fidelity vs. Capacity (the trade-off between keeping every detail and fitting more in the window)πŸ›  Still yoursFact extraction is an LLM (large language model: the AI that reads and writes text (here, Claude)) rewrite: keep exact facts elsewhereDeep dive
The Hot/Cold State Architecture (splitting memory into what is in the current call (hot) and what is saved for later (cold))🀝 ComplementShort-term chat is hot; memory blocks are coldDeep dive
Structured Storage (SQL/Postgres) (a database with fixed tables for exact facts)πŸ›  Still yoursA SQL chat store holds messages, not your recordsDeep dive
Semantic Storage (Vector DB like Pinecone, Weaviate, or Chroma) (a vector database that finds text by meaning)πŸ” ReplaceVectorMemoryBlock on any LlamaIndex vector store (a database that finds text by meaning, using embeddings)Deep dive
Session Caching (Redis/Key-Value) (saving a conversation's state so it can pause and resume)πŸ” Replacesession_id with a SQL chat store (async_database_uri)Deep dive
The Rehydration Pattern (fetch saved state, keep only what's relevant, and put it back into the next call)πŸ” Replacememory.get() returns recent chat plus memory blocksDeep dive
Sanitization layer (code that masks personal details and secrets before anything is saved)πŸ›  Still yoursNot on the memory pageDeep dive
TTL (time-to-live) expiration (deleting saved data automatically after a set time)πŸ›  Still yoursNot mentionedDeep dive
GDPR Right to Be Forgotten (a person's right to have their stored data deleted (from the EU's GDPR law))🀝 ComplementDelete messages in the chat store by sessionDeep dive
Engineering Fix: Recursive Goal Injection (repeating a short reminder of the rules before every AI answer)🀝 ComplementA StaticMemoryBlock reminder is inserted every turn †Deep dive
Engineering Fix: Strict RAG and Citation Enforcement (answering only from retrieved sources, and flagging any answer without one)🀝 ComplementCitation-style query engines return numbered sources; checking them is yours †Deep dive
Input Filtering: Relevance Pruning (checking and trimming a question before the AI sees it)πŸ›  Still yoursYours †Deep dive
Process Control: Self-Correction Loop (checking the AI's answer and sending it back once to fix what failed)🀝 ComplementWorkflows (a fixed series of steps the app runs) can loop back; the check is yours †Deep dive
Output Guardrails: Schema Enforcement (requiring the AI's answer to match a fixed shape, checked in code)πŸ” ReplaceStructured output with a Pydantic (a library that checks data fits a fixed form) output_cls †Deep dive

Use both: what you still build

Still yours with LlamaIndex:

Use both (complement), with your rules on top:

In NurseOps Now

Not used in NurseOps Now; its RAG (retrieval-augmented generation: the AI looks things up before it answers) is built directly on Chroma (the database that stores the policy vectors) and sentence-transformers (a library that turns text into vectors).

Trade-offs

Interview answer

"In LlamaIndex I'd use Memory per session with a token (the unit the AI reads and is billed by, about three quarters of a word) limit, a static block with the rules at priority zero so they're never cut, and a fact or vector (text turned into a list of numbers so similar meanings sit close together) block to catch what overflows. It's the best built-in window management of the four; persistence and deletion I'd wire to our own database."

All data in this post is made up.

← Back to all 27 solutions

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: In plain words↩ Back to where you were
agentic outcome: hybrid memory systems
Recent chat in the window plus long-term search.Used in: The 27 solutions with LlamaIndex↩ Back to where you were
agentic outcome: strict state serialization
Saving state so work can pause, crash and resume without loss.Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ Back to where you were
agentic outcome: token budgets
Keeping each call within a planned size.Used in: The 27 solutions with LlamaIndex↩ Back to where you were
API key
A secret code that lets the app use a paid service.Used in: How to implement it (ServiceApps)↩ Back to where you were
audit log
A permanent record of who did what and when.Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ Back to where you were
Chroma
The database that stores the policy vectors.Used in: In NurseOps Now↩ Back to where you were
dynamic context loading
Giving the AI tools to fetch data only when it needs it, instead of putting everything in the prompt.Used in: The 27 solutions with LlamaIndex↩ Back to where you were
engineering fix: recursive goal injection
Repeating a short reminder of the rules before every AI answer.Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ Back to where you were
engineering fix: strict rag and citation enforcement
Answering only from retrieved sources, and flagging any answer without one.Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ Back to where you were
entity extraction
Pulling key facts (names, dates, IDs) out of text into a structured record.Used in: The 27 solutions with LlamaIndex↩ Back to where you were
gdpr right to be forgotten
A person's right to have their stored data deleted (from the EU's GDPR law).Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ Back to where you were
input filtering: relevance pruning
Checking and trimming a question before the AI sees it.Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ Back to where you were
LLM
Large language model: the AI that reads and writes text (here, Claude).Used in: The 27 solutions with LlamaIndex, Use both: what you still build, Trade-offs↩ Back to where you were
output guardrails: schema enforcement
Requiring the AI's answer to match a fixed shape, checked in code.Used in: The 27 solutions with LlamaIndex↩ Back to where you were
process control: self-correction loop
Checking the AI's answer and sending it back once to fix what failed.Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ Back to where you were
Pydantic
A library that checks data fits a fixed form.Used in: The 27 solutions with LlamaIndex↩ Back to where you were
RAG
Retrieval-augmented generation: the AI looks things up before it answers.Used in: In plain words, In NurseOps Now, Trade-offs↩ Back to where you were
rolling summaries
A short running summary that replaces old conversation turns.Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ Back to where you were
sanitization layer
Code that masks personal details and secrets before anything is saved.Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ Back to where you were
semantic storage (vector db like pinecone, weaviate, or chroma)
A vector database that finds text by meaning.Used in: The 27 solutions with LlamaIndex↩ Back to where you were
sentence-transformers
A library that turns text into vectors.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
session caching (redis/key-value)
Saving a conversation's state so it can pause and resume.Used in: The 27 solutions with LlamaIndex↩ Back to where you were
structured storage (sql/postgres)
A database with fixed tables for exact facts.Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ Back to where you were
system prompt pinning
Keeping the rules in a protected place that is sent on every call and never trimmed.Used in: The 27 solutions with LlamaIndex↩ Back to where you were
textual summarization
Rewriting old conversation into short, dense notes.Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ Back to where you were
the engineering trade-off: fidelity vs. capacity
The trade-off between keeping every detail and fitting more in the window.Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ Back to where you were
the hot/cold state architecture
Splitting memory into what is in the current call (hot) and what is saved for later (cold).Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ Back to where you were
the rehydration pattern
Fetch saved state, keep only what's relevant, and put it back into the next call.Used in: The 27 solutions with LlamaIndex↩ Back to where you were
three-tier memory: episodic (experience log)
A record of what happened, step by step.Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ Back to where you were
three-tier memory: long-term (vector store)
Knowledge saved outside the model and searched when needed.Used in: The 27 solutions with LlamaIndex↩ Back to where you were
three-tier memory: short-term (context window)
What the AI sees in the current call.Used in: The 27 solutions with LlamaIndex↩ Back to where you were
token
The unit the AI reads and is billed by, about three quarters of a word.Used in: In plain words, Trade-offs, Interview answer↩ Back to where you were
token counting middleware
Code that counts tokens before every AI call and acts when the window gets too full.Used in: The 27 solutions with LlamaIndex↩ Back to where you were
tokens
Pieces of words the AI reads and writes; cost is per token.Used in: What it gives you for memory, The 27 solutions with LlamaIndex↩ Back to where you were
tool
A function the AI can call, such as policy search.Used in: The 27 solutions with LlamaIndex↩ Back to where you were
ttl (time-to-live) expiration
Deleting saved data automatically after a set time.Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ 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), Interview answer↩ Back to where you were
vector compression via rag
Storing text as vectors and pulling back only the parts that match.Used in: The 27 solutions with LlamaIndex↩ Back to where you were
vector store
A database that finds text by meaning, using embeddings.Used in: In plain words, The 27 solutions with LlamaIndex↩ Back to where you were
workflow
A fixed series of steps the app runs.Used in: The 27 solutions with LlamaIndex, Use both: what you still build↩ Back to where you were
workflow state
Where an article is in its life: draft, review, published or retired.Used in: What it gives you for memory↩ Back to where you were