Using evaluation frameworks critically: the same metric, two ways to compute it

Study time
≈ 2 h (estimate)
Needs
L2-M06-L04
Updated
2026-11-04

Progress is saved in this browser only. No account, nothing is sent to a server.

Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Module: L2-M06 · Duration: ~120 min (estimate, including the independent exercise) · Previous: L04 · Next: L2-M07-L01 (module Model Comparison and Evaluation Pipelines, not yet written)

1. Introduction

RAG evaluation frameworks such as Ragas, DeepEval, TruLens or promptfoo come with metrics that carry familiar names: faithfulness, context precision, answer relevancy. Using them saves effort, but a number only means something when you know how it is computed, what input it needs, who grades and whether it can be repeated. This lesson teaches reading a framework's metric the way you would read a metric function of your own: rewrite it in two ways, put them side by side and explain every place they differ.

The "choosing a tool" part is written from documentation read on 2026-11-04, not from memory, and does not recommend any vendor: the lesson gives sourced criteria (§4.2) and ways to check for yourself (§5, §6.2). The lab runs no framework and calls no model; the "judge" and the "model-based metric" here are seeded simulations. The output of the lesson: the same metric computed two ways with a table explaining the differences, and a metric description (descriptor) with a lint for one documentation page.

2. Learning objectives

  1. Compute the same metric (context precision, faithfulness) in two ways and list the cases that differ. Practice: §8.2 parts A, B, §9 (TODO 1, 2).
  2. Explain each difference with one cause (rank order, threshold, synonyms, noise). Practice: §5.1, §5.2, §8.2 part B.
  3. Check the repeatability of a model-based metric (simulated) by running it several times. Practice: §8.2 part C (change flip and the number of runs of SimulatedLLMMetric).
  4. Write a descriptor for a metric from a documentation page and run the lint. Practice: §9 (TODO 3).
  5. State what the lesson does not allow you to conclude about any tool. Practice: §8.4 (read test_shipped_tool_notes_and_what_the_lint_says_about_them), §6.1.

3. Prerequisites and tools

  • L2-M06-L02 and L03 (the original metrics and checks), L2-M04-L05 (a versioned judge, rerunning), L1-M06 (repeating a case). The code lab code-labs/l2-m06.
  • Separating the meanings. A "metric" here is a function that computes a score; a metric function (deterministic grader, L2-M03-L01) is the deterministic kind written in code; a judge is a model-based grader (L2-M04). "Context" is the retrieved context (L01).

4. Concepts

4.1 Same name, different computation

The Ragas documentation defines context precision as the retriever's ability to rank relevant chunks above irrelevant ones: the mean of precision@k at each rank k that holds a relevant chunk, multiplied by the relevance indicator v_k (0 or 1), divided by the number of relevant chunks in the top K [R1]. The same page lists four variants: comparing each chunk with a reference answer using an LLM; comparing with the generated answer using an LLM (when there is no reference); a method that uses no LLM (such as string distance); and comparing by chunk id against reference ids [R1]. The page announces that the older metrics will stop being used in version 0.4 and be removed in 1.0 [R1], so the version needs to be recorded.

Faithfulness also goes by several names: Ragas [R3], DeepEval ("measures if the generated answer is factually consistent with the provided context") [R5], TruLens (called groundedness: split the answer into claims, check each claim) [R6] and promptfoo (context-faithfulness, checks whether the output is supported by the context) [R7]. The idea is the same; the formula, the grading model and the threshold can differ. A name does not determine the computation.

4.2 The criteria to ask before trusting a number

For each metric, answer seven questions: (1) is the formula on the documentation page; (2) what input does it need, is a reference answer required; (3) who grades: an LLM, an embedding or a rule; (4) does a rerun give the same number; (5) is there a path that needs no external LLM or that uses a local model; (6) what are the default values (such as the threshold); (7) what does it return when an input is missing or there is no correct chunk. The table records what the page that was read says (data/tool_notes.json); "not stated" means that page does not say, not that the tool lacks it:

Metric (tool) Uses an LLM Needs a reference Formula on the page Non-LLM or local path
ContextPrecision, reference-based (Ragas) [R1] yes yes yes yes (a non-LLM variant, by id)
IDBasedContextPrecision (Ragas) [R1] no yes (reference ids) yes yes
ContextRecall (Ragas) [R2] yes (default version) yes yes yes (NonLLMContextRecall, IDBasedContextRecall)
Faithfulness (Ragas) [R3] yes (the example builds an LLM) no yes partly: a local HHEM for the claim-checking step [R3]
AnswerRelevancy (Ragas) [R4] yes, and an embedding no yes not stated
Faithfulness (DeepEval) [R5] yes by default; system_one mode makes no LLM call not stated not seen yes: a local judge such as Ollama; system_one needs a TypeSafe AI API key and the page does not say where Jev runs
Groundedness (TruLens) [R6] not stated not stated not seen not stated
context-faithfulness (promptfoo) [R7] yes no not seen not stated

