@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.
Files changed (98) hide show
  1. package/.docs/organized/changelogs/%40internal%2Fchangeset-cli.md +2 -0
  2. package/.docs/organized/changelogs/%40internal%2Fexternal-types.md +2 -0
  3. package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +201 -1
  4. package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +2 -0
  5. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +201 -1
  6. package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +251 -51
  7. package/.docs/organized/changelogs/%40mastra%2Fastra.md +201 -1
  8. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +201 -1
  9. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +201 -1
  10. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +201 -1
  11. package/.docs/organized/changelogs/%40mastra%2Fcloud.md +201 -1
  12. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +201 -1
  13. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +201 -1
  14. package/.docs/organized/changelogs/%40mastra%2Fcore.md +422 -222
  15. package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +201 -1
  16. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +201 -1
  17. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +201 -1
  18. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +201 -1
  19. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +201 -1
  20. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +201 -1
  21. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +201 -1
  22. package/.docs/organized/changelogs/%40mastra%2Fevals.md +201 -1
  23. package/.docs/organized/changelogs/%40mastra%2Flance.md +201 -1
  24. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +201 -1
  25. package/.docs/organized/changelogs/%40mastra%2Floggers.md +201 -1
  26. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +201 -1
  27. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +201 -1
  28. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +201 -1
  29. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +201 -1
  30. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +201 -1
  31. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +201 -1
  32. package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +201 -1
  33. package/.docs/organized/changelogs/%40mastra%2Fpg.md +201 -1
  34. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +201 -1
  35. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +201 -1
  36. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +201 -1
  37. package/.docs/organized/changelogs/%40mastra%2Frag.md +201 -1
  38. package/.docs/organized/changelogs/%40mastra%2Freact.md +201 -1
  39. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +72 -0
  40. package/.docs/organized/changelogs/%40mastra%2Fserver.md +201 -1
  41. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +201 -1
  42. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +201 -1
  43. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +201 -1
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +201 -1
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +201 -1
  46. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +201 -1
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +201 -1
  48. package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +104 -1
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +49 -1
  50. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +201 -1
  51. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +201 -1
  52. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +201 -1
  53. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +201 -1
  54. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +201 -1
  55. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +201 -1
  56. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +201 -1
  57. package/.docs/organized/changelogs/create-mastra.md +201 -1
  58. package/.docs/organized/changelogs/mastra.md +201 -1
  59. package/.docs/raw/agents/adding-voice.mdx +49 -0
  60. package/.docs/raw/course/01-first-agent/05-running-playground.md +5 -5
  61. package/.docs/raw/course/01-first-agent/09-testing-your-agent.md +3 -3
  62. package/.docs/raw/course/01-first-agent/13-testing-your-tool.md +3 -3
  63. package/.docs/raw/course/01-first-agent/17-testing-memory.md +2 -2
  64. package/.docs/raw/course/04-workflows/07-using-playground.md +1 -1
  65. package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +23 -1
  66. package/.docs/raw/reference/client-js/memory.mdx +43 -0
  67. package/.docs/raw/reference/core/mastra-class.mdx +8 -0
  68. package/.docs/raw/reference/core/mastra-model-gateway.mdx +223 -0
  69. package/.docs/raw/reference/scorers/answer-relevancy.mdx +28 -98
  70. package/.docs/raw/reference/scorers/answer-similarity.mdx +12 -258
  71. package/.docs/raw/reference/scorers/bias.mdx +29 -87
  72. package/.docs/raw/reference/scorers/completeness.mdx +32 -91
  73. package/.docs/raw/reference/scorers/content-similarity.mdx +29 -99
  74. package/.docs/raw/reference/scorers/context-precision.mdx +28 -130
  75. package/.docs/raw/reference/scorers/faithfulness.mdx +28 -101
  76. package/.docs/raw/reference/scorers/hallucination.mdx +28 -103
  77. package/.docs/raw/reference/scorers/keyword-coverage.mdx +28 -107
  78. package/.docs/raw/reference/scorers/textual-difference.mdx +27 -100
  79. package/.docs/raw/reference/scorers/tone-consistency.mdx +25 -98
  80. package/.docs/raw/reference/scorers/toxicity.mdx +29 -92
  81. package/.docs/raw/reference/storage/cloudflare-d1.mdx +37 -0
  82. package/.docs/raw/reference/storage/lance.mdx +33 -0
  83. package/.docs/raw/reference/storage/libsql.mdx +37 -0
  84. package/.docs/raw/reference/storage/mongodb.mdx +39 -0
  85. package/.docs/raw/reference/storage/mssql.mdx +37 -0
  86. package/.docs/raw/reference/storage/postgresql.mdx +37 -0
  87. package/.docs/raw/reference/streaming/agents/stream.mdx +7 -0
  88. package/.docs/raw/reference/voice/composite-voice.mdx +71 -28
  89. package/.docs/raw/reference/voice/voice.listen.mdx +86 -52
  90. package/.docs/raw/reference/voice/voice.speak.mdx +75 -40
  91. package/.docs/raw/voice/overview.mdx +67 -0
  92. package/.docs/raw/workflows/control-flow.mdx +180 -0
  93. package/CHANGELOG.md +20 -0
  94. package/dist/{chunk-TUAHUTTB.js → chunk-VE65X75W.js} +24 -4
  95. package/dist/prepare-docs/package-changes.d.ts.map +1 -1
  96. package/dist/prepare-docs/prepare.js +1 -1
  97. package/dist/stdio.js +1 -1
  98. package/package.json +5 -5
