Skip to content

7. Find where it fails: the weakness map

Goal: go from "the score is 67" to "the Paris questions fail because their document never reached the index". Before you start: install rag-titan 0.16.0 or later and extract the starter kit (recipe 1); this recipe uses the kit's weakness-map/ folder. No model, API key or GPU is needed.

An overall score says how good the answers are. It does not say which questions fail or where in the pipeline they are lost. The analysis answers three questions, with no model call:

Question The part that answers it
How sure can I be of this score? an error range beside every headline number
At which stage are questions lost? the funnel: chunking, retrieval, reranking, context, generation
Which kind of question fails, and why? slices by question type or topic, and a failure code for every failed question

What you will see

Finding where a RAG fails: score, funnel and weakest areas

The terminal replays the real output of this recipe's commands.

Teaching data with a planted fault

make_data.py is a tiny stand-in for your RAG. It answers 222 golden questions about six office policies, and one policy file (Paris) never reaches its search index, like a failed upload. The scores are computed by the real rag-titan evaluator. Nothing here is a language model.

1. Make the data

cd rag-titan-cookbook/weakness-map
python make_data.py

It writes golden.json (the questions) and the logs of three runs. Look at one golden question. Next to the usual labels it has two metadata keys, task_type and topic. They cost nothing to add and they are what lets a report be cut into slices:

{
  "id": "f3-0",
  "question": "What is the vacation days for Paris office?",
  "expected_answer": "The vacation days for Paris office is 15 days.",
  "required_facts": ["15 days"],
  "expected_evidence": ["The vacation days for Paris office is 15 days."],
  "answerable": true,
  "task_type": "fact",
  "topic": "Paris office",
  "validated": true
}

The set has 180 single-fact questions, 30 questions that compare two offices (multi_hop) and 12 that the documents cannot answer (unanswerable). The other keys you can use are in Build a golden set.

2. Score it, with the golden file

rag-titan evaluate --input data.json --golden golden.json --output report.json --k 5

--golden is new in 0.16.0. With --input it gives the question metadata for the slices. You get the usual summary first:

Reports saved: report.json and report.md
Overall score: 67.0/100 (Average)
Status: Action Required | Measurement coverage: 68%
First failing stage: augmentation
...

and then the analysis:

Overall 67 / 100 (Average)  [64 to 70]      222 questions
Task success 0.80 [0.74 to 0.84]  (177 of 222)

Where answers are lost (210 answerable questions)
  chunking 1.00 -> retrieval 0.79 -> reranking 1.00 -> context 1.00 -> generation 1.00
  most lost at retrieval: 45 of 45 lost questions; a perfect retrieval would lift
      success to 1.00

Weakest areas
  1. topic=Paris office: 30 of 40 fail as RETRIEVAL_MISS (also accounts for the
      RETRIEVAL_MISS failures of task_type=fact)
       try: check that the documents of this topic were parsed and indexed: search finds
           nothing of it; then try keyword search (rag-titan index --files <the
           documents of this topic>, then retriever="hybrid")
  2. task_type=multi_hop: 10 of 30 fail as RETRIEVAL_PARTIAL (also accounts for the
      RETRIEVAL_PARTIAL failures of topic=Paris office)
       try: search more than once, or search several rewrites of the question
           (rag_type="iterative" or "rag_fusion")

Right or wrong was decided by word matching for 210 of 222 questions (no judge model).

3. Read it in three steps

The headline has a range. Overall 67 / 100 [64 to 70]: with these 222 questions the true score could be anywhere from 64 to 70. Task success 0.80 [0.74 to 0.84] is the share of questions answered right, with its range. If the ranges of two scores do not overlap, the difference is real. If they do, use the baseline comparison: it compares the same questions one by one, which is sharper.

The funnel says where answers are lost. Each rate is the share of questions that a stage kept, among those that reached it. Here every one of the 45 lost questions was lost at retrieval: the right chunk was not in the top 5. Chunking, reranking, context and generation lost nothing. The line "a perfect retrieval would lift success to 1.00" is the success rate you would get if only that stage were fixed.

The weakest areas say which questions. A cell is a slice of the questions together with one failure code. It is listed only when its failure rate is clearly higher than the rest of the questions (z above 2.6), it has at least 5 failures, and both the slice and the rest have at least 30 questions. The list is ordered by how many failures it has in excess of the rest.

  • topic=Paris office: 30 of 40 fail as RETRIEVAL_MISS: three quarters of the Paris questions find nothing. A topic that search cannot find at all is first a question of indexing, and that is the advice you get.
  • task_type=multi_hop: 10 of 30 fail as RETRIEVAL_PARTIAL: a comparison needs two pieces of evidence, search found one. That is the sign of a pipeline that searches only once. It suggests rag_type="iterative" or "rag_fusion".
  • task_type=fact is not listed, although 35 of its 180 questions fail. Every Paris question is a fact question, so 30 of those 35 failures are the Paris ones. When most failures of a broad slice are inside a more concentrated one, the map shows the concentrated one and says so: "also accounts for the RETRIEVAL_MISS failures of task_type=fact".

Two different 'first failing stage' answers

The older line First failing stage: augmentation compares averages with fixed minimums. The funnel counts questions. They can disagree, as they do here. Use the funnel to see where questions are lost, and the older line as a rough hint when you have no per-question labels.

4. Open the report

report.md has the same numbers with more room. These are real excerpts:

The funnel as a table:

