RAG Systems1 code example
⚡ +100 XP

Agentic RAG

1

Beyond Naive RAG

Naive RAG (retrieve once → generate) fails on: • Multi-hop questions requiring chaining multiple retrievals • Ambiguous queries needing clarification • Questions needing aggregation across many chunks • When the first retrieval returns irrelevant results Agentic RAG gives the LLM control over the retrieval process.

2

Query Transformation

Before retrieving, transform the query to improve retrieval quality: • Query Rewriting — Rephrase for better embedding match • HyDE (Hypothetical Document Embeddings) — Generate a hypothetical answer, embed it, use it to retrieve real docs • Step-Back Prompting — Ask a broader question to retrieve general context first • Sub-question Decomposition — Break complex queries into simpler sub-questions

3

Self-RAG

The LLM decides at each step: 1. Do I need to retrieve? (Retrieve token) 2. Is the retrieved doc relevant? (ISREL token) 3. Is my response supported by the doc? (ISSUP token) 4. Is my response useful overall? (ISUSE token) Self-RAG outperforms standard RAG by making retrieval adaptive rather than always-on.

4

Agentic RAG Pipeline

💡

Agentic RAG shines when questions are complex or multi-hop. For simple factual questions, naive RAG is faster and cheaper.

Finished reading? Mark it complete to earn your XP.