In addition: promptfoo records a default threshold of 0.5 [R7]; DeepEval says most built-in metrics use LLM-as-a-judge, lets you use any LLM as the judge, and has a system_one mode, run by the Jev model, that runs all metrics without calling an LLM (it needs a TypeSafe AI API key) [R5]; Ragas ContextRecall always needs a reference [R2].

4.3 What the table (as of the reading date) allows you to conclude

The table does not allow you to say which tool is best: it does not measure accuracy, and says nothing about Vietnamese, price or license. It allows you to rule out by constraint: if you must not call an external API and have no local model, a metric that has only an external LLM path does not meet that constraint. The procedure the lab proposes: (a) list the project's constraints; (b) read the current version of the documentation for each metric and fill in the descriptor; (c) run a side-by-side check as in §5 on your own labelled set; (d) record the version, the judge configuration and the results. The documentation may already differ from the table above.

5. Technical deep dive

5.1 Context precision, two ways

context_precision_rank_aware implements the formula as Ragas describes it [R1] on a 0/1 indicator by rank; context_precision_plain takes only (number of relevant chunks) / (number of chunks returned), which is the idea of the id-based variant, ignoring order; it differs from the precision@k of L02 in the denominator: the number of chunks returned, not k. With [1, 0, 1] the first way gives (1 + 2/3) / 2 = 5/6, the second 2/3; with [1, 1, 0] it is 1 and 2/3: same chunks, two orders, the plain way does not distinguish them. With [0, 0] the first way is 0/0, and the lab returns None; the second is 0. The page that was read does not say what the tool returns in this case: check on the real tool.

On the 22 questions that have an answer, with the top 3 of BM25 (simulated, duplicates merged), the two ways are equal on 5 questions and differ on 17; for example Q01 has the indicator [1, 1, 0]: 1 versus 2/3. The difference has two causes mixed together, and neither way is wrong: the rank order, and the denominator (the rank-aware way divides by the number of relevant chunks, the plain way by the number of chunks returned). Because of that denominator, the rank-aware way ignores noise at the end: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0] gives 1, whereas the plain way gives 1/10; the Ragas page says an irrelevant chunk at the second position does not change the value, while at the first position it lowers it [R1]. So a retriever that pads the list with noise chunks is not penalized by this metric; read it together with precision@k.

5.2 Faithfulness, two ways

faithfulness_checker is the share of claims supported by claim_supported (threshold 3/4). faithfulness_sim_judge uses the simulated judge (L03: threshold 1/2, a few bridge words, random errors of 1/10 by hash). On the 16 labelled answers, the two ways are equal on 12 and differ on 4. Explaining each case (separating out the noise by running the judge with an error rate of 0):

  • A07 (0 versus 1): a bridge word lets the judge accept a paraphrase that the rule rejects: bridge word. Human label: supported.
  • A05 (0.5 versus 1): "Một tấn nặng hơn một tạ" (a tonne is heavier than a quintal) passes the judge's threshold of 1/2 but not 3/4: threshold. Human label: not supported, so the judge is wrong.
  • A09 (1 versus 0.5) and A12 (0.5 versus 1): with an error rate of 0 the two ways coincide, so the difference comes from the judge's seeded noise.

Which way is "more right" can only be settled with human labels (L03): compared with the rule, the judge fixes one false reject (A07), lets two more wrong claims through (A05, A12) and causes one new false reject (A09).

5.3 Repeatability, versions and two ways to measure recall

SimulatedLLMMetric simulates a metric that asks a model: the same (claim, passage) pair but each call may give a different result. Running 8 times: the rule gives 8/8 True; the simulated metric gives True, False, True, True, True, True, False, True. A model-based metric must be run several times and reported as a mean with an interval, along with the version and the judge configuration (L2-M04-L05). The 1/5 error rate was set by the lab; the variability of a real model must be measured, and the sources that were read state no figure.

