fastrag.benchmark.metrics.generation#
Generation metrics: a free bag-of-words baseline, and three judge-backed scores.
Classes
|
How relevant the answer is to the question asked, per the judge. |
|
How correct the answer is against the sample's expected answers, per the judge. |
|
How well the answer is supported by its retrieved sources, per the judge. |
|
Shared machinery for a metric scored by asking a chat model to grade. |
Bag-of-words F1 between the answer and the best-matching expected answer. |
- class fastrag.benchmark.metrics.generation.TokenOverlap[source]#
Bases:
MetricBag-of-words F1 between the answer and the best-matching expected answer.
A cheap smoke-test baseline, never accuracy: it rewards word overlap, not correctness, and a fluent answer that restates the question can score well while being wrong. Reach for the retrieval metrics or a judge-backed metric when the number needs to mean something.
- name = 'token_overlap'#
- needs_answer: bool = True#
Truewhenscore()readsoutcome.answer— never satisfied by a bareRetriever.
- async score(sample, outcome)[source]#
Best F1 across expected answers, or
Nonewhen there are none.- Parameters:
sample (EvalSample)
outcome (QueryOutcome)
- Return type:
float | None
- aggregate(scores)#
Aggregate this metric’s per-sample scores. Override to change how.
- Parameters:
- Return type:
- class fastrag.benchmark.metrics.generation.JudgeMetric(*, judge)[source]#
Bases:
MetricShared machinery for a metric scored by asking a chat model to grade.
- Parameters:
judge (ChatModel) – The chat model asked to grade each sample.
- needs_answer: bool = True#
Truewhenscore()readsoutcome.answer— never satisfied by a bareRetriever.
- aggregate(scores)#
Aggregate this metric’s per-sample scores. Override to change how.
- Parameters:
- Return type:
- higher_is_better: bool = True#
Which direction improves.
Falseforlatency_ms,total_tokens, andcost_usd.
- abstractmethod async score(sample, outcome)#
This sample’s score, or
Nonewhen it is not measurable.- Parameters:
sample (EvalSample)
outcome (QueryOutcome)
- Return type:
float | None
- class fastrag.benchmark.metrics.generation.Faithfulness(*, judge)[source]#
Bases:
JudgeMetricHow well the answer is supported by its retrieved sources, per the judge.
- Parameters:
judge (ChatModel)
- name = 'faithfulness'#
- async score(sample, outcome)[source]#
Ask the judge to score how well the answer is grounded in its sources.
- Parameters:
sample (EvalSample)
outcome (QueryOutcome)
- Return type:
float | None
- aggregate(scores)#
Aggregate this metric’s per-sample scores. Override to change how.
- Parameters:
- Return type:
- higher_is_better: bool = True#
Which direction improves.
Falseforlatency_ms,total_tokens, andcost_usd.
- class fastrag.benchmark.metrics.generation.AnswerRelevancy(*, judge)[source]#
Bases:
JudgeMetricHow relevant the answer is to the question asked, per the judge.
- Parameters:
judge (ChatModel)
- name = 'answer_relevancy'#
- async score(sample, outcome)[source]#
Ask the judge to score how relevant the answer is to the question.
- Parameters:
sample (EvalSample)
outcome (QueryOutcome)
- Return type:
float | None
- aggregate(scores)#
Aggregate this metric’s per-sample scores. Override to change how.
- Parameters:
- Return type:
- higher_is_better: bool = True#
Which direction improves.
Falseforlatency_ms,total_tokens, andcost_usd.
- class fastrag.benchmark.metrics.generation.Correctness(*, judge)[source]#
Bases:
JudgeMetricHow correct the answer is against the sample’s expected answers, per the judge.
- Parameters:
judge (ChatModel)
- name = 'correctness'#
- async score(sample, outcome)[source]#
Ask the judge to score correctness, or
Nonewith no expected answers.- Parameters:
sample (EvalSample)
outcome (QueryOutcome)
- Return type:
float | None
- aggregate(scores)#
Aggregate this metric’s per-sample scores. Override to change how.
- Parameters:
- Return type:
- higher_is_better: bool = True#
Which direction improves.
Falseforlatency_ms,total_tokens, andcost_usd.