@mastra/mcp-docs-server 1.0.0-beta.3 → 1.0.0-beta.5

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 (219) hide show
  1. package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +201 -1
  2. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +201 -1
  3. package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +201 -1
  4. package/.docs/organized/changelogs/%40mastra%2Fastra.md +201 -1
  5. package/.docs/organized/changelogs/%40mastra%2Fauth.md +6 -0
  6. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +201 -1
  7. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +201 -1
  8. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +201 -1
  9. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +201 -1
  10. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +201 -1
  11. package/.docs/organized/changelogs/%40mastra%2Fcore.md +370 -170
  12. package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +201 -1
  13. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +201 -1
  14. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +201 -1
  15. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +201 -1
  16. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +201 -1
  17. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +201 -1
  18. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +201 -1
  19. package/.docs/organized/changelogs/%40mastra%2Fevals.md +201 -1
  20. package/.docs/organized/changelogs/%40mastra%2Flance.md +201 -1
  21. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +201 -1
  22. package/.docs/organized/changelogs/%40mastra%2Floggers.md +201 -1
  23. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +201 -1
  24. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +201 -1
  25. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +201 -1
  26. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +201 -1
  27. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +201 -1
  28. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +201 -1
  29. package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +201 -1
  30. package/.docs/organized/changelogs/%40mastra%2Fpg.md +201 -1
  31. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +201 -1
  32. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +201 -1
  33. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +201 -1
  34. package/.docs/organized/changelogs/%40mastra%2Frag.md +201 -1
  35. package/.docs/organized/changelogs/%40mastra%2Freact.md +80 -1
  36. package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +36 -0
  38. package/.docs/organized/changelogs/%40mastra%2Fserver.md +201 -1
  39. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +201 -1
  40. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +201 -1
  41. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +201 -1
  42. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +201 -1
  43. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +201 -1
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +201 -1
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +201 -1
  46. package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +92 -1
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +67 -1
  48. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +201 -1
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +201 -1
  50. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +201 -1
  51. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +201 -1
  52. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +201 -1
  53. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +201 -1
  54. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +201 -1
  55. package/.docs/organized/changelogs/create-mastra.md +201 -1
  56. package/.docs/organized/changelogs/mastra.md +201 -1
  57. package/.docs/organized/code-examples/memory-with-processors.md +1 -1
  58. package/.docs/organized/code-examples/quick-start.md +1 -1
  59. package/.docs/raw/agents/adding-voice.mdx +55 -9
  60. package/.docs/raw/agents/guardrails.mdx +19 -20
  61. package/.docs/raw/agents/human-in-the-loop-with-tools.mdx +6 -5
  62. package/.docs/raw/agents/networks.mdx +1 -2
  63. package/.docs/raw/agents/overview.mdx +5 -5
  64. package/.docs/raw/agents/using-tools.mdx +4 -5
  65. package/.docs/raw/course/01-first-agent/05-running-playground.md +5 -5
  66. package/.docs/raw/course/01-first-agent/09-testing-your-agent.md +3 -3
  67. package/.docs/raw/course/01-first-agent/13-testing-your-tool.md +3 -3
  68. package/.docs/raw/course/01-first-agent/17-testing-memory.md +2 -2
  69. package/.docs/raw/course/04-workflows/07-using-playground.md +1 -1
  70. package/.docs/raw/deployment/building-mastra.mdx +1 -1
  71. package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +1 -1
  72. package/.docs/raw/deployment/cloud-providers/aws-lambda.mdx +1 -1
  73. package/.docs/raw/deployment/cloud-providers/azure-app-services.mdx +1 -1
  74. package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +1 -1
  75. package/.docs/raw/deployment/cloud-providers/index.mdx +1 -1
  76. package/.docs/raw/deployment/mastra-cloud/observability.mdx +19 -17
  77. package/.docs/raw/deployment/mastra-cloud/setting-up.mdx +1 -1
  78. package/.docs/raw/deployment/overview.mdx +2 -2
  79. package/.docs/raw/deployment/web-framework.mdx +5 -5
  80. package/.docs/raw/evals/custom-scorers.mdx +3 -5
  81. package/.docs/raw/evals/overview.mdx +2 -3
  82. package/.docs/raw/getting-started/project-structure.mdx +1 -1
  83. package/.docs/raw/getting-started/start.mdx +72 -0
  84. package/.docs/raw/getting-started/studio.mdx +1 -1
  85. package/.docs/raw/{frameworks/agentic-uis/ai-sdk.mdx → guides/build-your-ui/ai-sdk-ui.mdx} +105 -11
  86. package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/astro.mdx +23 -25
  87. package/.docs/raw/{frameworks/servers → guides/getting-started}/express.mdx +3 -4
  88. package/.docs/raw/guides/{guide → getting-started}/manual-install.mdx +1 -1
  89. package/.docs/raw/guides/{quickstarts/nextjs.mdx → getting-started/next-js.mdx} +11 -11
  90. package/.docs/raw/guides/{quickstarts/standalone-server.mdx → getting-started/quickstart.mdx} +7 -7
  91. package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/sveltekit.mdx +23 -25
  92. package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/vite-react.mdx +7 -7
  93. package/.docs/raw/guides/guide/ai-recruiter.mdx +2 -3
  94. package/.docs/raw/guides/guide/chef-michel.mdx +2 -3
  95. package/.docs/raw/guides/guide/notes-mcp-server.mdx +2 -2
  96. package/.docs/raw/guides/guide/research-assistant.mdx +7 -8
  97. package/.docs/raw/guides/guide/stock-agent.mdx +4 -6
  98. package/.docs/raw/guides/guide/web-search.mdx +12 -10
  99. package/.docs/raw/guides/migrations/agentnetwork.mdx +4 -4
  100. package/.docs/raw/guides/migrations/ai-sdk-v4-to-v5.mdx +1 -1
  101. package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +29 -0
  102. package/.docs/raw/guides/migrations/upgrade-to-v1/tools.mdx +5 -0
  103. package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +22 -0
  104. package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +2 -2
  105. package/.docs/raw/index.mdx +2 -2
  106. package/.docs/raw/mcp/overview.mdx +3 -5
  107. package/.docs/raw/memory/memory-processors.mdx +1 -2
  108. package/.docs/raw/memory/semantic-recall.mdx +7 -7
  109. package/.docs/raw/memory/storage/memory-with-libsql.mdx +2 -4
  110. package/.docs/raw/memory/storage/memory-with-mongodb.mdx +2 -4
  111. package/.docs/raw/memory/storage/memory-with-pg.mdx +2 -4
  112. package/.docs/raw/memory/storage/memory-with-upstash.mdx +2 -4
  113. package/.docs/raw/memory/threads-and-resources.mdx +3 -3
  114. package/.docs/raw/memory/working-memory.mdx +4 -5
  115. package/.docs/raw/{logging.mdx → observability/logging.mdx} +1 -1
  116. package/.docs/raw/observability/overview.mdx +2 -2
  117. package/.docs/raw/observability/tracing/exporters/otel.mdx +21 -2
  118. package/.docs/raw/observability/tracing/exporters/posthog.mdx +107 -0
  119. package/.docs/raw/observability/tracing/overview.mdx +3 -2
  120. package/.docs/raw/rag/chunking-and-embedding.mdx +16 -17
  121. package/.docs/raw/rag/overview.mdx +3 -2
  122. package/.docs/raw/rag/retrieval.mdx +20 -32
  123. package/.docs/raw/reference/agents/agent.mdx +7 -10
  124. package/.docs/raw/reference/agents/generate.mdx +11 -92
  125. package/.docs/raw/reference/agents/generateLegacy.mdx +2 -2
  126. package/.docs/raw/reference/agents/getLLM.mdx +1 -1
  127. package/.docs/raw/reference/agents/network.mdx +5 -88
  128. package/.docs/raw/reference/cli/mastra.mdx +2 -1
  129. package/.docs/raw/reference/client-js/agents.mdx +3 -3
  130. package/.docs/raw/reference/core/getLogger.mdx +1 -1
  131. package/.docs/raw/reference/core/listLogs.mdx +1 -1
  132. package/.docs/raw/reference/core/listLogsByRunId.mdx +1 -1
  133. package/.docs/raw/reference/core/mastra-model-gateway.mdx +5 -19
  134. package/.docs/raw/reference/core/setLogger.mdx +1 -1
  135. package/.docs/raw/reference/core/setTelemetry.mdx +1 -1
  136. package/.docs/raw/reference/evals/answer-relevancy.mdx +28 -98
  137. package/.docs/raw/reference/evals/answer-similarity.mdx +12 -258
  138. package/.docs/raw/reference/evals/bias.mdx +29 -87
  139. package/.docs/raw/reference/evals/completeness.mdx +31 -90
  140. package/.docs/raw/reference/evals/content-similarity.mdx +28 -88
  141. package/.docs/raw/reference/evals/context-precision.mdx +28 -130
  142. package/.docs/raw/reference/evals/context-relevance.mdx +11 -11
  143. package/.docs/raw/reference/evals/faithfulness.mdx +28 -101
  144. package/.docs/raw/reference/evals/hallucination.mdx +28 -103
  145. package/.docs/raw/reference/evals/keyword-coverage.mdx +28 -107
  146. package/.docs/raw/reference/evals/noise-sensitivity.mdx +11 -11
  147. package/.docs/raw/reference/evals/prompt-alignment.mdx +15 -15
  148. package/.docs/raw/reference/evals/textual-difference.mdx +27 -100
  149. package/.docs/raw/reference/evals/tone-consistency.mdx +25 -98
  150. package/.docs/raw/reference/evals/tool-call-accuracy.mdx +7 -7
  151. package/.docs/raw/reference/evals/toxicity.mdx +29 -92
  152. package/.docs/raw/reference/memory/memory-class.mdx +5 -7
  153. package/.docs/raw/reference/observability/tracing/exporters/posthog.mdx +132 -0
  154. package/.docs/raw/reference/processors/batch-parts-processor.mdx +1 -1
  155. package/.docs/raw/reference/processors/language-detector.mdx +1 -1
  156. package/.docs/raw/reference/processors/moderation-processor.mdx +2 -2
  157. package/.docs/raw/reference/processors/pii-detector.mdx +2 -2
  158. package/.docs/raw/reference/processors/prompt-injection-detector.mdx +1 -1
  159. package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -3
  160. package/.docs/raw/reference/processors/token-limiter-processor.mdx +2 -2
  161. package/.docs/raw/reference/processors/unicode-normalizer.mdx +1 -1
  162. package/.docs/raw/reference/rag/embeddings.mdx +5 -5
  163. package/.docs/raw/reference/rag/rerank.mdx +1 -2
  164. package/.docs/raw/reference/rag/rerankWithScorer.mdx +0 -1
  165. package/.docs/raw/reference/streaming/agents/stream.mdx +11 -93
  166. package/.docs/raw/reference/templates/overview.mdx +1 -4
  167. package/.docs/raw/reference/tools/client.mdx +1 -2
  168. package/.docs/raw/reference/tools/create-tool.mdx +132 -0
  169. package/.docs/raw/reference/tools/graph-rag-tool.mdx +5 -5
  170. package/.docs/raw/reference/tools/mcp-client.mdx +2 -4
  171. package/.docs/raw/reference/tools/mcp-server.mdx +1 -2
  172. package/.docs/raw/reference/tools/vector-query-tool.mdx +14 -15
  173. package/.docs/raw/reference/vectors/chroma.mdx +81 -1
  174. package/.docs/raw/reference/vectors/couchbase.mdx +24 -17
  175. package/.docs/raw/reference/vectors/lance.mdx +38 -22
  176. package/.docs/raw/reference/vectors/libsql.mdx +35 -2
  177. package/.docs/raw/reference/vectors/mongodb.mdx +35 -2
  178. package/.docs/raw/reference/vectors/opensearch.mdx +37 -16
  179. package/.docs/raw/reference/vectors/pg.mdx +43 -36
  180. package/.docs/raw/reference/vectors/pinecone.mdx +48 -1
  181. package/.docs/raw/reference/vectors/qdrant.mdx +36 -1
  182. package/.docs/raw/reference/vectors/turbopuffer.mdx +74 -0
  183. package/.docs/raw/reference/voice/composite-voice.mdx +71 -28
  184. package/.docs/raw/reference/voice/openai-realtime.mdx +2 -2
  185. package/.docs/raw/reference/voice/voice.addInstructions.mdx +2 -3
  186. package/.docs/raw/reference/voice/voice.addTools.mdx +1 -1
  187. package/.docs/raw/reference/voice/voice.answer.mdx +1 -1
  188. package/.docs/raw/reference/voice/voice.close.mdx +1 -1
  189. package/.docs/raw/reference/voice/voice.connect.mdx +1 -1
  190. package/.docs/raw/reference/voice/voice.listen.mdx +86 -52
  191. package/.docs/raw/reference/voice/voice.off.mdx +1 -1
  192. package/.docs/raw/reference/voice/voice.on.mdx +1 -1
  193. package/.docs/raw/reference/voice/voice.send.mdx +1 -1
  194. package/.docs/raw/reference/voice/voice.speak.mdx +75 -40
  195. package/.docs/raw/reference/voice/voice.updateConfig.mdx +1 -1
  196. package/.docs/raw/server-db/mastra-client.mdx +1 -2
  197. package/.docs/raw/streaming/overview.mdx +20 -9
  198. package/.docs/raw/streaming/tool-streaming.mdx +47 -4
  199. package/.docs/raw/tools-mcp/advanced-usage.mdx +1 -2
  200. package/.docs/raw/tools-mcp/mcp-overview.mdx +3 -5
  201. package/.docs/raw/voice/overview.mdx +87 -40
  202. package/.docs/raw/voice/speech-to-speech.mdx +4 -4
  203. package/.docs/raw/voice/speech-to-text.mdx +1 -2
  204. package/.docs/raw/voice/text-to-speech.mdx +1 -2
  205. package/.docs/raw/workflows/control-flow.mdx +180 -0
  206. package/.docs/raw/workflows/overview.mdx +1 -1
  207. package/CHANGELOG.md +17 -0
  208. package/dist/{chunk-5NJC7NRO.js → chunk-4CM2BQNP.js} +24 -4
  209. package/dist/prepare-docs/package-changes.d.ts.map +1 -1
  210. package/dist/prepare-docs/prepare.js +1 -1
  211. package/dist/stdio.js +1 -1
  212. package/package.json +7 -7
  213. package/.docs/raw/frameworks/agentic-uis/cedar-os.mdx +0 -102
  214. package/.docs/raw/frameworks/agentic-uis/openrouter.mdx +0 -179
  215. package/.docs/raw/frameworks/web-frameworks/next-js.mdx +0 -379
  216. package/.docs/raw/getting-started/quickstart.mdx +0 -27
  217. package/.docs/raw/getting-started/templates.mdx +0 -73
  218. /package/.docs/raw/{frameworks/agentic-uis → guides/build-your-ui}/assistant-ui.mdx +0 -0
  219. /package/.docs/raw/{frameworks/agentic-uis → guides/build-your-ui}/copilotkit.mdx +0 -0
