Skip to main content
skill CX Codex

debug-rag — Claude Code skill: diagnosing a broken RAG pipeline

Walks you from a symptom to the actual cause when retrieval or generation misbehaves. Useful once your RAG is built and the answers are still wrong.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add TakaGoto/rag-learning-academy --skill debug-rag -a claude-code
Open on GitHub

What debug-rag does

The skill starts with your complaint and sorts it into a symptom class: made-up facts, irrelevant hits, context that never arrives, malformed output, slow responses. Each class gets its own diagnostic path. Retrieval trouble means checking the query wording, chunk size, similarity against the chunk you expected, top-k and metadata filters. Generation trouble means printing the whole prompt, looking at context order and temperature, then feeding the model known-good context to see which half of the pipeline is at fault.

The indexing section covers bugs that never raise an error. A fact can straddle two neighbouring chunks so neither one holds it in full. Vectors may have been built with one embedding model while queries are encoded with another. A metadata filter can quietly drop the right documents over letter case or a field type. The skill has you print both configs side by side instead of guessing.

Fixes get verified by re-running the query that failed and comparing the two runs, then written down in progress/debug-log.md. Diagnosis needs your real query plus the expected and received answers; without those it turns into speculation.

What it helps with

  • trace why the model invents facts absent from the context
  • find what makes vector search return the wrong chunks
  • catch an embedding model mismatch between indexing and querying
  • test whether a metadata filter is excluding valid documents
  • measure which pipeline stage eats the latency

Example prompts for the agent

  • The model keeps making things up instead of using the docs. Walk me through the diagnosis.
  • Retrieval gives me irrelevant chunks — here is the query and what comes back in top-k.
  • The answer is right but formatted wrong. What should I change in the prompt?

How to install debug-rag

1Skills CLI (Vercel)

npx skills add TakaGoto/rag-learning-academy --skill debug-rag -a claude-code

2Manually: put the files in place

~/.claude/skills/debug-rag/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/debug-rag/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about debug-rag

How do I install debug-rag in Claude Code?

Run npx skills add TakaGoto/rag-learning-academy --skill debug-rag -a claude-code. The skill lands at ~/.claude/skills/debug-rag/SKILL.md.

What does debug-rag do?

It runs an interactive diagnosis of your RAG pipeline, moving from the symptom through targeted checks to a specific code or config change. Then it has you confirm the fix and log what you learned.

How is it different from a quick fix?

Here the point is understanding the failure, not just patching it. The skill itself points to /fix when you want the change with no explanation.

Source text

SKILL.md · MIT
---
name: debug-rag
description: "Diagnose and fix common RAG failure modes"
---

# 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:

1. **Hallucination**: The model generates information not in the retrieved context
2. **Irrelevant retrieval**: The retrieved documents do not match the query
3. **Missing context**: Relevant information exists in the corpus but is not retrieved
4. **Incomplete answers**: The answer is partially correct but missing key details
5. **Contradictory answers**: The answer contradicts the source documents
6. **Repetitive or generic responses**: The model ignores context and gives generic answers
7. **Wrong format**: The answer is correct but not in the expected format
8. **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.

1. **Check the query**: Is the query well-formed? Try rephrasing it.
2. **Inspect chunks**: Look at the actual chunks in the vector store. Are they the right size? Do they contain the expected information?
3. **Test embedding similarity**: Compute the similarity between the query embedding and the expected chunk embedding. Is it above the retrieval threshold?
4. **Check top-k**: Are you retrieving enough documents? Try increasing top-k.
5. **Examine metadata filters**: Are any filters accidentally excluding relevant results?
6. **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)

1. **Inspect the prompt**: Print the full prompt sent to the LLM. Is the context included correctly?
2. **Check context ordering**: Are the most relevant documents first in the context?
3. **Look for context overflow**: Is the context exceeding the model's context window?
4. **Test with perfect context**: Manually provide the correct context and see if the model generates correctly. This isolates retrieval vs. generation issues.
5. **Review system prompt**: Does it instruct the model to only use the provided context?
6. **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.

1. **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.
2. **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-large` at 3072 dims, querying with `text-embedding-3-small` at 1536 dims) produces nonsense scores that look numerically plausible. Print both configs side by side.
3. **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 integer `2024`).
4. **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).
5. **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)

1. **Profile each stage**: Measure time for embedding, retrieval, and generation separately.
2. **Check batch sizes**: Are embeddings computed one at a time instead of in batches?
3. **Inspect vector DB performance**: Is the index optimized? How many vectors are stored?
4. **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

© TakaGoto · MIT · TakaGoto/rag-learning-academy

Similar skills

All skills for AI and ML →

From the same set5

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor