| name | self-rag |
| title | Self-RAG - Self-Reflective Retrieval |
| description | Use self-reflective loops to make dynamic retrieval decisions and assess response quality. |
| allowed-tools | ["Read","Grep","Glob","Bash"] |
| category | retrieval-strategies |
| tags | ["self-rag","reflection","retrieval-decision","relevance-evaluation"] |
Overview
Self-RAG is a reflective framework that decides whether to retrieve information, evaluates the relevance of retrieved documents, assesses response support, and rates output utility. This dynamic approach optimizes retrieval decisions based on query characteristics and retrieved content quality.
Problem Statement
Traditional RAG systems lack introspection:
- Blind Retrieval: Always retrieves regardless of whether it's needed
- Irrelevant Context: Cannot filter out irrelevant retrieved documents
- No Grounding Assessment: Cannot verify if responses are supported by context
- Fixed Strategy: Cannot adapt to different query types
- Poor Quality Control: No mechanism to assess output utility
Key Concepts
- Retrieval Decision: LLM determines if retrieval is necessary for the query
- Relevance Evaluation: Each retrieved document assessed for query relevance
- Response Generation: Answers generated using only relevant context
- Support Assessment: Evaluation of how well responses are grounded in context
- Utility Rating: Assessment of how well the response addresses the original query
Implementation Guide
Step 1: Implement Retrieval Decision
Use an LLM to determine if the query requires retrieval or can be answered directly.
Why: Not all queries need retrieval - some can be answered from general knowledge or are simple enough that retrieval adds unnecessary cost and latency.
Direct the LLM to make a binary decision: retrieve from documents or answer without retrieval.
Step 2: Implement Relevance Evaluation
Assess each retrieved document for its relevance to the original query.
Why: Not all retrieved documents are equally relevant. Filtering ensures only pertinent information is used for generation, reducing noise and improving answer quality.
For each retrieved document, have the LLM rate its relevance to the query on a scale or classify as relevant/irrelevant.
Step 3: Implement Context Filtering
Build a pipeline that filters documents based on relevance scores.
Why: A systematic filtering process ensures consistent quality and prevents irrelevant information from contaminating the generation process.
Select only documents that meet a relevance threshold for use in response generation.
Step 4: Implement Response Generation
Generate responses using only relevant context, or without context if none is relevant.
Why: Using only relevant context improves factual grounding. When no relevant context exists, the system can still provide a response (with appropriate caveats) rather than forcing use of irrelevant information.
Generate responses conditioned on whether relevant context was found - using context if available, answering from general knowledge if not.
Step 5: Implement Support Assessment
Evaluate how well the generated response is supported by the context.
Why: Support assessment provides a confidence metric and helps detect hallucinations - responses not supported by context can be flagged or refined.
Have the LLM classify the level of support: fully supported, partially supported, or no support.
Step 6: Implement Utility Rating
Rate the usefulness of the generated response for the original query.
Why: Utility rating provides feedback on response quality and can be used for continuous improvement, A/B testing, or filtering low-quality responses.
Rate the response on a scale (e.g., 1-5) based on how well it addresses the user's query.
Step 7: Build Complete Self-RAG Pipeline
Combine all components into a cohesive reflective system.
Why: A complete pipeline with clear decision points allows for monitoring, optimization, and understanding of system behavior.
Chain together the retrieval decision, relevance evaluation, response generation, and assessment steps into a unified workflow.
For implementation patterns, see the Self-RAG paper, LangGraph agentic RAG guide, and LlamaIndex SelfRAG pack.
When to Use This Skill
- Building RAG systems where response accuracy is critical
- When retrieval quality varies significantly across queries
- For applications requiring confidence scoring
- When you need to detect and handle hallucinations
- For systems that must adapt to different query types
When NOT to Use This Skill
- For extremely latency-sensitive applications (multiple LLM calls)
- When using a vector database with high-precision retrieval
- For simple FAQ systems where queries are well-structured
- When cost is a major constraint (multiple LLM calls per query)
- For real-time systems with strict latency budgets
Related Skills
Metrics & Success Criteria
- Retrieval Efficiency: Reduced unnecessary retrievals by 30-50%
- Relevance Filtering: High precision in identifying irrelevant documents
- Response Accuracy: Improved factual grounding of responses
- Support Confidence: Reliable support assessment metrics
- Utility Rating: Consistent utility scores correlate with human evaluation