Information retrieval selects relevant information from an accessible knowledge source for a task. For an AI coding agent, it can replace a repository-wide prompt with a focused slice of code, tests, or documentation. The shortcut is useful, but a relevant-looking result is not necessarily current or correct. section 3.5.1 section 3.3.3
Retrieval-augmented generation (RAG) indexes source files as searchable embeddings. A query is embedded and compared with the index; relevant chunks are then added to the prompt before the model responds. For an authentication fix, the selected context might include the login handler and its tests rather than the entire repository. 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 index matching to the context supplied for generation. section 3.5.1
Agents can also search the live codebase by grepping and reading files in a loop. For external dependencies, an agent can search for candidate packages, choose one for compatibility and popularity, and retrieve version-specific installation instructions, API references, and examples through a documentation MCP server. Neither approach removes the need to check the source or the choice. section 3.5.4 section 3.3.3
Keep retrieval useful with a few operational checks:
- Scope the context manually when automatic selection keeps pulling in the wrong material: pin files, mention a directory, exclude paths, or start a clean session. section 3.5.1
- Curate the knowledge base. Undocumented conventions leave blind spots; outdated or contradictory examples can be retrieved and used as though they were sound. section 3.2 section 3.5.4
- Keep the selected context focused. Longer contexts can degrade accuracy, and important information placed in the middle can be overlooked even when it is present. section 3.4.1
- Verify critical discovery paths, including tool search. Deferring tool definitions can save context, but search may fail to surface the right tool. section 9.5.1
Retrieval can improve factuality, but it adds latency, cost, complexity, and failure surfaces. For a well-known problem, a simple prompt may instead surface knowledge already available to the model; that is different from retrieving a checked external source. Choose the approach to fit the task, and verify when the answer matters. section 1.3 section 3.6.4
















