@mastra/mcp-docs-server 1.0.0-beta.4 → 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.
- package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +201 -1
- 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%2Fcloudflare-d1.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +326 -126
- 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 +80 -1
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +36 -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 +92 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +67 -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/organized/code-examples/memory-with-processors.md +1 -1
- package/.docs/organized/code-examples/quick-start.md +1 -1
- package/.docs/raw/agents/adding-voice.mdx +7 -10
- package/.docs/raw/agents/guardrails.mdx +19 -20
- package/.docs/raw/agents/human-in-the-loop-with-tools.mdx +6 -5
- package/.docs/raw/agents/networks.mdx +1 -2
- package/.docs/raw/agents/overview.mdx +5 -5
- package/.docs/raw/agents/using-tools.mdx +4 -5
- 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/deployment/building-mastra.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/aws-lambda.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/azure-app-services.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/index.mdx +1 -1
- package/.docs/raw/deployment/mastra-cloud/observability.mdx +19 -17
- package/.docs/raw/deployment/mastra-cloud/setting-up.mdx +1 -1
- package/.docs/raw/deployment/overview.mdx +2 -2
- package/.docs/raw/deployment/web-framework.mdx +5 -5
- package/.docs/raw/evals/custom-scorers.mdx +3 -5
- package/.docs/raw/evals/overview.mdx +2 -3
- package/.docs/raw/getting-started/project-structure.mdx +1 -1
- package/.docs/raw/getting-started/start.mdx +72 -0
- package/.docs/raw/getting-started/studio.mdx +1 -1
- package/.docs/raw/{frameworks/agentic-uis/ai-sdk.mdx → guides/build-your-ui/ai-sdk-ui.mdx} +105 -11
- package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/astro.mdx +23 -25
- package/.docs/raw/{frameworks/servers → guides/getting-started}/express.mdx +3 -4
- package/.docs/raw/guides/{guide → getting-started}/manual-install.mdx +1 -1
- package/.docs/raw/guides/{quickstarts/nextjs.mdx → getting-started/next-js.mdx} +11 -11
- package/.docs/raw/guides/{quickstarts/standalone-server.mdx → getting-started/quickstart.mdx} +7 -7
- package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/sveltekit.mdx +23 -25
- package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/vite-react.mdx +7 -7
- package/.docs/raw/guides/guide/ai-recruiter.mdx +2 -3
- package/.docs/raw/guides/guide/chef-michel.mdx +2 -3
- package/.docs/raw/guides/guide/notes-mcp-server.mdx +2 -2
- package/.docs/raw/guides/guide/research-assistant.mdx +7 -8
- package/.docs/raw/guides/guide/stock-agent.mdx +4 -6
- package/.docs/raw/guides/guide/web-search.mdx +12 -10
- package/.docs/raw/guides/migrations/agentnetwork.mdx +4 -4
- package/.docs/raw/guides/migrations/ai-sdk-v4-to-v5.mdx +1 -1
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +29 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/tools.mdx +5 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +22 -0
- package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +2 -2
- package/.docs/raw/index.mdx +2 -2
- package/.docs/raw/mcp/overview.mdx +3 -5
- package/.docs/raw/memory/memory-processors.mdx +1 -2
- package/.docs/raw/memory/semantic-recall.mdx +7 -7
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +2 -4
- package/.docs/raw/memory/storage/memory-with-mongodb.mdx +2 -4
- package/.docs/raw/memory/storage/memory-with-pg.mdx +2 -4
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +2 -4
- package/.docs/raw/memory/threads-and-resources.mdx +3 -3
- package/.docs/raw/memory/working-memory.mdx +4 -5
- package/.docs/raw/{logging.mdx → observability/logging.mdx} +1 -1
- package/.docs/raw/observability/overview.mdx +2 -2
- package/.docs/raw/observability/tracing/exporters/otel.mdx +21 -2
- package/.docs/raw/observability/tracing/exporters/posthog.mdx +107 -0
- package/.docs/raw/observability/tracing/overview.mdx +3 -2
- package/.docs/raw/rag/chunking-and-embedding.mdx +16 -17
- package/.docs/raw/rag/overview.mdx +3 -2
- package/.docs/raw/rag/retrieval.mdx +20 -32
- package/.docs/raw/reference/agents/agent.mdx +7 -10
- package/.docs/raw/reference/agents/generateLegacy.mdx +2 -2
- package/.docs/raw/reference/agents/getLLM.mdx +1 -1
- package/.docs/raw/reference/agents/network.mdx +2 -3
- package/.docs/raw/reference/cli/mastra.mdx +2 -1
- package/.docs/raw/reference/client-js/agents.mdx +3 -3
- package/.docs/raw/reference/core/getLogger.mdx +1 -1
- package/.docs/raw/reference/core/listLogs.mdx +1 -1
- package/.docs/raw/reference/core/listLogsByRunId.mdx +1 -1
- package/.docs/raw/reference/core/mastra-model-gateway.mdx +5 -19
- package/.docs/raw/reference/core/setLogger.mdx +1 -1
- package/.docs/raw/reference/core/setTelemetry.mdx +1 -1
- package/.docs/raw/reference/evals/answer-relevancy.mdx +28 -98
- package/.docs/raw/reference/evals/answer-similarity.mdx +12 -258
- package/.docs/raw/reference/evals/bias.mdx +29 -87
- package/.docs/raw/reference/evals/completeness.mdx +31 -90
- package/.docs/raw/reference/evals/content-similarity.mdx +28 -88
- package/.docs/raw/reference/evals/context-precision.mdx +28 -130
- package/.docs/raw/reference/evals/context-relevance.mdx +11 -11
- package/.docs/raw/reference/evals/faithfulness.mdx +28 -101
- package/.docs/raw/reference/evals/hallucination.mdx +28 -103
- package/.docs/raw/reference/evals/keyword-coverage.mdx +28 -107
- package/.docs/raw/reference/evals/noise-sensitivity.mdx +11 -11
- package/.docs/raw/reference/evals/prompt-alignment.mdx +15 -15
- package/.docs/raw/reference/evals/textual-difference.mdx +27 -100
- package/.docs/raw/reference/evals/tone-consistency.mdx +25 -98
- package/.docs/raw/reference/evals/tool-call-accuracy.mdx +7 -7
- package/.docs/raw/reference/evals/toxicity.mdx +29 -92
- package/.docs/raw/reference/memory/memory-class.mdx +5 -7
- package/.docs/raw/reference/observability/tracing/exporters/posthog.mdx +132 -0
- package/.docs/raw/reference/processors/batch-parts-processor.mdx +1 -1
- package/.docs/raw/reference/processors/language-detector.mdx +1 -1
- package/.docs/raw/reference/processors/moderation-processor.mdx +2 -2
- package/.docs/raw/reference/processors/pii-detector.mdx +2 -2
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +1 -1
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -3
- package/.docs/raw/reference/processors/token-limiter-processor.mdx +2 -2
- package/.docs/raw/reference/processors/unicode-normalizer.mdx +1 -1
- package/.docs/raw/reference/rag/embeddings.mdx +5 -5
- package/.docs/raw/reference/rag/rerank.mdx +1 -2
- package/.docs/raw/reference/rag/rerankWithScorer.mdx +0 -1
- package/.docs/raw/reference/streaming/agents/stream.mdx +8 -1
- package/.docs/raw/reference/templates/overview.mdx +1 -4
- package/.docs/raw/reference/tools/client.mdx +1 -2
- package/.docs/raw/reference/tools/create-tool.mdx +132 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +5 -5
- package/.docs/raw/reference/tools/mcp-client.mdx +2 -4
- package/.docs/raw/reference/tools/mcp-server.mdx +1 -2
- package/.docs/raw/reference/tools/vector-query-tool.mdx +14 -15
- package/.docs/raw/reference/vectors/chroma.mdx +81 -1
- package/.docs/raw/reference/vectors/couchbase.mdx +24 -17
- package/.docs/raw/reference/vectors/lance.mdx +38 -22
- package/.docs/raw/reference/vectors/libsql.mdx +35 -2
- package/.docs/raw/reference/vectors/mongodb.mdx +35 -2
- package/.docs/raw/reference/vectors/opensearch.mdx +37 -16
- package/.docs/raw/reference/vectors/pg.mdx +43 -36
- package/.docs/raw/reference/vectors/pinecone.mdx +48 -1
- package/.docs/raw/reference/vectors/qdrant.mdx +36 -1
- package/.docs/raw/reference/vectors/turbopuffer.mdx +74 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +2 -2
- package/.docs/raw/reference/voice/voice.addInstructions.mdx +2 -3
- package/.docs/raw/reference/voice/voice.addTools.mdx +1 -1
- package/.docs/raw/reference/voice/voice.answer.mdx +1 -1
- package/.docs/raw/reference/voice/voice.close.mdx +1 -1
- package/.docs/raw/reference/voice/voice.connect.mdx +1 -1
- package/.docs/raw/reference/voice/voice.off.mdx +1 -1
- package/.docs/raw/reference/voice/voice.on.mdx +1 -1
- package/.docs/raw/reference/voice/voice.send.mdx +1 -1
- package/.docs/raw/reference/voice/voice.updateConfig.mdx +1 -1
- package/.docs/raw/server-db/mastra-client.mdx +1 -2
- package/.docs/raw/streaming/overview.mdx +20 -9
- package/.docs/raw/streaming/tool-streaming.mdx +47 -4
- package/.docs/raw/tools-mcp/advanced-usage.mdx +1 -2
- package/.docs/raw/tools-mcp/mcp-overview.mdx +3 -5
- package/.docs/raw/voice/overview.mdx +21 -41
- package/.docs/raw/voice/speech-to-speech.mdx +4 -4
- package/.docs/raw/voice/speech-to-text.mdx +1 -2
- package/.docs/raw/voice/text-to-speech.mdx +1 -2
- package/.docs/raw/workflows/control-flow.mdx +180 -0
- package/CHANGELOG.md +10 -0
- package/dist/{chunk-5NJC7NRO.js → chunk-4CM2BQNP.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 +7 -7
- package/.docs/raw/frameworks/agentic-uis/cedar-os.mdx +0 -102
- package/.docs/raw/frameworks/agentic-uis/openrouter.mdx +0 -179
- package/.docs/raw/frameworks/web-frameworks/next-js.mdx +0 -379
- package/.docs/raw/getting-started/quickstart.mdx +0 -27
- package/.docs/raw/getting-started/templates.mdx +0 -73
- /package/.docs/raw/{frameworks/agentic-uis → guides/build-your-ui}/assistant-ui.mdx +0 -0
- /package/.docs/raw/{frameworks/agentic-uis → guides/build-your-ui}/copilotkit.mdx +0 -0
|
@@ -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
|
-
##
|
|
152
|
+
## Example
|
|
153
153
|
|
|
154
|
-
|
|
154
|
+
Evaluate agent responses for similarity to ground truth across different scenarios:
|
|
155
155
|
|
|
156
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
415
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
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/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
|
|
135
|
+
const scorer = createBiasScorer({ model: "openai/gpt-4o" });
|
|
200
136
|
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
162
|
+
For more details on `runEvals`, see the [runEvals reference](/reference/v1/evals/run-evals).
|
|
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/v1/evals/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
|
-
|
|
113
|
-
|
|
114
|
-
```typescript title="src/example-high-completeness.ts" showLineNumbers copy
|
|
115
|
-
import { createCompletenessScorer } from "@mastra/evals/scorers/prebuilt";
|
|
116
|
-
|
|
117
|
-
const scorer = createCompletenessScorer({ model: "openai/gpt-4o-mini" });
|
|
118
|
-
|
|
119
|
-
const query =
|
|
120
|
-
"Explain the process of photosynthesis, including the inputs, outputs, and stages involved.";
|
|
121
|
-
const response =
|
|
122
|
-
"Photosynthesis is the process by which plants convert sunlight into chemical energy. Inputs: Carbon dioxide (CO2) from the air enters through stomata, water (H2O) is absorbed by roots, and sunlight provides energy captured by chlorophyll. The process occurs in two main stages: 1) Light-dependent reactions in the thylakoids convert light energy to ATP and NADPH while splitting water and releasing oxygen. 2) Light-independent reactions (Calvin cycle) in the stroma use ATP, NADPH, and CO2 to produce glucose. Outputs: Glucose (C6H12O6) serves as food for the plant, and oxygen (O2) is released as a byproduct. The overall equation is: 6CO2 + 6H2O + light energy → C6H12O6 + 6O2.";
|
|
123
|
-
|
|
124
|
-
const result = await scorer.run({
|
|
125
|
-
input: [{ role: "user", content: query }],
|
|
126
|
-
output: { text: response },
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
console.log(result);
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
#### High completeness output
|
|
133
|
-
|
|
134
|
-
The output receives a high score because it addresses all requested aspects: inputs, outputs, stages, and provides additional context.
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
{
|
|
138
|
-
score: 1,
|
|
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/prebuilt";
|
|
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
|
|
112
|
+
```typescript title="src/example-completeness.ts" showLineNumbers copy
|
|
113
|
+
import { runEvals } from "@mastra/core/evals";
|
|
181
114
|
import { createCompletenessScorer } from "@mastra/evals/scorers/prebuilt";
|
|
115
|
+
import { myAgent } from "./agent";
|
|
182
116
|
|
|
183
|
-
const scorer = createCompletenessScorer(
|
|
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.";
|
|
117
|
+
const scorer = createCompletenessScorer();
|
|
189
118
|
|
|
190
|
-
const result = await
|
|
191
|
-
|
|
192
|
-
|
|
119
|
+
const result = await runEvals({
|
|
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.id].score,
|
|
139
|
+
});
|
|
140
|
+
},
|
|
193
141
|
});
|
|
194
142
|
|
|
195
|
-
console.log(result);
|
|
143
|
+
console.log(result.scores);
|
|
196
144
|
```
|
|
197
145
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
The output receives a low score because it only briefly mentions cost and environmental impact while completely missing sustainability and lacking detailed comparison.
|
|
146
|
+
For more details on `runEvals`, see the [runEvals reference](/reference/v1/evals/run-evals).
|
|
201
147
|
|
|
202
|
-
|
|
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/v1/evals/overview#adding-scorers-to-agents) guide.
|
|
208
149
|
|
|
209
150
|
## Related
|
|
210
151
|
|