3 External knowledge and retrieval
This chapter covers
- External knowledge as a context source beyond an LLM’s training data
- Retrieval-augmented generation (RAG) to encode and query external knowledge
- Knowledge graphs to structure and retrieve (graph RAG) external knowledge
- Advanced retrieval approaches, including hybrid, agentic, and vectorless RAG
- Cache-augmented generation (CAG) to preload external knowledge
- Context stuffing for direct injection of external knowledge
Chapter 1 introduced external knowledge as one of the six context sources that LLM-based systems supply to the model. While an LLM’s parametric memory is fixed after training, external knowledge connects the model to factual, proprietary, or up-to-date information. Context engineering manages this connection through three primary strategies: retrieval, caching, and direct injection. Retrieval workflows, such as retrieval-augmented generation (RAG) and its advanced variants (graph-based, hybrid, agentic, and vectorless RAG), locate relevant passages dynamically at query time. Caching architectures, such as cache-augmented generation (CAG), preload reusable context to reduce redundant retrieval and latency. Finally, direct injection (often called context stuffing) loads complete documents directly into the context window. The following sections explore each approach, their trade-offs, and the criteria for choosing among them.