self-rag
Skill8 starsChanged 7 months agoMITView on GitHub
Use self-reflective loops to make dynamic retrieval decisions and assess response quality.
In this repository39 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rag-skillsSkill
- choosing-a-chunking-frameworkSkill
- contextual-chunk-headersSkill
- hierarchical-chunkingSkill
- semantic-chunkingSkill
- chunkingSkill
- sliding-window-chunkingSkill
- rag-for-code-documentationSkill
- rag-for-multimodal-contentSkill
- data-type-handlingSkill
- index-versioning-and-reindexingSkill
- production-rag-deploymentSkill
- deploymentSkill
- generation-evaluation-metricsSkill
- rag-evaluation-frameworksSkill
- retrieval-evaluation-metricsSkill
- evaluation-metricsSkill
- optimize-retrieval-latencySkill
- performance-optimizationSkill
- agentic-rag-routingSkill
- multi-agent-rag-orchestrationSkill
- rag-agentsSkill
- adaptive-retrievalSkill
- context-enrichment-windowSkill
- crag-corrective-ragSkill
- explainable-retrievalSkill
- graph-ragSkill
- hybrid-search-bm25-denseSkill
- hyde-hypothetical-document-embeddingsSkill
- hype-hypothetical-prompt-embeddingsSkill
- multi-pass-retrieval-with-rerankingSkill
- query-transformation-strategiesSkill
- raptor-hierarchical-retrievalSkill
- retrieval-strategiesSkill
- choosing-vector-db-by-datatypeSkill
- qdrant-for-production-ragSkill
- qdrant-setup-ragSkill
- vector-databasesSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 9 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 19
Blind Retrieval: Always retrieves regardless of whether it's needed
- Distinctive: line 23
Poor Quality Control: No mechanism to assess output utility
- Distinctive: line 35
Use an LLM to determine if the query requires retrieval or can be answered directly.
- Distinctive: line 37
Why: Not all queries need retrieval - some can be answered from general knowledge or are simple enough that retrieval adds unnecessary cost …
- Distinctive: line 44
Why: Not all retrieved documents are equally relevant.
- Distinctive: line 87
When retrieval quality varies significantly across queries
- Distinctive: line 89
When you need to detect and handle hallucinations
- Distinctive: line 94
When using a vector database with high-precision retrieval
- Distinctive: line 96
When cost is a major constraint (multiple LLM calls per query)
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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
- CRAG (Corrective RAG) - Dynamic correction approach
- Adaptive Retrieval - Query-based strategy selection
- Explainable Retrieval - Citation and traceability
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
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

