A metric takes the full list ofDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/npow/context-bench/llms.txt
Use this file to discover all available pages before exploring further.
EvalRow objects for a system and returns a dict[str, float] of summary statistics. Metrics run after all examples have been processed.
The Metric protocol
rows is a flat list of EvalRow dataclass instances, one per (system, example) pair. Access scores with row.scores["f1"], token counts with row.input_tokens / row.output_tokens, and timing with row.latency.
The score_field parameter
Several metrics accept ascore_field parameter that selects which evaluator output to aggregate. For example, MeanScore(score_field="f1") averages the f1 field from AnswerQuality, while MeanScore(score_field="mc_accuracy") averages the mc_accuracy field from MultipleChoiceAccuracy.
Common score fields:
| Field | Source evaluator |
|---|---|
f1 | AnswerQuality |
exact_match | AnswerQuality |
recall | AnswerQuality |
contains | AnswerQuality |
rouge_l_f1 | SummarizationQuality |
mc_accuracy | MultipleChoiceAccuracy |
pass_at_1 | CodeExecution |
math_equiv | MathEquivalence |
nli_accuracy | NLILabelMatch |
ifeval_strict | IFEvalChecker |
judge_score | LLMJudge |
Built-in metrics
MeanScore
Average ofscore_field across all examples.
PassRate
Fraction of examples wherescore_field exceeds threshold.
threshold is 0.7. Override with --threshold on the CLI.
CompressionRatio
Measures how much the system reduces token count:1 - (output_tokens / input_tokens). Positive values mean compression; negative values mean expansion.
cl100k_base) by default. Swap the tokenizer via context_bench.utils.tokens.
CostOfPass
Output tokens spent per successful completion:total_output_tokens / num_passing_examples. Lower is better. Based on the methodology from arXiv:2504.13359.
PassRate to understand the efficiency trade-off: a system that passes more examples cheaply beats one that passes the same number expensively.
Latency
Per-example wall-clock timing. Reports four percentiles.System.process() to the return of the result.
PerDatasetBreakdown
Mean score sliced by dataset tag. Automatically enabled when you load more than one dataset.EvalRow carries a dataset field set from example["dataset"]. Rows without a dataset tag appear under "dataset:unknown".
ParetoRank
Ranks systems on the quality-vs-cost Pareto frontier. Automatically enabled for multi-system CLI runs.quality_field (default "score") and cost_field (default "cost_of_pass").
Using metrics
Pass metrics as a list toevaluate():
Implementing a custom metric
Any class withname and compute() satisfies the protocol:
Metric is a typing.Protocol. You do not need to import or subclass anything from context-bench to define a custom metric.