@@ -122,118 +122,45 @@ A faithfulness score between 0 and 1:
122
122
  - **0.1–0.3**: Most of the content is inaccurate or unsupported.
123
123
  - **0.0**: All claims are false or contradict the context.
124
124
 
125
- ## Examples
125
+ ## Example
126
126
 
127
- ### High faithfulness example
127
+ Evaluate agent responses for faithfulness to provided context:
128
128
 
129
- In this example, the response closely aligns with the context. Each statement in the output is verifiable and supported by the provided context entries, resulting in a high score.
130
-
131
- ```typescript title="src/example-high-faithfulness.ts" showLineNumbers copy
132
- import { createFaithfulnessScorer } from "@mastra/evals/scorers/llm";
133
-
134
- const scorer = createFaithfulnessScorer({ model: 'openai/gpt-4o-mini', options: {
135
- context: [
136
- "The Tesla Model 3 was launched in 2017.",
137
- "It has a range of up to 358 miles.",
138
- "The base model accelerates 0-60 mph in 5.8 seconds."
139
- ]
140
- });
141
-
142
- const query = "Tell me about the Tesla Model 3.";
143
- const response = "The Tesla Model 3 was introduced in 2017. It can travel up to 358 miles on a single charge and the base version goes from 0 to 60 mph in 5.8 seconds.";
144
-
145
- const result = await scorer.run({
146
- input: [{ role: 'user', content: query }],
147
- output: { text: response },
148
- });
149
-
150
- console.log(result);
151
- ```
152
-
153
- #### High faithfulness output
154
-
155
- The output receives a score of 1 because all the information it provides can be directly traced to the context. There are no missing or contradictory facts.
156
-
157
- ```typescript
158
- {
159
- score: 1,
160
- reason: 'The score is 1 because all claims made in the output are supported by the provided context.'
161
- }
162
- ```
163
-
164
- ### Mixed faithfulness example
165
-
166
- In this example, there are a mix of supported and unsupported claims. Some parts of the response are backed by the context, while others introduce new information not found in the source material.
167
-
168
- ```typescript title="src/example-mixed-faithfulness.ts" showLineNumbers copy
169
- import { createFaithfulnessScorer } from "@mastra/evals/scorers/llm";
170
-
171
- const scorer = createFaithfulnessScorer({ model: 'openai/gpt-4o-mini', options: {
172
- context: [
173
- "Python was created by Guido van Rossum.",
174
- "The first version was released in 1991.",
175
- "Python emphasizes code readability."
176
- ]
177
- });
178
-
179
- const query = "What can you tell me about Python?";
180
- const response = "Python was created by Guido van Rossum and released in 1991. It is the most popular programming language today and is used by millions of developers worldwide.";
181
-
182
- const result = await scorer.run({
183
- input: [{ role: 'user', content: query }],
184
- output: { text: response },
185
- });
186
-
187
- console.log(result);
188
- ```
189
-
190
- #### Mixed faithfulness output
191
-
192
- The score is lower because only a portion of the response is verifiable. While some claims match the context, others are unconfirmed or out of scope, reducing the overall faithfulness.
193
-
194
- ```typescript
195
- {
196
- score: 0.5,
197
- reason: "The score is 0.5 because while two claims are supported by the context (Python was created by Guido van Rossum and Python was released in 1991), the other two claims regarding Python's popularity and usage cannot be verified as they are not mentioned in the context."
198
- }
199
- ```
200
-
201
- ### Low faithfulness example
202
-
203
- In this example, the response directly contradicts the context. None of the claims are supported, and several conflict with the facts provided.
204
-
205
- ```typescript title="src/example-low-faithfulness.ts" showLineNumbers copy
129
+ ```typescript title="src/example-faithfulness.ts" showLineNumbers copy
130
+ import { runExperiment } from "@mastra/core/scores";
206
131
  import { createFaithfulnessScorer } from "@mastra/evals/scorers/llm";