Recall also has two ways: by chunk id (context_recall_by_ids) and by the reference's claims, which is the idea of Ragas ContextRecall (the number of the reference's claims supported by the context divided by the total number of claims) [R2]; the lab replaces the LLM with claim_supported. context_recall_by_ids is exactly the recall@k of L02 and has the same idea as IDBasedContextRecall on the Ragas page (the number of reference ids found divided by the total number of reference ids) [R2], and that page also has NonLLMContextRecall (string comparison, no LLM). Example: only D06-c2 is retrieved, and the set of correct chunks is D06-c1 and D06-c2: by id it is 1/2, by claims it is 1, because D06-c2 already contains both claims of the reference even though D06-c1 was not retrieved. The two numbers differ because they measure two things: which chunk was retrieved, and what content is in the context.

6. The QA perspective

6.1 What this lesson does not prove

  • The lab runs no framework. Every description of a tool comes from documentation pages read on 2026-11-04 through the automatic summary of the page-reading tool, not checked word by word; the documentation may have changed.
  • "Not stated" and "not seen" speak only about the page that was read; the tool may state it on another page.
  • It does not compare accuracy, Vietnamese support or price.
  • The table reflects only the reading date: the Ragas pages show an update date of day 9, month 12, 2025 and announce that older metrics will be discontinued.
  • The simulated judge and metric do not represent a real model; every error rate was set by the lab.
  • The Ragas paper describes a three-dimensional framework that needs no human labels [R8] (abstract-only); that does not say its metrics are accurate enough for your product.

6.2 Checklist before accepting a framework's number

Run the seven questions of §4.2 and record them in the descriptor (lint_descriptor catches a missing field, a source that is not https, a date in the wrong format, a formula that is not on the page); run the metric on your own labelled set and build a confusion table (L03); rerun it several times; pin the version; try empty input and a case with no correct chunk; record what data is sent to the grading model. A judge only flags; a person decides.

7. Real-world scenarios

Scenario 1 (fictional): "Two tools, two faithfulness scores". HocVui ran two tools on the same 16 answers and saw two different scores. They listed the cases that differ and assigned a cause (threshold, bridge word, noise), then reported both numbers together with human labels, instead of choosing the higher number.

Scenario 2 (fictional): "A score jump after a version upgrade". A context precision metric changed how it handles a case with no correct chunk and the mean rose though the system had not changed. The team pinned the version, added that case to the test set and recorded the expected behavior (None or 0).

8. Hands-on tutorial

8.1 Setup

cd academy-content/code-labs/l2-m06
python3 -m venv .venv && source .venv/bin/activate     # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest            # 80 passed

8.2 Run the demo

python -m lab.demo l05

Output (copied from a real run on Python 3.14.6 and 3.12.14, 2026-11-04; the two versions give identical output). The judge and the model-based metric are simulated:

A. context precision, two ways (1 = relevant at that rank)
   [1, 0, 1] rank-aware 5/6  plain 2/3
   [1, 1, 0] rank-aware 1  plain 2/3
   [0, 1] rank-aware 1/2  plain 1/2
   [0, 0] rank-aware None  plain 0
B. faithfulness, rule checker vs simulated judge (simulated) : equal 12 of 16  differ: [('A05', '0.500', '1.000'), ('A07', '0.000', '1.000'), ('A09', '1.000', '0.500'), ('A12', '0.500', '1.000')]
C. same call, 8 runs: rule 8 of 8 True; simulated LLM metric [True, False, True, True, True, True, False, True]
D. tool notes: 8 descriptors; lint problems: {'DeepEval Faithfulness': ['no formula on the page read: the number cannot be reproduced by hand from that page'], 'TruLens groundedness': ['no formula on the page read: the number cannot be reproduced by hand from that page'], 'promptfoo context-faithfulness': ['no formula on the page read: the number cannot be reproduced by hand from that page']}

Reading the output: A is four indicators and the two ways of computing context precision; B is the faithfulness of the two ways over 16 answers (differing on four); C is eight runs of the rule and of the simulated metric; D is the eight descriptors in data/tool_notes.json, three of which the lint flags for lacking a formula on the page that was read.

8.3 Try it yourself

Save this as try_l05.py in the lab's root folder (next to lab/), run python try_l05.py, then delete the file:

from fractions import Fraction as F
from lab import compare as CP, corpus as C, data, grade as GR, metrics as M, retrieve as R

