Supplying an entire repository to a language model can overload its context window and bury useful information. Retrieval-augmented generation (RAG) instead searches for relevant external information and adds a curated slice to the prompt before the model responds. section 3.5.1
A repository-based RAG workflow follows three steps:
- Index source files as searchable embeddings. section 3.5.1
- Convert the developer’s query into an embedding and compare it with the index to retrieve relevant chunks. section 3.5.1
- Add those chunks alongside the question so the model can generate a response using the retrieved context. section 3.5.1
Figure 3.7 Context-aware assistance flow. The developer's query is converted into an embedding, matched against the indexed codebase, and the most relevant chunks are injected into the prompt before the model generates its response.

Follow the query from embedding and repository matching through prompt augmentation and response generation. section 3.5.1
Fixing authentication
For an authentication request, retrieval can supply the login handler and its related tests instead of thousands of lines of unrelated code. Inspect the selected context: relevance is a retrieval decision, not a guarantee that the agent has everything it needs. section 3.5.1
When automatic retrieval repeatedly selects the wrong material, scope context manually: pin a file, mention a directory, exclude paths with an ignore file, or start a clean session if the current one has drifted. Arguing with the retrieval system in prose is less useful than explicitly selecting the context. section 3.5.1
RAG finds information relevant to the current query; it does not by itself preserve decisions across a long task. An agent can still lose earlier requirements or repeat fixed errors as conversation history exceeds its context window. Persistent, structured memory addresses a different problem, and retrieved help is less useful when the context is already bloated. section 3.5.2













































