@mastra/mcp-docs-server 0.0.0-commonjs-20250414101718
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/%40mastra%2Fastra.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +161 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +110 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +26 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +196 -0
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +250 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +250 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
- package/.docs/organized/changelogs/create-mastra.md +302 -0
- package/.docs/organized/changelogs/mastra.md +302 -0
- package/.docs/organized/code-examples/agent-network.md +282 -0
- package/.docs/organized/code-examples/agent.md +388 -0
- package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
- package/.docs/organized/code-examples/assistant-ui.md +37 -0
- package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
- package/.docs/organized/code-examples/client-side-tools.md +69 -0
- package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
- package/.docs/organized/code-examples/fireworks-r1.md +159 -0
- package/.docs/organized/code-examples/mcp-registry-registry.md +63 -0
- package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
- package/.docs/organized/code-examples/memory-with-context.md +167 -0
- package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
- package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
- package/.docs/organized/code-examples/memory-with-pg.md +224 -0
- package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
- package/.docs/organized/code-examples/quick-start.md +129 -0
- package/.docs/organized/code-examples/stock-price-tool.md +124 -0
- package/.docs/organized/code-examples/weather-agent.md +353 -0
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
- package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
- package/.docs/raw/agents/adding-tools.mdx +317 -0
- package/.docs/raw/agents/adding-voice.mdx +175 -0
- package/.docs/raw/agents/agent-memory.mdx +62 -0
- package/.docs/raw/agents/mcp-guide.mdx +215 -0
- package/.docs/raw/agents/overview.mdx +303 -0
- package/.docs/raw/community/discord.mdx +12 -0
- package/.docs/raw/community/licensing.mdx +63 -0
- package/.docs/raw/deployment/client.mdx +120 -0
- package/.docs/raw/deployment/deployment.mdx +127 -0
- package/.docs/raw/deployment/server.mdx +282 -0
- package/.docs/raw/evals/custom-eval.mdx +22 -0
- package/.docs/raw/evals/overview.mdx +95 -0
- package/.docs/raw/evals/running-in-ci.mdx +81 -0
- package/.docs/raw/evals/textual-evals.mdx +54 -0
- package/.docs/raw/faq/index.mdx +63 -0
- package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
- package/.docs/raw/frameworks/next-js.mdx +238 -0
- package/.docs/raw/getting-started/installation.mdx +442 -0
- package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
- package/.docs/raw/getting-started/project-structure.mdx +80 -0
- package/.docs/raw/index.mdx +22 -0
- package/.docs/raw/integrations/index.mdx +213 -0
- package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
- package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
- package/.docs/raw/local-dev/mastra-dev.mdx +108 -0
- package/.docs/raw/memory/memory-processors.mdx +131 -0
- package/.docs/raw/memory/overview.mdx +119 -0
- package/.docs/raw/memory/semantic-recall.mdx +122 -0
- package/.docs/raw/memory/working-memory.mdx +87 -0
- package/.docs/raw/observability/logging.mdx +38 -0
- package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
- package/.docs/raw/observability/tracing.mdx +115 -0
- package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
- package/.docs/raw/rag/overview.mdx +85 -0
- package/.docs/raw/rag/retrieval.mdx +365 -0
- package/.docs/raw/rag/vector-databases.mdx +340 -0
- package/.docs/raw/reference/agents/createTool.mdx +229 -0
- package/.docs/raw/reference/agents/generate.mdx +334 -0
- package/.docs/raw/reference/agents/getAgent.mdx +54 -0
- package/.docs/raw/reference/agents/stream.mdx +369 -0
- package/.docs/raw/reference/cli/build.mdx +55 -0
- package/.docs/raw/reference/cli/dev.mdx +134 -0
- package/.docs/raw/reference/cli/init.mdx +43 -0
- package/.docs/raw/reference/client-js/agents.mdx +107 -0
- package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
- package/.docs/raw/reference/client-js/logs.mdx +24 -0
- package/.docs/raw/reference/client-js/memory.mdx +97 -0
- package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
- package/.docs/raw/reference/client-js/tools.mdx +44 -0
- package/.docs/raw/reference/client-js/vectors.mdx +79 -0
- package/.docs/raw/reference/client-js/workflows.mdx +136 -0
- package/.docs/raw/reference/core/mastra-class.mdx +232 -0
- package/.docs/raw/reference/deployer/cloudflare.mdx +207 -0
- package/.docs/raw/reference/deployer/deployer.mdx +159 -0
- package/.docs/raw/reference/deployer/netlify.mdx +109 -0
- package/.docs/raw/reference/deployer/vercel.mdx +117 -0
- package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
- package/.docs/raw/reference/evals/bias.mdx +186 -0
- package/.docs/raw/reference/evals/completeness.mdx +174 -0
- package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
- package/.docs/raw/reference/evals/context-position.mdx +190 -0
- package/.docs/raw/reference/evals/context-precision.mdx +189 -0
- package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
- package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
- package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
- package/.docs/raw/reference/evals/hallucination.mdx +219 -0
- package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
- package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
- package/.docs/raw/reference/evals/summarization.mdx +205 -0
- package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
- package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
- package/.docs/raw/reference/evals/toxicity.mdx +165 -0
- package/.docs/raw/reference/index.mdx +12 -0
- package/.docs/raw/reference/memory/Memory.mdx +212 -0
- package/.docs/raw/reference/memory/createThread.mdx +95 -0
- package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
- package/.docs/raw/reference/memory/query.mdx +167 -0
- package/.docs/raw/reference/networks/agent-network.mdx +159 -0
- package/.docs/raw/reference/observability/create-logger.mdx +106 -0
- package/.docs/raw/reference/observability/logger.mdx +55 -0
- package/.docs/raw/reference/observability/otel-config.mdx +120 -0
- package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
- package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
- package/.docs/raw/reference/observability/providers/index.mdx +16 -0
- package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
- package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
- package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
- package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
- package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
- package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
- package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
- package/.docs/raw/reference/rag/astra.mdx +258 -0
- package/.docs/raw/reference/rag/chroma.mdx +281 -0
- package/.docs/raw/reference/rag/chunk.mdx +235 -0
- package/.docs/raw/reference/rag/document.mdx +127 -0
- package/.docs/raw/reference/rag/embeddings.mdx +160 -0
- package/.docs/raw/reference/rag/extract-params.mdx +226 -0
- package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
- package/.docs/raw/reference/rag/libsql.mdx +357 -0
- package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
- package/.docs/raw/reference/rag/pg.mdx +477 -0
- package/.docs/raw/reference/rag/pinecone.mdx +281 -0
- package/.docs/raw/reference/rag/qdrant.mdx +236 -0
- package/.docs/raw/reference/rag/rerank.mdx +212 -0
- package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
- package/.docs/raw/reference/rag/upstash.mdx +247 -0
- package/.docs/raw/reference/rag/vectorize.mdx +298 -0
- package/.docs/raw/reference/storage/libsql.mdx +74 -0
- package/.docs/raw/reference/storage/postgresql.mdx +48 -0
- package/.docs/raw/reference/storage/upstash.mdx +86 -0
- package/.docs/raw/reference/tools/client.mdx +207 -0
- package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
- package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
- package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
- package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
- package/.docs/raw/reference/voice/deepgram.mdx +164 -0
- package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
- package/.docs/raw/reference/voice/google.mdx +198 -0
- package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
- package/.docs/raw/reference/voice/murf.mdx +251 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
- package/.docs/raw/reference/voice/openai.mdx +168 -0
- package/.docs/raw/reference/voice/playai.mdx +159 -0
- package/.docs/raw/reference/voice/sarvam.mdx +260 -0
- package/.docs/raw/reference/voice/speechify.mdx +145 -0
- package/.docs/raw/reference/voice/voice.answer.mdx +122 -0
- package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
- package/.docs/raw/reference/voice/voice.listen.mdx +195 -0
- package/.docs/raw/reference/voice/voice.on.mdx +189 -0
- package/.docs/raw/reference/voice/voice.send.mdx +118 -0
- package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
- package/.docs/raw/reference/workflows/after.mdx +88 -0
- package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
- package/.docs/raw/reference/workflows/commit.mdx +37 -0
- package/.docs/raw/reference/workflows/createRun.mdx +77 -0
- package/.docs/raw/reference/workflows/else.mdx +72 -0
- package/.docs/raw/reference/workflows/events.mdx +305 -0
- package/.docs/raw/reference/workflows/execute.mdx +110 -0
- package/.docs/raw/reference/workflows/if.mdx +107 -0
- package/.docs/raw/reference/workflows/resume.mdx +155 -0
- package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
- package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
- package/.docs/raw/reference/workflows/start.mdx +84 -0
- package/.docs/raw/reference/workflows/step-class.mdx +100 -0
- package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
- package/.docs/raw/reference/workflows/step-function.mdx +92 -0
- package/.docs/raw/reference/workflows/step-options.mdx +69 -0
- package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
- package/.docs/raw/reference/workflows/suspend.mdx +70 -0
- package/.docs/raw/reference/workflows/then.mdx +74 -0
- package/.docs/raw/reference/workflows/until.mdx +165 -0
- package/.docs/raw/reference/workflows/watch.mdx +118 -0
- package/.docs/raw/reference/workflows/while.mdx +168 -0
- package/.docs/raw/reference/workflows/workflow.mdx +233 -0
- package/.docs/raw/storage/overview.mdx +378 -0
- package/.docs/raw/voice/overview.mdx +135 -0
- package/.docs/raw/voice/speech-to-text.mdx +45 -0
- package/.docs/raw/voice/text-to-speech.mdx +52 -0
- package/.docs/raw/voice/voice-to-voice.mdx +310 -0
- package/.docs/raw/workflows/control-flow.mdx +778 -0
- package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
- package/.docs/raw/workflows/error-handling.mdx +183 -0
- package/.docs/raw/workflows/nested-workflows.mdx +352 -0
- package/.docs/raw/workflows/overview.mdx +203 -0
- package/.docs/raw/workflows/steps.mdx +108 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
- package/.docs/raw/workflows/variables.mdx +313 -0
- package/LICENSE.md +46 -0
- package/README.md +129 -0
- package/dist/_tsup-dts-rollup.d.ts +149 -0
- package/dist/chunk-QWYMT5LP.js +194 -0
- package/dist/prepare-docs/prepare.d.ts +1 -0
- package/dist/prepare-docs/prepare.js +1 -0
- package/dist/stdio.d.ts +1 -0
- package/dist/stdio.js +518 -0
- package/package.json +60 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Hallucination | Metrics | Evals | Mastra Docs"
|
|
3
|
+
description: Documentation for the Hallucination Metric in Mastra, which evaluates the factual correctness of LLM outputs by identifying contradictions with provided context.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# HallucinationMetric
|
|
7
|
+
|
|
8
|
+
The `HallucinationMetric` evaluates whether an LLM generates factually correct information by comparing its output against the provided context. This metric measures hallucination by identifying direct contradictions between the context and the output.
|
|
9
|
+
|
|
10
|
+
## Basic Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { openai } from "@ai-sdk/openai";
|
|
14
|
+
import { HallucinationMetric } from "@mastra/evals/llm";
|
|
15
|
+
|
|
16
|
+
// Configure the model for evaluation
|
|
17
|
+
const model = openai("gpt-4o-mini");
|
|
18
|
+
|
|
19
|
+
const metric = new HallucinationMetric(model, {
|
|
20
|
+
context: [
|
|
21
|
+
"Tesla was founded in 2003 by Martin Eberhard and Marc Tarpenning in San Carlos, California.",
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const result = await metric.measure(
|
|
26
|
+
"Tell me about Tesla's founding.",
|
|
27
|
+
"Tesla was founded in 2004 by Elon Musk in California.",
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
console.log(result.score); // Score from 0-1
|
|
31
|
+
console.log(result.info.reason); // Explanation of the score
|
|
32
|
+
|
|
33
|
+
// Example output:
|
|
34
|
+
// {
|
|
35
|
+
// score: 0.67,
|
|
36
|
+
// info: {
|
|
37
|
+
// reason: "The score is 0.67 because two out of three statements from the context
|
|
38
|
+
// (founding year and founders) were contradicted by the output, while the
|
|
39
|
+
// location statement was not contradicted."
|
|
40
|
+
// }
|
|
41
|
+
// }
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Constructor Parameters
|
|
45
|
+
|
|
46
|
+
<PropertiesTable
|
|
47
|
+
content={[
|
|
48
|
+
{
|
|
49
|
+
name: "model",
|
|
50
|
+
type: "LanguageModel",
|
|
51
|
+
description: "Configuration for the model used to evaluate hallucination",
|
|
52
|
+
isOptional: false,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "options",
|
|
56
|
+
type: "HallucinationMetricOptions",
|
|
57
|
+
description: "Configuration options for the metric",
|
|
58
|
+
isOptional: false,
|
|
59
|
+
},
|
|
60
|
+
]}
|
|
61
|
+
/>
|
|
62
|
+
|
|
63
|
+
### HallucinationMetricOptions
|
|
64
|
+
|
|
65
|
+
<PropertiesTable
|
|
66
|
+
content={[
|
|
67
|
+
{
|
|
68
|
+
name: "scale",
|
|
69
|
+
type: "number",
|
|
70
|
+
description: "Maximum score value",
|
|
71
|
+
isOptional: true,
|
|
72
|
+
defaultValue: "1",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: "context",
|
|
76
|
+
type: "string[]",
|
|
77
|
+
description: "Array of context pieces used as the source of truth",
|
|
78
|
+
isOptional: false,
|
|
79
|
+
},
|
|
80
|
+
]}
|
|
81
|
+
/>
|
|
82
|
+
|
|
83
|
+
## measure() Parameters
|
|
84
|
+
|
|
85
|
+
<PropertiesTable
|
|
86
|
+
content={[
|
|
87
|
+
{
|
|
88
|
+
name: "input",
|
|
89
|
+
type: "string",
|
|
90
|
+
description: "The original query or prompt",
|
|
91
|
+
isOptional: false,
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: "output",
|
|
95
|
+
type: "string",
|
|
96
|
+
description: "The LLM's response to evaluate",
|
|
97
|
+
isOptional: false,
|
|
98
|
+
},
|
|
99
|
+
]}
|
|
100
|
+
/>
|
|
101
|
+
|
|
102
|
+
## Returns
|
|
103
|
+
|
|
104
|
+
<PropertiesTable
|
|
105
|
+
content={[
|
|
106
|
+
{
|
|
107
|
+
name: "score",
|
|
108
|
+
type: "number",
|
|
109
|
+
description: "Hallucination score (0 to scale, default 0-1)",
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "info",
|
|
113
|
+
type: "object",
|
|
114
|
+
description: "Object containing the reason for the score",
|
|
115
|
+
properties: [
|
|
116
|
+
{
|
|
117
|
+
type: "string",
|
|
118
|
+
parameters: [
|
|
119
|
+
{
|
|
120
|
+
name: "reason",
|
|
121
|
+
type: "string",
|
|
122
|
+
description:
|
|
123
|
+
"Detailed explanation of the score and identified contradictions",
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
]}
|
|
130
|
+
/>
|
|
131
|
+
|
|
132
|
+
## Scoring Details
|
|
133
|
+
|
|
134
|
+
The metric evaluates hallucination through contradiction detection and unsupported claim analysis.
|
|
135
|
+
|
|
136
|
+
### Scoring Process
|
|
137
|
+
|
|
138
|
+
1. Analyzes factual content:
|
|
139
|
+
- Extracts statements from context
|
|
140
|
+
- Identifies numerical values and dates
|
|
141
|
+
- Maps statement relationships
|
|
142
|
+
|
|
143
|
+
2. Analyzes output for hallucinations:
|
|
144
|
+
- Compares against context statements
|
|
145
|
+
- Marks direct conflicts as hallucinations
|
|
146
|
+
- Identifies unsupported claims as hallucinations
|
|
147
|
+
- Evaluates numerical accuracy
|
|
148
|
+
- Considers approximation context
|
|
149
|
+
|
|
150
|
+
3. Calculates hallucination score:
|
|
151
|
+
- Counts hallucinated statements (contradictions and unsupported claims)
|
|
152
|
+
- Divides by total statements
|
|
153
|
+
- Scales to configured range
|
|
154
|
+
|
|
155
|
+
Final score: `(hallucinated_statements / total_statements) * scale`
|
|
156
|
+
|
|
157
|
+
### Important Considerations
|
|
158
|
+
|
|
159
|
+
- Claims not present in context are treated as hallucinations
|
|
160
|
+
- Subjective claims are hallucinations unless explicitly supported
|
|
161
|
+
- Speculative language ("might", "possibly") about facts IN context is allowed
|
|
162
|
+
- Speculative language about facts NOT in context is treated as hallucination
|
|
163
|
+
- Empty outputs result in zero hallucinations
|
|
164
|
+
- Numerical evaluation considers:
|
|
165
|
+
- Scale-appropriate precision
|
|
166
|
+
- Contextual approximations
|
|
167
|
+
- Explicit precision indicators
|
|
168
|
+
|
|
169
|
+
### Score interpretation
|
|
170
|
+
(0 to scale, default 0-1)
|
|
171
|
+
- 1.0: Complete hallucination - contradicts all context statements
|
|
172
|
+
- 0.75: High hallucination - contradicts 75% of context statements
|
|
173
|
+
- 0.5: Moderate hallucination - contradicts half of context statements
|
|
174
|
+
- 0.25: Low hallucination - contradicts 25% of context statements
|
|
175
|
+
- 0.0: No hallucination - output aligns with all context statements
|
|
176
|
+
|
|
177
|
+
**Note:** The score represents the degree of hallucination - lower scores indicate better factual alignment with the provided context
|
|
178
|
+
|
|
179
|
+
## Example with Analysis
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
import { openai } from "@ai-sdk/openai";
|
|
183
|
+
import { HallucinationMetric } from "@mastra/evals/llm";
|
|
184
|
+
|
|
185
|
+
// Configure the model for evaluation
|
|
186
|
+
const model = openai("gpt-4o-mini");
|
|
187
|
+
|
|
188
|
+
const metric = new HallucinationMetric(model, {
|
|
189
|
+
context: [
|
|
190
|
+
"OpenAI was founded in December 2015 by Sam Altman, Greg Brockman, and others.",
|
|
191
|
+
"The company launched with a $1 billion investment commitment.",
|
|
192
|
+
"Elon Musk was an early supporter but left the board in 2018.",
|
|
193
|
+
],
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const result = await metric.measure({
|
|
197
|
+
input: "What are the key details about OpenAI?",
|
|
198
|
+
output:
|
|
199
|
+
"OpenAI was founded in 2015 by Elon Musk and Sam Altman with a $2 billion investment.",
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// Example output:
|
|
203
|
+
// {
|
|
204
|
+
// score: 0.33,
|
|
205
|
+
// info: {
|
|
206
|
+
// reason: "The score is 0.33 because one out of three statements from the context
|
|
207
|
+
// was contradicted (the investment amount was stated as $2 billion instead
|
|
208
|
+
// of $1 billion). The founding date was correct, and while the output's
|
|
209
|
+
// description of founders was incomplete, it wasn't strictly contradictory."
|
|
210
|
+
// }
|
|
211
|
+
// }
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Related
|
|
215
|
+
|
|
216
|
+
- [Faithfulness Metric](./faithfulness)
|
|
217
|
+
- [Answer Relevancy Metric](./answer-relevancy)
|
|
218
|
+
- [Context Precision Metric](./context-precision)
|
|
219
|
+
- [Context Relevancy Metric](./context-relevancy)
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Keyword Coverage | Metrics | Evals | Mastra Docs"
|
|
3
|
+
description: Documentation for the Keyword Coverage Metric in Mastra, which evaluates how well LLM outputs cover important keywords from the input.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# KeywordCoverageMetric
|
|
7
|
+
|
|
8
|
+
The `KeywordCoverageMetric` class evaluates how well an LLM's output covers the important keywords from the input. It analyzes keyword presence and matches while ignoring common words and stop words.
|
|
9
|
+
|
|
10
|
+
## Basic Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { KeywordCoverageMetric } from "@mastra/evals/nlp";
|
|
14
|
+
|
|
15
|
+
const metric = new KeywordCoverageMetric();
|
|
16
|
+
|
|
17
|
+
const result = await metric.measure(
|
|
18
|
+
"What are the key features of Python programming language?",
|
|
19
|
+
"Python is a high-level programming language known for its simple syntax and extensive libraries."
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
console.log(result.score); // Coverage score from 0-1
|
|
23
|
+
console.log(result.info); // Object containing detailed metrics about keyword coverage
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## measure() Parameters
|
|
27
|
+
|
|
28
|
+
<PropertiesTable
|
|
29
|
+
content={[
|
|
30
|
+
{
|
|
31
|
+
name: "input",
|
|
32
|
+
type: "string",
|
|
33
|
+
description: "The original text containing keywords to be matched",
|
|
34
|
+
isOptional: false,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "output",
|
|
38
|
+
type: "string",
|
|
39
|
+
description: "The text to evaluate for keyword coverage",
|
|
40
|
+
isOptional: false,
|
|
41
|
+
}
|
|
42
|
+
]}
|
|
43
|
+
/>
|
|
44
|
+
|
|
45
|
+
## Returns
|
|
46
|
+
|
|
47
|
+
<PropertiesTable
|
|
48
|
+
content={[
|
|
49
|
+
{
|
|
50
|
+
name: "score",
|
|
51
|
+
type: "number",
|
|
52
|
+
description: "Coverage score (0-1) representing the proportion of matched keywords",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "info",
|
|
56
|
+
type: "object",
|
|
57
|
+
description: "Object containing detailed metrics about keyword coverage",
|
|
58
|
+
properties: [
|
|
59
|
+
{
|
|
60
|
+
type: "number",
|
|
61
|
+
parameters: [
|
|
62
|
+
{
|
|
63
|
+
name: "matchedKeywords",
|
|
64
|
+
type: "number",
|
|
65
|
+
description: "Number of keywords found in the output",
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: "number",
|
|
71
|
+
parameters: [
|
|
72
|
+
{
|
|
73
|
+
name: "totalKeywords",
|
|
74
|
+
type: "number",
|
|
75
|
+
description: "Total number of keywords from the input",
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
]}
|
|
82
|
+
/>
|
|
83
|
+
|
|
84
|
+
## Scoring Details
|
|
85
|
+
|
|
86
|
+
The metric evaluates keyword coverage by matching keywords with the following features:
|
|
87
|
+
- Common word and stop word filtering (e.g., "the", "a", "and")
|
|
88
|
+
- Case-insensitive matching
|
|
89
|
+
- Word form variation handling
|
|
90
|
+
- Special handling of technical terms and compound words
|
|
91
|
+
|
|
92
|
+
### Scoring Process
|
|
93
|
+
|
|
94
|
+
1. Processes keywords from input and output:
|
|
95
|
+
- Filters out common words and stop words
|
|
96
|
+
- Normalizes case and word forms
|
|
97
|
+
- Handles special terms and compounds
|
|
98
|
+
|
|
99
|
+
2. Calculates keyword coverage:
|
|
100
|
+
- Matches keywords between texts
|
|
101
|
+
- Counts successful matches
|
|
102
|
+
- Computes coverage ratio
|
|
103
|
+
|
|
104
|
+
Final score: `(matched_keywords / total_keywords) * scale`
|
|
105
|
+
|
|
106
|
+
### Score interpretation
|
|
107
|
+
(0 to scale, default 0-1)
|
|
108
|
+
- 1.0: Perfect keyword coverage
|
|
109
|
+
- 0.7-0.9: Good coverage with most keywords present
|
|
110
|
+
- 0.4-0.6: Moderate coverage with some keywords missing
|
|
111
|
+
- 0.1-0.3: Poor coverage with many keywords missing
|
|
112
|
+
- 0.0: No keyword matches
|
|
113
|
+
|
|
114
|
+
## Examples with Analysis
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { KeywordCoverageMetric } from "@mastra/evals/nlp";
|
|
118
|
+
|
|
119
|
+
const metric = new KeywordCoverageMetric();
|
|
120
|
+
|
|
121
|
+
// Perfect coverage example
|
|
122
|
+
const result1 = await metric.measure(
|
|
123
|
+
"The quick brown fox jumps over the lazy dog",
|
|
124
|
+
"A quick brown fox jumped over a lazy dog"
|
|
125
|
+
);
|
|
126
|
+
// {
|
|
127
|
+
// score: 1.0,
|
|
128
|
+
// info: {
|
|
129
|
+
// matchedKeywords: 6,
|
|
130
|
+
// totalKeywords: 6
|
|
131
|
+
// }
|
|
132
|
+
// }
|
|
133
|
+
|
|
134
|
+
// Partial coverage example
|
|
135
|
+
const result2 = await metric.measure(
|
|
136
|
+
"Python features include easy syntax, dynamic typing, and extensive libraries",
|
|
137
|
+
"Python has simple syntax and many libraries"
|
|
138
|
+
);
|
|
139
|
+
// {
|
|
140
|
+
// score: 0.67,
|
|
141
|
+
// info: {
|
|
142
|
+
// matchedKeywords: 4,
|
|
143
|
+
// totalKeywords: 6
|
|
144
|
+
// }
|
|
145
|
+
// }
|
|
146
|
+
|
|
147
|
+
// Technical terms example
|
|
148
|
+
const result3 = await metric.measure(
|
|
149
|
+
"Discuss React.js component lifecycle and state management",
|
|
150
|
+
"React components have lifecycle methods and manage state"
|
|
151
|
+
);
|
|
152
|
+
// {
|
|
153
|
+
// score: 1.0,
|
|
154
|
+
// info: {
|
|
155
|
+
// matchedKeywords: 4,
|
|
156
|
+
// totalKeywords: 4
|
|
157
|
+
// }
|
|
158
|
+
// }
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Special Cases
|
|
162
|
+
|
|
163
|
+
The metric handles several special cases:
|
|
164
|
+
- Empty input/output: Returns score of 1.0 if both empty, 0.0 if only one is empty
|
|
165
|
+
- Single word: Treated as a single keyword
|
|
166
|
+
- Technical terms: Preserves compound technical terms (e.g., "React.js", "machine learning")
|
|
167
|
+
- Case differences: "JavaScript" matches "javascript"
|
|
168
|
+
- Common words: Ignored in scoring to focus on meaningful keywords
|
|
169
|
+
|
|
170
|
+
## Related
|
|
171
|
+
|
|
172
|
+
- [Completeness Metric](./completeness)
|
|
173
|
+
- [Content Similarity Metric](./content-similarity)
|
|
174
|
+
- [Answer Relevancy Metric](./answer-relevancy)
|
|
175
|
+
- [Textual Difference Metric](./textual-difference)
|
|
176
|
+
- [Context Relevancy Metric](./context-relevancy)
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Prompt Alignment | Metrics | Evals | Mastra Docs"
|
|
3
|
+
description: Documentation for the Prompt Alignment Metric in Mastra, which evaluates how well LLM outputs adhere to given prompt instructions.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# PromptAlignmentMetric
|
|
7
|
+
|
|
8
|
+
The `PromptAlignmentMetric` class evaluates how strictly an LLM's output follows a set of given prompt instructions. It uses a judge-based system to verify each instruction is followed exactly and provides detailed reasoning for any deviations.
|
|
9
|
+
|
|
10
|
+
## Basic Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { openai } from "@ai-sdk/openai";
|
|
14
|
+
import { PromptAlignmentMetric } from "@mastra/evals/llm";
|
|
15
|
+
|
|
16
|
+
// Configure the model for evaluation
|
|
17
|
+
const model = openai("gpt-4o-mini");
|
|
18
|
+
|
|
19
|
+
const instructions = [
|
|
20
|
+
"Start sentences with capital letters",
|
|
21
|
+
"End each sentence with a period",
|
|
22
|
+
"Use present tense",
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const metric = new PromptAlignmentMetric(model, {
|
|
26
|
+
instructions,
|
|
27
|
+
scale: 1,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const result = await metric.measure(
|
|
31
|
+
"describe the weather",
|
|
32
|
+
"The sun is shining. Clouds float in the sky. A gentle breeze blows.",
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
console.log(result.score); // Alignment score from 0-1
|
|
36
|
+
console.log(result.info.reason); // Explanation of the score
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Constructor Parameters
|
|
40
|
+
|
|
41
|
+
<PropertiesTable
|
|
42
|
+
content={[
|
|
43
|
+
{
|
|
44
|
+
name: "model",
|
|
45
|
+
type: "LanguageModel",
|
|
46
|
+
description:
|
|
47
|
+
"Configuration for the model used to evaluate instruction alignment",
|
|
48
|
+
isOptional: false,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "options",
|
|
52
|
+
type: "PromptAlignmentOptions",
|
|
53
|
+
description: "Configuration options for the metric",
|
|
54
|
+
isOptional: false,
|
|
55
|
+
},
|
|
56
|
+
]}
|
|
57
|
+
/>
|
|
58
|
+
|
|
59
|
+
### PromptAlignmentOptions
|
|
60
|
+
|
|
61
|
+
<PropertiesTable
|
|
62
|
+
content={[
|
|
63
|
+
{
|
|
64
|
+
name: "instructions",
|
|
65
|
+
type: "string[]",
|
|
66
|
+
description: "Array of instructions that the output should follow",
|
|
67
|
+
isOptional: false,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "scale",
|
|
71
|
+
type: "number",
|
|
72
|
+
description: "Maximum score value",
|
|
73
|
+
isOptional: true,
|
|
74
|
+
defaultValue: "1",
|
|
75
|
+
},
|
|
76
|
+
]}
|
|
77
|
+
/>
|
|
78
|
+
|
|
79
|
+
## measure() Parameters
|
|
80
|
+
|
|
81
|
+
<PropertiesTable
|
|
82
|
+
content={[
|
|
83
|
+
{
|
|
84
|
+
name: "input",
|
|
85
|
+
type: "string",
|
|
86
|
+
description: "The original prompt or query",
|
|
87
|
+
isOptional: false,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "output",
|
|
91
|
+
type: "string",
|
|
92
|
+
description: "The LLM's response to evaluate",
|
|
93
|
+
isOptional: false,
|
|
94
|
+
},
|
|
95
|
+
]}
|
|
96
|
+
/>
|
|
97
|
+
|
|
98
|
+
## Returns
|
|
99
|
+
|
|
100
|
+
<PropertiesTable
|
|
101
|
+
content={[
|
|
102
|
+
{
|
|
103
|
+
name: "score",
|
|
104
|
+
type: "number",
|
|
105
|
+
description: "Alignment score (0 to scale, default 0-1)",
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: "info",
|
|
109
|
+
type: "object",
|
|
110
|
+
description:
|
|
111
|
+
"Object containing detailed metrics about instruction compliance",
|
|
112
|
+
properties: [
|
|
113
|
+
{
|
|
114
|
+
type: "string",
|
|
115
|
+
parameters: [
|
|
116
|
+
{
|
|
117
|
+
name: "reason",
|
|
118
|
+
type: "string",
|
|
119
|
+
description:
|
|
120
|
+
"Detailed explanation of the score and instruction compliance",
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
]}
|
|
127
|
+
/>
|
|
128
|
+
|
|
129
|
+
## Scoring Details
|
|
130
|
+
|
|
131
|
+
The metric evaluates instruction alignment through:
|
|
132
|
+
- Applicability assessment for each instruction
|
|
133
|
+
- Strict compliance evaluation for applicable instructions
|
|
134
|
+
- Detailed reasoning for all verdicts
|
|
135
|
+
- Proportional scoring based on applicable instructions
|
|
136
|
+
|
|
137
|
+
### Instruction Verdicts
|
|
138
|
+
|
|
139
|
+
Each instruction receives one of three verdicts:
|
|
140
|
+
- "yes": Instruction is applicable and completely followed
|
|
141
|
+
- "no": Instruction is applicable but not followed or only partially followed
|
|
142
|
+
- "n/a": Instruction is not applicable to the given context
|
|
143
|
+
|
|
144
|
+
### Scoring Process
|
|
145
|
+
|
|
146
|
+
1. Evaluates instruction applicability:
|
|
147
|
+
- Determines if each instruction applies to the context
|
|
148
|
+
- Marks irrelevant instructions as "n/a"
|
|
149
|
+
- Considers domain-specific requirements
|
|
150
|
+
|
|
151
|
+
2. Assesses compliance for applicable instructions:
|
|
152
|
+
- Evaluates each applicable instruction independently
|
|
153
|
+
- Requires complete compliance for "yes" verdict
|
|
154
|
+
- Documents specific reasons for all verdicts
|
|
155
|
+
|
|
156
|
+
3. Calculates alignment score:
|
|
157
|
+
- Counts followed instructions ("yes" verdicts)
|
|
158
|
+
- Divides by total applicable instructions (excluding "n/a")
|
|
159
|
+
- Scales to configured range
|
|
160
|
+
|
|
161
|
+
Final score: `(followed_instructions / applicable_instructions) * scale`
|
|
162
|
+
|
|
163
|
+
### Important Considerations
|
|
164
|
+
|
|
165
|
+
- Empty outputs:
|
|
166
|
+
- All formatting instructions are considered applicable
|
|
167
|
+
- Marked as "no" since they cannot satisfy requirements
|
|
168
|
+
- Domain-specific instructions:
|
|
169
|
+
- Always applicable if about the queried domain
|
|
170
|
+
- Marked as "no" if not followed, not "n/a"
|
|
171
|
+
- "n/a" verdicts:
|
|
172
|
+
- Only used for completely different domains
|
|
173
|
+
- Do not affect the final score calculation
|
|
174
|
+
|
|
175
|
+
### Score interpretation
|
|
176
|
+
(0 to scale, default 0-1)
|
|
177
|
+
- 1.0: All applicable instructions followed perfectly
|
|
178
|
+
- 0.7-0.9: Most applicable instructions followed
|
|
179
|
+
- 0.4-0.6: Mixed compliance with applicable instructions
|
|
180
|
+
- 0.1-0.3: Limited compliance with applicable instructions
|
|
181
|
+
- 0.0: No applicable instructions followed
|
|
182
|
+
|
|
183
|
+
## Example with Analysis
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import { openai } from "@ai-sdk/openai";
|
|
187
|
+
import { PromptAlignmentMetric } from "@mastra/evals/llm";
|
|
188
|
+
|
|
189
|
+
// Configure the model for evaluation
|
|
190
|
+
const model = openai("gpt-4o-mini");
|
|
191
|
+
|
|
192
|
+
const metric = new PromptAlignmentMetric(model, {
|
|
193
|
+
instructions: [
|
|
194
|
+
"Use bullet points for each item",
|
|
195
|
+
"Include exactly three examples",
|
|
196
|
+
"End each point with a semicolon"
|
|
197
|
+
],
|
|
198
|
+
scale: 1
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const result = await metric.measure(
|
|
202
|
+
"List three fruits",
|
|
203
|
+
"• Apple is red and sweet;
|
|
204
|
+
• Banana is yellow and curved;
|
|
205
|
+
• Orange is citrus and round."
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
// Example output:
|
|
209
|
+
// {
|
|
210
|
+
// score: 1.0,
|
|
211
|
+
// info: {
|
|
212
|
+
// reason: "The score is 1.0 because all instructions were followed exactly:
|
|
213
|
+
// bullet points were used, exactly three examples were provided, and
|
|
214
|
+
// each point ends with a semicolon."
|
|
215
|
+
// }
|
|
216
|
+
// }
|
|
217
|
+
|
|
218
|
+
const result2 = await metric.measure(
|
|
219
|
+
"List three fruits",
|
|
220
|
+
"1. Apple
|
|
221
|
+
2. Banana
|
|
222
|
+
3. Orange and Grape"
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
// Example output:
|
|
226
|
+
// {
|
|
227
|
+
// score: 0.33,
|
|
228
|
+
// info: {
|
|
229
|
+
// reason: "The score is 0.33 because: numbered lists were used instead of bullet points,
|
|
230
|
+
// no semicolons were used, and four fruits were listed instead of exactly three."
|
|
231
|
+
// }
|
|
232
|
+
// }
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Related
|
|
236
|
+
|
|
237
|
+
- [Answer Relevancy Metric](./answer-relevancy)
|
|
238
|
+
- [Keyword Coverage Metric](./keyword-coverage)
|