3 External knowledge and retrieval
This chapter covers
- External knowledge as a source of context 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 foundational sources of context in LLM-based systems. This chapter examines how LLMs leverage this context source to expand their internal knowledge beyond their training data and produce responses grounded in real-time or domain-specific information. One of the most popular ways to incorporate external knowledge is through retrieval techniques, implemented through workflows such as retrieval-augmented generation (RAG) and its more advanced variants (graph-based, hybrid, and agentic RAG). To improve the efficiency of these retrieval workflows, caching techniques such as cache-augmented generation can be used. Finally, context injection techniques (the so-called context stuffing) can be employed to place external knowledge directly into the context window.