Stage Reached Kept Lost Rate Success if perfect
chunking 210 210 0 1.00 0.79
retrieval 210 165 45 0.79 1.00
reranking 165 165 0 1.00 0.79
context 165 165 0 1.00 0.79
generation 165 165 0 1.00 0.79

The weakest areas, with what to try:

Slice Failure Count z Excess What to try
topic=Paris office (also accounts for the RETRIEVAL_MISS failures of task_type=fact) RETRIEVAL_MISS 30 of 40 11.4 28.9 check that the documents of this topic were parsed and indexed: search finds nothing of it; then try keyword search (rag-titan index --files <the documents of this topic>, then retriever="hybrid")
task_type=multi_hop (also accounts for the RETRIEVAL_PARTIAL failures of topic=Paris office) RETRIEVAL_PARTIAL 10 of 30 8.2 10.0 search more than once, or search several rewrites of the question (rag_type="iterative" or "rag_fusion")

...

Every failed question grouped by cause, with what was asked, expected and answered, and the evidence it should have found:

RETRIEVAL_MISS (35)

  • f2-4: I need to find out the notice period for Berlin office.
  • expected: The notice period for Berlin office is 30 weeks.
  • answered: I could not find that in the documents.
  • evidence: The notice period for Berlin office is 30 weeks.
  • ...

And a slice table for each kind of metadata. This is the one that gives the Paris problem away:

By topic

Value Questions Pass rate Range
Berlin office 42 0.93 [0.81 to 0.98]
Madrid office 38 0.97 [0.87 to 1.00]
Oslo office 34 0.97 [0.85 to 0.99]
Paris office 40 0.05 [0.01 to 0.17]
Rome office 36 0.97 [0.86 to 1.00]
Vienna office 32 0.97 [0.84 to 0.99]

A slice with fewer than 30 questions is shown but marked not ranked: with so few questions its range is about ±18 points, enough to see a broken slice, not enough to rank it.

5. Act on it, and run again

The Paris policy was not indexed. Index it (here the script does it for you: data-fixed.json) and score again, with the first run as a baseline:

rag-titan evaluate --input data-fixed.json --golden golden.json --output fixed.json --k 5 --baseline report.json
Overall 77 / 100 (Good)  [75 to 78]      222 questions
Task success 0.97 [0.94 to 0.99]  (216 of 222)

Where answers are lost (210 answerable questions)
  chunking 1.00 -> retrieval 0.97 -> reranking 1.00 -> context 1.00 -> generation 1.00
  most lost at retrieval: 6 of 6 lost questions; a perfect retrieval would lift success
      to 1.00

Most common failures (no slice stands out)
  RETRIEVAL_MISS: 6
    try: add keyword search, rewrite the question, or return more results
        (retriever="hybrid", rag_type="rag_fusion", or a larger top_k)

Right or wrong was decided by word matching for 210 of 222 questions (no judge model).

Task success went from 0.80 to 0.97, and the two ranges do not overlap. No cell stands out any more. Six questions still miss: the same notice-period question in the same wording ("I need to find out ..."), once for each office. No topic or question type explains them, so the map lists them without a pattern. The pattern is in the wording, which this golden set does not tag. Regressions against the baseline: none because nothing got worse.

What the failure codes mean

Every failed question gets one code, from the first stage that lost its evidence.

Code The question was lost because ... First thing to try
CHUNKING_SPLIT a chunk boundary cut the evidence bigger chunks or overlap, a structure-aware chunker, parent_child
EMBEDDING_MISS even an exact vector search does not find it another embedding model
RETRIEVAL_MISS it is findable, but the retriever did not return it hybrid search, a rewritten question, a larger top_k
RETRIEVAL_PARTIAL some of the several pieces of evidence were found, not all search again: iterative or rag_fusion
RERANK_DROP it was retrieved, then pushed out by the reranker another reranker, or none
CONTEXT_DROP it was reranked, but not packed into the context a larger top_n
OVER_REFUSAL the evidence was there and the system declined a less cautious prompt
HALLUCINATION the answer says something the context does not support a stricter grounding prompt
INCOMPLETE some required facts are in the answer, not all a prompt that lists the parts
WRONG_ANSWER the evidence was there and the answer is wrong another model
FALSE_ANSWER a question the documents cannot answer was answered corrective, a stricter decline instruction

The analysis reference says exactly how each is decided.

How far to trust it

  • Right or wrong is word matching unless you give task_success labels: the required facts must be in the answer, or the answer must overlap the reference. A correct answer in other words can be called wrong. The report says how many questions were decided this way.
  • A cell points, it does not prove. It says where failures concentrate. The advice is where to look first.
  • Stages with no data are skipped, never guessed. If your logs have no reranked_ids, reranking cannot be blamed, and the report lists the stages it could not check.
  • The labels are only as good as the golden set. The report says how many golden questions a person checked.

Use it on your own RAG

rag-titan evaluate --input my-data.json --golden golden.json --output report.json
rag-titan evaluate --files docs/*.md --golden golden.json --rag-type simple iterative

Indexes your documents, asks every golden question and scores every stage. Several --rag-type, --chunker or --retriever values give a report each and a comparison.

from rag_titan.evaluation import RAGEvaluator, analyze

report = RAGEvaluator(k=5).evaluate(**data)
report["analysis"] = analyze(report, data, golden="golden.json", k=5)
print(report["analysis"]["summary"])

Next: Catch regressions, or add task_type and topic to your own golden set.