@mastra/evals 1.10.11 → 1.10.12-alpha.1
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.
- package/dist/checks-CVR2yDHg.cjs +0 -2
- package/dist/checks-DXG9awTJ.js +0 -2
- package/dist/docs/SKILL.md +4 -5
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-evals-built-in-scorers.md +1 -1
- package/dist/docs/references/docs-evals-overview.md +5 -1
- package/dist/docs/references/docs-evals-quick-checks.md +1 -1
- package/dist/docs/references/docs-guides-build-an-eval-loop.md +1 -1
- package/dist/docs/references/reference-evals-answer-relevancy.md +2 -2
- package/dist/docs/references/reference-evals-bias.md +2 -2
- package/dist/docs/references/reference-evals-checks.md +1 -1
- package/dist/docs/references/reference-evals-completeness.md +4 -5
- package/dist/docs/references/reference-evals-content-similarity.md +6 -8
- package/dist/docs/references/reference-evals-context-precision.md +6 -6
- package/dist/docs/references/reference-evals-context-recall.md +1 -1
- package/dist/docs/references/reference-evals-context-relevance.md +9 -9
- package/dist/docs/references/reference-evals-faithfulness.md +2 -2
- package/dist/docs/references/reference-evals-hallucination.md +8 -8
- package/dist/docs/references/reference-evals-keyword-coverage.md +2 -2
- package/dist/docs/references/reference-evals-multi-turn-judge.md +3 -3
- package/dist/docs/references/reference-evals-noise-sensitivity.md +25 -18
- package/dist/docs/references/reference-evals-prompt-alignment.md +25 -25
- package/dist/docs/references/reference-evals-scorer-utils.md +1 -1
- package/dist/docs/references/reference-evals-summarization.md +1 -1
- package/dist/docs/references/reference-evals-textual-difference.md +2 -2
- package/dist/docs/references/reference-evals-tone-consistency.md +2 -2
- package/dist/docs/references/reference-evals-tool-call-accuracy.md +11 -11
- package/dist/docs/references/reference-evals-toxicity.md +2 -2
- package/dist/docs/references/reference-evals-trajectory-accuracy.md +2 -2
- package/dist/index.cjs +0 -2
- package/dist/index.js +0 -2
- package/dist/matchers-CL0xCK25.cjs +0 -2
- package/dist/matchers-CVIJYGVp.js +0 -2
- package/dist/scorers/prebuilt/index.cjs +33 -17
- package/dist/scorers/prebuilt/index.js +32 -16
- package/dist/scorers/utils.cjs +13 -29
- package/dist/scorers/utils.js +13 -29
- package/dist/vitest/index.cjs +0 -2
- package/dist/vitest/index.js +0 -2
- package/dist/vitest/setup.cjs +0 -2
- package/dist/vitest/setup.js +0 -2
- package/package.json +10 -9
- package/dist/checks-CVR2yDHg.cjs.map +0 -1
- package/dist/checks-DXG9awTJ.js.map +0 -1
- package/dist/checks.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/docs/references/reference-migrations-upgrade-to-v1-evals.md +0 -243
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/matchers-CL0xCK25.cjs.map +0 -1
- package/dist/matchers-CVIJYGVp.js.map +0 -1
- package/dist/scorers/code/checks/index.d.ts.map +0 -1
- package/dist/scorers/code/completeness/index.d.ts.map +0 -1
- package/dist/scorers/code/content-similarity/index.d.ts.map +0 -1
- package/dist/scorers/code/index.d.ts.map +0 -1
- package/dist/scorers/code/keyword-coverage/index.d.ts.map +0 -1
- package/dist/scorers/code/textual-difference/index.d.ts.map +0 -1
- package/dist/scorers/code/tone/index.d.ts.map +0 -1
- package/dist/scorers/code/tool-call-accuracy/index.d.ts.map +0 -1
- package/dist/scorers/code/trajectory/index.d.ts.map +0 -1
- package/dist/scorers/index.d.ts.map +0 -1
- package/dist/scorers/llm/answer-relevancy/index.d.ts.map +0 -1
- package/dist/scorers/llm/answer-relevancy/prompts.d.ts.map +0 -1
- package/dist/scorers/llm/answer-similarity/index.d.ts.map +0 -1
- package/dist/scorers/llm/answer-similarity/prompts.d.ts.map +0 -1
- package/dist/scorers/llm/bias/index.d.ts.map +0 -1
- package/dist/scorers/llm/bias/prompts.d.ts.map +0 -1
- package/dist/scorers/llm/context-precision/index.d.ts.map +0 -1
- package/dist/scorers/llm/context-precision/prompts.d.ts.map +0 -1
- package/dist/scorers/llm/context-recall/index.d.ts.map +0 -1
- package/dist/scorers/llm/context-recall/prompts.d.ts.map +0 -1
- package/dist/scorers/llm/context-relevance/index.d.ts.map +0 -1
- package/dist/scorers/llm/context-relevance/prompts.d.ts.map +0 -1
- package/dist/scorers/llm/faithfulness/index.d.ts.map +0 -1
- package/dist/scorers/llm/faithfulness/prompts.d.ts.map +0 -1
- package/dist/scorers/llm/hallucination/index.d.ts.map +0 -1
- package/dist/scorers/llm/hallucination/prompts.d.ts.map +0 -1
- package/dist/scorers/llm/index.d.ts.map +0 -1
- package/dist/scorers/llm/multi-turn-judge/index.d.ts.map +0 -1
- package/dist/scorers/llm/multi-turn-judge/prompts.d.ts.map +0 -1
- package/dist/scorers/llm/noise-sensitivity/index.d.ts.map +0 -1
- package/dist/scorers/llm/noise-sensitivity/prompts.d.ts.map +0 -1
- package/dist/scorers/llm/prompt-alignment/index.d.ts.map +0 -1
- package/dist/scorers/llm/prompt-alignment/prompts.d.ts.map +0 -1
- package/dist/scorers/llm/rubric/index.d.ts.map +0 -1
- package/dist/scorers/llm/rubric/prompts.d.ts.map +0 -1
- package/dist/scorers/llm/summarization/index.d.ts.map +0 -1
- package/dist/scorers/llm/summarization/prompts.d.ts.map +0 -1
- package/dist/scorers/llm/tool-call-accuracy/index.d.ts.map +0 -1
- package/dist/scorers/llm/tool-call-accuracy/prompts.d.ts.map +0 -1
- package/dist/scorers/llm/toxicity/index.d.ts.map +0 -1
- package/dist/scorers/llm/toxicity/prompts.d.ts.map +0 -1
- package/dist/scorers/llm/trajectory/index.d.ts.map +0 -1
- package/dist/scorers/llm/trajectory/prompts.d.ts.map +0 -1
- package/dist/scorers/prebuilt/index.cjs.map +0 -1
- package/dist/scorers/prebuilt/index.d.ts.map +0 -1
- package/dist/scorers/prebuilt/index.js.map +0 -1
- package/dist/scorers/utils.cjs.map +0 -1
- package/dist/scorers/utils.d.ts.map +0 -1
- package/dist/scorers/utils.js.map +0 -1
- package/dist/vitest/expect-evals.d.ts.map +0 -1
- package/dist/vitest/index.cjs.map +0 -1
- package/dist/vitest/index.d.ts.map +0 -1
- package/dist/vitest/index.js.map +0 -1
- package/dist/vitest/matchers.d.ts.map +0 -1
- package/dist/vitest/meta.d.ts.map +0 -1
- package/dist/vitest/reporter.d.ts.map +0 -1
- package/dist/vitest/setup.cjs.map +0 -1
- package/dist/vitest/setup.d.ts.map +0 -1
- package/dist/vitest/setup.js.map +0 -1
package/dist/checks-CVR2yDHg.cjs
CHANGED
package/dist/checks-DXG9awTJ.js
CHANGED
|
@@ -387,5 +387,3 @@ const checks = {
|
|
|
387
387
|
noToolErrors
|
|
388
388
|
};
|
|
389
389
|
export { excludes as a, maxToolCalls as c, toolOrder as d, usedNoTools as f, equals as i, noToolErrors as l, checks as n, includes as o, didNotCall as r, matches as s, calledTool as t, similarity as u };
|
|
390
|
-
|
|
391
|
-
//# sourceMappingURL=checks-DXG9awTJ.js.map
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -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.10.
|
|
6
|
+
version: "1.10.12-alpha.1"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -26,10 +26,10 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
26
26
|
|
|
27
27
|
- [Reference: Answer relevancy scorer](references/reference-evals-answer-relevancy.md) - Use createAnswerRelevancyScorer() to evaluate how directly an LLM response addresses the input query, with configurable model and scoring options.
|
|
28
28
|
- [Reference: Answer similarity scorer](references/reference-evals-answer-similarity.md) - The createAnswerSimilarityScorer() function creates a scorer that evaluates how similar an agent's output is to a ground truth answer.
|
|
29
|
-
- [Reference: Bias scorer](references/reference-evals-bias.md) - Use createBiasScorer() to evaluate LLM output for gender, political, racial
|
|
29
|
+
- [Reference: Bias scorer](references/reference-evals-bias.md) - Use createBiasScorer() to evaluate LLM output for gender, political, racial or ethnic, and geographic bias with an LLM judge.
|
|
30
30
|
- [Reference: Quick Checks](references/reference-evals-checks.md) - Use Mastra Quick Checks as zero-LLM, composable micro-scorers for text matching, tool usage, tool ordering, latency, and other deterministic assertions.
|
|
31
|
-
- [Reference: Completeness scorer](references/reference-evals-completeness.md) - The createCompletenessScorer() function evaluates how
|
|
32
|
-
- [Reference: Content similarity scorer](references/reference-evals-content-similarity.md) - The createContentSimilarityScorer() function measures the textual similarity between two strings, providing a score that indicates how
|
|
31
|
+
- [Reference: Completeness scorer](references/reference-evals-completeness.md) - The createCompletenessScorer() function evaluates how well an LLM's output covers the key elements present in the input.
|
|
32
|
+
- [Reference: Content similarity scorer](references/reference-evals-content-similarity.md) - The createContentSimilarityScorer() function measures the textual similarity between two strings, providing a score that indicates how similar they are.
|
|
33
33
|
- [Reference: Context precision scorer](references/reference-evals-context-precision.md) - The createContextPrecisionScorer() function creates a scorer that evaluates how relevant and well-positioned retrieved context pieces are for generating expected outputs.
|
|
34
34
|
- [Reference: Context recall scorer](references/reference-evals-context-recall.md) - The createContextRecallScorer() function creates a scorer that evaluates how well retrieved context covers the claims in a ground-truth reference answer.
|
|
35
35
|
- [Reference: Context relevance scorer](references/reference-evals-context-relevance.md) - The createContextRelevanceScorerLLM() function creates a scorer that evaluates how relevant and useful provided context was for generating agent responses.
|
|
@@ -47,7 +47,6 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
47
47
|
- [Reference: Tool call accuracy scorers](references/reference-evals-tool-call-accuracy.md) - Use tool-call accuracy scorers to evaluate whether an LLM selected the expected tools, either from recorded calls or against available tool definitions.
|
|
48
48
|
- [Reference: Toxicity scorer](references/reference-evals-toxicity.md) - The createToxicityScorer() function evaluates whether an LLM's output contains racist, biased, or toxic elements.
|
|
49
49
|
- [Reference: Trajectory accuracy scorers](references/reference-evals-trajectory-accuracy.md) - Use trajectory accuracy scorers to compare an agent or workflow's tool and step sequence with an expected execution path or ordered trajectory.
|
|
50
|
-
- [Evals and scorers](references/reference-migrations-upgrade-to-v1-evals.md) - The evaluation API has been consolidated on the new scorers system with updated naming conventions and configuration requirements.
|
|
51
50
|
|
|
52
51
|
|
|
53
52
|
Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
|
|
@@ -52,7 +52,7 @@ These scorers evaluate adherence to format, style, and safety requirements:
|
|
|
52
52
|
- [`bias`](https://mastra.ai/reference/evals/bias): Detects potential biases in the output (`0-1`, lower is better)
|
|
53
53
|
- [`keyword-coverage`](https://mastra.ai/reference/evals/keyword-coverage): Assesses technical terminology usage (`0-1`, higher is better)
|
|
54
54
|
|
|
55
|
-
### Quick
|
|
55
|
+
### Quick checks
|
|
56
56
|
|
|
57
57
|
Zero-LLM micro-scorers for fast, deterministic assertions. See the [Quick Checks](https://mastra.ai/docs/evals/quick-checks) guide for usage details.
|
|
58
58
|
|
|
@@ -10,6 +10,8 @@ Scorers are automated tests that evaluate Agents outputs using model-graded, rul
|
|
|
10
10
|
|
|
11
11
|
Scorers can run in the cloud to capture real-time results. Scorers can also be part of your CI/CD pipeline for testing and monitoring agents over time.
|
|
12
12
|
|
|
13
|
+
Scorers measure a single output. To improve an agent over time, combine them with [datasets](https://mastra.ai/docs/evals/datasets), which store versioned test cases, and [experiments](https://mastra.ai/docs/evals/experiments), which run an agent or workflow against a dataset, optionally score each result, and keep the results for comparison. [Build an eval loop](https://mastra.ai/docs/guides/build-an-eval-loop) walks through using them together.
|
|
14
|
+
|
|
13
15
|
> **📹 Watch:** Watch [Mastra evals overview](https://www.youtube.com/watch?v=12WN6u2DrBk) for an introduction to evals and how to reason about agent quality.
|
|
14
16
|
|
|
15
17
|
## Types of scorers
|
|
@@ -214,12 +216,14 @@ const mastra = new Mastra({
|
|
|
214
216
|
Once registered, you can score traces interactively within Studio under the **Observability** section. Open Studio to manage scorers and review scores, plus run experiments.
|
|
215
217
|
|
|
216
218
|
- **Scorers list**: Browse all registered scorers with their description, and the number of agents and workflows each scorer is attached to.
|
|
217
|
-
- **Score results**: Select a scorer to see a paginated list of every score it has produced.
|
|
219
|
+
- **Score results**: Select a scorer to see a paginated list of every score it has produced. Select a row to open the detail panel, which shows the score value, reason, input, output, and the prompts used by the judge. From this panel, save any result as a dataset item for future experiments.
|
|
218
220
|
- **Agent Evaluate tab**: Open the Evaluate tab on any agent to manage scorers and datasets. You can also run experiments there. Experiment results display per-item scores alongside pass/fail status and version tags.
|
|
219
221
|
- **Trace scoring**: In the Observability section, run a scorer against any historical trace or span to evaluate past interactions. Filter scores by agent or workflow.
|
|
220
222
|
|
|
221
223
|
## Next steps
|
|
222
224
|
|
|
225
|
+
- Follow [Build an eval loop](https://mastra.ai/docs/guides/build-an-eval-loop) to compare agent changes with datasets, scorers, and experiments
|
|
226
|
+
- Store test cases in [datasets](https://mastra.ai/docs/evals/datasets) and run them with [experiments](https://mastra.ai/docs/evals/experiments)
|
|
223
227
|
- Use [Quick Checks](https://mastra.ai/docs/evals/quick-checks) for fast, deterministic assertions on text and tool usage
|
|
224
228
|
- Add [gates and verdicts](https://mastra.ai/docs/evals/gates-and-verdicts) to enforce hard requirements and quality thresholds
|
|
225
229
|
- Test [multi-turn conversations](https://mastra.ai/docs/evals/multi-turn) where behavior emerges across sequential turns
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
Quick Checks are composable micro-scorers for common assertions like "output contains X" or "agent called tool Y." They run instantly without an LLM and plug into the same `scorers: [...]` array as any other scorer.
|
|
8
8
|
|
|
9
|
-
## When to use
|
|
9
|
+
## When to use quick checks
|
|
10
10
|
|
|
11
11
|
Use Quick Checks when you need fast, deterministic assertions:
|
|
12
12
|
|
|
@@ -171,7 +171,7 @@ export const refundCorrectnessScorer = createScorer({
|
|
|
171
171
|
description: 'Checks an answer against the test case’s expected outcome.',
|
|
172
172
|
type: 'agent',
|
|
173
173
|
judge: {
|
|
174
|
-
model: 'anthropic/claude-sonnet-5
|
|
174
|
+
model: 'anthropic/claude-sonnet-5.5',
|
|
175
175
|
instructions: `
|
|
176
176
|
Evaluate correctness against the supplied ground truth.
|
|
177
177
|
Pass only if every "must" criterion is satisfied and no "mustNot"
|
|
@@ -40,7 +40,7 @@ This function returns an instance of the MastraScorer class. The `.run()` method
|
|
|
40
40
|
|
|
41
41
|
The scorer evaluates relevancy through query-answer alignment, considering completeness and detail level, but not factual correctness.
|
|
42
42
|
|
|
43
|
-
### Scoring
|
|
43
|
+
### Scoring process
|
|
44
44
|
|
|
45
45
|
1. **Statement Preprocess:**
|
|
46
46
|
- Breaks output into useful statements while preserving context.
|
|
@@ -56,7 +56,7 @@ The scorer evaluates relevancy through query-answer alignment, considering compl
|
|
|
56
56
|
3. **Score Calculation:**
|
|
57
57
|
- `((direct + uncertainty * partial) / total_statements) * scale`
|
|
58
58
|
|
|
59
|
-
### Score
|
|
59
|
+
### Score interpretation
|
|
60
60
|
|
|
61
61
|
A relevancy score between 0 and `scale` (0 to 1 with the default scale). The ranges below assume the default scale:
|
|
62
62
|
|
|
@@ -53,7 +53,7 @@ The scorer evaluates bias through opinion analysis based on:
|
|
|
53
53
|
- Balance in perspective presentation
|
|
54
54
|
- Loaded or prejudicial terminology
|
|
55
55
|
|
|
56
|
-
### Scoring
|
|
56
|
+
### Scoring process
|
|
57
57
|
|
|
58
58
|
1. Extracts opinions from text:
|
|
59
59
|
|
|
@@ -77,7 +77,7 @@ A bias score between 0 and `scale` (0 to 1 with the default scale). The ranges b
|
|
|
77
77
|
- **0.7 to 0.9**: Includes strong prejudiced assumptions or generalizations.
|
|
78
78
|
- **0.4 to 0.6**: Mixes reasonable points with subtle bias or stereotypes.
|
|
79
79
|
- **0.1 to 0.3**: Mostly neutral with minor biased language or assumptions.
|
|
80
|
-
- **0.0**:
|
|
80
|
+
- **0.0**: Fully objective and free from bias.
|
|
81
81
|
|
|
82
82
|
## Example
|
|
83
83
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
4
4
|
|
|
5
|
-
# Quick
|
|
5
|
+
# Quick checks
|
|
6
6
|
|
|
7
7
|
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.
|
|
8
8
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
# Completeness scorer
|
|
6
6
|
|
|
7
|
-
The `createCompletenessScorer()` function evaluates how
|
|
7
|
+
The `createCompletenessScorer()` function evaluates how well 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.
|
|
8
8
|
|
|
9
9
|
## Parameters
|
|
10
10
|
|
|
@@ -47,7 +47,6 @@ The scorer extracts and analyzes several types of elements:
|
|
|
47
47
|
The extraction process includes:
|
|
48
48
|
|
|
49
49
|
- Normalization of text (removing diacritics, converting to lowercase)
|
|
50
|
-
- Splitting camelCase words
|
|
51
50
|
- Handling of word boundaries
|
|
52
51
|
- Special handling of short words (3 characters or less)
|
|
53
52
|
- Deduplication of elements
|
|
@@ -65,7 +64,7 @@ From the `.run()` method, you can get the `preprocessStepResult` object with the
|
|
|
65
64
|
|
|
66
65
|
The scorer evaluates completeness through linguistic element coverage analysis.
|
|
67
66
|
|
|
68
|
-
### Scoring
|
|
67
|
+
### Scoring process
|
|
69
68
|
|
|
70
69
|
1. Extracts key elements:
|
|
71
70
|
|
|
@@ -90,8 +89,8 @@ The completeness scorer has no `scale` option. The score is always between 0 and
|
|
|
90
89
|
A completeness score between 0 and 1:
|
|
91
90
|
|
|
92
91
|
- **1.0**: Addresses all aspects of the query in detail.
|
|
93
|
-
- **0.7 to 0.9**: Covers most important
|
|
94
|
-
- **0.4 to 0.6**: Addresses some key points but
|
|
92
|
+
- **0.7 to 0.9**: Covers most of the important points with good detail, minor gaps.
|
|
93
|
+
- **0.4 to 0.6**: Addresses some key points but misses important points or lacks detail.
|
|
95
94
|
- **0.1 to 0.3**: Only partially addresses the query with substantial gaps.
|
|
96
95
|
- **0.0**: Fails to address the query or provides irrelevant information.
|
|
97
96
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
# Content similarity scorer
|
|
6
6
|
|
|
7
|
-
The `createContentSimilarityScorer()` function measures the textual similarity between two strings, providing a score that indicates how
|
|
7
|
+
The `createContentSimilarityScorer()` function measures the textual similarity between two strings, providing a score that indicates how similar they are. It supports configurable options for case sensitivity and whitespace handling.
|
|
8
8
|
|
|
9
9
|
## Parameters
|
|
10
10
|
|
|
@@ -12,25 +12,23 @@ The `createContentSimilarityScorer()` function accepts a single options object w
|
|
|
12
12
|
|
|
13
13
|
**ignoreCase** (`boolean`): Whether to ignore case differences when comparing strings. Defaults to true only when no options object is passed. If you pass an options object, an omitted value is treated as false. (Default: `true`)
|
|
14
14
|
|
|
15
|
-
**ignoreWhitespace** (`boolean`): Whether to normalize whitespace when comparing strings.
|
|
15
|
+
**ignoreWhitespace** (`boolean`): Whether to normalize whitespace when comparing strings. When false, whitespace characters count in the comparison. (Default: `true`)
|
|
16
16
|
|
|
17
17
|
This function returns an instance of the MastraScorer class. See the [MastraScorer reference](https://mastra.ai/reference/evals/mastra-scorer) for details on the `.run()` method and its input/output.
|
|
18
18
|
|
|
19
19
|
## `.run()` returns
|
|
20
20
|
|
|
21
|
-
**runId** (`string`): The id of the run
|
|
21
|
+
**runId** (`string`): The id of the run.
|
|
22
22
|
|
|
23
23
|
**preprocessStepResult** (`object`): Object with processed input and output: { processedInput: string, processedOutput: string }
|
|
24
24
|
|
|
25
|
-
**analyzeStepResult** (`object`): Object with similarity: { similarity: number }
|
|
26
|
-
|
|
27
25
|
**score** (`number`): Similarity score (0-1) where 1 indicates perfect similarity.
|
|
28
26
|
|
|
29
27
|
## Scoring details
|
|
30
28
|
|
|
31
29
|
The scorer evaluates textual similarity through character-level matching and configurable text normalization.
|
|
32
30
|
|
|
33
|
-
### Scoring
|
|
31
|
+
### Scoring process
|
|
34
32
|
|
|
35
33
|
1. Normalizes text:
|
|
36
34
|
|
|
@@ -91,11 +89,11 @@ To add this scorer to an agent, see the [Scorers overview](https://mastra.ai/doc
|
|
|
91
89
|
|
|
92
90
|
A similarity score between 0 and 1:
|
|
93
91
|
|
|
94
|
-
- **1.0**: Perfect match, content is
|
|
92
|
+
- **1.0**: Perfect match, content is identical in substance.
|
|
95
93
|
- **0.7 to 0.9**: High similarity, minor differences in word choice or structure.
|
|
96
94
|
- **0.4 to 0.6**: Moderate similarity, general overlap with noticeable variation.
|
|
97
95
|
- **0.1 to 0.3**: Low similarity, few common elements or shared meaning.
|
|
98
|
-
- **0.0**: No similarity,
|
|
96
|
+
- **0.0**: No similarity, unrelated content.
|
|
99
97
|
|
|
100
98
|
## Related
|
|
101
99
|
|
|
@@ -42,7 +42,7 @@ If you pass `context`, the array must be non-empty. The constructor throws `Cont
|
|
|
42
42
|
|
|
43
43
|
## Scoring details
|
|
44
44
|
|
|
45
|
-
### Mean
|
|
45
|
+
### Mean average precision (MAP)
|
|
46
46
|
|
|
47
47
|
Context Precision uses **Mean Average Precision** to evaluate both relevance and positioning:
|
|
48
48
|
|
|
@@ -51,7 +51,7 @@ Context Precision uses **Mean Average Precision** to evaluate both relevance and
|
|
|
51
51
|
3. **Average Precision**: Sum all precision values and divide by total relevant items
|
|
52
52
|
4. **Final Score**: Multiply by scale factor and round to 2 decimals
|
|
53
53
|
|
|
54
|
-
### Scoring
|
|
54
|
+
### Scoring formula
|
|
55
55
|
|
|
56
56
|
```text
|
|
57
57
|
MAP = (Σ Precision@k) / R
|
|
@@ -62,12 +62,12 @@ Where:
|
|
|
62
62
|
- Only calculated at positions where relevant items appear
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
### Score
|
|
65
|
+
### Score interpretation
|
|
66
66
|
|
|
67
|
-
- **0.9-1.0**:
|
|
67
|
+
- **0.9-1.0**: High precision - all relevant context early in sequence
|
|
68
68
|
- **0.7-0.8**: Good precision - most relevant context well-positioned
|
|
69
69
|
- **0.4-0.6**: Moderate precision - relevant context mixed with irrelevant
|
|
70
|
-
- **0.1-0.3**: Poor precision - little relevant context or
|
|
70
|
+
- **0.1-0.3**: Poor precision - little relevant context or badly positioned
|
|
71
71
|
- **0.0**: No relevant context found
|
|
72
72
|
|
|
73
73
|
### Reason analysis
|
|
@@ -87,7 +87,7 @@ Use results to:
|
|
|
87
87
|
- **Tune chunk size**: Balance context detail vs. relevance precision
|
|
88
88
|
- **Evaluate embeddings**: Test different embedding models for better retrieval
|
|
89
89
|
|
|
90
|
-
### Example
|
|
90
|
+
### Example calculation
|
|
91
91
|
|
|
92
92
|
context: `[relevant, irrelevant, relevant, irrelevant]`
|
|
93
93
|
|
|
@@ -64,7 +64,7 @@ Where:
|
|
|
64
64
|
|
|
65
65
|
These ranges assume the default `scale` of 1. When using a custom scale, multiply accordingly.
|
|
66
66
|
|
|
67
|
-
- **0.9-1.0**:
|
|
67
|
+
- **0.9-1.0**: High recall, context covers almost all ground-truth claims
|
|
68
68
|
- **0.7-0.8**: Good recall. Most claims are covered, with minor gaps
|
|
69
69
|
- **0.4-0.6**: Moderate recall, substantial information missing from context
|
|
70
70
|
- **0.1-0.3**: Poor recall, most ground-truth claims not found in context
|
|
@@ -40,7 +40,7 @@ Note: Either `context` or `contextExtractor` must be provided. If both are provi
|
|
|
40
40
|
|
|
41
41
|
## Scoring details
|
|
42
42
|
|
|
43
|
-
### Weighted
|
|
43
|
+
### Weighted relevance scoring
|
|
44
44
|
|
|
45
45
|
Context Relevance uses a advanced scoring algorithm that considers:
|
|
46
46
|
|
|
@@ -49,7 +49,7 @@ Context Relevance uses a advanced scoring algorithm that considers:
|
|
|
49
49
|
- `high` = 1.0 (directly addresses the query)
|
|
50
50
|
- `medium` = 0.7 (supporting information)
|
|
51
51
|
- `low` = 0.3 (tangentially related)
|
|
52
|
-
- `none` = 0.0 (
|
|
52
|
+
- `none` = 0.0 (irrelevant)
|
|
53
53
|
|
|
54
54
|
2. **Usage Detection**: Tracks whether relevant context was actually used in the response
|
|
55
55
|
|
|
@@ -58,7 +58,7 @@ Context Relevance uses a advanced scoring algorithm that considers:
|
|
|
58
58
|
- **Unused High-Relevance**: `unusedHighRelevanceContext` penalty per unused high-relevance context (default: 0.1)
|
|
59
59
|
- **Missing Context**: Up to `maxMissingContextPenalty` for identified missing information (default: 0.5)
|
|
60
60
|
|
|
61
|
-
### Scoring
|
|
61
|
+
### Scoring formula
|
|
62
62
|
|
|
63
63
|
```text
|
|
64
64
|
Base Score = Σ(relevance_weights) / (num_contexts × 1.0)
|
|
@@ -77,11 +77,11 @@ Final Score = max(0, Base Score - Usage Penalty - Missing Penalty) × scale
|
|
|
77
77
|
|
|
78
78
|
### Score interpretation
|
|
79
79
|
|
|
80
|
-
- **0.9-1.0**:
|
|
80
|
+
- **0.9-1.0**: High - all context highly relevant and used
|
|
81
81
|
- **0.7-0.8**: Good - mostly relevant with minor gaps
|
|
82
82
|
- **0.4-0.6**: Mixed - substantial irrelevant or unused context
|
|
83
83
|
- **0.2-0.3**: Poor - mostly irrelevant context
|
|
84
|
-
- **0.0-0.1**:
|
|
84
|
+
- **0.0-0.1**: Low - no relevant context found
|
|
85
85
|
|
|
86
86
|
### Reason analysis
|
|
87
87
|
|
|
@@ -97,12 +97,12 @@ The reason field provides insights on:
|
|
|
97
97
|
Use results to improve your system:
|
|
98
98
|
|
|
99
99
|
- **Filter irrelevant context**: Remove low/none relevance pieces before processing
|
|
100
|
-
- **Ensure context usage**:
|
|
100
|
+
- **Ensure context usage**: Ensure high-relevance context is incorporated
|
|
101
101
|
- **Fill context gaps**: Add missing information identified by the scorer
|
|
102
102
|
- **Balance context size**: Find optimal amount of context for best relevance
|
|
103
103
|
- **Tune penalty sensitivity**: Adjust `unusedHighRelevanceContext`, `missingContextPerItem`, and `maxMissingContextPenalty` based on your application's tolerance for unused or missing context
|
|
104
104
|
|
|
105
|
-
### Difference from
|
|
105
|
+
### Difference from context precision
|
|
106
106
|
|
|
107
107
|
| Aspect | Context Relevance | Context Precision |
|
|
108
108
|
| ------------- | -------------------------------------- | ---------------------------------- |
|
|
@@ -183,7 +183,7 @@ console.log('Strict penalties:', strictResult.score) // Lower score due to unuse
|
|
|
183
183
|
console.log('Lenient penalties:', lenientResult.score) // Higher score, less penalty
|
|
184
184
|
```
|
|
185
185
|
|
|
186
|
-
### Dynamic
|
|
186
|
+
### Dynamic context extraction
|
|
187
187
|
|
|
188
188
|
```typescript
|
|
189
189
|
const scorer = createContextRelevanceScorerLLM({
|
|
@@ -246,7 +246,7 @@ const scorer = createContextRelevanceScorerLLM({
|
|
|
246
246
|
|
|
247
247
|
### High relevance example
|
|
248
248
|
|
|
249
|
-
This example shows
|
|
249
|
+
This example shows strong context relevance where all context directly supports the response:
|
|
250
250
|
|
|
251
251
|
```typescript
|
|
252
252
|
import { createContextRelevanceScorerLLM } from '@mastra/evals/scorers/prebuilt'
|
|
@@ -10,7 +10,7 @@ The `createFaithfulnessScorer()` function evaluates how factually accurate an LL
|
|
|
10
10
|
|
|
11
11
|
The `createFaithfulnessScorer()` function accepts a single options object with the following properties:
|
|
12
12
|
|
|
13
|
-
**model** (`
|
|
13
|
+
**model** (`MastraModelConfig`): Configuration for the model used to evaluate faithfulness.
|
|
14
14
|
|
|
15
15
|
**options** (`{ context?: string[]; scale?: number }`): Configuration options for the scorer.
|
|
16
16
|
|
|
@@ -42,7 +42,7 @@ This function returns an instance of the MastraScorer class. The `.run()` method
|
|
|
42
42
|
|
|
43
43
|
The scorer evaluates faithfulness through claim verification against provided context.
|
|
44
44
|
|
|
45
|
-
### Scoring
|
|
45
|
+
### Scoring process
|
|
46
46
|
|
|
47
47
|
1. Analyzes claims and context:
|
|
48
48
|
|
|
@@ -14,7 +14,7 @@ The `createHallucinationScorer()` function accepts a single options object with
|
|
|
14
14
|
|
|
15
15
|
**options** (`Options`): Configuration options.
|
|
16
16
|
|
|
17
|
-
**options.scale** (`number`): Maximum score value.
|
|
17
|
+
**options.scale** (`number`): Maximum score value. A value of 0 falls back to 1.
|
|
18
18
|
|
|
19
19
|
**options.context** (`string[]`): Static context strings to use as ground truth for hallucination detection.
|
|
20
20
|
|
|
@@ -44,7 +44,7 @@ This function returns an instance of the MastraScorer class. The `.run()` method
|
|
|
44
44
|
|
|
45
45
|
The scorer evaluates hallucination through contradiction detection and unsupported claim analysis.
|
|
46
46
|
|
|
47
|
-
### Scoring
|
|
47
|
+
### Scoring process
|
|
48
48
|
|
|
49
49
|
1. Extracts claims from the output:
|
|
50
50
|
|
|
@@ -65,9 +65,9 @@ The scorer evaluates hallucination through contradiction detection and unsupport
|
|
|
65
65
|
- Divides by total statements
|
|
66
66
|
- Scales to configured range
|
|
67
67
|
|
|
68
|
-
Final score: `min(1, hallucinated_statements / total_statements) * scale
|
|
68
|
+
Final score: `min(1, hallucinated_statements / total_statements) * (scale || 1)`, rounded to two decimal places, when `total_statements > 0`, otherwise `0`.
|
|
69
69
|
|
|
70
|
-
### Important
|
|
70
|
+
### Important considerations
|
|
71
71
|
|
|
72
72
|
- Claims not present in context are treated as hallucinations
|
|
73
73
|
|
|
@@ -99,7 +99,7 @@ The score represents the degree of hallucination - lower scores indicate better
|
|
|
99
99
|
|
|
100
100
|
## Examples
|
|
101
101
|
|
|
102
|
-
### Static
|
|
102
|
+
### Static context
|
|
103
103
|
|
|
104
104
|
Use static context when you have known ground truth to compare against:
|
|
105
105
|
|
|
@@ -118,7 +118,7 @@ const scorer = createHallucinationScorer({
|
|
|
118
118
|
})
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
### Dynamic
|
|
121
|
+
### Dynamic context with `getContext`
|
|
122
122
|
|
|
123
123
|
Use `getContext` for live scoring scenarios where context comes from tool results:
|
|
124
124
|
|
|
@@ -138,7 +138,7 @@ const scorer = createHallucinationScorer({
|
|
|
138
138
|
})
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
-
### Live
|
|
141
|
+
### Live scoring with agent
|
|
142
142
|
|
|
143
143
|
Attach the scorer to an agent for live evaluation:
|
|
144
144
|
|
|
@@ -168,7 +168,7 @@ const agent = new Agent({
|
|
|
168
168
|
})
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
-
### Batch
|
|
171
|
+
### Batch evaluation with `runEvals`
|
|
172
172
|
|
|
173
173
|
```typescript
|
|
174
174
|
import { runEvals } from '@mastra/core/evals'
|
|
@@ -48,7 +48,7 @@ The scorer evaluates keyword coverage by matching keywords with the following fe
|
|
|
48
48
|
- Word form variation handling
|
|
49
49
|
- Special handling of technical terms and compound words
|
|
50
50
|
|
|
51
|
-
### Scoring
|
|
51
|
+
### Scoring process
|
|
52
52
|
|
|
53
53
|
1. Processes keywords from input and output:
|
|
54
54
|
|
|
@@ -74,7 +74,7 @@ A coverage score between 0 and 1:
|
|
|
74
74
|
- **0.1 to 0.3**: Low coverage, few keywords matched.
|
|
75
75
|
- **0.0**: The response contains none of the keywords.
|
|
76
76
|
|
|
77
|
-
### Special
|
|
77
|
+
### Special cases
|
|
78
78
|
|
|
79
79
|
The scorer handles several special cases:
|
|
80
80
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
4
4
|
|
|
5
|
-
# Multi-turn
|
|
5
|
+
# Multi-turn judge scorer
|
|
6
6
|
|
|
7
7
|
**Added in:** `@mastra/evals@1.9.0`
|
|
8
8
|
|
|
@@ -49,7 +49,7 @@ const result = await runEvals({
|
|
|
49
49
|
scorers: [
|
|
50
50
|
{
|
|
51
51
|
scorer: createMultiTurnJudgeScorer({
|
|
52
|
-
model: 'anthropic/claude-haiku-5
|
|
52
|
+
model: 'anthropic/claude-haiku-5.5',
|
|
53
53
|
criterion:
|
|
54
54
|
'The agent provided weather forecasts for London, Paris, and Tokyo, and gave weather-appropriate packing or clothing advice.',
|
|
55
55
|
}),
|
|
@@ -75,7 +75,7 @@ export const mastra = new Mastra({
|
|
|
75
75
|
storage: new LibSQLStore({ url: 'file:./mastra.db' }),
|
|
76
76
|
scorers: {
|
|
77
77
|
'multi-turn-judge-scorer': createMultiTurnJudgeScorer({
|
|
78
|
-
model: 'anthropic/claude-haiku-5
|
|
78
|
+
model: 'anthropic/claude-haiku-5.5',
|
|
79
79
|
criterion: 'placeholder',
|
|
80
80
|
}),
|
|
81
81
|
},
|