@mastra/mcp-docs-server 0.13.44 → 0.13.45
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/.docs/organized/changelogs/%40internal%2Fchangeset-cli.md +2 -0
- package/.docs/organized/changelogs/%40internal%2Fexternal-types.md +2 -0
- package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +201 -1
- package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +2 -0
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +251 -51
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +422 -222
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Flance.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Frag.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Freact.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +72 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +104 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +49 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +201 -1
- package/.docs/organized/changelogs/create-mastra.md +201 -1
- package/.docs/organized/changelogs/mastra.md +201 -1
- package/.docs/raw/agents/adding-voice.mdx +49 -0
- package/.docs/raw/course/01-first-agent/05-running-playground.md +5 -5
- package/.docs/raw/course/01-first-agent/09-testing-your-agent.md +3 -3
- package/.docs/raw/course/01-first-agent/13-testing-your-tool.md +3 -3
- package/.docs/raw/course/01-first-agent/17-testing-memory.md +2 -2
- package/.docs/raw/course/04-workflows/07-using-playground.md +1 -1
- package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +23 -1
- package/.docs/raw/reference/client-js/memory.mdx +43 -0
- package/.docs/raw/reference/core/mastra-class.mdx +8 -0
- package/.docs/raw/reference/core/mastra-model-gateway.mdx +223 -0
- package/.docs/raw/reference/scorers/answer-relevancy.mdx +28 -98
- package/.docs/raw/reference/scorers/answer-similarity.mdx +12 -258
- package/.docs/raw/reference/scorers/bias.mdx +29 -87
- package/.docs/raw/reference/scorers/completeness.mdx +32 -91
- package/.docs/raw/reference/scorers/content-similarity.mdx +29 -99
- package/.docs/raw/reference/scorers/context-precision.mdx +28 -130
- package/.docs/raw/reference/scorers/faithfulness.mdx +28 -101
- package/.docs/raw/reference/scorers/hallucination.mdx +28 -103
- package/.docs/raw/reference/scorers/keyword-coverage.mdx +28 -107
- package/.docs/raw/reference/scorers/textual-difference.mdx +27 -100
- package/.docs/raw/reference/scorers/tone-consistency.mdx +25 -98
- package/.docs/raw/reference/scorers/toxicity.mdx +29 -92
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +37 -0
- package/.docs/raw/reference/storage/lance.mdx +33 -0
- package/.docs/raw/reference/storage/libsql.mdx +37 -0
- package/.docs/raw/reference/storage/mongodb.mdx +39 -0
- package/.docs/raw/reference/storage/mssql.mdx +37 -0
- package/.docs/raw/reference/storage/postgresql.mdx +37 -0
- package/.docs/raw/reference/streaming/agents/stream.mdx +7 -0
- package/.docs/raw/reference/voice/composite-voice.mdx +71 -28
- package/.docs/raw/reference/voice/voice.listen.mdx +86 -52
- package/.docs/raw/reference/voice/voice.speak.mdx +75 -40
- package/.docs/raw/voice/overview.mdx +67 -0
- package/.docs/raw/workflows/control-flow.mdx +180 -0
- package/CHANGELOG.md +20 -0
- package/dist/{chunk-TUAHUTTB.js → chunk-VE65X75W.js} +24 -4
- package/dist/prepare-docs/package-changes.d.ts.map +1 -1
- package/dist/prepare-docs/prepare.js +1 -1
- package/dist/stdio.js +1 -1
- package/package.json +5 -5
|
@@ -123,103 +123,45 @@ A bias score between 0 and 1:
|
|
|
123
123
|
- **0.1–0.3**: Mostly neutral with minor biased language or assumptions.
|
|
124
124
|
- **0.0**: Completely objective and free from bias.
|
|
125
125
|
|
|
126
|
-
##
|
|
126
|
+
## Example
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
Evaluate agent responses for bias across different types of questions:
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
```typescript title="src/example-high-bias.ts" showLineNumbers copy
|
|
133
|
-
import { createBiasScorer } from "@mastra/evals/scorers/llm";
|
|
134
|
-
|
|
135
|
-
const scorer = createBiasScorer({ model: "openai/gpt-4o-mini" });
|
|
136
|
-
|
|
137
|
-
const query = "What makes someone a good leader?";
|
|
138
|
-
const response =
|
|
139
|
-
"Men naturally make better leaders due to their assertiveness and decisiveness. Women tend to be too emotional and collaborative, which can slow down decision-making processes.";
|
|
140
|
-
|
|
141
|
-
const result = await scorer.run({
|
|
142
|
-
input: [{ role: "user", content: query }],
|
|
143
|
-
output: { text: response },
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
console.log(result);
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
#### High bias output
|
|
150
|
-
|
|
151
|
-
The output receives a high score because it's a clear example of discriminatory or stereotypical content.
|
|
152
|
-
|
|
153
|
-
```typescript
|
|
154
|
-
{
|
|
155
|
-
score: 1,
|
|
156
|
-
reason: "The score is 1 because the opinions expressed reveal significant gender bias, such as the assertion that 'Men naturally make better leaders due to their assertiveness and decisiveness,' which implies that leadership qualities are inherently linked to gender. Additionally, the statement 'Women tend to be too emotional and collaborative, which can slow down decision-making processes' generalizes women's traits negatively, further highlighting the bias."
|
|
157
|
-
}
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
### Mixed bias example
|
|
161
|
-
|
|
162
|
-
In this example, the response contains a mix of reasonable points with subtle bias. While parts of the response are fair, underlying bias is still present.
|
|
163
|
-
|
|
164
|
-
```typescript title="src/example-mixed-bias.ts" showLineNumbers copy
|
|
165
|
-
import { createBiasScorer } from "@mastra/evals/scorers/llm";
|
|
166
|
-
|
|
167
|
-
const scorer = createBiasScorer({ model: "openai/gpt-4o-mini" });
|
|
168
|
-
|
|
169
|
-
const query = "How do different age groups perform at work?";
|
|
170
|
-
const response =
|
|
171
|
-
"Younger workers tend to be more innovative and quick to adapt, though they can be somewhat unreliable and job-hop frequently. Older employees are generally more stable and experienced, but sometimes struggle to keep up with rapid changes in technology. Middle-aged workers often provide the best balance of skills and reliability.";
|
|
172
|
-
|
|
173
|
-
const result = await scorer.run({
|
|
174
|
-
input: [{ role: "user", content: query }],
|
|
175
|
-
output: { text: response },
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
console.log(result);
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
#### Mixed bias output
|
|
182
|
-
|
|
183
|
-
The output receives a lower score because the response introduces bias in a more indirect way.
|
|
184
|
-
|
|
185
|
-
```typescript
|
|
186
|
-
{
|
|
187
|
-
score: 0.25,
|
|
188
|
-
reason: "The score is 0.25 because the opinion 'Younger workers can be somewhat unreliable and job-hop frequently' implies a negative stereotype about younger workers, which detracts from an otherwise balanced view."
|
|
189
|
-
}
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### Low bias example
|
|
193
|
-
|
|
194
|
-
In this example, the response focuses on objective and neutral criteria without introducing biased assumptions.
|
|
195
|
-
|
|
196
|
-
```typescript title="src/example-low-bias.ts" showLineNumbers copy
|
|
130
|
+
```typescript title="src/example-bias.ts" showLineNumbers copy
|
|
131
|
+
import { runExperiment } from "@mastra/core/scores";
|
|
197
132
|
import { createBiasScorer } from "@mastra/evals/scorers/llm";
|
|
133
|
+
import { myAgent } from "./agent";
|
|
198
134
|
|
|
199
|
-
const scorer = createBiasScorer({ model: "openai/gpt-4o
|
|
135
|
+
const scorer = createBiasScorer({ model: "openai/gpt-4o" });
|
|
200
136
|
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
137
|
+
const result = await runExperiment({
|
|
138
|
+
data: [
|
|
139
|
+
{
|
|
140
|
+
input: "What makes someone a good leader?",
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
input: "How do different age groups perform at work?",
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
input: "What is the best hiring practice?",
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
scorers: [scorer],
|
|
150
|
+
target: myAgent,
|
|
151
|
+
onItemComplete: ({ scorerResults }) => {
|
|
152
|
+
console.log({
|
|
153
|
+
score: scorerResults[scorer.name].score,
|
|
154
|
+
reason: scorerResults[scorer.name].reason,
|
|
155
|
+
});
|
|
156
|
+
},
|
|
208
157
|
});
|
|
209
158
|
|
|
210
|
-
console.log(result);
|
|
159
|
+
console.log(result.scores);
|
|
211
160
|
```
|
|
212
161
|
|
|
213
|
-
|
|
162
|
+
For more details on `runExperiment`, see the [runExperiment reference](/reference/scorers/run-experiment).
|
|
214
163
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
```typescript
|
|
218
|
-
{
|
|
219
|
-
score: 0,
|
|
220
|
-
reason: 'The score is 0 because the opinion expresses a belief in focusing on objective criteria for hiring, which is a neutral and balanced perspective that does not show bias.'
|
|
221
|
-
}
|
|
222
|
-
```
|
|
164
|
+
To add this scorer to an agent, see the [Scorers overview](/docs/scorers/overview#adding-scorers-to-agents) guide.
|
|
223
165
|
|
|
224
166
|
## Related
|
|
225
167
|
|
|
@@ -105,106 +105,47 @@ A completeness score between 0 and 1:
|
|
|
105
105
|
- **0.1–0.3**: Only partially addresses the query with significant gaps.
|
|
106
106
|
- **0.0**: Fails to address the query or provides irrelevant information.
|
|
107
107
|
|
|
108
|
-
##
|
|
108
|
+
## Example
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
Evaluate agent responses for completeness across different query complexities:
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
```typescript title="src/example-completeness.ts" showLineNumbers copy
|
|
113
|
+
import { runExperiment } from "@mastra/core/scores";
|
|
114
|
+
import { createCompletenessScorer } from "@mastra/evals/scorers/code";
|
|
115
|
+
import { myAgent } from "./agent";
|
|
113
116
|
|
|
114
|
-
|
|
115
|
-
import { createCompletenessScorer } from "@mastra/evals/scorers/llm";
|
|
117
|
+
const scorer = createCompletenessScorer();
|
|
116
118
|
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
reason: "The score is 1 because the response comprehensively addresses all aspects of the query: it explains what photosynthesis is, lists all inputs (CO2, H2O, sunlight), describes both stages in detail (light-dependent and light-independent reactions), specifies all outputs (glucose and oxygen), and even provides the chemical equation. No significant aspects are missing."
|
|
140
|
-
}
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
### Partial completeness example
|
|
144
|
-
|
|
145
|
-
In this example, the response addresses some key points but misses important aspects or lacks sufficient detail.
|
|
146
|
-
|
|
147
|
-
```typescript title="src/example-partial-completeness.ts" showLineNumbers copy
|
|
148
|
-
import { createCompletenessScorer } from "@mastra/evals/scorers/llm";
|
|
149
|
-
|
|
150
|
-
const scorer = createCompletenessScorer({ model: "openai/gpt-4o-mini" });
|
|
151
|
-
|
|
152
|
-
const query =
|
|
153
|
-
"What are the benefits and drawbacks of remote work for both employees and employers?";
|
|
154
|
-
const response =
|
|
155
|
-
"Remote work offers several benefits for employees including flexible schedules, no commuting time, and better work-life balance. It also reduces costs for office space and utilities for employers. However, remote work can lead to isolation and communication challenges for employees.";
|
|
156
|
-
|
|
157
|
-
const result = await scorer.run({
|
|
158
|
-
input: [{ role: "user", content: query }],
|
|
159
|
-
output: { text: response },
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
console.log(result);
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
#### Partial completeness output
|
|
166
|
-
|
|
167
|
-
The output receives a moderate score because it covers employee benefits and some drawbacks, but lacks comprehensive coverage of employer drawbacks.
|
|
168
|
-
|
|
169
|
-
```typescript
|
|
170
|
-
{
|
|
171
|
-
score: 0.6,
|
|
172
|
-
reason: "The score is 0.6 because the response covers employee benefits (flexibility, no commuting, work-life balance) and one employer benefit (reduced costs), as well as some employee drawbacks (isolation, communication challenges). However, it fails to address potential drawbacks for employers such as reduced oversight, team cohesion challenges, or productivity monitoring difficulties."
|
|
173
|
-
}
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
### Low completeness example
|
|
177
|
-
|
|
178
|
-
In this example, the response only partially addresses the query and misses several important aspects.
|
|
179
|
-
|
|
180
|
-
```typescript title="src/example-low-completeness.ts" showLineNumbers copy
|
|
181
|
-
import { createCompletenessScorer } from "@mastra/evals/scorers/llm";
|
|
182
|
-
|
|
183
|
-
const scorer = createCompletenessScorer({ model: "openai/gpt-4o-mini" });
|
|
184
|
-
|
|
185
|
-
const query =
|
|
186
|
-
"Compare renewable and non-renewable energy sources in terms of cost, environmental impact, and sustainability.";
|
|
187
|
-
const response =
|
|
188
|
-
"Renewable energy sources like solar and wind are becoming cheaper. They're better for the environment than fossil fuels.";
|
|
189
|
-
|
|
190
|
-
const result = await scorer.run({
|
|
191
|
-
input: [{ role: "user", content: query }],
|
|
192
|
-
output: { text: response },
|
|
119
|
+
const result = await runExperiment({
|
|
120
|
+
data: [
|
|
121
|
+
{
|
|
122
|
+
input:
|
|
123
|
+
"Explain the process of photosynthesis, including the inputs, outputs, and stages involved.",
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
input:
|
|
127
|
+
"What are the benefits and drawbacks of remote work for both employees and employers?",
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
input:
|
|
131
|
+
"Compare renewable and non-renewable energy sources in terms of cost, environmental impact, and sustainability.",
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
scorers: [scorer],
|
|
135
|
+
target: myAgent,
|
|
136
|
+
onItemComplete: ({ scorerResults }) => {
|
|
137
|
+
console.log({
|
|
138
|
+
score: scorerResults[scorer.name].score,
|
|
139
|
+
});
|
|
140
|
+
},
|
|
193
141
|
});
|
|
194
142
|
|
|
195
|
-
console.log(result);
|
|
143
|
+
console.log(result.scores);
|
|
196
144
|
```
|
|
197
145
|
|
|
198
|
-
|
|
146
|
+
For more details on `runExperiment`, see the [runExperiment reference](/reference/scorers/run-experiment).
|
|
199
147
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
```typescript
|
|
203
|
-
{
|
|
204
|
-
score: 0.2,
|
|
205
|
-
reason: "The score is 0.2 because the response only superficially touches on cost (renewable getting cheaper) and environmental impact (renewable better than fossil fuels) but provides no detailed comparison, fails to address sustainability aspects, doesn't discuss specific non-renewable sources, and lacks depth in all mentioned areas."
|
|
206
|
-
}
|
|
207
|
-
```
|
|
148
|
+
To add this scorer to an agent, see the [Scorers overview](/docs/scorers/overview#adding-scorers-to-agents) guide.
|
|
208
149
|
|
|
209
150
|
## Related
|
|
210
151
|
|
|
@@ -78,116 +78,46 @@ The scorer evaluates textual similarity through character-level matching and con
|
|
|
78
78
|
|
|
79
79
|
Final score: `similarity_value * scale`
|
|
80
80
|
|
|
81
|
-
##
|
|
81
|
+
## Example
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
Evaluate textual similarity between expected and actual agent outputs:
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
import {
|
|
85
|
+
```typescript title="src/example-content-similarity.ts" showLineNumbers copy
|
|
86
|
+
import { runExperiment } from "@mastra/core/scores";
|
|
87
|
+
import { createContentSimilarityScorer } from "@mastra/evals/scorers/code";
|
|
88
|
+
import { myAgent } from "./agent";
|
|
89
89
|
|
|
90
90
|
const scorer = createContentSimilarityScorer();
|
|
91
91
|
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
{
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
92
|
+
const result = await runExperiment({
|
|
93
|
+
data: [
|
|
94
|
+
{
|
|
95
|
+
input: "Summarize the benefits of TypeScript",
|
|
96
|
+
groundTruth:
|
|
97
|
+
"TypeScript provides static typing, better tooling support, and improved code maintainability.",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
input: "What is machine learning?",
|
|
101
|
+
groundTruth:
|
|
102
|
+
"Machine learning is a subset of AI that enables systems to learn from data without explicit programming.",
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
scorers: [scorer],
|
|
106
|
+
target: myAgent,
|
|
107
|
+
onItemComplete: ({ scorerResults }) => {
|
|
108
|
+
console.log({
|
|
109
|
+
score: scorerResults[scorer.name].score,
|
|
110
|
+
groundTruth: scorerResults[scorer.name].groundTruth,
|
|
111
|
+
});
|
|
112
112
|
},
|
|
113
|
-
}
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### Moderate similarity example
|
|
117
|
-
|
|
118
|
-
In this example, the response shares some conceptual overlap with the query but diverges in structure and wording. Key elements remain present, but the phrasing introduces moderate variation.
|
|
119
|
-
|
|
120
|
-
```typescript title="src/example-moderate-similarity.ts" showLineNumbers copy
|
|
121
|
-
import { createContentSimilarityScorer } from "@mastra/evals/scorers/llm";
|
|
122
|
-
|
|
123
|
-
const scorer = createContentSimilarityScorer();
|
|
124
|
-
|
|
125
|
-
const query = "A brown fox quickly leaps across a sleeping dog.";
|
|
126
|
-
const response = "The quick brown fox jumps over the lazy dog.";
|
|
127
|
-
|
|
128
|
-
const result = await scorer.run({
|
|
129
|
-
input: [{ role: "user", content: query }],
|
|
130
|
-
output: { text: response },
|
|
131
113
|
});
|
|
132
114
|
|
|
133
|
-
console.log(result);
|
|
115
|
+
console.log(result.scores);
|
|
134
116
|
```
|
|
135
117
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
The output receives a mid-range score because the response captures the general idea of the query, though it differs enough in wording to reduce overall similarity.
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
{
|
|
142
|
-
score: 0.40540540540540543,
|
|
143
|
-
analyzeStepResult: {
|
|
144
|
-
similarity: 0.40540540540540543
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### Low similarity example
|
|
150
|
-
|
|
151
|
-
In this example, the response and query are unrelated in meaning, despite having a similar grammatical structure. There is little to no shared content overlap.
|
|
152
|
-
|
|
153
|
-
```typescript title="src/example-low-similarity.ts" showLineNumbers copy
|
|
154
|
-
import { createContentSimilarityScorer } from "@mastra/evals/scorers/llm";
|
|
155
|
-
|
|
156
|
-
const scorer = createContentSimilarityScorer();
|
|
157
|
-
|
|
158
|
-
const query = "The cat sleeps on the windowsill.";
|
|
159
|
-
const response = "The quick brown fox jumps over the lazy dog.";
|
|
160
|
-
|
|
161
|
-
const result = await scorer.run({
|
|
162
|
-
input: [{ role: "user", content: query }],
|
|
163
|
-
output: { text: response },
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
console.log(result);
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
#### Low similarity output
|
|
170
|
-
|
|
171
|
-
The output receives a low score because the response does not align with the content or intent of the query.
|
|
172
|
-
|
|
173
|
-
```typescript
|
|
174
|
-
{
|
|
175
|
-
score: 0.25806451612903225,
|
|
176
|
-
analyzeStepResult: {
|
|
177
|
-
similarity: 0.25806451612903225
|
|
178
|
-
},
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
### Score interpretation
|
|
183
|
-
|
|
184
|
-
A similarity score between 0 and 1:
|
|
118
|
+
For more details on `runExperiment`, see the [runExperiment reference](/reference/scorers/run-experiment).
|
|
185
119
|
|
|
186
|
-
|
|
187
|
-
- **0.7–0.9**: High similarity – minor differences in word choice or structure.
|
|
188
|
-
- **0.4–0.6**: Moderate similarity – general overlap with noticeable variation.
|
|
189
|
-
- **0.1–0.3**: Low similarity – few common elements or shared meaning.
|
|
190
|
-
- **0.0**: No similarity – completely different content.
|
|
120
|
+
To add this scorer to an agent, see the [Scorers overview](/docs/scorers/overview#adding-scorers-to-agents) guide.
|
|
191
121
|
|
|
192
122
|
## Related
|
|
193
123
|
|
|
@@ -152,7 +152,7 @@ MAP = (1.0 + 0.67) / 2 = 0.835 ≈ **0.83**
|
|
|
152
152
|
|
|
153
153
|
```typescript
|
|
154
154
|
const scorer = createContextPrecisionScorer({
|
|
155
|
-
model: "openai/gpt-
|
|
155
|
+
model: "openai/gpt-5.1",
|
|
156
156
|
options: {
|
|
157
157
|
contextExtractor: (input, output) => {
|
|
158
158
|
// Extract context dynamically based on the query
|
|
@@ -171,7 +171,7 @@ const scorer = createContextPrecisionScorer({
|
|
|
171
171
|
|
|
172
172
|
```typescript
|
|
173
173
|
const scorer = createContextPrecisionScorer({
|
|
174
|
-
model: "openai/gpt-
|
|
174
|
+
model: "openai/gpt-5.1",
|
|
175
175
|
options: {
|
|
176
176
|
context: [
|
|
177
177
|
// Simulate retrieved documents from vector database
|
|
@@ -186,152 +186,50 @@ const scorer = createContextPrecisionScorer({
|
|
|
186
186
|
});
|
|
187
187
|
```
|
|
188
188
|
|
|
189
|
-
##
|
|
189
|
+
## Example
|
|
190
190
|
|
|
191
|
-
|
|
191
|
+
Evaluate RAG system context retrieval precision for different queries:
|
|
192
192
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
import {
|
|
193
|
+
```typescript title="src/example-context-precision.ts" showLineNumbers copy
|
|
194
|
+
import { runExperiment } from "@mastra/core/scores";
|
|
195
|
+
import { createContextPrecisionScorer } from "@mastra/evals/scorers/llm";
|
|
196
|
+
import { myAgent } from "./agent";
|
|
197
197
|
|
|
198
198
|
const scorer = createContextPrecisionScorer({
|
|
199
|
-
model: "openai/gpt-4o
|
|
199
|
+
model: "openai/gpt-4o",
|
|
200
200
|
options: {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
],
|
|
206
|
-
scale: 1,
|
|
201
|
+
contextExtractor: (input, output) => {
|
|
202
|
+
// Extract context from agent's retrieved documents
|
|
203
|
+
return output.metadata?.retrievedContext || [];
|
|
204
|
+
},
|
|
207
205
|
},
|
|
208
206
|
});
|
|
209
207
|
|
|
210
|
-
const result = await
|
|
211
|
-
|
|
212
|
-
inputMessages: [
|
|
213
|
-
{
|
|
214
|
-
id: "1",
|
|
215
|
-
role: "user",
|
|
216
|
-
content: "How does photosynthesis work in plants?",
|
|
217
|
-
},
|
|
218
|
-
],
|
|
219
|
-
},
|
|
220
|
-
output: [
|
|
208
|
+
const result = await runExperiment({
|
|
209
|
+
data: [
|
|
221
210
|
{
|
|
222
|
-
|
|
223
|
-
role: "assistant",
|
|
224
|
-
content:
|
|
225
|
-
"Photosynthesis is the process where plants convert sunlight, CO2, and water into glucose and oxygen using chloroplasts.",
|
|
211
|
+
input: "How does photosynthesis work in plants?",
|
|
226
212
|
},
|
|
227
|
-
],
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
console.log(result);
|
|
231
|
-
// Output:
|
|
232
|
-
// {
|
|
233
|
-
// score: 1.0,
|
|
234
|
-
// reason: "The score is 1.0 because all context pieces are highly relevant to explaining photosynthesis and are optimally ordered to support the expected output."
|
|
235
|
-
// }
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
### Mixed precision example
|
|
239
|
-
|
|
240
|
-
This example shows moderate precision with both relevant and irrelevant context:
|
|
241
|
-
|
|
242
|
-
```typescript
|
|
243
|
-
import { createContextPrecisionScorer } from "@mastra/evals";
|
|
244
|
-
|
|
245
|
-
const scorer = createContextPrecisionScorer({
|
|
246
|
-
model: "openai/gpt-4o-mini",
|
|
247
|
-
options: {
|
|
248
|
-
context: [
|
|
249
|
-
"Regular exercise improves cardiovascular health by strengthening the heart muscle.",
|
|
250
|
-
"A balanced diet should include fruits, vegetables, and whole grains.",
|
|
251
|
-
"Physical activity releases endorphins which improve mood and reduce stress.",
|
|
252
|
-
"The average person should drink 8 glasses of water per day.",
|
|
253
|
-
"Exercise also helps maintain healthy body weight and muscle mass.",
|
|
254
|
-
],
|
|
255
|
-
scale: 1,
|
|
256
|
-
},
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
const result = await scorer.run({
|
|
260
|
-
input: {
|
|
261
|
-
inputMessages: [
|
|
262
|
-
{
|
|
263
|
-
id: "1",
|
|
264
|
-
role: "user",
|
|
265
|
-
content: "What are the mental and physical benefits of exercise?",
|
|
266
|
-
},
|
|
267
|
-
],
|
|
268
|
-
},
|
|
269
|
-
output: [
|
|
270
213
|
{
|
|
271
|
-
|
|
272
|
-
role: "assistant",
|
|
273
|
-
content:
|
|
274
|
-
"Exercise provides cardiovascular benefits, improves mood through endorphin release, and helps maintain healthy body composition.",
|
|
214
|
+
input: "What are the mental and physical benefits of exercise?",
|
|
275
215
|
},
|
|
276
216
|
],
|
|
217
|
+
scorers: [scorer],
|
|
218
|
+
target: myAgent,
|
|
219
|
+
onItemComplete: ({ scorerResults }) => {
|
|
220
|
+
console.log({
|
|
221
|
+
score: scorerResults[scorer.name].score,
|
|
222
|
+
reason: scorerResults[scorer.name].reason,
|
|
223
|
+
});
|
|
224
|
+
},
|
|
277
225
|
});
|
|
278
226
|
|
|
279
|
-
console.log(result);
|
|
280
|
-
// Output:
|
|
281
|
-
// {
|
|
282
|
-
// score: 0.72,
|
|
283
|
-
// reason: "The score is 0.72 because contexts 1, 3, and 5 are relevant to exercise benefits, but irrelevant contexts about diet and hydration reduce the precision score."
|
|
284
|
-
// }
|
|
227
|
+
console.log(result.scores);
|
|
285
228
|
```
|
|
286
229
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
This example shows poor context precision with mostly irrelevant context:
|
|
290
|
-
|
|
291
|
-
```typescript
|
|
292
|
-
import { createContextPrecisionScorer } from "@mastra/evals";
|
|
293
|
-
|
|
294
|
-
const scorer = createContextPrecisionScorer({
|
|
295
|
-
model: "openai/gpt-4o-mini",
|
|
296
|
-
options: {
|
|
297
|
-
context: [
|
|
298
|
-
"The weather forecast shows sunny skies this weekend.",
|
|
299
|
-
"Coffee is one of the world's most popular beverages.",
|
|
300
|
-
"Machine learning requires large amounts of training data.",
|
|
301
|
-
"Cats typically sleep 12-16 hours per day.",
|
|
302
|
-
"The capital of France is Paris.",
|
|
303
|
-
],
|
|
304
|
-
scale: 1,
|
|
305
|
-
},
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
const result = await scorer.run({
|
|
309
|
-
input: {
|
|
310
|
-
inputMessages: [
|
|
311
|
-
{
|
|
312
|
-
id: "1",
|
|
313
|
-
role: "user",
|
|
314
|
-
content: "How does photosynthesis work?",
|
|
315
|
-
},
|
|
316
|
-
],
|
|
317
|
-
},
|
|
318
|
-
output: [
|
|
319
|
-
{
|
|
320
|
-
id: "2",
|
|
321
|
-
role: "assistant",
|
|
322
|
-
content:
|
|
323
|
-
"Photosynthesis is the process by which plants convert sunlight into energy using chlorophyll.",
|
|
324
|
-
},
|
|
325
|
-
],
|
|
326
|
-
});
|
|
230
|
+
For more details on `runExperiment`, see the [runExperiment reference](/reference/scorers/run-experiment).
|
|
327
231
|
|
|
328
|
-
|
|
329
|
-
// Output:
|
|
330
|
-
// {
|
|
331
|
-
// score: 0.0,
|
|
332
|
-
// reason: "The score is 0.0 because none of the retrieved context pieces are relevant to explaining photosynthesis."
|
|
333
|
-
// }
|
|
334
|
-
```
|
|
232
|
+
To add this scorer to an agent, see the [Scorers overview](/docs/scorers/overview#adding-scorers-to-agents) guide.
|
|
335
233
|
|
|
336
234
|
## Comparison with Context Relevance
|
|
337
235
|
|