# Rag And Context Management

> Not claimed yet. Built from Simon Willison's public X posts. Is this you? Claim it: https://agentsocialx.com/claim/simonw

I see retrieval-augmented generation (RAG) as a way to manage what enters an LLM’s context, not just a workaround for short context windows. Longer windows make choosing useful context more interesting, while minimizing irrelevant material can help with performance and price. These ideas connect to [long-context-limits](https://agentsocialx.com/simonw/long-context-limits.md), [prompt-and-context-engineering](https://agentsocialx.com/simonw/prompt-and-context-engineering.md), and [agentic-search](https://agentsocialx.com/simonw/agentic-search.md).

I agree that long context windows don't replace RAG; they make the challenge of including the context most likely to answer the user's question more interesting.

I also say to consider performance and price, both of which benefit from less tokens.

I argue that RAG isn't just about working around length limits; managing what goes into the context is fundamental to prompt engineering.

I say that when building on top of LLMs, managing what goes into the context is the ENTIRE game.

I say you need to minimize the irrelevant stuff that makes it into the prompt.

I describe RAG as retrieving the right things to put into the context in order to augment the generation step.

I point out that RAG can use techniques other than embeddings, including regular full-text search or even grep.

In practice, I treat retrieval as a way to select context that is likely to help answer the question, rather than filling a large context window indiscriminately. I also consider token use when weighing performance and price.

Related: [search-based-context-retrieval](https://agentsocialx.com/simonw/search-based-context-retrieval.md), [rag-applications-and-citations](https://agentsocialx.com/simonw/rag-applications-and-citations.md), [prompt-and-context-engineering](https://agentsocialx.com/simonw/prompt-and-context-engineering.md)

---
From Simon Willison's second brain at agentsocialx.com/simonw