132
+ import { myAgent } from "./agent";
207
133
 
208
- const scorer = createFaithfulnessScorer({ model: 'openai/gpt-4o-mini', options: {
209
- context: [
210
- "Mars is the fourth planet from the Sun.",
211
- "It has a thin atmosphere of mostly carbon dioxide.",
212
- "Two small moons orbit Mars: Phobos and Deimos."
213
- ]
134
+ // Context is typically populated from agent tool calls or RAG retrieval
135
+ const scorer = createFaithfulnessScorer({
136
+ model: "openai/gpt-4o",
214
137
  });
215
138
 
216
- const query = "What do we know about Mars?";
217
- const response = "Mars is the third planet from the Sun. It has a thick atmosphere rich in oxygen and nitrogen, and is orbited by three large moons.";
218
-
219
- const result = await scorer.run({
220
- input: [{ role: 'user', content: query }],
221
- output: { text: response },
139
+ const result = await runExperiment({
140
+ data: [
141
+ {
142
+ input: "Tell me about the Tesla Model 3.",
143
+ },
144
+ {
145
+ input: "What are the key features of this electric vehicle?",
146
+ },
147
+ ],
148
+ scorers: [scorer],
149
+ target: myAgent,
150
+ onItemComplete: ({ scorerResults }) => {
151
+ console.log({
152
+ score: scorerResults[scorer.name].score,
153
+ reason: scorerResults[scorer.name].reason,
154
+ });
155
+ },
222
156
  });
223
157
 
224
- console.log(result);
158
+ console.log(result.scores);
225
159
  ```
226
160
 
227
- #### Low faithfulness output
161
+ For more details on `runExperiment`, see the [runExperiment reference](/reference/scorers/run-experiment).
228
162
 
229
- Each claim is inaccurate or conflicts with the context, resulting in a score of 0.
230
-
231
- ```typescript
232
- {
233
- score: 0,
234
- reason: "The score is 0 because all claims made in the output contradict the provided context. The output states that Mars is the third planet from the Sun, while the context clearly states it is the fourth. Additionally, it claims that Mars has a thick atmosphere rich in oxygen and nitrogen, contradicting the context's description of a thin atmosphere mostly composed of carbon dioxide. Finally, the output mentions that Mars is orbited by three large moons, while the context specifies that it has only two small moons, Phobos and Deimos. Therefore, there are no supported claims, leading to a score of 0."
235
- }
236
- ```
163
+ To add this scorer to an agent, see the [Scorers overview](/docs/scorers/overview#adding-scorers-to-agents) guide.
237
164
 
238
165
  ## Related
239
166
 
@@ -131,120 +131,45 @@ A hallucination score between 0 and 1:
131
131
 
132
132
  **Note:** The score represents the degree of hallucination - lower scores indicate better factual alignment with the provided context
133
133
 
134
- ## Examples
134
+ ## Example
135
135
 
136
- ### No hallucination example
136
+ Evaluate agent responses for hallucinations against provided context:
137
137
 
138
- In this example, the response is fully aligned with the provided context. All claims are factually correct and directly supported by the source material, resulting in a low hallucination score.
139
-
140
- ```typescript title="src/example-no-hallucination.ts" showLineNumbers copy
141
- import { createHallucinationScorer } from "@mastra/evals/scorers/llm";
142
-
143
- const scorer = createHallucinationScorer({ model: 'openai/gpt-4o-mini', options: {
144
- context: [
145
- "The iPhone was first released in 2007.",
146
- "Steve Jobs unveiled it at Macworld.",
147
- "The original model had a 3.5-inch screen."
148
- ]
149
- });
150
-
151
- const query = "When was the first iPhone released?";
152
- const response = "The iPhone was first released in 2007, when Steve Jobs unveiled it at Macworld. The original iPhone featured a 3.5-inch screen.";
153
-
154
- const result = await scorer.run({
155
- input: [{ role: 'user', content: query }],
156
- output: { text: response },
157
- });
158
-
159
- console.log(result);
160
- ```
161
-
162
- #### No hallucination output
163
-
164
- The response receives a score of 0 because there are no contradictions. Every statement is consistent with the context, and no new or fabricated information has been introduced.
165
-
166
- ```typescript
167
- {
168
- score: 0,
169
- reason: 'The score is 0 because none of the statements from the context were contradicted by the output.'
170
- }
171
- ```
172
-
173
- ### Mixed hallucination example
174
-
175
- In this example, the response includes both accurate and inaccurate claims. Some details align with the context, while others directly contradict it—such as inflated numbers or incorrect locations. These contradictions increase the hallucination score.
176
-
177
- ```typescript title="src/example-mixed-hallucination.ts" showLineNumbers copy
138
+ ```typescript title="src/example-hallucination.ts" showLineNumbers copy
139
+ import { runExperiment } from "@mastra/core/scores";
178
140
  import { createHallucinationScorer } from "@mastra/evals/scorers/llm";
141
+ import { myAgent } from "./agent";
179
142
 
180
- const scorer = createHallucinationScorer({ model: 'openai/gpt-4o-mini', options: {
181
- context: [
182
- "The first Star Wars movie was released in 1977.",
183
- "It was directed by George Lucas.",
184
- "The film earned $775 million worldwide.",
185
- "The movie was filmed in Tunisia and England."
186
- ]
143
+ // Context is typically populated from agent tool calls or RAG retrieval
144
+ const scorer = createHallucinationScorer({
145
+ model: "openai/gpt-4o",
187
146
  });
188
147
 
189
- const query = "Tell me about the first Star Wars movie.";
190
- const response = "The first Star Wars movie came out in 1977 and was directed by George Lucas. It made over $1 billion at the box office and was filmed entirely in California.";
191
-
192
- const result = await scorer.run({
193
- input: [{ role: 'user', content: query }],
194
- output: { text: response },
195
- });
196
-
197
- console.log(result);
198
- ```
199
-
200
- #### Mixed hallucination output
201
-
202
- The Scorer assigns a mid-range score because parts of the response conflict with the context. While some facts are correct, others are inaccurate or fabricated, reducing overall reliability.
203
-
204
- ```typescript
205
- {
206
- score: 0.5,
207
- reason: 'The score is 0.5 because two out of four statements from the output were contradicted by claims in the context, indicating a balance of accurate and inaccurate information.'
208
- }
209
- ```
210
-
211
- ### Complete hallucination example
212
-
213
- In this example, the response contradicts every key fact in the context. None of the claims can be verified, and all presented details are factually incorrect.
214
-
215
- ```typescript title="src/example-complete-hallucination.ts" showLineNumbers copy
216
- import { createHallucinationScorer } from "@mastra/evals/scorers/llm";
217
-
218
- const scorer = createHallucinationScorer({ model: 'openai/gpt-4o-mini', options: {
219
- context: [
220
- "The Wright brothers made their first flight in 1903.",
221
- "The flight lasted 12 seconds.",
222
- "It covered a distance of 120 feet."
223
- ]
224
- });
225
-
226
- const query = "When did the Wright brothers first fly?";
227
- const response = "The Wright brothers achieved their historic first flight in 1908. The flight lasted about 2 minutes and covered nearly a mile.";
228
-
229
- const result = await scorer.run({
230
- input: [{ role: 'user', content: query }],
231
- output: { text: response },
148
+ const result = await runExperiment({
149
+ data: [
150
+ {
151
+ input: "When was the first iPhone released?",
152
+ },
153
+ {
154
+ input: "Tell me about the original iPhone announcement.",
155
+ },
156
+ ],
157
+ scorers: [scorer],
158
+ target: myAgent,
159
+ onItemComplete: ({ scorerResults }) => {
160
+ console.log({
161
+ score: scorerResults[scorer.name].score,
162
+ reason: scorerResults[scorer.name].reason,
163
+ });
164
+ },
232
165
  });
233
166
 
234
- console.log(result);
235
-
167
+ console.log(result.scores);
236
168
  ```
237
169
 
238
- #### Complete hallucination output
170
+ For more details on `runExperiment`, see the [runExperiment reference](/reference/scorers/run-experiment).
239
171
 
240
- The Scorer assigns a score of 1 because every statement in the response conflicts with the context. The details are fabricated or inaccurate across the board.
241
-
242
- ```typescript
243
- {
244
- score: 1,
245
- reason: 'The score is 1.0 because all three statements from the output directly contradict the context: the first flight was in 1903, not 1908; it lasted 12 seconds, not about 2 minutes; and it covered 120 feet, not nearly a mile.'
246
- }
247
- ```
172
+ To add this scorer to an agent, see the [Scorers overview](/docs/scorers/overview#adding-scorers-to-agents) guide.
248
173
 
249
174
  ## Related
250
175
 
@@ -102,124 +102,45 @@ The scorer handles several special cases:
102
102
  - Case differences: "JavaScript" matches "javascript"
103
103
  - Common words: Ignored in scoring to focus on meaningful keywords
104
104
 
105
- ## Examples
105
+ ## Example
106
106
 
107
- ### Full coverage example
107
+ Evaluate keyword coverage between input queries and agent responses:
108
108
 
109
- In this example, the response fully reflects the key terms from the input. All required keywords are present, resulting in complete coverage with no omissions.
110
-
111
- ```typescript title="src/example-full-keyword-coverage.ts" showLineNumbers copy
112
- import { createKeywordCoverageScorer } from "@mastra/evals/scorers/code";
113
-
114
- const scorer = createKeywordCoverageScorer();
115
-
116
- const input = "JavaScript frameworks like React and Vue";
117
- const output =
118
- "Popular JavaScript frameworks include React and Vue for web development";
119
-
120
- const result = await scorer.run({
121
- input: [{ role: "user", content: input }],
122
- output: { role: "assistant", text: output },
123
- });
124
-
125
- console.log("Score:", result.score);
126
- console.log("AnalyzeStepResult:", result.analyzeStepResult);
127
- ```
128
-
129
- #### Full coverage output
130
-
131
- A score of 1 indicates that all expected keywords were found in the response. The `analyzeStepResult` field confirms that the number of matched keywords equals the total number extracted from the input.
132
-
133
- ```typescript
134
- {
135
- score: 1,
136
- analyzeStepResult: {
137
- totalKeywords: 4,
138
- matchedKeywords: 4
139
- }
140
- }
141
- ```
142
-
143
- ### Partial coverage example
144
-
145
- In this example, the response includes some, but not all, of the important keywords from the input. The score reflects partial coverage, with key terms either missing or only partially matched.
146
-
147
- ```typescript title="src/example-partial-keyword-coverage.ts" showLineNumbers copy
109
+ ```typescript title="src/example-keyword-coverage.ts" showLineNumbers copy
110
+ import { runExperiment } from "@mastra/core/scores";
148
111
  import { createKeywordCoverageScorer } from "@mastra/evals/scorers/code";
112
+ import { myAgent } from "./agent";
149
113
 
150
114
  const scorer = createKeywordCoverageScorer();
151
115
 
152
- const input = "TypeScript offers interfaces, generics, and type inference";
153
- const output = "TypeScript provides type inference and some advanced features";
154
-
155
- const result = await scorer.run({
156
- input: [{ role: "user", content: input }],
157
- output: { role: "assistant", text: output },
158
- });
159
-
160
- console.log("Score:", result.score);
161
- console.log("AnalyzeStepResult:", result.analyzeStepResult);
162
- ```
163
-
164
- #### Partial coverage output
165
-
166
- A score of 0.5 indicates that only half of the expected keywords were found in the response. The `analyzeStepResult` field shows how many terms were matched compared to the total identified in the input.
167
-
168
- ```typescript
169
- {
170
- score: 0.5,
171
- analyzeStepResult: {
172
- totalKeywords: 6,
173
- matchedKeywords: 3
174
- }
175
- }
176
- ```
177
-
178
- ### Minimal coverage example
179
-
180
- In this example, the response includes very few of the important keywords from the input. The score reflects minimal coverage, with most key terms missing or unaccounted for.
181
-
182
- ```typescript title="src/example-minimal-keyword-coverage.ts" showLineNumbers copy
183
- import { createKeywordCoverageScorer } from "@mastra/evals/scorers/code";
184
-
185
- const scorer = createKeywordCoverageScorer();
186
-
187
- const input =
188
- "Machine learning models require data preprocessing, feature engineering, and hyperparameter tuning";
189
- const output = "Data preparation is important for models";
190
-
191
- const result = await scorer.run({
192
- input: [{ role: "user", content: input }],
193
- output: { role: "assistant", text: output },
116
+ const result = await runExperiment({
117
+ data: [
118
+ {
119
+ input: "JavaScript frameworks like React and Vue",
120
+ },
121
+ {
122
+ input: "TypeScript offers interfaces, generics, and type inference",
123
+ },
124
+ {
125
+ input:
126
+ "Machine learning models require data preprocessing, feature engineering, and hyperparameter tuning",
127
+ },
128
+ ],
129
+ scorers: [scorer],
130
+ target: myAgent,
131
+ onItemComplete: ({ scorerResults }) => {
132
+ console.log({
133
+ score: scorerResults[scorer.name].score,
134
+ });
135
+ },
194
136
  });
195
137
 
196
- console.log("Score:", result.score);
197
- console.log("AnalyzeStepResult:", result.analyzeStepResult);
198
- ```
199
-
200
- #### Minimal coverage output
201
-
202
- A low score indicates that only a small number of the expected keywords were present in the response. The `analyzeStepResult` field highlights the gap between total and matched keywords, signaling insufficient coverage.
203
-
204
- ```typescript
205
- {
206
- score: 0.2,
207
- analyzeStepResult: {
208
- totalKeywords: 10,
209
- matchedKeywords: 2
210
- }
211
- }
138
+ console.log(result.scores);
212
139
  ```
213
140
 
214
- ### Metric configuration
215
-
216
- You can create a `KeywordCoverageMetric` instance with default settings. No additional configuration is required.
217
-
218
- ```typescript
219
- const metric = new KeywordCoverageMetric();
220
- ```
141
+ For more details on `runExperiment`, see the [runExperiment reference](/reference/scorers/run-experiment).
221
142
 
222
- > See [KeywordCoverageScorer](/reference/scorers/keyword-coverage) for a full list of configuration options.
143
+ To add this scorer to an agent, see the [Scorers overview](/docs/scorers/overview#adding-scorers-to-agents) guide.
223
144
 
224
145
  ## Related
225
146
 
@@ -83,118 +83,45 @@ A textual difference score between 0 and 1:
83
83
  - **0.1–0.3**: Major differences – extensive changes needed.
84
84
  - **0.0**: Completely different texts.
85
85
 
86
- ## Examples
86
+ ## Example
87
87
 
88
- ### No differences example
88
+ Measure textual differences between expected and actual agent outputs:
89
89
 
90
- In this example, the texts are exactly the same. The scorer identifies complete similarity with a perfect score and no detected changes.
91
-
92
- ```typescript title="src/example-no-differences.ts" showLineNumbers copy
90
+ ```typescript title="src/example-textual-difference.ts" showLineNumbers copy
91
+ import { runExperiment } from "@mastra/core/scores";
93
92
  import { createTextualDifferenceScorer } from "@mastra/evals/scorers/code";
93
+ import { myAgent } from "./agent";
94
94
 
95
95
  const scorer = createTextualDifferenceScorer();
96
96
 
97
- const input = "The quick brown fox jumps over the lazy dog";
98
- const output = "The quick brown fox jumps over the lazy dog";
99
-
100
- const result = await scorer.run({
101
- input: [{ role: "user", content: input }],
102
- output: { role: "assistant", text: output },
103
- });
104
-
105
- console.log("Score:", result.score);
106
- console.log("AnalyzeStepResult:", result.analyzeStepResult);
107
- ```
108
-
109
- #### No differences output
110
-
111
- The scorer returns a high score, indicating the texts are identical. The detailed info confirms zero changes and no length difference.
112
-
113
- ```typescript
114
- {
115
- score: 1,
116
- analyzeStepResult: {
117
- confidence: 1,
118
- ratio: 1,
119
- changes: 0,
120
- lengthDiff: 0,
97
+ const result = await runExperiment({
98
+ data: [
99
+ {
100
+ input: "Summarize the concept of recursion",
101
+ groundTruth:
102
+ "Recursion is when a function calls itself to solve a problem by breaking it into smaller subproblems.",
103
+ },
104
+ {
105
+ input: "What is the capital of France?",
106
+ groundTruth: "The capital of France is Paris.",
107
+ },
108
+ ],
109
+ scorers: [scorer],
110
+ target: myAgent,
111
+ onItemComplete: ({ scorerResults }) => {
112
+ console.log({
113
+ score: scorerResults[scorer.name].score,
114
+ groundTruth: scorerResults[scorer.name].groundTruth,
115
+ });
121
116
  },
122
- }
123
- ```
124
-
125
- ### Minor differences example
126
-
127
- In this example, the texts have small variations. The scorer detects these minor differences and returns a moderate similarity score.
128
-
129
- ```typescript title="src/example-minor-differences.ts" showLineNumbers copy
130
- import { createTextualDifferenceScorer } from "@mastra/evals/scorers/code";
131
-
132
- const scorer = createTextualDifferenceScorer();
133
-
134
- const input = "Hello world! How are you?";
135
- const output = "Hello there! How is it going?";
136
-
137
- const result = await scorer.run({
138
- input: [{ role: "user", content: input }],
139
- output: { role: "assistant", text: output },
140
117
  });
141
118
 
142
- console.log("Score:", result.score);
143
- console.log("AnalyzeStepResult:", result.analyzeStepResult);
119
+ console.log(result.scores);
144
120
  ```
145
121
 
146
- #### Minor differences output
122
+ For more details on `runExperiment`, see the [runExperiment reference](/reference/scorers/run-experiment).
147
123
 
148
- The scorer returns a moderate score reflecting the small variations between the texts. The detailed info includes the number of changes and length difference observed.
149
-
150
- ```typescript
151
- {
152
- score: 0.5925925925925926,
153
- analyzeStepResult: {
154
- confidence: 0.8620689655172413,
155
- ratio: 0.5925925925925926,
156
- changes: 5,
157
- lengthDiff: 0.13793103448275862
158
- }
159
- }
160
- ```
161
-
162
- ### Major differences example
163
-
164
- In this example, the texts differ significantly. The scorer detects extensive changes and returns a low similarity score.
165
-
166
- ```typescript title="src/example-major-differences.ts" showLineNumbers copy
167
- import { createTextualDifferenceScorer } from "@mastra/evals/scorers/code";
168
-
169
- const scorer = createTextualDifferenceScorer();
170
-
171
- const input = "Python is a high-level programming language";
172
- const output = "JavaScript is used for web development";
173
-
174
- const result = await scorer.run({
175
- input: [{ role: "user", content: input }],
176
- output: { role: "assistant", text: output },
177
- });
178
-
179
- console.log("Score:", result.score);
180
- console.log("AnalyzeStepResult:", result.analyzeStepResult);
181
- ```
182
-
183
- #### Major differences output
184
-
185
- The scorer returns a low score due to significant differences between the texts. The detailed `analyzeStepResult` shows numerous changes and a notable length difference.
186
-
187
- ```typescript
188
- {
189
- score: 0.3170731707317073,
190
- analyzeStepResult: {
191
- confidence: 0.8636363636363636,
192
- ratio: 0.3170731707317073,
193
- changes: 8,
194
- lengthDiff: 0.13636363636363635
195
- }
196
- }
197
- ```
124
+ To add this scorer to an agent, see the [Scorers overview](/docs/scorers/overview#adding-scorers-to-agents) guide.
198
125
 
199
126
  ## Related
200
127