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
- In plain words
- What it gives you for memory: from the current docs
- How to implement it (ServiceApps): code and output
- The 27 solutions with LlamaIndex: replace, complement or still yours
- Use both: what you still build
- 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:
- Short-term:
Memory.from_defaults(session_id=..., token_limit=...); pastchat_history_token_ratio, the oldest messages are flushed (token_flush_size); tiktoken counts tokens (pieces of words the AI reads and writes; cost is per token) by default. - Long-term blocks:
StaticMemoryBlock(always inserted),FactExtractionMemoryBlock(max_facts=...),VectorMemoryBlock(vector_store, embed_model, similarity_top_k);prioritydecides what's truncated first (0 = never). - Persistence: an in-memory SQLite chat store by default; a remote SQL database via
async_database_uri; workflow state (where an article is in its life: draft, review, published or retired) withctx.to_dict()/Context.from_dict(). - Older classes (
ChatMemoryBuffer,ChatSummaryMemoryBuffer,VectorMemory) are deprecated in favor ofMemory. - Deleting: chat-store level (delete messages by session); no TTL.
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.
- Create
Memory.from_defaults(session_id=..., token_limit=...)per conversation. - Add a
StaticMemoryBlockwithpriority=0for the rules (never truncated). - Add a
FactExtractionMemoryBlockorVectorMemoryBlockto keep what gets flushed. - 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.
- Without a fact or vector (text turned into a list of numbers so similar meanings sit close together) block, flushed messages simply leave the window.
- The default store is in memory: configure a database for anything that must survive a restart.
- No redaction or TTL: mask before
put()and clean up by session.
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 solution | With LlamaIndex | How | Solution |
|---|---|---|---|
| Three-Tier Memory: Short-Term (Context Window) (what the AI sees in the current call) | π Replace | Memory.from_defaults(session_id=..., token_limit=...) manages the chat history | Deep dive |
| Three-Tier Memory: Long-Term (Vector Store) (knowledge saved outside the model and searched when needed) | π Replace | VectorMemoryBlock 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) | π€ Complement | The chat store keeps messages per session; the audit log (a permanent record of who did what and when) is yours | Deep dive |
| Agentic Outcome: Token Budgets (keeping each call within a planned size) | π Replace | token_limit, chat_history_token_ratio and block priority decide what's kept | Deep dive |
| Agentic Outcome: Hybrid Memory Systems (recent chat in the window plus long-term search) | π Replace | Short-term chat + memory blocks in one Memory | Deep dive |
| Agentic Outcome: Strict State Serialization (saving state so work can pause, crash and resume without loss) | π€ Complement | Workflow (a fixed series of steps the app runs) ctx.to_dict() / Context.from_dict(); Memory is stored separately | Deep dive |
| Token Counting Middleware (code that counts tokens before every AI call and acts when the window gets too full) | π Replace | Counts tokens (pieces of words the AI reads and writes; cost is per token) (tiktoken by default) and flushes old messages past the limit | Deep dive |
| Dynamic Context Loading (giving the AI tools to fetch data only when it needs it, instead of putting everything in the prompt) | π Replace | Tools (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) | π Replace | StaticMemoryBlock with priority=0 is always inserted, never truncated β | Deep dive |
| Textual Summarization (rewriting old conversation into short, dense notes) | π Still yours | The summary buffer is deprecated; old messages are flushed to memory blocks instead | Deep dive |
| Rolling Summaries (a short running summary that replaces old conversation turns) | π€ Complement | Past chat_history_token_ratio, the oldest messages move to long-term blocks | Deep dive |
| Entity Extraction (pulling key facts (names, dates, IDs) out of text into a structured record) | π Replace | FactExtractionMemoryBlock(max_facts=...) | Deep dive |
| Vector Compression via RAG (storing text as vectors and pulling back only the parts that match) | π Replace | Flushed messages go into a VectorMemoryBlock | Deep dive |
| The Engineering Trade-off: Fidelity vs. Capacity (the trade-off between keeping every detail and fitting more in the window) | π Still yours | Fact extraction is an LLM (large language model: the AI that reads and writes text (here, Claude)) rewrite: keep exact facts elsewhere | Deep dive |
| The Hot/Cold State Architecture (splitting memory into what is in the current call (hot) and what is saved for later (cold)) | π€ Complement | Short-term chat is hot; memory blocks are cold | Deep dive |
| Structured Storage (SQL/Postgres) (a database with fixed tables for exact facts) | π Still yours | A SQL chat store holds messages, not your records | Deep dive |
| Semantic Storage (Vector DB like Pinecone, Weaviate, or Chroma) (a vector database that finds text by meaning) | π Replace | VectorMemoryBlock 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) | π Replace | session_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) | π Replace | memory.get() returns recent chat plus memory blocks | Deep dive |
| Sanitization layer (code that masks personal details and secrets before anything is saved) | π Still yours | Not on the memory page | Deep dive |
| TTL (time-to-live) expiration (deleting saved data automatically after a set time) | π Still yours | Not mentioned | Deep dive |
| GDPR Right to Be Forgotten (a person's right to have their stored data deleted (from the EU's GDPR law)) | π€ Complement | Delete messages in the chat store by session | Deep dive |
| Engineering Fix: Recursive Goal Injection (repeating a short reminder of the rules before every AI answer) | π€ Complement | A 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) | π€ Complement | Citation-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 yours | Yours β | Deep dive |
| Process Control: Self-Correction Loop (checking the AI's answer and sending it back once to fix what failed) | π€ Complement | Workflows (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) | π Replace | Structured 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:
- Textual Summarization (rewriting old conversation into short, dense notes): The summary buffer is deprecated; old messages are flushed to memory blocks instead
- The Engineering Trade-off: Fidelity vs. Capacity (the trade-off between keeping every detail and fitting more in the window): Fact extraction is an LLM (large language model: the AI that reads and writes text (here, Claude)) rewrite: keep exact facts elsewhere
- Structured Storage (SQL/Postgres) (a database with fixed tables for exact facts): A SQL chat store holds messages, not your records
- Sanitization layer (code that masks personal details and secrets before anything is saved): Not on the memory page
- TTL (time-to-live) expiration (deleting saved data automatically after a set time): Not mentioned
- Input Filtering: Relevance Pruning (checking and trimming a question before the AI sees it): Yours
Use both (complement), with your rules on top:
- Three-Tier Memory: Episodic (Experience Log) (a record of what happened, step by step): The chat store keeps messages per session; the audit log (a permanent record of who did what and when) is yours
- Agentic Outcome: Strict State Serialization (saving state so work can pause, crash and resume without loss): Workflow (a fixed series of steps the app runs)
ctx.to_dict()/Context.from_dict(); Memory is stored separately - Rolling Summaries (a short running summary that replaces old conversation turns): Past
chat_history_token_ratio, the oldest messages move to long-term blocks - The Hot/Cold State Architecture (splitting memory into what is in the current call (hot) and what is saved for later (cold)): Short-term chat is hot; memory blocks are cold
- GDPR Right to Be Forgotten (a person's right to have their stored data deleted (from the EU's GDPR law)): Delete messages in the chat store by session
- Engineering Fix: Recursive Goal Injection (repeating a short reminder of the rules before every AI answer): A
StaticMemoryBlockreminder is inserted every turn - Engineering Fix: Strict RAG and Citation Enforcement (answering only from retrieved sources, and flagging any answer without one): Citation-style query engines return numbered sources; checking them is yours
- Process Control: Self-Correction Loop (checking the AI's answer and sending it back once to fix what failed): Workflows (a fixed series of steps the app runs) can loop back; the check is yours
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
- The best built-in token (the unit the AI reads and is billed by, about three quarters of a word) window plus long-term blocks, and strong RAG (retrieval-augmented generation: the AI looks things up before it answers), but persistence and deletion are lower-level.
- Fact extraction is an LLM (large language model: the AI that reads and writes text (here, Claude)) rewrite: useful, but not a record of truth.
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.
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