LLM Memory: Developers Tackle Goldfish Memory With Hybrid Architectures
Serge Bulaev
Large language models (LLMs) are sometimes seen as forgetful, but the issue may actually be about where their memory is stored. The model's knowledge lives in frozen weights, while chat history and facts are kept outside in session context or databases. Developers use different strategies - like sliding windows, vector searches, and memory managers - to help LLMs remember more and work better. However, making LLMs handle bigger memories may raise costs and slow responses, so engineers carefully limit and manage what information is sent each time. Reports suggest that simply increasing context size does not always improve results, and hybrid systems are being developed to handle memory more effectively.

The challenge of LLM memory is not forgetfulness but architecture. A model's core knowledge is frozen in its weights, while chat history and facts reside externally. Developers use hybrid systems with vector search and managed context to improve recall, as simply expanding the context window proves inefficient and costly.
Because today's leading LLM APIs are stateless, applications must resend the entire context - including chat history, summaries, and retrieved data - with every new request. A typical large context window might allocate only a portion of tokens for the model's actual response. The rest is consumed by system prompts, tool definitions, conversation history, and documents. This approach is expensive in both cost and latency, as doubling context size can significantly increase the computational load for self-attention, increasing GPU memory usage and response times.
Working memory versus persistent memory
LLM systems use a tiered memory model. The first layer is the static, trained memory within the model's weights. The second is temporary working memory in the context window for a single interaction. The third is persistent application memory, like databases, for long-term storage across sessions.
These memory types include:
1. Trained memory - frozen weights updated only during model retraining.
2. Working memory - the prompt window where tokens are attended to during the current call.
3. Application memory - databases, vector stores, or logs that survive across sessions.
While these layers interact, developers manage them carefully. Even as prompt windows expand - with some modern systems accepting very large token counts - engineers remain cautious. Benchmarks show that while latency may increase with input size, the cost of self-attention grows super-linearly, making large contexts resource-intensive.
Common context-extension tactics
To manage these constraints, developers employ several common tactics to extend memory efficiently:
- Sliding window keeps only the last N turns when space runs low.
- Vector retrieval fetches semantic matches from an external store.
- Structured extraction writes confirmed facts into typed tables.
- Profile memory pins stable user preferences so they are always injected.
When long windows are not enough
Recent benchmarks indicate that effective recall is more critical than raw context window size. Even in models with very large context windows, performance can degrade when recalling information from the middle of the context. This "lost in the middle" problem reinforces the need for hybrid memory stacks, where a dedicated memory manager orchestrates what to retrieve, cache, and summarize for each turn.
Economic signals developers watch
The economics of LLM APIs heavily influence architecture. For example, pricing models often charge more for larger contexts, with some providers increasing per-token costs above certain thresholds. Furthermore, prefill latency - the time taken to process the entire input - increases with context size. Consequently, engineers carefully budget tokens, often using moderate context sizes for interactive sessions even when the model supports more.
Minimal architecture that works in production
A minimal yet robust production architecture for LLM memory includes several key components:
- SQL or document store for user, session, and audit metadata.
- Vector database for semantic recall of facts and summaries.
- Keyword index for exact IDs and numbers.
- Memory manager service that filters, ranks, and injects relevant context per call.
For effective governance, every memory entry should be tagged with metadata like user ID, timestamp, and confidence scores to handle stale or conflicting information. Retrieval strategies are typically hybrid, combining semantic search with keyword matching, followed by re-ranking to ensure relevance. All memory operations, including retrieval and summarization, must be logged for debugging and compliance.
Maintenance processes are also crucial. Summaries can be consolidated during off-peak hours, and data should expire based on time-to-live (TTL) policies. Engineers must monitor key metrics like retrieval precision and prompt overhead to get early warnings about knowledge drift or unexpected cost increases.
What are the three types of memory in LLM systems?
Modern LLM applications distinguish between three distinct memory layers:
- Trained memory - the model's weights containing general knowledge from pre-training, which remain static during typical API usage
- Working memory - the context window (measured in tokens) that acts as temporary workspace for each individual call
- Persistent application memory - external stores including databases, vector stores, and user profiles that maintain state across sessions
This architecture matters because LLMs do not inherently remember conversations - the surrounding application must deliberately reconstruct context for every request.
Why do costs and latency increase with longer conversations?
Each conversational round accumulates token processing that drives up both expense and response time. In a typical large token allocation, the breakdown reveals where resources go:
| Component | Token Budget |
|---|---|
| System instructions | Significant portion |
| Tool definitions | Significant portion |
| Conversation history | Largest portion |
| Retrieved documents | Significant portion |
| Current question | Small portion |
| Remaining for response | Remaining portion |
By request N, the system may process substantially more tokens than a single query. This creates superlinear cost pressure since attention mechanisms scale roughly quadratically with sequence length in transformer architectures.
What techniques do developers use to extend effective memory?
Production systems now employ hybrid memory stacks rather than simply expanding context windows:
| Technique | Purpose |
|---|---|
| Sliding window | Retains only recent conversation turns |
| Summarization/compaction | Compresses older exchanges into condensed representations |
| Structured extraction | Pulls specific facts into persistent stores |
| Vector-store-backed retrieval | Fetches relevant documents via semantic similarity |
| Long-term profiles | Maintains user preferences and durable knowledge |
A critical challenge: summarization is lossy, and repeated compression can distort meaning over time - a phenomenon known as "context rot."
How should memory systems be architected in production?
The strongest current practice treats memory as a data system with explicit governance rather than a prompt manipulation trick. A robust implementation combines:
- Application database for session metadata, timestamps, and audit trails
- Vector store for semantic retrieval of facts and conversation fragments
- Keyword/BM25 index for exact lookups on names, IDs, and specific terms
- Memory manager service that handles selection, compression, and insertion
Key implementation principles include:
- Write memory explicitly with triggers at task completion rather than automatic logging
- Attach metadata (user ID, session ID, timestamps, confidence scores) to every item
- Use hybrid retrieval combining vector similarity with keyword matching, then re-rank results
- Define TTL and forgetting policies to prevent stale data accumulation
- Log all memory operations for debugging and evaluation
What is the current state of context window technology?
Modern systems offer very large context windows for frontier models, with some systems reaching impressive token counts. However, the industry has shifted focus from raw size to effective context utilization:
"Raw context length has become less important than how models manage, compress, retrieve, and persist information across a session."
Advanced optimizations now include structured context compression (two-pass relevance filtering), KV-cache quantization to reduce memory pressure, paged attention for efficient serving, and sparse attention mechanisms that reduce computational complexity from quadratic toward linear.
For interactive applications, moderate token counts remain the practical sweet spot balancing latency and utility, while very large contexts serve batch analysis where completeness matters more than speed.