chunks = C.chunk_sentences(data.load_json("corpus.json"))
by = {c["id"]: c["text"] for c in chunks}
queries = data.load_jsonl("queries.jsonl")
groups = C.duplicate_groups(chunks)
bm = R.BM25(chunks)
same, differ = 0, []
for q in queries:
    gains = {groups.get(c, c): g for c, g in M.qrels_for(q, chunks).items()}
    rel = {c for c, g in gains.items() if g > 0}
    if not rel:
        continue
    ids = M.canonical(bm.search(q["text"], 3), groups)
    v = CP.flags(ids, rel, 3)
    a, p = CP.context_precision_rank_aware(v), CP.context_precision_plain(v)
    if a == p:
        same += 1
    else:
        differ.append((q["id"], v, str(a), str(p)))
print(same, len(differ)); print(differ[:3])
ctx = {"D06-c2": by["D06-c2"]}
print(CP.context_recall_by_ids(["D06-c2"], ["D06-c1", "D06-c2"]), GR.context_recall_claims("Một tạ bằng 100 ki-lô-gam. Một tấn bằng 10 tạ.", ctx))
print(CP.compare_metric(CP.faithfulness_checker, CP.faithfulness_checker, {"a": ("Một giờ có 60 phút.", {"D05-c1": by["D05-c1"]})}))

Output (Python 3.14.6 and 3.12.14 identical):

5 17
[('Q01', [1, 1, 0], '1', '2/3'), ('Q02', [1, 1, 0], '1', '2/3'), ('Q03', [1, 0], '1', '1/2')]
1/2 1
{'n': 1, 'equal': 1, 'differ': [], 'max_abs_diff': Fraction(0, 1)}

Reading: line 1: 5 questions equal, 17 different. Line 2: the first three cases (id, indicator, rank-aware way, plain way). Line 3: recall by id 1/2, by claims 1. Line 4: a metric compared with itself shows no difference. The lab does not check a real framework for any number.

8.4 Run the lesson's tests

python -m pytest tests/test_l05_frameworks.py -v

Result: 11 passed. Read test_context_precision_two_ways_by_hand, test_rule_checker_and_simulated_judge_differ_on_named_items and test_descriptor_lint_catches_each_problem. The tests run on in-memory values and the lab's data; no test calls a framework or a model.

8.5 Troubleshooting

Symptom Cause Fix
lint_descriptor reports missing ... The descriptor lacks a required field Fill in all the fields in compare.NEEDED
None when comparing two metrics One side is undefined (for example no correct chunk) A None on one side counts as a difference; handle it separately

9. Independent exercise

Problem: Compute context precision two ways on eight indicator logs, and write a descriptor for a documentation page from notes that were taken.

Requirements: complete exercises/test_l05_frameworks.py:

  1. TODO 1: DIFFER: the set of question ids for which both ways are defined and differ.
  2. TODO 2: ONLY_PLAIN: the set of ids for which the plain way has a value but the rank-aware way is None.
  3. TODO 3: DESCRIPTOR: a dict that passes lint_descriptor for the page in ex_page_notes.json; the fields come from the notes; where the notes do not say, the value is None (the rule is in ex_page_notes.json).

Test data: exercises/ex_flags.json (8 questions), exercises/ex_page_notes.json (notes on a documentation page, read on 2026-11-04).

Deliverable: the three variables above, in exercises/test_l05_frameworks.py itself.

Acceptance criteria: python -m pytest exercises/test_l05_frameworks.py passes (3 tests): the two sets are recomputed with compare, the descriptor passes the lint and matches the notes. The test does not check whether you reread the current documentation page.

Hints: TODO 1 and 2: compute both values for each question and compare. TODO 3: read NEEDED in lab/compare.py to learn which fields are required and their types.

10. Knowledge check

0/16 done · Results are kept in this browser only.

P02 · True or false

The rank-aware way of computing context precision penalizes a retriever that stretches the list with many noise chunks at the end.

P04 · Select all that apply

According to the notes table (pages read on 2026-11-04), select every metric for which the page explicitly states a path that needs no external LLM or uses a local model.

P05 · Put in order

Put in order the steps of the process the lab proposes when choosing a metric from a framework.

  1. Record the version, the judge configuration and the result
  2. List the project's constraints (data, cost, whether a local model is available)
  3. Read the current-version documentation for each metric and fill in the descriptor
  4. Run a parity check on the project's labeled set, build a confusion table

P06 · Match

Match each metric with what the page that was read says (according to the notes table).

P07 · Spot the bug

The descriptor below describes the Ragas ContextRecall page but lint_descriptor reports one problem. Find the bug.