@@ -15,9 +15,8 @@ import { createOpenAICompatible } from '@ai-sdk/openai-compatible-v5';
15
15
  import type { LanguageModelV2 } from '@ai-sdk/provider-v5';
16
16
 
17
17
  class MyCustomGateway extends MastraModelGateway {
18
- readonly id = 'my-custom-gateway';
18
+ readonly id = 'custom';
19
19
  readonly name = 'My Custom Gateway';
20
- readonly prefix = 'custom';
21
20
 
22
21
  async fetchProviders(): Promise<Record<string, ProviderConfig>> {
23
22
  return {
@@ -66,7 +65,7 @@ class MyCustomGateway extends MastraModelGateway {
66
65
  {
67
66
  name: 'id',
68
67
  type: 'string',
69
- description: 'Unique identifier for the gateway. Used for versioning and identification.',
68
+ description: 'Unique identifier for the gateway. This ID is used as the prefix for all providers from this gateway (e.g., "netlify/anthropic"). Exception: models.dev is a provider registry and doesn\'t use a prefix.',
70
69
  },
71
70
  {
72
71
  name: 'name',
@@ -76,18 +75,6 @@ class MyCustomGateway extends MastraModelGateway {
76
75
  ]}
77
76
  />
78
77
 
79
- ## Optional Properties
80
-
81
- <PropertiesTable
82
- content={[
83
- {
84
- name: 'prefix',
85
- type: 'string | undefined',
86
- description: 'Optional prefix for provider IDs. If set, all providers from this gateway will be prefixed (e.g., "netlify/openai"). Registry gateways typically don\'t have a prefix.',
87
- },
88
- ]}
89
- />
90
-
91
78
  ## Required Methods
92
79
 
93
80
  ### fetchProviders()
@@ -217,15 +204,14 @@ Returns the gateway's unique identifier.
217
204
 
218
205
  ## Model ID Format
219
206
 
220
- When a gateway has a prefix, models are accessed using this format:
207
+ For true gateways, the gateway ID is used as a prefix and models are accessed using this format:
221
208
 
222
209
  ```
223
- [prefix]/[provider]/[model]
210
+ [gateway-id]/[provider]/[model]
224
211
  ```
225
212
 
226
213
  Examples:
227
- - With prefix `'custom'`: `'custom/my-provider/model-1'`
228
- - Without prefix: `'my-provider/model-1'`
214
+ - Gateway with `id = 'custom'`: `'custom/my-provider/model-1'`
229
215
 
230
216
  ## Built-in Implementations
231
217
 
@@ -45,5 +45,5 @@ This method does not return a value.
45
45
 
46
46
  ## Related
47
47
 
48
- - [Logging overview](/docs/v1/logging)
48
+ - [Logging overview](/docs/v1/observability/logging)
49
49
  - [Logger reference](/reference/v1/logging/pino-logger)
@@ -32,5 +32,5 @@ This method does not return a value.
32
32
 
33
33
  ## Related
34
34
 
35
- - [Logging](/docs/v1/logging)
35
+ - [Logging](/docs/v1/observability/logging)
36
36
  - [PinoLogger](/reference/v1/logging/pino-logger)
@@ -112,115 +112,45 @@ A relevancy score between 0 and 1:
112
112
  - **0.1–0.3**: The response includes minimal relevant content and largely misses the intent of the query.
113
113
  - **0.0**: The response is entirely unrelated and does not answer the query.
114
114
 
115
- ## Examples
115
+ ## Example
116
116
 
117
- ### High relevancy example
117
+ Evaluate agent responses for relevancy across different scenarios:
118
118
 
119
- In this example, the response accurately addresses the input query with specific and relevant information.
120
-
121
- ```typescript title="src/example-high-answer-relevancy.ts" showLineNumbers copy
119
+ ```typescript title="src/example-answer-relevancy.ts" showLineNumbers copy
120
+ import { runEvals } from "@mastra/core/evals";
122
121
  import { createAnswerRelevancyScorer } from "@mastra/evals/scorers/prebuilt";
122
+ import { myAgent } from "./agent";
123
123
 
124
- const scorer = createAnswerRelevancyScorer({ model: "openai/gpt-4o-mini" });
124
+ const scorer = createAnswerRelevancyScorer({ model: "openai/gpt-4o" });
125
125
 
126
- const inputMessages = [
127
- {
128
- role: "user",
129
- content: "What are the health benefits of regular exercise?",
126
+ const result = await runEvals({
127
+ data: [
128
+ {
129
+ input: "What are the health benefits of regular exercise?",
130
+ },
131
+ {
132
+ input: "What should a healthy breakfast include?",
133
+ },
134
+ {
135
+ input: "What are the benefits of meditation?",
136
+ },
137
+ ],
138
+ scorers: [scorer],
139
+ target: myAgent,
140
+ onItemComplete: ({ scorerResults }) => {
141
+ console.log({
142
+ score: scorerResults[scorer.id].score,
143
+ reason: scorerResults[scorer.id].reason,
144
+ });
130
145
  },
131
- ];
132
- const outputMessage = {
133
- text: "Regular exercise improves cardiovascular health, strengthens muscles, boosts metabolism, and enhances mental well-being through the release of endorphins.",
134
- };
135
-
136
- const result = await scorer.run({
137
- input: inputMessages,
138
- output: outputMessage,
139
146
  });
140
147
 
141
- console.log(result);
148
+ console.log(result.scores);
142
149
  ```
143
150
 
144
- #### High relevancy output
145
-
146
- The output receives a high score because it accurately answers the query without including unrelated information.
147
-
148
- ```typescript
149
- {
150
- score: 1,
151
- reason: 'The score is 1 because the output directly addresses the question by providing multiple explicit health benefits of regular exercise, including improvements in cardiovascular health, muscle strength, metabolism, and mental well-being. Each point is relevant and contributes to a comprehensive understanding of the health benefits.'
152
- }
153
- ```
151
+ For more details on `runEvals`, see the [runEvals reference](/reference/v1/evals/run-evals).
154
152
 
155
- ### Partial relevancy example
156
-
157
- In this example, the response addresses the query in part but includes additional information that isn't directly relevant.
158
-
159
- ```typescript title="src/example-partial-answer-relevancy.ts" showLineNumbers copy
160
- import { createAnswerRelevancyScorer } from "@mastra/evals/scorers/prebuilt";
161
-
162
- const scorer = createAnswerRelevancyScorer({ model: "openai/gpt-4o-mini" });
163
-
164
- const inputMessages = [
165
- { role: "user", content: "What should a healthy breakfast include?" },
166
- ];
167
- const outputMessage = {
168
- text: "A nutritious breakfast should include whole grains and protein. However, the timing of your breakfast is just as important - studies show eating within 2 hours of waking optimizes metabolism and energy levels throughout the day.",
169
- };
170
-
171
- const result = await scorer.run({
172
- input: inputMessages,
173
- output: outputMessage,
174
- });
175
-
176
- console.log(result);
177
- ```
178
-
179
- #### Partial relevancy output
180
-
181
- The output receives a lower score because it partially answers the query. While some relevant information is included, unrelated details reduce the overall relevance.
182
-
183
- ```typescript
184
- {
185
- score: 0.25,
186
- reason: 'The score is 0.25 because the output provides a direct answer by mentioning whole grains and protein as components of a healthy breakfast, which is relevant. However, the additional information about the timing of breakfast and its effects on metabolism and energy levels is not directly related to the question, leading to a lower overall relevance score.'
187
- }
188
- ```
189
-
190
- ## Low relevancy example
191
-
192
- In this example, the response does not address the query and contains information that is entirely unrelated.
193
-
194
- ```typescript title="src/example-low-answer-relevancy.ts" showLineNumbers copy
195
- import { createAnswerRelevancyScorer } from "@mastra/evals/scorers/prebuilt";
196
-
197
- const scorer = createAnswerRelevancyScorer({ model: "openai/gpt-4o-mini" });
198
-
199
- const inputMessages = [
200
- { role: "user", content: "What are the benefits of meditation?" },
201
- ];
202
- const outputMessage = {
203
- text: "The Great Wall of China is over 13,000 miles long and was built during the Ming Dynasty to protect against invasions.",
204
- };
205
-
206
- const result = await scorer.run({
207
- input: inputMessages,
208
- output: outputMessage,
209
- });
210
-
211
- console.log(result);
212
- ```
213
-
214
- #### Low relevancy output
215
-
216
- The output receives a score of 0 because it fails to answer the query or provide any relevant information.
217
-
218
- ```typescript
219
- {
220
- score: 0,
221
- reason: 'The score is 0 because the output about the Great Wall of China is completely unrelated to the benefits of meditation, providing no relevant information or context that addresses the input question.'
222
- }
223
- ```
153
+ To add this scorer to an agent, see the [Scorers overview](/docs/v1/evals/overview) guide.
224
154
 
225
155
  ## Related
226
156
 
@@ -149,46 +149,16 @@ The scorer uses a multi-step process:
149
149
 
150
150
  Score calculation: `max(0, base_score - contradiction_penalty - missing_penalty - extra_info_penalty) × scale`
151
151
 
152
- ## Examples
152
+ ## Example
153
153
 
154
- ### Usage with runEvals
154
+ Evaluate agent responses for similarity to ground truth across different scenarios:
155
155
 
156
- This scorer is designed for use with `runEvals` for CI/CD testing:
157
-
158
- ```typescript
159
- import { runEvals } from "@mastra/core/evals";
160
- import { createAnswerSimilarityScorer } from "@mastra/evals/scorers/prebuilt";
161
-
162
- const scorer = createAnswerSimilarityScorer({ model });
163
-
164
- await runEvals({
165
- data: [
166
- {
167
- input: "What is the capital of France?",
168
- groundTruth: "Paris is the capital of France",
169
- },
170
- ],
171
- scorers: [scorer],
172
- target: myAgent,
173
- onItemComplete: ({ scorerResults }) => {
174
- // Assert similarity score meets threshold
175
- expect(scorerResults["Answer Similarity Scorer"].score).toBeGreaterThan(
176
- 0.8,
177
- );
178
- },
179
- });
180
- ```
181
-
182
- ### Perfect similarity example
183
-
184
- In this example, the agent's output semantically matches the ground truth perfectly.
185
-
186
- ```typescript title="src/example-perfect-similarity.ts" showLineNumbers copy
156
+ ```typescript title="src/example-answer-similarity.ts" showLineNumbers copy
187
157
  import { runEvals } from "@mastra/core/evals";
188
158
  import { createAnswerSimilarityScorer } from "@mastra/evals/scorers/prebuilt";
189
159
  import { myAgent } from "./agent";
190
160
 
191
- const scorer = createAnswerSimilarityScorer({ model: "openai/gpt-4o-mini" });
161
+ const scorer = createAnswerSimilarityScorer({ model: "openai/gpt-4o" });
192
162
 
193
163
  const result = await runEvals({
194
164
  data: [
@@ -196,78 +166,10 @@ const result = await runEvals({
196
166
  input: "What is 2+2?",
197
167
  groundTruth: "4",
198
168
  },
199
- ],
200
- scorers: [scorer],
201
- target: myAgent,
202
- });
203
-
204
- console.log(result.scores);
205
- ```
206
-
207
- #### Perfect similarity output
208
-
209
- The output receives a perfect score because both the agent's answer and ground truth are identical.
210
-
211
- ```typescript
212
- {
213
- "Answer Similarity Scorer": {
214
- score: 1.0,
215
- reason: "The score is 1.0/1 because the output matches the ground truth exactly. The agent correctly provided the numerical answer. No improvements needed as the response is fully accurate."
216
- }
217
- }
218
- ```
219
-
220
- ### High semantic similarity example
221
-
222
- In this example, the agent provides the same information as the ground truth but with different phrasing.
223
-
224
- ```typescript title="src/example-semantic-similarity.ts" showLineNumbers copy
225
- import { runEvals } from "@mastra/core/evals";
226
- import { createAnswerSimilarityScorer } from "@mastra/evals/scorers/prebuilt";
227
- import { myAgent } from "./agent";
228
-
229
- const scorer = createAnswerSimilarityScorer({ model: "openai/gpt-4o-mini" });
230
-
231
- const result = await runEvals({
232
- data: [
233
169
  {
234
170
  input: "What is the capital of France?",
235
171
  groundTruth: "The capital of France is Paris",
236
172
  },
237
- ],
238
- scorers: [scorer],
239
- target: myAgent,
240
- });
241
-
242
- console.log(result.scores);
243
- ```
244
-
245
- #### High semantic similarity output
246
-
247
- The output receives a high score because it conveys the same information with equivalent meaning.
248
-
249
- ```typescript
250
- {
251
- "Answer Similarity Scorer": {
252
- score: 0.9,
253
- reason: "The score is 0.9/1 because both answers convey the same information about Paris being the capital of France. The agent correctly identified the main fact with slightly different phrasing. Minor variation in structure but semantically equivalent."
254
- }
255
- }
256
- ```
257
-
258
- ### Partial similarity example
259
-
260
- In this example, the agent's response is partially correct but missing key information.
261
-
262
- ```typescript title="src/example-partial-similarity.ts" showLineNumbers copy
263
- import { runEvals } from "@mastra/core/evals";
264
- import { createAnswerSimilarityScorer } from "@mastra/evals/scorers/prebuilt";
265
- import { myAgent } from "./agent";
266
-
267
- const scorer = createAnswerSimilarityScorer({ model: "openai/gpt-4o-mini" });
268
-
269
- const result = await runEvals({
270
- data: [
271
173
  {
272
174
  input: "What are the primary colors?",
273
175
  groundTruth: "The primary colors are red, blue, and yellow",
@@ -275,165 +177,17 @@ const result = await runEvals({
275
177
  ],
276
178
  scorers: [scorer],
277
179
  target: myAgent,
278
- });
279
-
280
- console.log(result.scores);
281
- ```
282
-
283
- #### Partial similarity output
284
-
285
- The output receives a moderate score because it includes some correct information but is incomplete.
286
-
287
- ```typescript
288
- {
289
- "Answer Similarity Scorer": {
290
- score: 0.6,
291
- reason: "The score is 0.6/1 because the answer captures some key elements but is incomplete. The agent correctly identified red and blue as primary colors. However, it missed the critical color yellow, which is essential for a complete answer."
292
- }
293
- }
294
- ```
295
-
296
- ### Contradiction example
297
-
298
- In this example, the agent provides factually incorrect information that contradicts the ground truth.
299
-
300
- ```typescript title="src/example-contradiction.ts" showLineNumbers copy
301
- import { runEvals } from "@mastra/core/evals";
302
- import { createAnswerSimilarityScorer } from "@mastra/evals/scorers/prebuilt";
303
- import { myAgent } from "./agent";
304
-
305
- const scorer = createAnswerSimilarityScorer({ model: "openai/gpt-4o-mini" });
306
-
307
- const result = await runEvals({
308
- data: [
309
- {
310
- input: "Who wrote Romeo and Juliet?",
311
- groundTruth: "William Shakespeare wrote Romeo and Juliet",
312
- },
313
- ],
314
- scorers: [scorer],
315
- target: myAgent,
316
- });
317
-
318
- console.log(result.scores);
319
- ```
320
-
321
- #### Contradiction output
322
-
323
- The output receives a very low score because it contains factually incorrect information.
324
-
325
- ```typescript
326
- {
327
- "Answer Similarity Scorer": {
328
- score: 0.0,
329
- reason: "The score is 0.0/1 because the output contains a critical error regarding authorship. The agent correctly identified the play title but incorrectly attributed it to Christopher Marlowe instead of William Shakespeare, which is a fundamental contradiction."
330
- }
331
- }
332
- ```
333
-
334
- ### CI/CD Integration example
335
-
336
- Use the scorer in your test suites to ensure agent consistency over time:
337
-
338
- ```typescript title="src/ci-integration.test.ts" showLineNumbers copy
339
- import { describe, it, expect } from "vitest";
340
- import { runEvals } from "@mastra/core/evals";
341
- import { createAnswerSimilarityScorer } from "@mastra/evals/scorers/prebuilt";
342
- import { myAgent } from "./agent";
343
-
344
- describe("Agent Consistency Tests", () => {
345
- const scorer = createAnswerSimilarityScorer({ model: "openai/gpt-4o-mini" });
346
-
347
- it("should provide accurate factual answers", async () => {
348
- const result = await runEvals({
349
- data: [
350
- {
351
- input: "What is the speed of light?",
352
- groundTruth:
353
- "The speed of light in vacuum is 299,792,458 meters per second",
354
- },
355
- {
356
- input: "What is the capital of Japan?",
357
- groundTruth: "Tokyo is the capital of Japan",
358
- },
359
- ],
360
- scorers: [scorer],
361
- target: myAgent,
180
+ onItemComplete: ({ scorerResults }) => {
181
+ console.log({
182
+ score: scorerResults[scorer.id].score,
183
+ reason: scorerResults[scorer.id].reason,
362
184
  });
363
-
364
- // Assert all answers meet similarity threshold
365
- expect(result.scores["Answer Similarity Scorer"].score).toBeGreaterThan(
366
- 0.8,
367
- );
368
- });
369
-
370
- it("should maintain consistency across runs", async () => {
371
- const testData = {
372
- input: "Define machine learning",
373
- groundTruth:
374
- "Machine learning is a subset of AI that enables systems to learn and improve from experience",
375
- };
376
-
377
- // Run multiple times to check consistency
378
- const results = await Promise.all([
379
- runEvals({ data: [testData], scorers: [scorer], target: myAgent }),
380
- runEvals({ data: [testData], scorers: [scorer], target: myAgent }),
381
- runEvals({ data: [testData], scorers: [scorer], target: myAgent }),
382
- ]);
383
-
384
- // Check that all runs produce similar scores (within 0.1 tolerance)
385
- const scores = results.map(
386
- (r) => r.scores["Answer Similarity Scorer"].score,
387
- );
388
- const maxDiff = Math.max(...scores) - Math.min(...scores);
389
- expect(maxDiff).toBeLessThan(0.1);
390
- });
391
- });
392
- ```
393
-
394
- ### Custom configuration example
395
-
396
- Customize the scorer behavior for specific use cases:
397
-
398
- ```typescript title="src/custom-config.ts" showLineNumbers copy
399
- import { runEvals } from "@mastra/core/evals";
400
- import { createAnswerSimilarityScorer } from "@mastra/evals/scorers/prebuilt";
401
- import { myAgent } from "./agent";
402
-
403
- // Configure for strict exact matching with high scale
404
- const strictScorer = createAnswerSimilarityScorer({
405
- model: "openai/gpt-4o-mini",
406
- options: {
407
- exactMatchBonus: 0.5, // Higher bonus for exact matches
408
- contradictionPenalty: 2.0, // Very strict on contradictions
409
- missingPenalty: 0.3, // Higher penalty for missing info
410
- scale: 10, // Score out of 10 instead of 1
411
185
  },
412
186
  });
413
187
 
414
- // Configure for lenient semantic matching
415
- const lenientScorer = createAnswerSimilarityScorer({
416
- model: "openai/gpt-4o-mini",
417
- options: {
418
- semanticThreshold: 0.6, // Lower threshold for semantic matches
419
- contradictionPenalty: 0.5, // More forgiving on minor contradictions
420
- extraInfoPenalty: 0, // No penalty for extra information
421
- requireGroundTruth: false, // Allow missing ground truth
422
- },
423
- });
188
+ console.log(result.scores);
189
+ ```
424
190
 
425
- const result = await runEvals({
426
- data: [
427
- {
428
- input: "Explain photosynthesis",
429
- groundTruth:
430
- "Photosynthesis is the process by which plants convert light energy into chemical energy",
431
- },
432
- ],
433
- scorers: [strictScorer, lenientScorer],
434
- target: myAgent,
435
- });
191
+ For more details on `runEvals`, see the [runEvals reference](/reference/v1/evals/run-evals).
436
192
 
437
- console.log("Strict scorer:", result.scores["Answer Similarity Scorer"].score); // Out of 10
438
- console.log("Lenient scorer:", result.scores["Answer Similarity Scorer"].score); // Out of 1
439
- ```
193
+ To add this scorer to an agent, see the [Scorers overview](/docs/v1/evals/overview#adding-scorers-to-agents) guide.
@@ -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
- ## Examples
126
+ ## Example
127
127
 
128
- ### High bias example
128
+ Evaluate agent responses for bias across different types of questions:
129
129
 
130
- In this example, the response contains overtly biased language and generalizations. The assumptions are explicit and strongly reinforce stereotypes or discriminatory views.
131
-
132
- ```typescript title="src/example-high-bias.ts" showLineNumbers copy
133
- import { createBiasScorer } from "@mastra/evals/scorers/prebuilt";
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/prebuilt";
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 { runEvals } from "@mastra/core/evals";
197
132
  import { createBiasScorer } from "@mastra/evals/scorers/prebuilt";
133
+ import { myAgent } from "./agent";
198
134
 
199
- const scorer = createBiasScorer({ model: "openai/gpt-4o-mini" });
135
+ const scorer = createBiasScorer({ model: "openai/gpt-4o" });
200
136
 
201
- const query = "What is the best hiring practice?";
202
- const response =
203
- "Effective hiring practices focus on objective criteria such as skills, experience, and demonstrated abilities. Using structured interviews and standardized assessments helps ensure fair evaluation of all candidates based on merit.";
204
-
205
- const result = await scorer.run({
206
- input: [{ role: "user", content: query }],
207
- output: { text: response },
137
+ const result = await runEvals({
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.id].score,
154
+ reason: scorerResults[scorer.id].reason,
155
+ });
156
+ },
208
157
  });
209
158
 
210
- console.log(result);
159
+ console.log(result.scores);
211
160
  ```
212
161
 
213
- #### Low bias output
162
+ For more details on `runEvals`, see the [runEvals reference](/reference/v1/evals/run-evals).
214
163
 
215
- The output receives a low score because it does not exhibit biased language or reasoning.
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/v1/evals/overview#adding-scorers-to-agents) guide.
223
165
 
224
166
  ## Related
225
167