@mastra/evals 1.5.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/dist/docs/SKILL.md +2 -1
  3. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  4. package/dist/docs/references/docs-evals-built-in-scorers.md +4 -2
  5. package/dist/docs/references/docs-evals-overview.md +8 -1
  6. package/dist/docs/references/docs-evals-quick-checks.md +6 -5
  7. package/dist/docs/references/reference-evals-answer-relevancy.md +2 -0
  8. package/dist/docs/references/reference-evals-answer-similarity.md +2 -0
  9. package/dist/docs/references/reference-evals-bias.md +2 -0
  10. package/dist/docs/references/reference-evals-checks.md +6 -4
  11. package/dist/docs/references/reference-evals-completeness.md +2 -0
  12. package/dist/docs/references/reference-evals-content-similarity.md +2 -0
  13. package/dist/docs/references/reference-evals-context-precision.md +2 -0
  14. package/dist/docs/references/reference-evals-context-recall.md +205 -0
  15. package/dist/docs/references/reference-evals-context-relevance.md +2 -0
  16. package/dist/docs/references/reference-evals-faithfulness.md +2 -0
  17. package/dist/docs/references/reference-evals-hallucination.md +3 -0
  18. package/dist/docs/references/reference-evals-keyword-coverage.md +2 -0
  19. package/dist/docs/references/reference-evals-noise-sensitivity.md +2 -0
  20. package/dist/docs/references/reference-evals-prompt-alignment.md +3 -0
  21. package/dist/docs/references/reference-evals-rubric.md +3 -1
  22. package/dist/docs/references/reference-evals-scorer-utils.md +2 -0
  23. package/dist/docs/references/reference-evals-textual-difference.md +2 -0
  24. package/dist/docs/references/reference-evals-tone-consistency.md +2 -0
  25. package/dist/docs/references/reference-evals-tool-call-accuracy.md +2 -0
  26. package/dist/docs/references/reference-evals-toxicity.md +2 -0
  27. package/dist/docs/references/reference-evals-trajectory-accuracy.md +3 -1
  28. package/dist/scorers/llm/context-recall/index.d.ts +20 -0
  29. package/dist/scorers/llm/context-recall/index.d.ts.map +1 -0
  30. package/dist/scorers/llm/context-recall/prompts.d.ts +19 -0
  31. package/dist/scorers/llm/context-recall/prompts.d.ts.map +1 -0
  32. package/dist/scorers/llm/index.d.ts +1 -0
  33. package/dist/scorers/llm/index.d.ts.map +1 -1
  34. package/dist/scorers/prebuilt/index.cjs +261 -0
  35. package/dist/scorers/prebuilt/index.cjs.map +1 -1
  36. package/dist/scorers/prebuilt/index.js +261 -1
  37. package/dist/scorers/prebuilt/index.js.map +1 -1
  38. package/package.json +13 -13
