Analysis reference
The analysis (0.16.0) reads a finished report and the questions behind it and says more than the averages can: how sure each number is, which questions failed, at which stage they were lost, and which kind of question fails most. It never changes a score and it calls no model. For a walk-through on real output, start with Find where it fails.
Get it
rag-titan evaluate --input data.json --golden golden.json --output report.json
rag-titan evaluate --files docs/*.md --golden golden.json
--golden with --input adds the analysis to your own logged data. With --files it runs
your pipeline on the golden questions, scores every stage (embeddings included), and
analyses the result. See the command line.
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"])
data is the input of RAGEvaluator.evaluate(). golden supplies the question
metadata for the slices and may be left out.
The Markdown report gets a section for each part when the report has an analysis; a report
without one is written exactly as before.
Key of analysis |
What it holds |
|---|---|
summary |
the text shown in the terminal |
questions |
how many questions there are, answerable, unanswerable, with a known result, failed |
task_success |
the share of questions that passed, with its error range |
basis |
how many questions were judged by each rule of right or wrong |
intervals |
an error range for every per-question metric and for the scorecard |
codes, failures |
the failure code of every failed question, with the question, expected answer, answer and evidence |
funnel |
where the answerable questions stop |
unanswerable |
how many questions the documents cannot answer were answered anyway |
slices |
the pass rate of each slice |
weakness_map |
the flagged cells, largest excess first, with what to try |
coarser |
the stages the pipeline gave no data for |
labels |
how many golden questions a person checked |
outcomes |
every question as passed, failed or unknown: what comparing two reports pairs |
How a question is followed
Each answerable question has gold evidence: the pieces of the documents the answer needs. They are turned into groups, one group for each piece, holding every chunk that contains it. A stage keeps a group when one of its chunks is in that stage's list. The groups come from the first of these a question has:
| Gold label | One group for each |
|---|---|
relevance (graded chunk ids) |
chunk with the best grade |
expected_evidence (quotes or spans) |
piece of evidence: the chunks that overlap it |
required_evidence_ids (file or page labels) |
label: the chunks of that file or page |
expected_chunk_ids |
listed chunk id |
The lists checked are retrieved_ids (the first k only: the k of the evaluation),
reranked_ids and context_ids. A stage with no data is skipped and listed under
coarser; it is never guessed.
Right or wrong
Without a judge model, whether an answer is right is decided by the first of these that applies:
| Rule | Decides |
|---|---|
task_success label on the question |
as labelled |
the question cannot be answered (answerable: false) |
right when the system declined (abstained) |
required_facts |
right when every fact is in the answer |
expected_answer |
right when the word overlap (answer F1) is at least 0.5 |
The last two are word matching: a correct answer in other words can be called wrong. The
analysis counts how many questions each rule decided (basis) and says so in the summary.
Failure codes
A question gets a code only when it failed: its answer is wrong, or, when no answer is
known, its evidence was lost. A question answered right even though its evidence was lost has
no code; the funnel counts it as correct_anyway, which usually means incomplete labels.
The code is the first of these that applies:
| Order | Code | Decided by |
|---|---|---|
| 0 | FALSE_ANSWER |
the question cannot be answered, and the system answered |
| 1 | CHUNKING_SPLIT |
a gold span does not lie whole inside one chunk (needs quotes or spans, the documents and chunk offsets) |
| 2 | EMBEDDING_MISS |
no group is in the top k, and an exact cosine search over the vectors does not find one either (needs embeddings) |
| 2 | RETRIEVAL_MISS |
no group is in the top k (and an exact search would find one, or no vectors were given) |
| 2 | RETRIEVAL_PARTIAL |
some groups are in the top k, not all |
| 3 | RERANK_DROP |
a group is missing from reranked_ids |
| 4 | CONTEXT_DROP |
a group is missing from context_ids |
| 5 | OVER_REFUSAL |
the evidence reached the model and it declined (abstained) |
| 5 | HALLUCINATION |
a verified claim is unsupported, or the answer has a number the context does not |
| 5 | INCOMPLETE |
some, not all, of the required facts are in the answer |
| 5 | WRONG_ANSWER |
none of the above: the evidence was there and the answer is wrong |
Each code comes with a first thing to try; see the table in the recipe.
The funnel
For the answerable questions, a row for each stage with data: how many reached it, how many
it kept, the rate (kept over reached), and if_perfect:
with \(r_j\) the rate of stage \(j\). A question lost at one stage does not reach the next. The last row is generation: of the questions whose evidence reached the model, how many were right. When every stage has data and every answer is known, the rates multiply to the share of answerable questions answered right.
Slices
A slice groups the questions that share a value of a golden metadata key. The pass rate of a slice has a Wilson range. A slice of fewer than 30 questions is shown but not ranked, and never flagged: with so few its range is about ±18 points.
| Key | Meaning | Allowed values |
|---|---|---|
task_type |
the kind of question | any text: fact, numeric, multi_hop, unanswerable, ... |
difficulty |
how hard it is | easy, medium, hard |
difficulty_score |
the same as a number | 0 to 1 |
topic |
what it is about | any text |
hops |
how many passages the answer needs | a whole number from 1 |
style |
how it is worded | any text: natural, paraphrase, keyword, noisy |
weight, smoke, validation |
reserved for later releases | a number above 0, true or false, a dict |
Every key is optional, and a wrong value is refused with a message naming the question. The
slice answerable (can the documents answer it?) always exists.
Error ranges
All ranges are 95% by default, and repeat exactly for the same seed.
A pass rate (task success, a slice): the Wilson score interval for \(s\) passes out of \(n\) questions, with \(z\) = 1.96:
with \(\hat p = s/n\). It stays between 0 and 1 and is sensible for small \(n\).
Any average of per-question values (recall, answer F1): the questions are drawn again with replacement 1000 times; the range holds the middle 95% of the averages.
The scorecard (overall and each stage): the same draw is applied to every stage, so a
question that is hard for one stage stays hard for the next. The averaged metrics are rebuilt
from the per-question rows, and the scorecard is scored again for each draw. Metrics that are
not averages of questions (latency percentiles, chunking and embedding numbers) keep their
measured value, so the range shows only the effect of which questions you asked. A stage
made only of such metrics has no range. If the report was scored with custom weights, pass the
same scorer to analyze(); otherwise the scorecard range is skipped, with a note.
Any RAG: evaluate_any
evaluate_any(rag, golden, files=... or documents=...) (0.16.1) runs a RAG on the golden
questions and builds the evaluation input for you. A rag-titan pipeline goes through
collect_dataset(), so its report is exactly that of evaluate_stages(). Any other system
answers through a function or a RagAdapter; then:
- Returned text is placed in the documents: in its
doc_id, or else in any document. Spacing and line breaks may differ; the words may not. A passage without an id gets one from its words, so the same passage has the same id wherever it comes back. Text that is in no document is listed inreport["warnings"]and counts as not gold. - Stand-in gold chunks. The system shows only the chunks it returned. When no returned
chunk holds a piece of gold evidence, the evidence itself becomes a gold chunk
(
gold:<doc>:<start>-<end>). Without it a missed question would have no gold chunk and its recall would be "not measured" instead of 0. With it, retrieval scores match those of a pipeline whose every chunk is known. - Chunking is scored only when the adapter's
chunks(doc_ids)gives the system's chunks of the documents that hold gold evidence. It is asked once, for those documents only, and the chunking stage is scored on them alone. Returned passages are matched to the system's own ids by their words. Withoutchunks()the chunking stage and theCHUNKING_SPLITcheck are skipped and listed as not checked. - Documents from a function (
documents=fetch) are fetched only when they hold gold evidence or were named in a returneddoc_id; evidence must then name its document. - A question where the system raises is recorded in
report["errors"]and counted as failed;workers=asks several questions at once, and the results keep the golden order.
evaluate_logs(runs, golden, ...) and rag-titan evaluate --runs do the same from a log: each
run is matched to its golden question by id or by question text, and keeps only the timings
it recorded.
Comparing two runs
Both runs answered the same questions, so they are compared question by question.
Paired bootstrap (paired_bootstrap(a, b)): the per-question differences \(b_i - a_i\) are
drawn again; the verdict is "b better" or "a better" only if the whole range of the mean
difference is on one side of 0, otherwise "within noise".
McNemar (mcnemar(a, b)) for pass or fail: with \(b\) questions only A passed and \(c\)
questions only B passed,
and the difference is significant at 5% when the p-value is below 0.05. The p-value is the exact two-sided binomial one up to 1000 disagreeing questions, and the chi-square one above. For small counts the plain \(\chi^2 > 3.84\) rule says "real difference" too easily: 17 against 7 gives \(p = 0.041\) by chi-square but 0.064 exactly. Example: 384 questions, A right on 300 and B on 280, \(b = 32\), \(c = 12\): \(\chi^2 = 9.09\), exact \(p = 0.0037\); the two separate ranges overlap, yet the difference is real.
Comparing two reports
compare_reports(a, b, names=[...]) and rag-titan compare a.json b.json put two reports of
the same golden questions side by side:
| Row | How it is judged |
|---|---|
| task success | paired bootstrap on the questions whose result is known in both, and McNemar |
| a metric that is the average of per-question values (recall, MRR, answer F1, ...) | paired bootstrap on the shared questions, in the metric's own direction (lower context noise is better) |
| latency, cost | no per-question values: only the direction (slower, faster) |
| the overall score | both values, no verdict |
A verdict names the better setup only when the whole range of the difference is on one side
of zero; otherwise it is within noise. Below 20 shared questions there is no verdict. Slices
ranked (30 or more questions) in both reports are listed with their pass-rate change; that
change is not tested for noise.
Regressions beyond noise
ReportManager().compare_with_baseline(report, baseline) and the --baseline option of the
command line list a metric as a regression only if it is worse by more than the tolerance
(0.02 for scores) and a paired bootstrap on the shared questions puts the whole range of the
change on the worse side. It applies when both reports keep the per-question values behind the
metric, the metric is their average, and at least 20 questions are in both. Otherwise the fixed
tolerance decides, as find_regressions() always does. Changes beyond the tolerance but within
the noise are returned as within_noise and shown in the report, but not counted.
The weakness map
Every failure code is counted in every slice and compared with the other questions. For a slice of \(n_1\) questions with failure rate \(p_1\), the other questions \(n_2\) with \(p_2\), and \(p\) the rate of all:
A cell is flagged when:
- \(z > 2.6\) (about the 0.5% level: strict, because many cells are tested at once);
- it has at least 5 failures, because with fewer the \(z\) score is noise;
- the slice and the rest each have at least 30 questions.
Cells are listed by excess: the failures beyond what the rest of the questions would predict, so the largest real problem is first. Cells are per failure code.
Overlapping slices. Every Paris question is also a fact question. If at least 80% of
the failures of a cell are also failures of a more concentrated cell with the same code, the
broad cell only repeats the specific one: it is left out and named in the specific cell's
also_explains.
Limits
- Right or wrong is word matching unless
task_successis given. A judge model comes in a later release. - A cell points to where failures concentrate; it does not prove the cause.
- Cells are per failure code. The same total can be spread over several codes and none flagged.
- Only metrics that are averages of questions have a range that depends on the questions.
- The analysis is only as good as the golden set: it reports how many questions a person checked.
Python functions
| Function | Does |
|---|---|
analyze(report, data, golden, k) |
the whole analysis (above) |
attribute_failures(report, data, k) |
one record with the failure code for each question |
build_funnel(records) |
the funnel of those records |
wilson_interval(successes, n) |
range of a pass rate |
bootstrap_interval(values) |
range of an average |
paired_bootstrap(a, b) |
the difference of two runs, with its range and verdict |
mcnemar(a, b) |
pass or fail comparison of two runs |
ReportManager().compare_with_baseline(report, baseline) |
regressions beyond noise |
compare_reports(a, b, names) |
two reports side by side, with verdicts |
evaluate_any(rag, golden, files) |
run any RAG on the golden set and analyse it |
evaluate_logs(runs, golden, files), runs_from_jsonl(path, rename) |
the same from logs |
FunctionRag(function, chunks=None), RagAdapter |
connect a RAG system |
The analysis functions are in rag_titan.evaluation.analysis; the adapters, evaluate_logs
and runs_from_jsonl in rag_titan.evaluation.adapters. analyze, evaluate_any,
FunctionRag and RagAdapter are also in rag_titan.evaluation.