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

5. Sample configuration

retrieval:
  hybrid: { sparse_k: 24, dense_k: 24, rerank_k: 8 }
memory:
  compress_after_step: true
  summary_max_tokens: 256

6. 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.