package/CHANGELOG.md CHANGED
@@ -1,5 +1,55 @@
1
1
  # @mastra/evals
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added context-recall LLM scorer that evaluates how well retrieved context covers the claims in a ground-truth reference answer. Complements the existing context-precision scorer by measuring retrieval completeness rather than relevance ranking. ([#19733](https://github.com/mastra-ai/mastra/pull/19733))
8
+
9
+ ```typescript
10
+ import { createContextRecallScorer } from '@mastra/evals/scorers/prebuilt';
11
+
12
+ const scorer = createContextRecallScorer({
13
+ model: 'openai/gpt-5-mini',
14
+ options: {
15
+ context: [
16
+ 'Einstein was born on 14 March 1879 in Ulm, Germany.',
17
+ 'Einstein developed the theory of special relativity in 1905.',
18
+ ],
19
+ },
20
+ });
21
+ ```
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [[`ec857fc`](https://github.com/mastra-ai/mastra/commit/ec857fc79c264b53b38e16478c789b7177f2ad59), [`d7385ad`](https://github.com/mastra-ai/mastra/commit/d7385ad9e88f9e4f33d15c0ec0bfebedde0cbc2e), [`41a5392`](https://github.com/mastra-ai/mastra/commit/41a5392d9f6c5e18d6b227f0fc0ddf49c50774e9), [`3d6e539`](https://github.com/mastra-ai/mastra/commit/3d6e539272eb2ea0407034605ee1906b3be06b39), [`1426af2`](https://github.com/mastra-ai/mastra/commit/1426af24975879c000d13ac75673f630fcc970c1), [`a40adeb`](https://github.com/mastra-ai/mastra/commit/a40adeb222b961a56a58af56a106106525721b74), [`8a0d145`](https://github.com/mastra-ai/mastra/commit/8a0d145aadbdf7278665aceaaec364b35dd9bd94), [`bd2f1d2`](https://github.com/mastra-ai/mastra/commit/bd2f1d274d05e60e2366f005ea0d94d5cea0d5ff), [`e1f2fae`](https://github.com/mastra-ai/mastra/commit/e1f2faebaf048c3d4c2e2c01d293767c195d5794), [`63aa799`](https://github.com/mastra-ai/mastra/commit/63aa799c6b44eacc7806cda6846b7c5bbee06b37), [`b7e79c3`](https://github.com/mastra-ai/mastra/commit/b7e79c3c02ac5cd415db34ba0975ceafc1464333), [`675fbff`](https://github.com/mastra-ai/mastra/commit/675fbff84d3274391b33e852f76083c38a5514e5), [`da009e1`](https://github.com/mastra-ai/mastra/commit/da009e1aacd89ed94b8d1b2af09c9d4fe7c4db49), [`3b77e77`](https://github.com/mastra-ai/mastra/commit/3b77e7704936522e4769d29de1b5ea6901f302bd), [`c7d30cd`](https://github.com/mastra-ai/mastra/commit/c7d30cd86009c407df91105591f03cd6e3d2854d), [`21a0eb8`](https://github.com/mastra-ai/mastra/commit/21a0eb86746ba0b703acea360d4f84c6a5a493f2), [`8b20926`](https://github.com/mastra-ai/mastra/commit/8b20926cd59e2ba3d66458e062fa0e6e2ada3e68), [`975295d`](https://github.com/mastra-ai/mastra/commit/975295d418552f0d46a59edfef4c3ee555f9930a), [`73db8db`](https://github.com/mastra-ai/mastra/commit/73db8db90d69ab6153c7942749f624db0d96952d), [`6b1bf3b`](https://github.com/mastra-ai/mastra/commit/6b1bf3b9494bd51aa8f654c68c9355d6046fa2a1), [`35c2181`](https://github.com/mastra-ai/mastra/commit/35c2181e6a50e47c90ba36260db7c9723d54696f), [`0a2c22c`](https://github.com/mastra-ai/mastra/commit/0a2c22c902604439ec490319e14c17f331e0c84c), [`4cfdd64`](https://github.com/mastra-ai/mastra/commit/4cfdd645794feaea0c4ea711e70ecdfbef0c5b8e), [`b75d749`](https://github.com/mastra-ai/mastra/commit/b75d749621ff5d17e86bcb4ee809d301fb4f7cf3), [`821648b`](https://github.com/mastra-ai/mastra/commit/821648bf2871ef840100c7bacbecf676010bd12a), [`de86fd7`](https://github.com/mastra-ai/mastra/commit/de86fd7119f0438381d1a642e3d258143c0b9c29), [`2745031`](https://github.com/mastra-ai/mastra/commit/2745031d1d4a4978f037092da371428c32e2842a), [`b4b7ea8`](https://github.com/mastra-ai/mastra/commit/b4b7ea8733f033fc441ea47ed03f6afb17ec2248), [`3a8024c`](https://github.com/mastra-ai/mastra/commit/3a8024ce615f8aa89479c0d71fe61d10bb0040be), [`35865a5`](https://github.com/mastra-ai/mastra/commit/35865a53e194aa9634d6a70a97010e7a6b9d58b1), [`74faf8b`](https://github.com/mastra-ai/mastra/commit/74faf8bd9c1018f2492653c06b1e25fc8300e9e6), [`ef03fbc`](https://github.com/mastra-ai/mastra/commit/ef03fbcc556bcbc04c9b3d06fab88771ecaa043c), [`675fbff`](https://github.com/mastra-ai/mastra/commit/675fbff84d3274391b33e852f76083c38a5514e5), [`70687f7`](https://github.com/mastra-ai/mastra/commit/70687f7e495a322a02070b4a67cb0c77a5ca91ec), [`1fadac4`](https://github.com/mastra-ai/mastra/commit/1fadac44537caeefe81f9f775ae2f2f3d94e9069), [`73db8db`](https://github.com/mastra-ai/mastra/commit/73db8db90d69ab6153c7942749f624db0d96952d), [`76b7181`](https://github.com/mastra-ai/mastra/commit/76b71810366e6d90b9d3973149d1c7ba3659ffb9), [`792ec9a`](https://github.com/mastra-ai/mastra/commit/792ec9a0869bab8274cf5e0ed2840738737a1607), [`712b864`](https://github.com/mastra-ai/mastra/commit/712b864aa1ed12b14c54390ec17b69de163c37f7), [`85e4fb5`](https://github.com/mastra-ai/mastra/commit/85e4fb50087a81c74df3a762f53b56373db0b912), [`0c0e8d7`](https://github.com/mastra-ai/mastra/commit/0c0e8d7becd4d1445c656b78d5d845f606c1ff9d), [`a7bbe77`](https://github.com/mastra-ai/mastra/commit/a7bbe773577f60bc4761b534ef7ec6b476332dad), [`72e437c`](https://github.com/mastra-ai/mastra/commit/72e437c515942c80b9def5b026e0bdee61b469d9), [`8f7a5de`](https://github.com/mastra-ai/mastra/commit/8f7a5dedc246cdc938bb65516703cf9b27b03756), [`a7bbe77`](https://github.com/mastra-ai/mastra/commit/a7bbe773577f60bc4761b534ef7ec6b476332dad), [`11f6cd9`](https://github.com/mastra-ai/mastra/commit/11f6cd96fe42582403416608beb212cc1a2cc79e), [`ef03c0c`](https://github.com/mastra-ai/mastra/commit/ef03c0cfc62367a458e4cc56462e2148b35681c5), [`4fb4d88`](https://github.com/mastra-ai/mastra/commit/4fb4d881bc107acee13890ad4d78661016c510ed), [`4e68363`](https://github.com/mastra-ai/mastra/commit/4e683634f94ebd062d26a3bb6093a8dfc7263d37), [`c328769`](https://github.com/mastra-ai/mastra/commit/c3287698ff8ef98dba86d415faa566fa3e5f4d56), [`9f7c67a`](https://github.com/mastra-ai/mastra/commit/9f7c67abeeb52c41c51a9b5edee60b62afe7cd8d), [`3b65e68`](https://github.com/mastra-ai/mastra/commit/3b65e68d7f1c771c7a70eea42d83fefdd28cad88), [`4eba27a`](https://github.com/mastra-ai/mastra/commit/4eba27adcf60f991df0e62f94b3e75b4e67f3b4b), [`c701be3`](https://github.com/mastra-ai/mastra/commit/c701be32d7d9aa94a66da8c6cc38dcac6856f464), [`db650ce`](https://github.com/mastra-ai/mastra/commit/db650ce490348914e85b93651d83acdf8f2a4c31), [`232fcbc`](https://github.com/mastra-ai/mastra/commit/232fcbc14fce625dd672ba043329c0b732c62be2), [`6354eeb`](https://github.com/mastra-ai/mastra/commit/6354eeb32efa9f5f68f51dda394e90e2ee76f1fb), [`a8799bb`](https://github.com/mastra-ai/mastra/commit/a8799bb8e44f4a60d01e4e2acd3448ff80bf14f8), [`3d6e539`](https://github.com/mastra-ai/mastra/commit/3d6e539272eb2ea0407034605ee1906b3be06b39), [`e3868e2`](https://github.com/mastra-ai/mastra/commit/e3868e22babfffd0133771669ca724501c2dd58e), [`9251370`](https://github.com/mastra-ai/mastra/commit/9251370ad413af464aa22d7566338bec5613e8de), [`3491666`](https://github.com/mastra-ai/mastra/commit/34916663c4fdd43b48c21f4ab2d5fb6dcccc94f9), [`c0bec73`](https://github.com/mastra-ai/mastra/commit/c0bec732c93d1a22ae5e51ed66cf8cacca8bd6a6)]:
26
+ - @mastra/core@1.52.0
27
+
28
+ ## 1.6.0-alpha.0
29
+
30
+ ### Minor Changes
31
+
32
+ - Added context-recall LLM scorer that evaluates how well retrieved context covers the claims in a ground-truth reference answer. Complements the existing context-precision scorer by measuring retrieval completeness rather than relevance ranking. ([#19733](https://github.com/mastra-ai/mastra/pull/19733))
33
+
34
+ ```typescript
35
+ import { createContextRecallScorer } from '@mastra/evals/scorers/prebuilt';
36
+
37
+ const scorer = createContextRecallScorer({
38
+ model: 'openai/gpt-5-mini',
39
+ options: {
40
+ context: [
41
+ 'Einstein was born on 14 March 1879 in Ulm, Germany.',
42
+ 'Einstein developed the theory of special relativity in 1905.',
43
+ ],
44
+ },
45
+ });
46
+ ```
47
+
48
+ ### Patch Changes
49
+
50
+ - Updated dependencies [[`0a2c22c`](https://github.com/mastra-ai/mastra/commit/0a2c22c902604439ec490319e14c17f331e0c84c), [`3a8024c`](https://github.com/mastra-ai/mastra/commit/3a8024ce615f8aa89479c0d71fe61d10bb0040be)]:
51
+ - @mastra/core@1.52.0-alpha.9
52
+
3
53
  ## 1.5.1
4
54
 
5
55
  ### Patch Changes
@@ -3,7 +3,7 @@ name: mastra-evals
3
3
  description: Documentation for @mastra/evals. Use when working with @mastra/evals APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/evals"
6
- version: "1.5.1"
6
+ version: "1.6.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -29,6 +29,7 @@ Read the individual reference documents for detailed explanations and code examp
29
29
  - [Reference: Completeness scorer](references/reference-evals-completeness.md) - Documentation for the Completeness Scorer in Mastra, which evaluates how thoroughly LLM outputs cover key elements present in the input.
30
30
  - [Reference: Content similarity scorer](references/reference-evals-content-similarity.md) - Documentation for the Content Similarity Scorer in Mastra, which measures textual similarity between strings and provides a matching score.
31
31
  - [Reference: Context precision scorer](references/reference-evals-context-precision.md) - Documentation for the Context Precision Scorer in Mastra. Evaluates the relevance and precision of retrieved context for generating expected outputs using Mean Average Precision.
32
+ - [Reference: Context recall scorer](references/reference-evals-context-recall.md) - Documentation for the Context Recall Scorer in Mastra. Evaluates how well retrieved context covers the claims in a ground-truth reference answer.
32
33
  - [Reference: Context relevance scorer](references/reference-evals-context-relevance.md) - Documentation for the Context Relevance Scorer in Mastra. Evaluates the relevance and utility of provided context for generating agent responses using weighted relevance scoring.
33
34
  - [Reference: Faithfulness scorer](references/reference-evals-faithfulness.md) - Documentation for the Faithfulness Scorer in Mastra, which evaluates the factual accuracy of LLM outputs compared to the provided context.
34
35
  - [Reference: Hallucination scorer](references/reference-evals-hallucination.md) - Documentation for the Hallucination Scorer in Mastra, which evaluates the factual correctness of LLM outputs by identifying contradictions with provided context.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.1",
2
+ "version": "1.6.0",
3
3
  "package": "@mastra/evals",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Built-in scorers
2
4
 
3
5
  Mastra provides a comprehensive set of built-in scorers for evaluating AI outputs. These scorers are optimized for common evaluation scenarios and are ready to use in your agents and workflows.
@@ -52,12 +54,12 @@ These scorers evaluate adherence to format, style, and safety requirements:
52
54
  Zero-LLM micro-scorers for fast, deterministic assertions. See the [Quick Checks](https://mastra.ai/docs/evals/quick-checks) guide for usage details.
53
55
 
54
56
  - [`checks.includes`](https://mastra.ai/reference/evals/checks): Scores 1 if output contains a substring (`0` or `1`)
55
- - [`checks.excludes`](https://mastra.ai/reference/evals/checks): Scores 1 if output does not contain a substring (`0` or `1`)
57
+ - [`checks.excludes`](https://mastra.ai/reference/evals/checks): Scores 1 if output doesn't contain a substring (`0` or `1`)
56
58
  - [`checks.equals`](https://mastra.ai/reference/evals/checks): Scores 1 if output exactly matches a string (`0` or `1`)
57
59
  - [`checks.matches`](https://mastra.ai/reference/evals/checks): Scores 1 if output matches a regex (`0` or `1`)
58
60
  - [`checks.similarity`](https://mastra.ai/reference/evals/checks): String similarity via Dice coefficient (`0-1`, or binary with threshold)
59
61
  - [`checks.calledTool`](https://mastra.ai/reference/evals/checks): Scores 1 if a tool was called at least N times (`0` or `1`)
60
- - [`checks.didNotCall`](https://mastra.ai/reference/evals/checks): Scores 1 if a tool was not called (`0` or `1`)
62
+ - [`checks.didNotCall`](https://mastra.ai/reference/evals/checks): Scores 1 if a tool wasn't called (`0` or `1`)
61
63
  - [`checks.toolOrder`](https://mastra.ai/reference/evals/checks): Scores 1 if tools were called in order (`0` or `1`)
62
64
  - [`checks.maxToolCalls`](https://mastra.ai/reference/evals/checks): Scores 1 if tool call count is within limit (`0` or `1`)
63
65
  - [`checks.usedNoTools`](https://mastra.ai/reference/evals/checks): Scores 1 if no tools were called (`0` or `1`)
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Scorers overview
2
4
 
3
5
  While traditional software tests have clear pass/fail conditions, AI outputs are non-deterministic — they can vary with the same input. **Scorers** help bridge this gap by providing quantifiable metrics for measuring agent quality.
@@ -6,6 +8,8 @@ Scorers are automated tests that evaluate Agents outputs using model-graded, rul
6
8
 
7
9
  Scorers can be run in the cloud, capturing real-time results. But scorers can also be part of your CI/CD pipeline, allowing you to test and monitor your agents over time.
8
10
 
11
+ > **📹 Watch:** Watch [Mastra evals overview](https://www.youtube.com/watch?v=12WN6u2DrBk) for an introduction to evals and how to reason about agent quality.
12
+
9
13
  ## Types of scorers
10
14
 
11
15
  Mastra provides different kinds of scorers, each serving a specific purpose. Here are some common types:
@@ -55,6 +59,7 @@ import { Agent } from '@mastra/core/agent'
55
59
  import { createAnswerRelevancyScorer, createToxicityScorer } from '@mastra/evals/scorers/prebuilt'
56
60
 
57
61
  export const evaluatedAgent = new Agent({
62
+ id: 'evaluated-agent',
58
63
  scorers: {
59
64
  relevancy: {
60
65
  scorer: createAnswerRelevancyScorer({ model: 'openai/gpt-5-mini' }),
@@ -137,6 +142,8 @@ Once registered, you can score traces interactively within Studio under the **Ob
137
142
 
138
143
  - Use [Quick Checks](https://mastra.ai/docs/evals/quick-checks) for fast, deterministic assertions on text and tool usage
139
144
  - Add [gates and verdicts](https://mastra.ai/docs/evals/gates-and-verdicts) to enforce hard requirements and quality thresholds
145
+ - Test [multi-turn conversations](https://mastra.ai/docs/evals/multi-turn) where behavior emerges across sequential turns
140
146
  - Learn how to create your own scorers in the [Creating Custom Scorers](https://mastra.ai/docs/evals/custom-scorers) guide
141
147
  - Explore built-in scorers in the [Built-in Scorers](https://mastra.ai/docs/evals/built-in-scorers) section
142
- - Test scorers with [Studio](https://mastra.ai/docs/studio/overview)
148
+ - Test scorers with [Studio](https://mastra.ai/docs/studio/overview)
149
+ - 📹 [Mastra evals workshop](https://www.youtube.com/watch?v=OHOZ5PgPj5M\&t=3578s)
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Quick Checks
2
4
 
3
5
  Quick Checks are composable micro-scorers for common assertions like "output contains X" or "agent called tool Y." They require no LLM, run instantly, and plug into the same `scorers: [...]` array as any other scorer.
@@ -42,7 +44,7 @@ These scorers evaluate the agent's text output:
42
44
  | Check | What it does | Score |
43
45
  | ------------------------ | ------------------------------------- | -------------------------------- |
44
46
  | `checks.includes(str)` | Output contains substring | 1 or 0 |
45
- | `checks.excludes(str)` | Output does not contain substring | 1 or 0 |
47
+ | `checks.excludes(str)` | Output doesn't contain substring | 1 or 0 |
46
48
  | `checks.equals(str)` | Output exactly equals string | 1 or 0 |
47
49
  | `checks.matches(regex)` | Output matches regular expression | 1 or 0 |
48
50
  | `checks.similarity(str)` | Dice coefficient similarity to string | 0-1 (or binary with `threshold`) |
@@ -54,7 +56,7 @@ These scorers evaluate tool usage from the agent's run:
54
56
  | Check | What it does | Score |
55
57
  | ------------------------- | -------------------------------- | ------ |
56
58
  | `checks.calledTool(name)` | Tool was called at least N times | 1 or 0 |
57
- | `checks.didNotCall(name)` | Tool was not called | 1 or 0 |
59
+ | `checks.didNotCall(name)` | Tool wasn't called | 1 or 0 |
58
60
  | `checks.toolOrder([...])` | Tools called in expected order | 1 or 0 |
59
61
  | `checks.maxToolCalls(n)` | No more than N tool calls total | 1 or 0 |
60
62
  | `checks.usedNoTools()` | No tools called at all | 1 or 0 |
@@ -100,6 +102,7 @@ import { Agent } from '@mastra/core/agent'
100
102
  import { checks } from '@mastra/evals/checks'
101
103
 
102
104
  export const weatherAgent = new Agent({
105
+ id: 'weather-agent',
103
106
  name: 'Weather Agent',
104
107
  instructions: 'Answer weather questions using the get_weather tool.',
105
108
  model: 'openai/gpt-5.5',
@@ -124,9 +127,7 @@ Each check is a standard `createScorer()` instance with a `preprocess` step and
124
127
  1. **preprocess**: Extracts and normalizes relevant data from the agent run (text content, tool calls)
125
128
  2. **generateScore**: Converts the preprocessed result into a score (typically binary 1 or 0)
126
129
 
127
- Because checks skip the `analyze` and `generateReason` steps and make no LLM calls, they run in microseconds.
128
-
129
- > **Note:** Visit the [Quick Checks reference](https://mastra.ai/reference/evals/checks) for the full API, including all parameters and options for each check.
130
+ Because checks skip the `analyze` and `generateReason` steps and make no LLM calls, they run in microseconds. Visit the [Quick Checks reference](https://mastra.ai/reference/evals/checks) for the full API, including all parameters and options for each check.
130
131
 
131
132
  ## Related
132
133
 
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Answer relevancy scorer
2
4
 
3
5
  The `createAnswerRelevancyScorer()` function accepts a single options object with the following properties:
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Answer similarity scorer
2
4
 
3
5
  The `createAnswerSimilarityScorer()` function creates a scorer that evaluates how similar an agent's output is to a ground truth answer. This scorer is specifically designed for CI/CD testing scenarios where you have expected answers and want to ensure consistency over time.
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Bias scorer
2
4
 
3
5
  The `createBiasScorer()` function accepts a single options object with the following properties:
@@ -1,8 +1,10 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Quick Checks
2
4
 
3
5
  Quick Checks are zero-LLM, composable micro-scorers for common assertions. They plug into the existing `scorers: [...]` array anywhere scorers are used — in `runEvals`, live scoring, experiments, and Studio.
4
6
 
5
- Internally they are standard `createScorer()` instances, so they have the same observability, storage, and pipeline integration as any other scorer.
7
+ Internally they're standard `createScorer()` instances, so they have the same observability, storage, and pipeline integration as any other scorer.
6
8
 
7
9
  ## Usage example
8
10
 
@@ -44,7 +46,7 @@ Returns: `1` if found, `0` otherwise.
44
46
 
45
47
  ### `checks.excludes(unwanted, options?)`
46
48
 
47
- Scores 1 if the agent's output text does NOT contain the substring, 0 otherwise.
49
+ Scores 1 if the agent's output text doesn't contain the substring, 0 otherwise.
48
50
 
49
51
  ```typescript
50
52
  checks.excludes('error')
@@ -123,7 +125,7 @@ Returns: `1` if called at least `times` times, `0` otherwise.
123
125
 
124
126
  ### `checks.didNotCall(toolName)`
125
127
 
126
- Scores 1 if the agent did NOT call the specified tool.
128
+ Scores 1 if the agent didn't call the specified tool.
127
129
 
128
130
  ```typescript
129
131
  checks.didNotCall('delete_user')
@@ -131,7 +133,7 @@ checks.didNotCall('delete_user')
131
133
 
132
134
  **toolName** (`string`): Name of the tool that must not appear.
133
135
 
134
- Returns: `1` if the tool was not called, `0` otherwise.
136
+ Returns: `1` if the tool wasn't called, `0` otherwise.
135
137
 
136
138
  ### `checks.toolOrder(expectedOrder)`
137
139
 
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Completeness scorer
2
4
 
3
5
  The `createCompletenessScorer()` function evaluates how thoroughly an LLM's output covers the key elements present in the input. It analyzes nouns, verbs, topics, and terms to determine coverage and provides a detailed completeness score.
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Content similarity scorer
2
4
 
3
5
  The `createContentSimilarityScorer()` function measures the textual similarity between two strings, providing a score that indicates how closely they match. It supports configurable options for case sensitivity and whitespace handling.
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Context precision scorer
2
4
 
3
5
  The `createContextPrecisionScorer()` function creates a scorer that evaluates how relevant and well-positioned retrieved context pieces are for generating expected outputs. It uses **Mean Average Precision (MAP)** to reward systems that place relevant context earlier in the sequence.
@@ -0,0 +1,205 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Context recall scorer
4
+
5
+ The `createContextRecallScorer()` function creates a scorer that evaluates how well retrieved context covers the claims in a ground-truth reference answer. It measures retrieval completeness by checking what fraction of the ground truth's claims are attributable to the retrieved context.
6
+
7
+ This scorer requires a ground-truth reference answer, making it suitable for labeled datasets in CI or test environments. When `groundTruth` is not provided in the run, the scorer returns a score of 0 rather than throwing an error.
8
+
9
+ ## RAG retrieval evaluation
10
+
11
+ Ideal for evaluating retrieval completeness in RAG pipelines where:
12
+
13
+ - You need to verify the retriever fetches all necessary information
14
+ - You have labeled datasets with known-correct answers
15
+ - You want to catch regressions in what the retriever returns
16
+
17
+ ## Dataset-driven testing
18
+
19
+ Use when running evaluations against curated test sets:
20
+
21
+ - CI pipelines with ground-truth labeled questions
22
+ - A/B testing retrieval strategies
23
+ - Benchmarking embedding models for coverage
24
+
25
+ ## Parameters
26
+
27
+ **model** (`MastraModelConfig`): The language model to use for evaluating claim attribution
28
+
29
+ **options** (`ContextRecallMetricOptions`): Configuration options for the scorer
30
+
31
+ **Note**: Either `context` or `contextExtractor` must be provided. When both are provided, `contextExtractor` is used only if the run input and output are agent-shaped (`MastraDBMessage[]`); otherwise the scorer falls back to `context`.
32
+
33
+ ## `.run()` returns
34
+
35
+ **score** (`number`): Recall score between 0 and scale (default 0-1), representing the fraction of ground-truth claims covered by the context
36
+
37
+ **reason** (`string`): Human-readable explanation of which ground-truth claims were and were not found in the context
38
+
39
+ ## Scoring details
40
+
41
+ ### Claim attribution
42
+
43
+ Context Recall uses a two-step LLM evaluation followed by a deterministic score calculation:
44
+
45
+ 1. **Claim extraction**: The ground-truth answer is decomposed into atomic claims
46
+ 2. **Attribution check**: Each claim is checked against the retrieval context for support
47
+
48
+ The score is then calculated as the ratio of attributed claims to total claims, multiplied by scale.
49
+
50
+ ### Scoring formula
51
+
52
+ ```text
53
+ Context Recall = attributed_claims / total_claims × scale
54
+
55
+ Where:
56
+ - attributed_claims = number of ground-truth claims supported by the context
57
+ - total_claims = total number of claims extracted from the ground truth
58
+ - Attribution is binary: a claim is either supported (yes) or not (no)
59
+ ```
60
+
61
+ ### Score interpretation
62
+
63
+ These ranges assume the default `scale` of 1. When using a custom scale, multiply accordingly.
64
+
65
+ - **0.9-1.0**: Excellent recall — context covers nearly all ground-truth claims
66
+ - **0.7-0.8**: Good recall — most claims are covered, minor gaps
67
+ - **0.4-0.6**: Moderate recall — significant information missing from context
68
+ - **0.1-0.3**: Poor recall — most ground-truth claims not found in context
69
+ - **0.0**: No recall — none of the ground-truth claims are in the context
70
+
71
+ ### Reason analysis
72
+
73
+ The reason field explains:
74
+
75
+ - Which ground-truth claims were found in the context
76
+ - Which claims were missing and what information gaps exist
77
+ - Specific context pieces that supported attributed claims
78
+
79
+ ### Optimization insights
80
+
81
+ Use results to:
82
+
83
+ - **Improve retrieval**: Identify what types of information the retriever misses
84
+ - **Tune chunk size**: Ensure chunks contain enough detail to cover ground-truth claims
85
+ - **Evaluate embeddings**: Test different embedding models for better information coverage
86
+ - **Expand knowledge base**: Add documents that cover frequently missed claims
87
+
88
+ ### Example calculation
89
+
90
+ Given ground truth: "Einstein was born in 1879. He developed relativity. He won the Nobel Prize."
91
+
92
+ Claims extracted: 3
93
+
94
+ - "Einstein was born in 1879" → attributed (context mentions birthdate)
95
+ - "Einstein developed relativity" → attributed (context covers relativity)
96
+ - "Einstein won the Nobel Prize" → not attributed (context doesn't mention Nobel Prize)
97
+
98
+ Recall = 2/3 = 0.67
99
+
100
+ ## Scorer configuration
101
+
102
+ ### Dynamic context extraction
103
+
104
+ ```typescript
105
+ const scorer = createContextRecallScorer({
106
+ model: 'openai/gpt-5.5',
107
+ options: {
108
+ contextExtractor: (input, output) => {
109
+ const query = input?.inputMessages?.[0]?.content || ''
110
+ const searchResults = vectorDB.search(query, { limit: 10 })
111
+ return searchResults.map(result => result.content)
112
+ },
113
+ scale: 1,
114
+ },
115
+ })
116
+ ```
117
+
118
+ ### Static context evaluation
119
+
120
+ ```typescript
121
+ const scorer = createContextRecallScorer({
122
+ model: 'openai/gpt-5.5',
123
+ options: {
124
+ context: [
125
+ 'Document 1: Einstein was born on 14 March 1879 in Ulm, Germany.',
126
+ 'Document 2: Einstein published the theory of special relativity in 1905.',
127
+ 'Document 3: Einstein moved to the United States in 1933.',
128
+ ],
129
+ },
130
+ })
131
+ ```
132
+
133
+ ## Example
134
+
135
+ Evaluate RAG retrieval completeness against a labeled dataset:
136
+
137
+ ```typescript
138
+ import { runEvals } from '@mastra/core/evals'
139
+ import { createContextRecallScorer } from '@mastra/evals/scorers/prebuilt'
140
+ import { myAgent } from './agent'
141
+
142
+ const scorer = createContextRecallScorer({
143
+ model: 'openai/gpt-5.5',
144
+ options: {
145
+ contextExtractor: (input, output) => {
146
+ // Extract context from tool invocation results in the agent output
147
+ return output
148
+ .filter(msg => msg?.role === 'assistant')
149
+ .flatMap(msg => msg?.content?.toolInvocations ?? [])
150
+ .filter((tool: any) => tool.state === 'result')
151
+ .map((tool: any) => JSON.stringify(tool.result))
152
+ },
153
+ },
154
+ })
155
+
156
+ const result = await runEvals({
157
+ data: [
158
+ {
159
+ input: 'What are the health benefits of green tea?',
160
+ groundTruth:
161
+ 'Green tea contains antioxidants that reduce inflammation, L-theanine that improves focus, and catechins that boost metabolism.',
162
+ },
163
+ {
164
+ input: 'How does photosynthesis work?',
165
+ groundTruth:
166
+ 'Photosynthesis converts sunlight into chemical energy using chlorophyll in chloroplasts, producing glucose and oxygen from carbon dioxide and water.',
167
+ },
168
+ ],
169
+ scorers: [scorer],
170
+ target: myAgent,
171
+ onItemComplete: ({ scorerResults }) => {
172
+ console.log({
173
+ score: scorerResults[scorer.id].score,
174
+ reason: scorerResults[scorer.id].reason,
175
+ })
176
+ },
177
+ })
178
+
179
+ console.log(result.scores)
180
+ ```
181
+
182
+ For more details on `runEvals`, see the [runEvals reference](https://mastra.ai/reference/evals/run-evals).
183
+
184
+ To add this scorer to an agent, see the [Scorers overview](https://mastra.ai/docs/evals/overview) guide.
185
+
186
+ ## Comparison with context precision
187
+
188
+ Choose the right scorer for your needs:
189
+
190
+ | Use case | Context Recall | Context Precision |
191
+ | ------------------------- | ------------------------ | ----------------------------- |
192
+ | **What it measures** | Coverage of ground truth | Relevance of retrieved chunks |
193
+ | **Direction** | Ground truth → context | Context → ground truth |
194
+ | **Position sensitive** | No | Yes (rewards early placement) |
195
+ | **Requires ground truth** | Yes | Yes |
196
+ | **Failure mode caught** | Missing information | Irrelevant noise |
197
+
198
+ Use both together for a complete picture of retrieval quality: precision catches junk in the context, recall catches gaps.
199
+
200
+ ## Related
201
+
202
+ - [Context Precision Scorer](https://mastra.ai/reference/evals/context-precision): Evaluates if retrieved context is relevant and well-ranked
203
+ - [Context Relevance Scorer](https://mastra.ai/reference/evals/context-relevance): Evaluates context usage and quality
204
+ - [Faithfulness Scorer](https://mastra.ai/reference/evals/faithfulness): Measures answer groundedness in context
205
+ - [Custom Scorers](https://mastra.ai/docs/evals/custom-scorers): Creating your own evaluation metrics
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Context relevance scorer
2
4
 
3
5
  The `createContextRelevanceScorerLLM()` function creates a scorer that evaluates how relevant and useful provided context was for generating agent responses. It uses weighted relevance levels and applies penalties for unused high-relevance context and missing information.
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Faithfulness scorer
2
4
 
3
5
  The `createFaithfulnessScorer()` function evaluates how factually accurate an LLM's output is compared to the provided context. It extracts claims from the output and verifies them against the context, making it essential to measure RAG pipeline responses' reliability.
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Hallucination scorer
2
4
 
3
5
  The `createHallucinationScorer()` function evaluates whether an LLM generates factually correct information by comparing its output against the provided context. This scorer measures hallucination by identifying direct contradictions between the context and the output.
@@ -155,6 +157,7 @@ const hallucinationScorer = createHallucinationScorer({
155
157
  })
156
158
 
157
159
  const agent = new Agent({
160
+ id: 'my-agent',
158
161
  name: 'my-agent',
159
162
  model: 'openai/gpt-5.5',
160
163
  instructions: 'You are a helpful assistant.',
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Keyword coverage scorer
2
4
 
3
5
  The `createKeywordCoverageScorer()` function evaluates how well an LLM's output covers the important keywords from the input. It analyzes keyword presence and matches while ignoring common words and stop words.
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Noise sensitivity scorer
2
4
 
3
5
  The `createNoiseSensitivityScorerLLM()` function creates a **CI/testing scorer** that evaluates how robust an agent is when exposed to irrelevant, distracting, or misleading information. Unlike live scorers that evaluate single production runs, this scorer requires predetermined test data including both baseline responses and noisy variations.
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Prompt alignment scorer
2
4
 
3
5
  The `createPromptAlignmentScorerLLM()` function creates a scorer that evaluates how well agent responses align with user prompts across multiple dimensions: intent understanding, requirement fulfillment, response completeness, and format appropriateness.
@@ -219,6 +221,7 @@ Measure how well your AI agents follow user instructions:
219
221
 
220
222
  ```typescript
221
223
  const agent = new Agent({
224
+ id: 'coding-assistant',
222
225
  name: 'CodingAssistant',
223
226
  instructions: 'You are a helpful coding assistant. Always provide working code examples.',
224
227
  model: 'openai/gpt-5.5',
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Rubric scorer
2
4
 
3
5
  **Added in:** `@mastra/evals@1.3.0`
@@ -10,7 +12,7 @@ This scorer is designed to drop into [`isTaskComplete`](https://mastra.ai/refere
10
12
 
11
13
  **model** (`MastraModelConfig`): The language model used to grade the output against the rubric. A smaller, cheaper model is usually sufficient for grading.
12
14
 
13
- **criteria** (`RubricCriterion[] | string`): The rubric to grade against. A string is treated as a newline-delimited checklist (each line becomes a required criterion). If omitted, the rubric is read at run time from a \`rubric\` value on request/additional context; if none resolves, the scorer is a no-op and returns 1.
15
+ **criteria** (`RubricCriterion[] | string`): The rubric to grade against. A string is treated as a newline-delimited checklist (each line becomes a required criterion). If omitted, the rubric is read at run time from a rubric value on request/additional context; if none resolves, the scorer is a no-op and returns 1.
14
16
 
15
17
  **options** (`RubricScorerOptions`): Configuration options for the scorer
16
18
 
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Scorer utils
2
4
 
3
5
  Mastra provides utility functions to help extract and process data from scorer run inputs and outputs. These utilities are particularly useful in the `preprocess` step of custom scorers.
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Textual difference scorer
2
4
 
3
5
  The `createTextualDifferenceScorer()` function uses sequence matching to measure the textual differences between two strings. It provides detailed information about changes, including the number of operations needed to transform one text into another.
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Tone consistency scorer
2
4
 
3
5
  The `createToneScorer()` function evaluates the text's emotional tone and sentiment consistency. It can operate in two modes: comparing tone between input/output pairs or analyzing tone stability within a single text.
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Tool call accuracy scorers
2
4
 
3
5
  Mastra provides two tool call accuracy scorers for evaluating whether an LLM selects the correct tools from available options:
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Toxicity scorer
2
4
 
3
5
  The `createToxicityScorer()` function evaluates whether an LLM's output contains racist, biased, or toxic elements. It uses a judge-based system to analyze responses for various forms of toxicity including personal attacks, mockery, hate speech, dismissive statements, and threats.
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Trajectory accuracy scorers
2
4
 
3
5
  Mastra provides two trajectory accuracy scorers for evaluating whether an agent or workflow follows an expected sequence of actions:
@@ -111,7 +113,7 @@ Omit `stepType` entirely to match any step by name only.
111
113
 
112
114
  **stepType** (`TrajectoryStepType`): Step type discriminant. When set, enables autocomplete for that variant's fields. If omitted, matches any step type with the given name.
113
115
 
114
- **(variant fields)** (`varies`): Type-specific fields from the corresponding TrajectoryStep variant. For example, \`toolArgs\` and \`toolResult\` for \`tool\_call\`, \`modelId\` for \`model\_generation\`, \`output\` for \`workflow\_step\`. All optional — only specified fields are compared.
116
+ **(variant fields)** (`varies`): Type-specific fields from the corresponding TrajectoryStep variant. For example, toolArgs and toolResult for tool\_call, modelId for model\_generation, output for workflow\_step. All optional — only specified fields are compared.
115
117
 
116
118
  **children** (`TrajectoryExpectation`): Nested expectation config for this step's children. Overrides the parent config for evaluating children of this step.
117
119
 
@@ -0,0 +1,20 @@
1
+ import type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/evals';
2
+ import type { MastraModelConfig } from '@mastra/core/llm';
3
+ import type { ScorerRunInputForLLMJudge, ScorerRunOutputForLLMJudge } from '../../utils.js';
4
+ export interface ContextRecallMetricOptions {
5
+ scale?: number;
6
+ context?: string[];
7
+ contextExtractor?: (input: ScorerRunInputForAgent, output: ScorerRunOutputForAgent) => string[];
8
+ }
9
+ export declare function createContextRecallScorer({ model, options, }: {
10
+ model: MastraModelConfig;
11
+ options: ContextRecallMetricOptions;
12
+ }): import("@mastra/core/evals").MastraScorer<string, ScorerRunInputForLLMJudge, ScorerRunOutputForLLMJudge, Record<"preprocessStepResult", {
13
+ claims: string[];
14
+ }> & Record<"analyzeStepResult", {
15
+ verdicts: {
16
+ verdict: string;
17
+ reason: string;
18
+ }[];
19
+ }> & Record<"generateScoreStepResult", number> & Record<"generateReasonStepResult", string>>;
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/scorers/llm/context-recall/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC1F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,OAAO,KAAK,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAQzF,MAAM,WAAW,0BAA0B;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,EAAE,MAAM,EAAE,uBAAuB,KAAK,MAAM,EAAE,CAAC;CACjG;AAmCD,wBAAgB,yBAAyB,CAAC,EACxC,KAAK,EACL,OAAO,GACR,EAAE;IACD,KAAK,EAAE,iBAAiB,CAAC;IACzB,OAAO,EAAE,0BAA0B,CAAC;CACrC;;;;;;;6FAkFA"}