Course contentsShow
← AI Engineering
Lesson 436 of 1,88611. RAG - Improving GenerationFree lesson

Self-RAG: Reflection and Critique Loop

Implement reflection tokens where the model critiques its own generation and triggers re-retrieval when needed.

Self-RAG: Reflection and Critique Loop

What you'll learn: How to make your RAG system self-aware by having the model critique its own outputs and decide when to retrieve more information.

The Core Idea

Self-RAG introduces reflection tokens — special signals that the model generates alongside its answer to evaluate the quality of its own response. Think of it like a student who not only answers a question but also rates their confidence and decides whether they need to look up more information.

Instead of blindly accepting retrieved documents and generating an answer, the model asks itself critical questions:

  • "Is this retrieved context actually relevant?"
  • "Does my answer fully address the question?"
  • "Am I confident in this response, or should I search again?"

Based on these self-assessments, the system can trigger re-retrieval — fetching different or additional documents when the initial context proves inadequate.

How It Works

The model generates special tokens like [Relevant], [Irrelevant], [Supported], [Not Supported], or [Needs More Info] as it produces its answer. These aren't shown to the user but act as internal signals.

Example flow:

  1. Retrieve documents for query: "What causes the Northern Lights?"
  2. Model generates: "The Northern Lights are caused by..." [Relevant] [Supported]
  3. System accepts answer

Alternative flow with re-retrieval:

  1. Retrieve documents about "quantum computing applications"
  2. Model generates partial answer [Partially Relevant] [Needs More Info]
  3. System reformulates query, retrieves again with refined context
  4. Model completes answer with higher confidence

This creates a critique loop where the system iteratively improves its own outputs rather than serving whatever the first retrieval returned.

Key Takeaway: Self-RAG adds a reflection layer where the model evaluates its own generation quality and triggers additional retrieval when needed, creating a self-correcting RAG system that knows when it doesn't know enough.