0%
Retrieval-Augmented Generation12 min

Advanced RAG Techniques

A basic RAG implementation works. A production-quality RAG system requires several additional layers that address the failure modes of naive retrieval-augmented generation.

Query transformation

User queries are often ambiguous, conversational, or missing context. Transforming them before retrieval improves results: query expansion (generating related terms), query decomposition (splitting multi-part questions), and HyDE (Hypothetical Document Embeddings — generating what an ideal answer might look like and embedding that for retrieval).

Reranking

Initial vector retrieval optimises for broad relevance. A reranker (a cross-encoder model that scores each document-query pair jointly) reorders the retrieved results to prioritise the most relevant documents before they are passed to the generation model. Adding a reranker consistently improves RAG quality at modest additional cost.

Contextual chunk enrichment

Individual document chunks often lack context when read in isolation. Enriching each chunk with its document title, section heading, and neighbouring context before embedding — and including this context in the retrieved text — significantly improves generation quality.

Evaluation of RAG systems

RAG evaluation has two separate components: retrieval quality (did we retrieve the right documents?) and generation quality (did the model use them correctly?). Both should be evaluated independently. Frameworks like RAGAS provide automated metrics for both. Fixing retrieval often has more impact than improving generation for poorly performing RAG systems.

Naive RAG is easy to build. Production RAG is hard. The gap between them is almost entirely retrieval quality — invest in query transformation, reranking, and chunk quality before adding more complex generation techniques.

Check your understanding

3 questions, 70% to pass
1. What is HyDE?
2. What does a reranker do?
3. What is contextual chunk enrichment?