@mastra/evals 1.6.0 → 1.7.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.
- package/CHANGELOG.md +58 -0
- package/dist/checks-64AonnEK.js +379 -0
- package/dist/checks-64AonnEK.js.map +1 -0
- package/dist/checks-DGTgg-nW.cjs +479 -0
- package/dist/checks-DGTgg-nW.cjs.map +1 -0
- package/dist/checks.cjs +14 -56
- package/dist/checks.js +2 -3
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-evals-built-in-scorers.md +4 -4
- package/dist/docs/references/docs-evals-overview.md +6 -4
- package/dist/docs/references/docs-evals-quick-checks.md +2 -2
- package/dist/docs/references/reference-evals-answer-relevancy.md +5 -5
- package/dist/docs/references/reference-evals-answer-similarity.md +1 -1
- package/dist/docs/references/reference-evals-bias.md +4 -4
- package/dist/docs/references/reference-evals-checks.md +3 -3
- package/dist/docs/references/reference-evals-completeness.md +5 -5
- package/dist/docs/references/reference-evals-content-similarity.md +5 -5
- package/dist/docs/references/reference-evals-context-precision.md +5 -5
- package/dist/docs/references/reference-evals-context-recall.md +11 -11
- package/dist/docs/references/reference-evals-context-relevance.md +15 -15
- package/dist/docs/references/reference-evals-faithfulness.md +4 -4
- package/dist/docs/references/reference-evals-hallucination.md +11 -11
- package/dist/docs/references/reference-evals-keyword-coverage.md +6 -6
- package/dist/docs/references/reference-evals-noise-sensitivity.md +15 -15
- package/dist/docs/references/reference-evals-prompt-alignment.md +20 -20
- package/dist/docs/references/reference-evals-rubric.md +2 -2
- package/dist/docs/references/reference-evals-scorer-utils.md +4 -4
- package/dist/docs/references/reference-evals-summarization.md +203 -0
- package/dist/docs/references/reference-evals-textual-difference.md +4 -4
- package/dist/docs/references/reference-evals-tool-call-accuracy.md +4 -4
- package/dist/docs/references/reference-evals-toxicity.md +5 -5
- package/dist/docs/references/reference-evals-trajectory-accuracy.md +10 -10
- package/dist/index.cjs +12 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/dist/scorers/llm/index.d.ts +1 -0
- package/dist/scorers/llm/index.d.ts.map +1 -1
- package/dist/scorers/llm/summarization/index.d.ts +55 -0
- package/dist/scorers/llm/summarization/index.d.ts.map +1 -0
- package/dist/scorers/llm/summarization/prompts.d.ts +48 -0
- package/dist/scorers/llm/summarization/prompts.d.ts.map +1 -0
- package/dist/scorers/prebuilt/index.cjs +2753 -2848
- package/dist/scorers/prebuilt/index.cjs.map +1 -1
- package/dist/scorers/prebuilt/index.js +2735 -2791
- package/dist/scorers/prebuilt/index.js.map +1 -1
- package/dist/scorers/utils.cjs +966 -101
- package/dist/scorers/utils.cjs.map +1 -1
- package/dist/scorers/utils.js +939 -2
- package/dist/scorers/utils.js.map +1 -1
- package/package.json +11 -10
- package/dist/checks.cjs.map +0 -1
- package/dist/checks.js.map +0 -1
- package/dist/chunk-GGHVFNVI.cjs +0 -233
- package/dist/chunk-GGHVFNVI.cjs.map +0 -1
- package/dist/chunk-IZLA36WC.cjs +0 -654
- package/dist/chunk-IZLA36WC.cjs.map +0 -1
- package/dist/chunk-UJ4WCQ3F.js +0 -626
- package/dist/chunk-UJ4WCQ3F.js.map +0 -1
- package/dist/chunk-WEADJCUA.js +0 -216
- package/dist/chunk-WEADJCUA.js.map +0 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Scorers overview
|
|
4
4
|
|
|
5
|
-
While traditional software tests have clear pass/fail conditions, AI outputs are non-deterministic
|
|
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
|
|
|
7
7
|
Scorers are automated tests that evaluate Agents outputs using model-graded, rule-based, and statistical methods. Scorers return **scores**: numerical values (typically between 0 and 1) that quantify how well an output meets your evaluation criteria. These scores enable you to objectively track performance, compare different approaches, and identify areas for improvement in your AI systems. Scorers can be customized with your own prompts and scoring functions.
|
|
8
8
|
|
|
@@ -114,7 +114,9 @@ export const contentWorkflow = createWorkflow({ ... })
|
|
|
114
114
|
|
|
115
115
|
## Trace evaluations
|
|
116
116
|
|
|
117
|
-
In addition to live evaluations, you can use scorers to evaluate historical traces from your agent interactions and workflows.
|
|
117
|
+
In addition to live evaluations, you can use scorers to evaluate historical traces from your agent interactions and workflows.
|
|
118
|
+
|
|
119
|
+
This is particularly useful for analyzing past performance or debugging issues, or alternatively running batch evaluations.
|
|
118
120
|
|
|
119
121
|
> **Observability required:** To score traces, you must first configure observability in your Mastra instance to collect trace data. See [Tracing documentation](https://mastra.ai/docs/observability/tracing/overview) for setup instructions.
|
|
120
122
|
|
|
@@ -131,11 +133,11 @@ const mastra = new Mastra({
|
|
|
131
133
|
})
|
|
132
134
|
```
|
|
133
135
|
|
|
134
|
-
Once registered, you can score traces interactively within Studio under the **Observability** section. Open Studio to manage scorers
|
|
136
|
+
Once registered, you can score traces interactively within Studio under the **Observability** section. Open Studio to manage scorers and review scores, plus run experiments.
|
|
135
137
|
|
|
136
138
|
- **Scorers list**: Browse all registered scorers with their description, and the number of agents and workflows each scorer is attached to.
|
|
137
139
|
- **Score results**: Select a scorer to see a paginated list of every score it has produced. Click 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.
|
|
138
|
-
- **Agent Evaluate tab**: Open the Evaluate tab on any agent to
|
|
140
|
+
- **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.
|
|
139
141
|
- **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.
|
|
140
142
|
|
|
141
143
|
## Next steps
|
|
@@ -35,7 +35,7 @@ console.log(result.scores)
|
|
|
35
35
|
|
|
36
36
|
## Available checks
|
|
37
37
|
|
|
38
|
-
Quick Checks fall into
|
|
38
|
+
Quick Checks fall into these categories:
|
|
39
39
|
|
|
40
40
|
### Text checks
|
|
41
41
|
|
|
@@ -105,7 +105,7 @@ export const weatherAgent = new Agent({
|
|
|
105
105
|
id: 'weather-agent',
|
|
106
106
|
name: 'Weather Agent',
|
|
107
107
|
instructions: 'Answer weather questions using the get_weather tool.',
|
|
108
|
-
model: 'openai/gpt-5.
|
|
108
|
+
model: 'openai/gpt-5.6-sol',
|
|
109
109
|
tools: { get_weather: weatherTool },
|
|
110
110
|
scorers: {
|
|
111
111
|
noErrors: {
|
|
@@ -39,7 +39,7 @@ The scorer evaluates relevancy through query-answer alignment, considering compl
|
|
|
39
39
|
### Scoring Process
|
|
40
40
|
|
|
41
41
|
1. **Statement Preprocess:**
|
|
42
|
-
- Breaks output into
|
|
42
|
+
- Breaks output into useful statements while preserving context.
|
|
43
43
|
|
|
44
44
|
2. **Relevance Analysis:**
|
|
45
45
|
|
|
@@ -57,9 +57,9 @@ The scorer evaluates relevancy through query-answer alignment, considering compl
|
|
|
57
57
|
A relevancy score between 0 and 1:
|
|
58
58
|
|
|
59
59
|
- **1.0**: The response fully answers the query with relevant and focused information.
|
|
60
|
-
- **0.7
|
|
61
|
-
- **0.4
|
|
62
|
-
- **0.1
|
|
60
|
+
- **0.7 to 0.9**: The response mostly answers the query but may include minor unrelated content.
|
|
61
|
+
- **0.4 to 0.6**: The response partially answers the query, mixing relevant and unrelated information.
|
|
62
|
+
- **0.1 to 0.3**: The response includes minimal relevant content and largely misses the intent of the query.
|
|
63
63
|
- **0.0**: The response is entirely unrelated and doesn't answer the query.
|
|
64
64
|
|
|
65
65
|
## Example
|
|
@@ -71,7 +71,7 @@ import { runEvals } from '@mastra/core/evals'
|
|
|
71
71
|
import { createAnswerRelevancyScorer } from '@mastra/evals/scorers/prebuilt'
|
|
72
72
|
import { myAgent } from './agent'
|
|
73
73
|
|
|
74
|
-
const scorer = createAnswerRelevancyScorer({ model: 'openai/gpt-5.
|
|
74
|
+
const scorer = createAnswerRelevancyScorer({ model: 'openai/gpt-5.6-sol' })
|
|
75
75
|
|
|
76
76
|
const result = await runEvals({
|
|
77
77
|
data: [
|
|
@@ -64,7 +64,7 @@ import { runEvals } from '@mastra/core/evals'
|
|
|
64
64
|
import { createAnswerSimilarityScorer } from '@mastra/evals/scorers/prebuilt'
|
|
65
65
|
import { myAgent } from './agent'
|
|
66
66
|
|
|
67
|
-
const scorer = createAnswerSimilarityScorer({ model: 'openai/gpt-5.
|
|
67
|
+
const scorer = createAnswerSimilarityScorer({ model: 'openai/gpt-5.6-sol' })
|
|
68
68
|
|
|
69
69
|
const result = await runEvals({
|
|
70
70
|
data: [
|
|
@@ -70,9 +70,9 @@ Final score: `(biased_opinions / total_opinions) * scale`
|
|
|
70
70
|
A bias score between 0 and 1:
|
|
71
71
|
|
|
72
72
|
- **1.0**: Contains explicit discriminatory or stereotypical statements.
|
|
73
|
-
- **0.7
|
|
74
|
-
- **0.4
|
|
75
|
-
- **0.1
|
|
73
|
+
- **0.7 to 0.9**: Includes strong prejudiced assumptions or generalizations.
|
|
74
|
+
- **0.4 to 0.6**: Mixes reasonable points with subtle bias or stereotypes.
|
|
75
|
+
- **0.1 to 0.3**: Mostly neutral with minor biased language or assumptions.
|
|
76
76
|
- **0.0**: Completely objective and free from bias.
|
|
77
77
|
|
|
78
78
|
## Example
|
|
@@ -84,7 +84,7 @@ import { runEvals } from '@mastra/core/evals'
|
|
|
84
84
|
import { createBiasScorer } from '@mastra/evals/scorers/prebuilt'
|
|
85
85
|
import { myAgent } from './agent'
|
|
86
86
|
|
|
87
|
-
const scorer = createBiasScorer({ model: 'openai/gpt-5.
|
|
87
|
+
const scorer = createBiasScorer({ model: 'openai/gpt-5.6-sol' })
|
|
88
88
|
|
|
89
89
|
const result = await runEvals({
|
|
90
90
|
data: [
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Quick Checks
|
|
4
4
|
|
|
5
|
-
Quick Checks are zero-LLM, composable micro-scorers for common assertions. They plug into the existing `scorers: [...]` array anywhere scorers are used
|
|
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.
|
|
6
6
|
|
|
7
7
|
Internally they're standard `createScorer()` instances, so they have the same observability, storage, and pipeline integration as any other scorer.
|
|
8
8
|
|
|
@@ -76,7 +76,7 @@ Returns: `1` if equal, `0` otherwise.
|
|
|
76
76
|
|
|
77
77
|
### `checks.matches(pattern, options?)`
|
|
78
78
|
|
|
79
|
-
Scores 1 if the output matches the
|
|
79
|
+
Scores 1 if the output matches the regular expression.
|
|
80
80
|
|
|
81
81
|
```typescript
|
|
82
82
|
checks.matches(/\d+°[FC]/)
|
|
@@ -137,7 +137,7 @@ Returns: `1` if the tool wasn't called, `0` otherwise.
|
|
|
137
137
|
|
|
138
138
|
### `checks.toolOrder(expectedOrder)`
|
|
139
139
|
|
|
140
|
-
Scores 1 if the tools were called in the specified order. Uses relaxed matching
|
|
140
|
+
Scores 1 if the tools were called in the specified order. Uses relaxed matching. Other tool calls between the expected tools are allowed.
|
|
141
141
|
|
|
142
142
|
```typescript
|
|
143
143
|
checks.toolOrder(['search', 'summarize', 'respond'])
|
|
@@ -40,7 +40,7 @@ The scorer extracts and analyzes several types of elements:
|
|
|
40
40
|
- Nouns: Key objects, concepts, and entities
|
|
41
41
|
- Verbs: Actions and states (converted to infinitive form)
|
|
42
42
|
- Topics: Main subjects and themes
|
|
43
|
-
- Terms: Individual
|
|
43
|
+
- Terms: Individual substantial words
|
|
44
44
|
|
|
45
45
|
The extraction process includes:
|
|
46
46
|
|
|
@@ -83,10 +83,10 @@ Final score: `(covered_elements / total_input_elements) * scale`
|
|
|
83
83
|
|
|
84
84
|
A completeness score between 0 and 1:
|
|
85
85
|
|
|
86
|
-
- **1.0**: Thoroughly addresses all aspects of the query with
|
|
87
|
-
- **0.7
|
|
88
|
-
- **0.4
|
|
89
|
-
- **0.1
|
|
86
|
+
- **1.0**: Thoroughly addresses all aspects of the query with detailed detail.
|
|
87
|
+
- **0.7 to 0.9**: Covers most important aspects with good detail, minor gaps.
|
|
88
|
+
- **0.4 to 0.6**: Addresses some key points but missing important aspects or lacking detail.
|
|
89
|
+
- **0.1 to 0.3**: Only partially addresses the query with substantial gaps.
|
|
90
90
|
- **0.0**: Fails to address the query or provides irrelevant information.
|
|
91
91
|
|
|
92
92
|
## Example
|
|
@@ -89,11 +89,11 @@ To add this scorer to an agent, see the [Scorers overview](https://mastra.ai/doc
|
|
|
89
89
|
|
|
90
90
|
A similarity score between 0 and 1:
|
|
91
91
|
|
|
92
|
-
- **1.0**: Perfect match
|
|
93
|
-
- **0.7
|
|
94
|
-
- **0.4
|
|
95
|
-
- **0.1
|
|
96
|
-
- **0.0**: No similarity
|
|
92
|
+
- **1.0**: Perfect match, content is nearly identical.
|
|
93
|
+
- **0.7 to 0.9**: High similarity, minor differences in word choice or structure.
|
|
94
|
+
- **0.4 to 0.6**: Moderate similarity, general overlap with noticeable variation.
|
|
95
|
+
- **0.1 to 0.3**: Low similarity, few common elements or shared meaning.
|
|
96
|
+
- **0.0**: No similarity, completely different content.
|
|
97
97
|
|
|
98
98
|
## Related
|
|
99
99
|
|
|
@@ -28,7 +28,7 @@ Use when optimizing context selection for:
|
|
|
28
28
|
|
|
29
29
|
**options** (`ContextPrecisionMetricOptions`): Configuration options for the scorer
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
Either `context` or `contextExtractor` must be provided. If both are provided, `contextExtractor` takes precedence.
|
|
32
32
|
|
|
33
33
|
## `.run()` returns
|
|
34
34
|
|
|
@@ -85,7 +85,7 @@ Use results to:
|
|
|
85
85
|
|
|
86
86
|
### Example Calculation
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
context: `[relevant, irrelevant, relevant, irrelevant]`
|
|
89
89
|
|
|
90
90
|
- Position 0: Relevant → Precision = 1/1 = 1.0
|
|
91
91
|
- Position 1: Skip (irrelevant)
|
|
@@ -100,7 +100,7 @@ MAP = (1.0 + 0.67) / 2 = 0.835 ≈ **0.83**
|
|
|
100
100
|
|
|
101
101
|
```typescript
|
|
102
102
|
const scorer = createContextPrecisionScorer({
|
|
103
|
-
model: 'openai/gpt-5.
|
|
103
|
+
model: 'openai/gpt-5.6-sol',
|
|
104
104
|
options: {
|
|
105
105
|
contextExtractor: (input, output) => {
|
|
106
106
|
// Extract context dynamically based on the query
|
|
@@ -119,7 +119,7 @@ const scorer = createContextPrecisionScorer({
|
|
|
119
119
|
|
|
120
120
|
```typescript
|
|
121
121
|
const scorer = createContextPrecisionScorer({
|
|
122
|
-
model: 'openai/gpt-5.
|
|
122
|
+
model: 'openai/gpt-5.6-sol',
|
|
123
123
|
options: {
|
|
124
124
|
context: [
|
|
125
125
|
// Simulate retrieved documents from vector database
|
|
@@ -144,7 +144,7 @@ import { createContextPrecisionScorer } from '@mastra/evals/scorers/prebuilt'
|
|
|
144
144
|
import { myAgent } from './agent'
|
|
145
145
|
|
|
146
146
|
const scorer = createContextPrecisionScorer({
|
|
147
|
-
model: 'openai/gpt-5.
|
|
147
|
+
model: 'openai/gpt-5.6-sol',
|
|
148
148
|
options: {
|
|
149
149
|
contextExtractor: (input, output) => {
|
|
150
150
|
// Extract context from agent's retrieved documents
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
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
6
|
|
|
7
|
-
This scorer requires a ground-truth reference answer, making it suitable for labeled datasets in CI or test environments. When `groundTruth`
|
|
7
|
+
This scorer requires a ground-truth reference answer, making it suitable for labeled datasets in CI or test environments. When `groundTruth` isn't provided in the run, the scorer returns a score of 0 rather than throwing an error.
|
|
8
8
|
|
|
9
9
|
## RAG retrieval evaluation
|
|
10
10
|
|
|
@@ -28,7 +28,7 @@ Use when running evaluations against curated test sets:
|
|
|
28
28
|
|
|
29
29
|
**options** (`ContextRecallMetricOptions`): Configuration options for the scorer
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
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
32
|
|
|
33
33
|
## `.run()` returns
|
|
34
34
|
|
|
@@ -62,11 +62,11 @@ Where:
|
|
|
62
62
|
|
|
63
63
|
These ranges assume the default `scale` of 1. When using a custom scale, multiply accordingly.
|
|
64
64
|
|
|
65
|
-
- **0.9-1.0**: Excellent recall
|
|
66
|
-
- **0.7-0.8**: Good recall
|
|
67
|
-
- **0.4-0.6**: Moderate recall
|
|
68
|
-
- **0.1-0.3**: Poor recall
|
|
69
|
-
- **0.0**: No recall
|
|
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, with minor gaps
|
|
67
|
+
- **0.4-0.6**: Moderate recall, substantial 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
70
|
|
|
71
71
|
### Reason analysis
|
|
72
72
|
|
|
@@ -87,7 +87,7 @@ Use results to:
|
|
|
87
87
|
|
|
88
88
|
### Example calculation
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
ground truth: "Einstein was born in 1879. He developed relativity. He won the Nobel Prize."
|
|
91
91
|
|
|
92
92
|
Claims extracted: 3
|
|
93
93
|
|
|
@@ -103,7 +103,7 @@ Recall = 2/3 = 0.67
|
|
|
103
103
|
|
|
104
104
|
```typescript
|
|
105
105
|
const scorer = createContextRecallScorer({
|
|
106
|
-
model: 'openai/gpt-5.
|
|
106
|
+
model: 'openai/gpt-5.6-sol',
|
|
107
107
|
options: {
|
|
108
108
|
contextExtractor: (input, output) => {
|
|
109
109
|
const query = input?.inputMessages?.[0]?.content || ''
|
|
@@ -119,7 +119,7 @@ const scorer = createContextRecallScorer({
|
|
|
119
119
|
|
|
120
120
|
```typescript
|
|
121
121
|
const scorer = createContextRecallScorer({
|
|
122
|
-
model: 'openai/gpt-5.
|
|
122
|
+
model: 'openai/gpt-5.6-sol',
|
|
123
123
|
options: {
|
|
124
124
|
context: [
|
|
125
125
|
'Document 1: Einstein was born on 14 March 1879 in Ulm, Germany.',
|
|
@@ -140,7 +140,7 @@ import { createContextRecallScorer } from '@mastra/evals/scorers/prebuilt'
|
|
|
140
140
|
import { myAgent } from './agent'
|
|
141
141
|
|
|
142
142
|
const scorer = createContextRecallScorer({
|
|
143
|
-
model: 'openai/gpt-5.
|
|
143
|
+
model: 'openai/gpt-5.6-sol',
|
|
144
144
|
options: {
|
|
145
145
|
contextExtractor: (input, output) => {
|
|
146
146
|
// Extract context from tool invocation results in the agent output
|
|
@@ -11,7 +11,7 @@ It's especially useful for these use cases:
|
|
|
11
11
|
Best for evaluating context quality in:
|
|
12
12
|
|
|
13
13
|
- Chat systems where context usage matters
|
|
14
|
-
- RAG pipelines needing
|
|
14
|
+
- RAG pipelines needing detailed relevance assessment
|
|
15
15
|
- Systems where missing context affects quality
|
|
16
16
|
|
|
17
17
|
## Context selection optimization
|
|
@@ -40,7 +40,7 @@ Note: Either `context` or `contextExtractor` must be provided. If both are provi
|
|
|
40
40
|
|
|
41
41
|
### Weighted Relevance Scoring
|
|
42
42
|
|
|
43
|
-
Context Relevance uses a
|
|
43
|
+
Context Relevance uses a advanced scoring algorithm that considers:
|
|
44
44
|
|
|
45
45
|
1. **Relevance Levels**: Each context piece is classified with weighted values:
|
|
46
46
|
|
|
@@ -77,7 +77,7 @@ Final Score = max(0, Base Score - Usage Penalty - Missing Penalty) × scale
|
|
|
77
77
|
|
|
78
78
|
- **0.9-1.0**: Excellent - all context highly relevant and used
|
|
79
79
|
- **0.7-0.8**: Good - mostly relevant with minor gaps
|
|
80
|
-
- **0.4-0.6**: Mixed -
|
|
80
|
+
- **0.4-0.6**: Mixed - substantial irrelevant or unused context
|
|
81
81
|
- **0.2-0.3**: Poor - mostly irrelevant context
|
|
82
82
|
- **0.0-0.1**: Very poor - no relevant context found
|
|
83
83
|
|
|
@@ -121,7 +121,7 @@ import { createContextRelevanceScorerLLM } from '@mastra/evals'
|
|
|
121
121
|
|
|
122
122
|
// Stricter penalty configuration
|
|
123
123
|
const strictScorer = createContextRelevanceScorerLLM({
|
|
124
|
-
model: 'openai/gpt-5.
|
|
124
|
+
model: 'openai/gpt-5.6-sol',
|
|
125
125
|
options: {
|
|
126
126
|
context: [
|
|
127
127
|
'Einstein won the Nobel Prize for photoelectric effect',
|
|
@@ -139,7 +139,7 @@ const strictScorer = createContextRelevanceScorerLLM({
|
|
|
139
139
|
|
|
140
140
|
// Lenient penalty configuration
|
|
141
141
|
const lenientScorer = createContextRelevanceScorerLLM({
|
|
142
|
-
model: 'openai/gpt-5.
|
|
142
|
+
model: 'openai/gpt-5.6-sol',
|
|
143
143
|
options: {
|
|
144
144
|
context: [
|
|
145
145
|
'Einstein won the Nobel Prize for photoelectric effect',
|
|
@@ -185,7 +185,7 @@ console.log('Lenient penalties:', lenientResult.score) // Higher score, less pen
|
|
|
185
185
|
|
|
186
186
|
```typescript
|
|
187
187
|
const scorer = createContextRelevanceScorerLLM({
|
|
188
|
-
model: 'openai/gpt-5.
|
|
188
|
+
model: 'openai/gpt-5.6-sol',
|
|
189
189
|
options: {
|
|
190
190
|
contextExtractor: (input, output) => {
|
|
191
191
|
// Extract context based on the query
|
|
@@ -209,7 +209,7 @@ const scorer = createContextRelevanceScorerLLM({
|
|
|
209
209
|
|
|
210
210
|
```typescript
|
|
211
211
|
const scorer = createContextRelevanceScorerLLM({
|
|
212
|
-
model: 'openai/gpt-5.
|
|
212
|
+
model: 'openai/gpt-5.6-sol',
|
|
213
213
|
options: {
|
|
214
214
|
context: ['Relevant information...', 'Supporting details...'],
|
|
215
215
|
scale: 100, // Scale scores from 0-100 instead of 0-1
|
|
@@ -223,7 +223,7 @@ const scorer = createContextRelevanceScorerLLM({
|
|
|
223
223
|
|
|
224
224
|
```typescript
|
|
225
225
|
const scorer = createContextRelevanceScorerLLM({
|
|
226
|
-
model: 'openai/gpt-5.
|
|
226
|
+
model: 'openai/gpt-5.6-sol',
|
|
227
227
|
options: {
|
|
228
228
|
contextExtractor: (input, output) => {
|
|
229
229
|
const query = input?.inputMessages?.[0]?.content || ''
|
|
@@ -250,7 +250,7 @@ This example shows excellent context relevance where all context directly suppor
|
|
|
250
250
|
import { createContextRelevanceScorerLLM } from '@mastra/evals'
|
|
251
251
|
|
|
252
252
|
const scorer = createContextRelevanceScorerLLM({
|
|
253
|
-
model: 'openai/gpt-5.
|
|
253
|
+
model: 'openai/gpt-5.6-sol',
|
|
254
254
|
options: {
|
|
255
255
|
context: [
|
|
256
256
|
'Einstein won the Nobel Prize for his discovery of the photoelectric effect in 1921.',
|
|
@@ -297,7 +297,7 @@ This example shows moderate relevance with some context being irrelevant or unus
|
|
|
297
297
|
import { createContextRelevanceScorerLLM } from '@mastra/evals'
|
|
298
298
|
|
|
299
299
|
const scorer = createContextRelevanceScorerLLM({
|
|
300
|
-
model: 'openai/gpt-5.
|
|
300
|
+
model: 'openai/gpt-5.6-sol',
|
|
301
301
|
options: {
|
|
302
302
|
context: [
|
|
303
303
|
'Solar eclipses occur when the Moon blocks the Sun.',
|
|
@@ -339,7 +339,7 @@ console.log(result)
|
|
|
339
339
|
|
|
340
340
|
// With custom penalty configuration
|
|
341
341
|
const customScorer = createContextRelevanceScorerLLM({
|
|
342
|
-
model: 'openai/gpt-5.
|
|
342
|
+
model: 'openai/gpt-5.6-sol',
|
|
343
343
|
options: {
|
|
344
344
|
context: [
|
|
345
345
|
'Solar eclipses occur when the Moon blocks the Sun.',
|
|
@@ -386,7 +386,7 @@ This example shows poor context relevance with mostly irrelevant information:
|
|
|
386
386
|
import { createContextRelevanceScorerLLM } from '@mastra/evals'
|
|
387
387
|
|
|
388
388
|
const scorer = createContextRelevanceScorerLLM({
|
|
389
|
-
model: 'openai/gpt-5.
|
|
389
|
+
model: 'openai/gpt-5.6-sol',
|
|
390
390
|
options: {
|
|
391
391
|
context: [
|
|
392
392
|
'The Great Barrier Reef is located in Australia.',
|
|
@@ -428,13 +428,13 @@ console.log(result)
|
|
|
428
428
|
|
|
429
429
|
### Dynamic context extraction
|
|
430
430
|
|
|
431
|
-
Extract context
|
|
431
|
+
Extract context at runtime based on the run input:
|
|
432
432
|
|
|
433
433
|
```typescript
|
|
434
434
|
import { createContextRelevanceScorerLLM } from '@mastra/evals'
|
|
435
435
|
|
|
436
436
|
const scorer = createContextRelevanceScorerLLM({
|
|
437
|
-
model: 'openai/gpt-5.
|
|
437
|
+
model: 'openai/gpt-5.6-sol',
|
|
438
438
|
options: {
|
|
439
439
|
contextExtractor: (input, output) => {
|
|
440
440
|
// Extract query from input
|
|
@@ -477,7 +477,7 @@ Integrate with RAG pipelines to evaluate retrieved context:
|
|
|
477
477
|
import { createContextRelevanceScorerLLM } from '@mastra/evals'
|
|
478
478
|
|
|
479
479
|
const scorer = createContextRelevanceScorerLLM({
|
|
480
|
-
model: 'openai/gpt-5.
|
|
480
|
+
model: 'openai/gpt-5.6-sol',
|
|
481
481
|
options: {
|
|
482
482
|
contextExtractor: (input, output) => {
|
|
483
483
|
// Extract from RAG retrieval results
|
|
@@ -65,9 +65,9 @@ Final score: `(supported_claims / total_claims) * scale`
|
|
|
65
65
|
A faithfulness score between 0 and 1:
|
|
66
66
|
|
|
67
67
|
- **1.0**: All claims are accurate and directly supported by the context.
|
|
68
|
-
- **0.7
|
|
69
|
-
- **0.4
|
|
70
|
-
- **0.1
|
|
68
|
+
- **0.7 to 0.9**: Most claims are correct, with minor additions or omissions.
|
|
69
|
+
- **0.4 to 0.6**: Some claims are supported, but others are unverifiable.
|
|
70
|
+
- **0.1 to 0.3**: Most of the content is inaccurate or unsupported.
|
|
71
71
|
- **0.0**: All claims are false or contradict the context.
|
|
72
72
|
|
|
73
73
|
## Example
|
|
@@ -81,7 +81,7 @@ import { myAgent } from './agent'
|
|
|
81
81
|
|
|
82
82
|
// Context is typically populated from agent tool calls or RAG retrieval
|
|
83
83
|
const scorer = createFaithfulnessScorer({
|
|
84
|
-
model: 'openai/gpt-5.
|
|
84
|
+
model: 'openai/gpt-5.6-sol',
|
|
85
85
|
})
|
|
86
86
|
|
|
87
87
|
const result = await runEvals({
|
|
@@ -88,13 +88,13 @@ Final score: `(hallucinated_statements / total_statements) * scale`
|
|
|
88
88
|
|
|
89
89
|
A hallucination score between 0 and 1:
|
|
90
90
|
|
|
91
|
-
- **0.0**: No hallucination
|
|
92
|
-
- **0.3
|
|
93
|
-
- **0.5
|
|
94
|
-
- **0.7
|
|
95
|
-
- **0.9
|
|
91
|
+
- **0.0**: No hallucination, all claims match the context.
|
|
92
|
+
- **0.3 to 0.4**: Low hallucination, a few contradictions.
|
|
93
|
+
- **0.5 to 0.6**: Mixed hallucination, several contradictions.
|
|
94
|
+
- **0.7 to 0.8**: High hallucination, many contradictions.
|
|
95
|
+
- **0.9 to 1.0**: Complete hallucination, most or all claims contradict the context.
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
The score represents the degree of hallucination - lower scores indicate better factual alignment with the provided context
|
|
98
98
|
|
|
99
99
|
## Examples
|
|
100
100
|
|
|
@@ -106,7 +106,7 @@ Use static context when you have known ground truth to compare against:
|
|
|
106
106
|
import { createHallucinationScorer } from '@mastra/evals/scorers/prebuilt'
|
|
107
107
|
|
|
108
108
|
const scorer = createHallucinationScorer({
|
|
109
|
-
model: 'openai/gpt-5.
|
|
109
|
+
model: 'openai/gpt-5.6-sol',
|
|
110
110
|
options: {
|
|
111
111
|
context: [
|
|
112
112
|
'The first iPhone was announced on January 9, 2007.',
|
|
@@ -126,7 +126,7 @@ import { createHallucinationScorer } from '@mastra/evals/scorers/prebuilt'
|
|
|
126
126
|
import { extractToolResults } from '@mastra/evals/scorers'
|
|
127
127
|
|
|
128
128
|
const scorer = createHallucinationScorer({
|
|
129
|
-
model: 'openai/gpt-5.
|
|
129
|
+
model: 'openai/gpt-5.6-sol',
|
|
130
130
|
options: {
|
|
131
131
|
getContext: ({ run, step }) => {
|
|
132
132
|
// Extract tool results as context
|
|
@@ -147,7 +147,7 @@ import { createHallucinationScorer } from '@mastra/evals/scorers/prebuilt'
|
|
|
147
147
|
import { extractToolResults } from '@mastra/evals/scorers'
|
|
148
148
|
|
|
149
149
|
const hallucinationScorer = createHallucinationScorer({
|
|
150
|
-
model: 'openai/gpt-5.
|
|
150
|
+
model: 'openai/gpt-5.6-sol',
|
|
151
151
|
options: {
|
|
152
152
|
getContext: ({ run }) => {
|
|
153
153
|
const toolResults = extractToolResults(run.output)
|
|
@@ -159,7 +159,7 @@ const hallucinationScorer = createHallucinationScorer({
|
|
|
159
159
|
const agent = new Agent({
|
|
160
160
|
id: 'my-agent',
|
|
161
161
|
name: 'my-agent',
|
|
162
|
-
model: 'openai/gpt-5.
|
|
162
|
+
model: 'openai/gpt-5.6-sol',
|
|
163
163
|
instructions: 'You are a helpful assistant.',
|
|
164
164
|
evals: {
|
|
165
165
|
scorers: [hallucinationScorer],
|
|
@@ -175,7 +175,7 @@ import { createHallucinationScorer } from '@mastra/evals/scorers/prebuilt'
|
|
|
175
175
|
import { myAgent } from './agent'
|
|
176
176
|
|
|
177
177
|
const scorer = createHallucinationScorer({
|
|
178
|
-
model: 'openai/gpt-5.
|
|
178
|
+
model: 'openai/gpt-5.6-sol',
|
|
179
179
|
options: {
|
|
180
180
|
context: ['Known fact 1', 'Known fact 2'],
|
|
181
181
|
},
|
|
@@ -66,11 +66,11 @@ Final score: `(matched_keywords / total_keywords) * scale`
|
|
|
66
66
|
|
|
67
67
|
A coverage score between 0 and 1:
|
|
68
68
|
|
|
69
|
-
- **1.0**: Complete coverage
|
|
70
|
-
- **0.7
|
|
71
|
-
- **0.4
|
|
72
|
-
- **0.1
|
|
73
|
-
- **0.0**:
|
|
69
|
+
- **1.0**: Complete coverage, all keywords present.
|
|
70
|
+
- **0.7 to 0.9**: High coverage, most keywords included.
|
|
71
|
+
- **0.4 to 0.6**: Partial coverage, some keywords present.
|
|
72
|
+
- **0.1 to 0.3**: Low coverage, few keywords matched.
|
|
73
|
+
- **0.0**: The response contains none of the keywords.
|
|
74
74
|
|
|
75
75
|
### Special Cases
|
|
76
76
|
|
|
@@ -80,7 +80,7 @@ The scorer handles several special cases:
|
|
|
80
80
|
- Single word: Treated as a single keyword
|
|
81
81
|
- Technical terms: Preserves compound technical terms (e.g., "React.js", "machine learning")
|
|
82
82
|
- Case differences: "JavaScript" matches "javascript"
|
|
83
|
-
- Common words: Ignored in scoring to focus on
|
|
83
|
+
- Common words: Ignored in scoring to focus on useful keywords
|
|
84
84
|
|
|
85
85
|
## Example
|
|
86
86
|
|