@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,183 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Content Similarity | Evals | Mastra Docs"
|
|
3
|
+
description: Documentation for the Content Similarity Metric in Mastra, which measures textual similarity between strings and provides a matching score.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# ContentSimilarityMetric
|
|
7
|
+
|
|
8
|
+
The `ContentSimilarityMetric` class measures the textual similarity between two strings, providing a score that indicates how closely they match. It supports configurable options for case sensitivity and whitespace handling.
|
|
9
|
+
|
|
10
|
+
## Basic Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { ContentSimilarityMetric } from "@mastra/evals/nlp";
|
|
14
|
+
|
|
15
|
+
const metric = new ContentSimilarityMetric({
|
|
16
|
+
ignoreCase: true,
|
|
17
|
+
ignoreWhitespace: true
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const result = await metric.measure(
|
|
21
|
+
"Hello, world!",
|
|
22
|
+
"hello world"
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
console.log(result.score); // Similarity score from 0-1
|
|
26
|
+
console.log(result.info); // Detailed similarity metrics
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Constructor Parameters
|
|
30
|
+
|
|
31
|
+
<PropertiesTable
|
|
32
|
+
content={[
|
|
33
|
+
{
|
|
34
|
+
name: "options",
|
|
35
|
+
type: "ContentSimilarityOptions",
|
|
36
|
+
description: "Configuration options for similarity comparison",
|
|
37
|
+
isOptional: true,
|
|
38
|
+
defaultValue: "{ ignoreCase: true, ignoreWhitespace: true }",
|
|
39
|
+
}
|
|
40
|
+
]}
|
|
41
|
+
/>
|
|
42
|
+
|
|
43
|
+
### ContentSimilarityOptions
|
|
44
|
+
|
|
45
|
+
<PropertiesTable
|
|
46
|
+
content={[
|
|
47
|
+
{
|
|
48
|
+
name: "ignoreCase",
|
|
49
|
+
type: "boolean",
|
|
50
|
+
description: "Whether to ignore case differences when comparing strings",
|
|
51
|
+
isOptional: true,
|
|
52
|
+
defaultValue: "true",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "ignoreWhitespace",
|
|
56
|
+
type: "boolean",
|
|
57
|
+
description: "Whether to normalize whitespace when comparing strings",
|
|
58
|
+
isOptional: true,
|
|
59
|
+
defaultValue: "true",
|
|
60
|
+
}
|
|
61
|
+
]}
|
|
62
|
+
/>
|
|
63
|
+
|
|
64
|
+
## measure() Parameters
|
|
65
|
+
|
|
66
|
+
<PropertiesTable
|
|
67
|
+
content={[
|
|
68
|
+
{
|
|
69
|
+
name: "input",
|
|
70
|
+
type: "string",
|
|
71
|
+
description: "The reference text to compare against",
|
|
72
|
+
isOptional: false,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: "output",
|
|
76
|
+
type: "string",
|
|
77
|
+
description: "The text to evaluate for similarity",
|
|
78
|
+
isOptional: false,
|
|
79
|
+
}
|
|
80
|
+
]}
|
|
81
|
+
/>
|
|
82
|
+
|
|
83
|
+
## Returns
|
|
84
|
+
|
|
85
|
+
<PropertiesTable
|
|
86
|
+
content={[
|
|
87
|
+
{
|
|
88
|
+
name: "score",
|
|
89
|
+
type: "number",
|
|
90
|
+
description: "Similarity score (0-1) where 1 indicates perfect similarity",
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "info",
|
|
94
|
+
type: "object",
|
|
95
|
+
description: "Detailed similarity metrics",
|
|
96
|
+
properties: [
|
|
97
|
+
{
|
|
98
|
+
type: "number",
|
|
99
|
+
parameters: [
|
|
100
|
+
{
|
|
101
|
+
name: "similarity",
|
|
102
|
+
type: "number",
|
|
103
|
+
description: "Raw similarity score between the two texts",
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
]}
|
|
110
|
+
/>
|
|
111
|
+
|
|
112
|
+
## Scoring Details
|
|
113
|
+
|
|
114
|
+
The metric evaluates textual similarity through character-level matching and configurable text normalization.
|
|
115
|
+
|
|
116
|
+
### Scoring Process
|
|
117
|
+
|
|
118
|
+
1. Normalizes text:
|
|
119
|
+
- Case normalization (if ignoreCase: true)
|
|
120
|
+
- Whitespace normalization (if ignoreWhitespace: true)
|
|
121
|
+
|
|
122
|
+
2. Compares processed strings using string-similarity algorithm:
|
|
123
|
+
- Analyzes character sequences
|
|
124
|
+
- Aligns word boundaries
|
|
125
|
+
- Considers relative positions
|
|
126
|
+
- Accounts for length differences
|
|
127
|
+
|
|
128
|
+
Final score: `similarity_value * scale`
|
|
129
|
+
|
|
130
|
+
### Score interpretation
|
|
131
|
+
(0 to scale, default 0-1)
|
|
132
|
+
- 1.0: Perfect match - identical texts
|
|
133
|
+
- 0.7-0.9: High similarity - mostly matching content
|
|
134
|
+
- 0.4-0.6: Moderate similarity - partial matches
|
|
135
|
+
- 0.1-0.3: Low similarity - few matching patterns
|
|
136
|
+
- 0.0: No similarity - completely different texts
|
|
137
|
+
|
|
138
|
+
## Example with Different Options
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { ContentSimilarityMetric } from "@mastra/evals/nlp";
|
|
142
|
+
|
|
143
|
+
// Case-sensitive comparison
|
|
144
|
+
const caseSensitiveMetric = new ContentSimilarityMetric({
|
|
145
|
+
ignoreCase: false,
|
|
146
|
+
ignoreWhitespace: true
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const result1 = await caseSensitiveMetric.measure(
|
|
150
|
+
"Hello World",
|
|
151
|
+
"hello world"
|
|
152
|
+
); // Lower score due to case difference
|
|
153
|
+
|
|
154
|
+
// Example output:
|
|
155
|
+
// {
|
|
156
|
+
// score: 0.75,
|
|
157
|
+
// info: { similarity: 0.75 }
|
|
158
|
+
// }
|
|
159
|
+
|
|
160
|
+
// Strict whitespace comparison
|
|
161
|
+
const strictWhitespaceMetric = new ContentSimilarityMetric({
|
|
162
|
+
ignoreCase: true,
|
|
163
|
+
ignoreWhitespace: false
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const result2 = await strictWhitespaceMetric.measure(
|
|
167
|
+
"Hello World",
|
|
168
|
+
"Hello World"
|
|
169
|
+
); // Lower score due to whitespace difference
|
|
170
|
+
|
|
171
|
+
// Example output:
|
|
172
|
+
// {
|
|
173
|
+
// score: 0.85,
|
|
174
|
+
// info: { similarity: 0.85 }
|
|
175
|
+
// }
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Related
|
|
179
|
+
|
|
180
|
+
- [Completeness Metric](./completeness)
|
|
181
|
+
- [Textual Difference Metric](./textual-difference)
|
|
182
|
+
- [Answer Relevancy Metric](./answer-relevancy)
|
|
183
|
+
- [Keyword Coverage Metric](./keyword-coverage)
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Context Position | Metrics | Evals | Mastra Docs"
|
|
3
|
+
description: Documentation for the Context Position Metric in Mastra, which evaluates the ordering of context nodes based on their relevance to the query and output.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# ContextPositionMetric
|
|
7
|
+
|
|
8
|
+
The `ContextPositionMetric` class evaluates how well context nodes are ordered based on their relevance to the query and output. It uses position-weighted scoring to emphasize the importance of having the most relevant context pieces appear earlier in the sequence.
|
|
9
|
+
|
|
10
|
+
## Basic Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { openai } from "@ai-sdk/openai";
|
|
14
|
+
import { ContextPositionMetric } from "@mastra/evals/llm";
|
|
15
|
+
|
|
16
|
+
// Configure the model for evaluation
|
|
17
|
+
const model = openai("gpt-4o-mini");
|
|
18
|
+
|
|
19
|
+
const metric = new ContextPositionMetric(model, {
|
|
20
|
+
context: [
|
|
21
|
+
"Photosynthesis is a biological process used by plants to create energy from sunlight.",
|
|
22
|
+
"The process of photosynthesis produces oxygen as a byproduct.",
|
|
23
|
+
"Plants need water and nutrients from the soil to grow.",
|
|
24
|
+
],
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const result = await metric.measure(
|
|
28
|
+
"What is photosynthesis?",
|
|
29
|
+
"Photosynthesis is the process by which plants convert sunlight into energy.",
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
console.log(result.score); // Position score from 0-1
|
|
33
|
+
console.log(result.info.reason); // Explanation of the score
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Constructor Parameters
|
|
37
|
+
|
|
38
|
+
<PropertiesTable
|
|
39
|
+
content={[
|
|
40
|
+
{
|
|
41
|
+
name: "model",
|
|
42
|
+
type: "ModelConfig",
|
|
43
|
+
description:
|
|
44
|
+
"Configuration for the model used to evaluate context positioning",
|
|
45
|
+
isOptional: false,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "options",
|
|
49
|
+
type: "ContextPositionMetricOptions",
|
|
50
|
+
description: "Configuration options for the metric",
|
|
51
|
+
isOptional: false,
|
|
52
|
+
},
|
|
53
|
+
]}
|
|
54
|
+
/>
|
|
55
|
+
|
|
56
|
+
### ContextPositionMetricOptions
|
|
57
|
+
|
|
58
|
+
<PropertiesTable
|
|
59
|
+
content={[
|
|
60
|
+
{
|
|
61
|
+
name: "scale",
|
|
62
|
+
type: "number",
|
|
63
|
+
description: "Maximum score value",
|
|
64
|
+
isOptional: true,
|
|
65
|
+
defaultValue: "1",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "context",
|
|
69
|
+
type: "string[]",
|
|
70
|
+
description: "Array of context pieces in their retrieval order",
|
|
71
|
+
isOptional: false,
|
|
72
|
+
},
|
|
73
|
+
]}
|
|
74
|
+
/>
|
|
75
|
+
|
|
76
|
+
## measure() Parameters
|
|
77
|
+
|
|
78
|
+
<PropertiesTable
|
|
79
|
+
content={[
|
|
80
|
+
{
|
|
81
|
+
name: "input",
|
|
82
|
+
type: "string",
|
|
83
|
+
description: "The original query or prompt",
|
|
84
|
+
isOptional: false,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "output",
|
|
88
|
+
type: "string",
|
|
89
|
+
description: "The generated response to evaluate",
|
|
90
|
+
isOptional: false,
|
|
91
|
+
},
|
|
92
|
+
]}
|
|
93
|
+
/>
|
|
94
|
+
|
|
95
|
+
## Returns
|
|
96
|
+
|
|
97
|
+
<PropertiesTable
|
|
98
|
+
content={[
|
|
99
|
+
{
|
|
100
|
+
name: "score",
|
|
101
|
+
type: "number",
|
|
102
|
+
description: "Position score (0 to scale, default 0-1)",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "info",
|
|
106
|
+
type: "object",
|
|
107
|
+
description: "Object containing the reason for the score",
|
|
108
|
+
properties: [
|
|
109
|
+
{
|
|
110
|
+
type: "string",
|
|
111
|
+
parameters: [
|
|
112
|
+
{
|
|
113
|
+
name: "reason",
|
|
114
|
+
type: "string",
|
|
115
|
+
description: "Detailed explanation of the score",
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
]}
|
|
122
|
+
/>
|
|
123
|
+
|
|
124
|
+
## Scoring Details
|
|
125
|
+
|
|
126
|
+
The metric evaluates context positioning through binary relevance assessment and position-based weighting.
|
|
127
|
+
|
|
128
|
+
### Scoring Process
|
|
129
|
+
|
|
130
|
+
1. Evaluates context relevance:
|
|
131
|
+
- Assigns binary verdict (yes/no) to each piece
|
|
132
|
+
- Records position in sequence
|
|
133
|
+
- Documents relevance reasoning
|
|
134
|
+
|
|
135
|
+
2. Applies position weights:
|
|
136
|
+
- Earlier positions weighted more heavily (weight = 1/(position + 1))
|
|
137
|
+
- Sums weights of relevant pieces
|
|
138
|
+
- Normalizes by maximum possible score
|
|
139
|
+
|
|
140
|
+
Final score: `(weighted_sum / max_possible_sum) * scale`
|
|
141
|
+
|
|
142
|
+
### Score interpretation
|
|
143
|
+
(0 to scale, default 0-1)
|
|
144
|
+
- 1.0: Optimal - most relevant context first
|
|
145
|
+
- 0.7-0.9: Good - relevant context mostly early
|
|
146
|
+
- 0.4-0.6: Mixed - relevant context scattered
|
|
147
|
+
- 0.1-0.3: Suboptimal - relevant context mostly later
|
|
148
|
+
- 0.0: Poor ordering - relevant context at end or missing
|
|
149
|
+
|
|
150
|
+
## Example with Analysis
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import { openai } from "@ai-sdk/openai";
|
|
154
|
+
import { ContextPositionMetric } from "@mastra/evals/llm";
|
|
155
|
+
|
|
156
|
+
// Configure the model for evaluation
|
|
157
|
+
const model = openai("gpt-4o-mini");
|
|
158
|
+
|
|
159
|
+
const metric = new ContextPositionMetric(model, {
|
|
160
|
+
context: [
|
|
161
|
+
"A balanced diet is important for health.",
|
|
162
|
+
"Exercise strengthens the heart and improves blood circulation.",
|
|
163
|
+
"Regular physical activity reduces stress and anxiety.",
|
|
164
|
+
"Exercise equipment can be expensive.",
|
|
165
|
+
],
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const result = await metric.measure(
|
|
169
|
+
"What are the benefits of exercise?",
|
|
170
|
+
"Regular exercise improves cardiovascular health and mental wellbeing.",
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
// Example output:
|
|
174
|
+
// {
|
|
175
|
+
// score: 0.5,
|
|
176
|
+
// info: {
|
|
177
|
+
// reason: "The score is 0.5 because while the second and third contexts are highly
|
|
178
|
+
// relevant to the benefits of exercise, they are not optimally positioned at
|
|
179
|
+
// the beginning of the sequence. The first and last contexts are not relevant
|
|
180
|
+
// to the query, which impacts the position-weighted scoring."
|
|
181
|
+
// }
|
|
182
|
+
// }
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Related
|
|
186
|
+
|
|
187
|
+
- [Context Precision Metric](./context-precision)
|
|
188
|
+
- [Answer Relevancy Metric](./answer-relevancy)
|
|
189
|
+
- [Completeness Metric](./completeness)
|
|
190
|
+
+ [Context Relevancy Metric](./context-relevancy)
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Context Precision | Metrics | Evals | Mastra Docs"
|
|
3
|
+
description: Documentation for the Context Precision Metric in Mastra, which evaluates the relevance and precision of retrieved context nodes for generating expected outputs.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# ContextPrecisionMetric
|
|
7
|
+
|
|
8
|
+
The `ContextPrecisionMetric` class evaluates how relevant and precise the retrieved context nodes are for generating the expected output. It uses a judge-based system to analyze each context piece's contribution and provides weighted scoring based on position.
|
|
9
|
+
|
|
10
|
+
## Basic Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { openai } from "@ai-sdk/openai";
|
|
14
|
+
import { ContextPrecisionMetric } from "@mastra/evals/llm";
|
|
15
|
+
|
|
16
|
+
// Configure the model for evaluation
|
|
17
|
+
const model = openai("gpt-4o-mini");
|
|
18
|
+
|
|
19
|
+
const metric = new ContextPrecisionMetric(model, {
|
|
20
|
+
context: [
|
|
21
|
+
"Photosynthesis is a biological process used by plants to create energy from sunlight.",
|
|
22
|
+
"Plants need water and nutrients from the soil to grow.",
|
|
23
|
+
"The process of photosynthesis produces oxygen as a byproduct.",
|
|
24
|
+
],
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const result = await metric.measure(
|
|
28
|
+
"What is photosynthesis?",
|
|
29
|
+
"Photosynthesis is the process by which plants convert sunlight into energy.",
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
console.log(result.score); // Precision score from 0-1
|
|
33
|
+
console.log(result.info.reason); // Explanation of the score
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Constructor Parameters
|
|
37
|
+
|
|
38
|
+
<PropertiesTable
|
|
39
|
+
content={[
|
|
40
|
+
{
|
|
41
|
+
name: "model",
|
|
42
|
+
type: "LanguageModel",
|
|
43
|
+
description:
|
|
44
|
+
"Configuration for the model used to evaluate context relevance",
|
|
45
|
+
isOptional: false,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "options",
|
|
49
|
+
type: "ContextPrecisionMetricOptions",
|
|
50
|
+
description: "Configuration options for the metric",
|
|
51
|
+
isOptional: false,
|
|
52
|
+
},
|
|
53
|
+
]}
|
|
54
|
+
/>
|
|
55
|
+
|
|
56
|
+
### ContextPrecisionMetricOptions
|
|
57
|
+
|
|
58
|
+
<PropertiesTable
|
|
59
|
+
content={[
|
|
60
|
+
{
|
|
61
|
+
name: "scale",
|
|
62
|
+
type: "number",
|
|
63
|
+
description: "Maximum score value",
|
|
64
|
+
isOptional: true,
|
|
65
|
+
defaultValue: "1",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "context",
|
|
69
|
+
type: "string[]",
|
|
70
|
+
description: "Array of context pieces in their retrieval order",
|
|
71
|
+
isOptional: false,
|
|
72
|
+
},
|
|
73
|
+
]}
|
|
74
|
+
/>
|
|
75
|
+
|
|
76
|
+
## measure() Parameters
|
|
77
|
+
|
|
78
|
+
<PropertiesTable
|
|
79
|
+
content={[
|
|
80
|
+
{
|
|
81
|
+
name: "input",
|
|
82
|
+
type: "string",
|
|
83
|
+
description: "The original query or prompt",
|
|
84
|
+
isOptional: false,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "output",
|
|
88
|
+
type: "string",
|
|
89
|
+
description: "The generated response to evaluate",
|
|
90
|
+
isOptional: false,
|
|
91
|
+
},
|
|
92
|
+
]}
|
|
93
|
+
/>
|
|
94
|
+
|
|
95
|
+
## Returns
|
|
96
|
+
|
|
97
|
+
<PropertiesTable
|
|
98
|
+
content={[
|
|
99
|
+
{
|
|
100
|
+
name: "score",
|
|
101
|
+
type: "number",
|
|
102
|
+
description: "Precision score (0 to scale, default 0-1)",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "info",
|
|
106
|
+
type: "object",
|
|
107
|
+
description: "Object containing the reason for the score",
|
|
108
|
+
properties: [
|
|
109
|
+
{
|
|
110
|
+
type: "string",
|
|
111
|
+
parameters: [
|
|
112
|
+
{
|
|
113
|
+
name: "reason",
|
|
114
|
+
type: "string",
|
|
115
|
+
description: "Detailed explanation of the score",
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
]}
|
|
122
|
+
/>
|
|
123
|
+
|
|
124
|
+
## Scoring Details
|
|
125
|
+
|
|
126
|
+
The metric evaluates context precision through binary relevance assessment and Mean Average Precision (MAP) scoring.
|
|
127
|
+
|
|
128
|
+
### Scoring Process
|
|
129
|
+
|
|
130
|
+
1. Assigns binary relevance scores:
|
|
131
|
+
- Relevant context: 1
|
|
132
|
+
- Irrelevant context: 0
|
|
133
|
+
|
|
134
|
+
2. Calculates Mean Average Precision:
|
|
135
|
+
- Computes precision at each position
|
|
136
|
+
- Weights earlier positions more heavily
|
|
137
|
+
- Normalizes to configured scale
|
|
138
|
+
|
|
139
|
+
Final score: `Mean Average Precision * scale`
|
|
140
|
+
|
|
141
|
+
### Score interpretation
|
|
142
|
+
(0 to scale, default 0-1)
|
|
143
|
+
- 1.0: All relevant context in optimal order
|
|
144
|
+
- 0.7-0.9: Mostly relevant context with good ordering
|
|
145
|
+
- 0.4-0.6: Mixed relevance or suboptimal ordering
|
|
146
|
+
- 0.1-0.3: Limited relevance or poor ordering
|
|
147
|
+
- 0.0: No relevant context
|
|
148
|
+
|
|
149
|
+
## Example with Analysis
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { openai } from "@ai-sdk/openai";
|
|
153
|
+
import { ContextPrecisionMetric } from "@mastra/evals/llm";
|
|
154
|
+
|
|
155
|
+
// Configure the model for evaluation
|
|
156
|
+
const model = openai("gpt-4o-mini");
|
|
157
|
+
|
|
158
|
+
const metric = new ContextPrecisionMetric(model, {
|
|
159
|
+
context: [
|
|
160
|
+
"Exercise strengthens the heart and improves blood circulation.",
|
|
161
|
+
"A balanced diet is important for health.",
|
|
162
|
+
"Regular physical activity reduces stress and anxiety.",
|
|
163
|
+
"Exercise equipment can be expensive.",
|
|
164
|
+
],
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const result = await metric.measure(
|
|
168
|
+
"What are the benefits of exercise?",
|
|
169
|
+
"Regular exercise improves cardiovascular health and mental wellbeing.",
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
// Example output:
|
|
173
|
+
// {
|
|
174
|
+
// score: 0.75,
|
|
175
|
+
// info: {
|
|
176
|
+
// reason: "The score is 0.75 because the first and third contexts are highly relevant
|
|
177
|
+
// to the benefits mentioned in the output, while the second and fourth contexts
|
|
178
|
+
// are not directly related to exercise benefits. The relevant contexts are well-positioned
|
|
179
|
+
// at the beginning and middle of the sequence."
|
|
180
|
+
// }
|
|
181
|
+
// }
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Related
|
|
185
|
+
|
|
186
|
+
- [Answer Relevancy Metric](./answer-relevancy)
|
|
187
|
+
- [Context Position Metric](./context-position)
|
|
188
|
+
- [Completeness Metric](./completeness)
|
|
189
|
+
- [Context Relevancy Metric](./context-relevancy)
|