debug-rag
Skill24 starsChanged 17 days agoMITView on GitHub
Diagnose and fix common RAG failure modes
In this repository23 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- architectureSkill
- audit-contentSkill
- benchmarkSkill
- break-itSkill
- buildSkill
- challengeSkill
- code-reviewSkill
- compareSkill
- evaluateSkill
- explainSkill
- fixSkill
- glossarySkill
- journalSkill
- lessonSkill
- paper-reviewSkill
- quizSkill
- recapSkill
- roadmapSkill
- sandboxSkill
- startSkill
- triageSkill
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 11 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈11
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 16
Ask the learner to describe the problem they are seeing.
- Distinctive: line 27
If the learner is not sure, ask them to share an example query, the expected answer, and the actual answer.
- Distinctive: line 35
Start by inspecting what the retriever actually returns:
- Distinctive: line 40
Inspect chunks: Look at the actual chunks in the vector store.
- Distinctive: line 60
Embedding model mismatch: Verify the exact model name AND vector dimensions used at index time match query time.
- Distinctive: line 61
Metadata filter bugs: Run the exact same query with ALL metadata filters disabled.
- Distinctive: line 62
Stale index: If you've added many vectors without rebuilding the index, HNSW recall degrades.
- Distinctive: line 86
Check that the fix did not introduce new problems
- Distinctive: line 100
After resolving the issue, explain the broader pattern.
- Distinctive: line 110
Always start with the simplest possible cause before investigating complex ones
- Distinctive: line 112
Use the pipeline's actual data for debugging, not synthetic examples
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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
Debug RAG: Diagnose and Fix Pipeline Issues
Scope: This skill teaches debugging through guided diagnosis and explanation. For a fast fix without the teaching, use
/fix.
An interactive debugging workflow that helps learners identify and resolve common RAG failure modes. This skill builds debugging intuition alongside technical problem-solving.
Language awareness: See
.claude/LANGUAGE_AWARENESS.md.
Step 1: Identify the Symptom
Ask the learner to describe the problem they are seeing. Common symptoms include:
- Hallucination: The model generates information not in the retrieved context
- Irrelevant retrieval: The retrieved documents do not match the query
- Missing context: Relevant information exists in the corpus but is not retrieved
- Incomplete answers: The answer is partially correct but missing key details
- Contradictory answers: The answer contradicts the source documents
- Repetitive or generic responses: The model ignores context and gives generic answers
- Wrong format: The answer is correct but not in the expected format
- High latency: The pipeline is too slow
If the learner is not sure, ask them to share an example query, the expected answer, and the actual answer.
Step 2: Follow the Diagnostic Tree
Based on the symptom, walk through the appropriate diagnostic path:
For Retrieval Issues (irrelevant results, missing context)
Start by inspecting what the retriever actually returns:
Provide diagnostic code in the learner's chosen language that retrieves results and prints scores, sources, and text previews.
- Check the query: Is the query well-formed? Try rephrasing it.
- Inspect chunks: Look at the actual chunks in the vector store. Are they the right size? Do they contain the expected information?
- Test embedding similarity: Compute the similarity between the query embedding and the expected chunk embedding. Is it above the retrieval threshold?
- Check top-k: Are you retrieving enough documents? Try increasing top-k.
- Examine metadata filters: Are any filters accidentally excluding relevant results?
- Compare search methods: Try keyword search alongside vector search to see if the issue is in the embeddings.
For Generation Issues (hallucination, contradictions, generic responses)
- Inspect the prompt: Print the full prompt sent to the LLM. Is the context included correctly?
- Check context ordering: Are the most relevant documents first in the context?
- Look for context overflow: Is the context exceeding the model's context window?
- Test with perfect context: Manually provide the correct context and see if the model generates correctly. This isolates retrieval vs. generation issues.
- Review system prompt: Does it instruct the model to only use the provided context?
- Check temperature: High temperature increases hallucination risk.
For Indexing & Configuration Issues (chunk boundaries, model mismatches, filter bugs)
These are the sneakiest bugs — the pipeline runs without errors but produces bad results.
- Chunk boundary problems: The answer to a question might be split across two chunks, with neither chunk containing the complete fact. To diagnose: retrieve the chunks immediately before and after the expected chunk (by index). If the fact spans the boundary, the fix is larger chunks, more overlap, or semantic chunking.
- Embedding model mismatch: Verify the exact model name AND vector dimensions used at index time match query time. A mismatch (e.g., indexing with
text-embedding-3-largeat 3072 dims, querying withtext-embedding-3-smallat 1536 dims) produces nonsense scores that look numerically plausible. Print both configs side by side. - Metadata filter bugs: Run the exact same query with ALL metadata filters disabled. If results improve dramatically, re-enable filters one at a time. Common culprits: case-sensitive mismatches (
"PDF"vs"pdf"), filtering on a field that was never populated, type mismatches (string"2024"vs integer2024). - Stale index: If you've added many vectors without rebuilding the index, HNSW recall degrades. Check if your vector DB needs an explicit optimize/compact call (Qdrant does, ChromaDB handles it automatically).
- Asymmetric embedding prefixes: Many models (E5, BGE) require different prefixes for queries vs documents (
"query: "vs"passage: "). If you embed both the same way, retrieval quality drops silently.
For Performance Issues (high latency)
- Profile each stage: Measure time for embedding, retrieval, and generation separately.
- Check batch sizes: Are embeddings computed one at a time instead of in batches?
- Inspect vector DB performance: Is the index optimized? How many vectors are stored?
- Review model selection: Is the generation model appropriately sized for the task?
Step 3: Apply the Fix
For each identified issue, provide:
- A clear explanation of why this causes the problem
- The specific code change or configuration adjustment needed
- A way to verify the fix worked
Walk the learner through making the change and re-testing.
Step 4: Verify the Fix
Help the learner test that the fix resolved the original issue:
- Re-run the failing query
- Compare before and after results
- Check that the fix did not introduce new problems
Step 5: Document the Fix
Encourage good practices by helping the learner document:
- What the symptom was
- What the root cause was
- What the fix was
- How to prevent it in the future
Save debugging notes to progress/debug-log.md for future reference.
Step 6: Build Debugging Intuition
After resolving the issue, explain the broader pattern. For example: "Hallucination often comes from the prompt, not the model. Always check your prompt template first." This helps learners build a mental model for future debugging.
Suggest 2-3 relevant next steps using slash commands:
/evaluate— run a full evaluation to confirm the fix improved overall quality/build— rebuild or improve the component that caused the issue/code-review— get expert feedback to catch other potential problems
Guidelines
- Always start with the simplest possible cause before investigating complex ones
- Encourage the learner to form hypotheses before looking at the data
- Use the pipeline's actual data for debugging, not synthetic examples
- Teach the learner to isolate variables — change one thing at a time
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.

