Engineering · AI Agent Architecture
Long-Term Memory and RAG Window Budgeting for Agents
Layer working memory, episode summaries, and vector recall with sensible chunking, rerank, and compression defaults.
1. Three-layer memory
Working memory holds live tool output; episodic memory stores session summaries; semantic memory lives in a vector store plus fact tables. Tag writes with session|user|org scope and filter auth before hybrid search. Embed intent summaries, not entire chats.
2. Chunking, parent indexes, and rerank
Split long docs by heading hierarchy; child chunks point at parent IDs so recall can expand. Retrieve wide, then cross-encode down to a handful of passages. Treat tables and code as distinct chunk types with their own boosts.
3. Token budgets and compression
Reserve fixed budgets for system, tools, memory, and user text. After a subtask, compress observations into a short structured summary and cold-store the raw log. Near the limit, retrieve prior successful trajectories instead of truncating blindly.
4. Engineering checklist
- Scan for PII and secrets before indexing
- Evaluate recall and hallucination on golden questions
- Hot index recent sessions; archive cold data to object storage
5. Sample configuration
retrieval:
hybrid: { sparse_k: 24, dense_k: 24, rerank_k: 8 }
memory:
compress_after_step: true
summary_max_tokens: 2566. FAQ
- Do frequent vector updates slow queries?
- Use incremental segments plus periodic merge with atomic alias swaps.
- RAG still answers wrong—what first?
- Check rerank and chunk boundaries, then auth filters; miss-recall is more common than weak generation.