descriptor = {
    "name": "Ragas ContextRecall",
    "concept": "context recall",
    "inputs": ["user_input", "retrieved_contexts"],
    "needs_llm": True,
    "needs_reference": True,
    "non_llm_or_local_path_on_page": True,
    "formula_seen_on_page": True,
    "source": "https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/context_recall/",
    "accessed": "2026-11-04",
}

P08 · Short answer

The HocVui team (fictional) has 40 answers with human labels, must not send student content to an outside service, and needs a faithfulness measure. According to the notes table, what should it do to narrow the candidates, and what must it not conclude?

P09 · Essay

Write 5-8 sentences for a manager: two ways of computing faithfulness (simulated, made up) on 6 answers: the rule faithfulness_checker and the simulated judge faithfulness_sim_judge are equal on 5 answers and differ on 1 answer (the sentence "Một mét có 1000 xăng-ti-mét" in the context "Một mét có 100 xăng-ti-mét. Một ki-lô-mét có 1000 mét."; Vietnamese: one meter has one thousand centimeters, in the context one meter has one hundred centimeters and one kilometer has one thousand meters): the rule gives 0, the judge gives 1. Running the judge with an error rate of 0 still gives 1. State how to read it, the cause, and what to report.

P11 · Recall

Lesson: L2-M06-L02

The retriever returns two chunks [a, b] and only a is relevant. According to L2-M06-L02, what is the lab's precision@3, and what is this lesson's context_precision_plain (indicator [1, 0])?

P12 · Recall

Lesson: L2-M06-L03

Groundedness as the lab defines it (each claim cites an id that is in the context of the run and that passage supports it) and TruLens's groundedness are the same computation.

P13 · Multiple choice

The notes table records non_llm_or_local_path_on_page: None for Ragas AnswerRelevancy and "not stated on the page" in the non-LLM path column. What conclusion does that allow?

P14 · True or false

The notes table shows that a metric that has a formula on its page is a more accurate metric than one without a formula.

P15 · Select all that apply

Select everything that belongs on the checklist before accepting a framework's number.

P16 · Fill in the blank

The set of correct chunks is {W1-c1, W1-c2}; the retriever takes only W1-c2, a chunk that contains both sentences of the reference answer "Một mét có 100 xăng-ti-mét. Một ki-lô-mét có 1000 mét." (Vietnamese: one meter has one hundred centimeters. One kilometer has one thousand meters.) Recall by chunk id is ___ and recall by reference claim (computed with claim_supported) is ___.

11. Summary

  • Concepts: a name does not determine the computation; one metric has several ways of computing it; seven questions before trusting a number; "not stated" is different from "does not have".
  • Skills: writing two ways of computing, listing and explaining the cases that differ, rerunning a model-based metric, writing a descriptor with a lint.
  • Traps: choosing the higher number, trusting the metric name, ignoring the version, reading a criteria table as a ranking.
  • You can now: receive a score "faithfulness 0.82" from a framework and ask: which formula, who grades, how a rerun behaves, which version.

12. References

ID Title Publisher URL Accessed Relevance
R1 Context Precision (Ragas metrics) Ragas https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/context_precision/ 2026-11-04 WebFetch (automatic summary)
R2 Context Recall (Ragas metrics) Ragas https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/context_recall/ 2026-11-04 WebFetch (automatic summary)
R3 Faithfulness (Ragas metrics) Ragas https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/faithfulness/ 2026-11-04 WebFetch (automatic summary)
R4 Answer Relevancy (Ragas metrics) Ragas https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/answer_relevance/ 2026-11-04 WebFetch (automatic summary)
R5 Metrics introduction DeepEval https://deepeval.com/docs/metrics-introduction 2026-11-04 WebFetch (automatic summary)
R6 The RAG Triad TruLens https://www.trulens.org/getting_started/core_concepts/rag_triad/ 2026-11-04 WebFetch (automatic summary)
R7 Model-graded metrics promptfoo https://www.promptfoo.dev/docs/configuration/expected-outputs/model-graded/ 2026-11-04 WebFetch (automatic summary)
R8 Ragas: Automated Evaluation of Retrieval Augmented Generation (Es et al.) arXiv https://arxiv.org/abs/2309.15217 2026-11-04 Abstract-only (WebFetch, automatic summary)

Key terms (English ↔ Vietnamese)

English Tiếng Việt
Context precision (rank-aware) Context precision có xét hạng: trung bình precision@k tại các hạng chunk liên quan
Metric descriptor Bản mô tả metric: nó cần gì, ai chấm, công thức ở đâu, nguồn và ngày đọc
Repeat-run check Kiểm bằng chạy lặp: cùng đầu vào, nhiều lần