@mastra/mcp-docs-server 0.13.7-alpha.0 → 0.13.7-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +39 -39
  2. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +18 -18
  3. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +18 -18
  4. package/.docs/organized/changelogs/%40mastra%2Fcore.md +45 -45
  5. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +21 -21
  6. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +44 -44
  7. package/.docs/organized/changelogs/%40mastra%2Fevals.md +11 -11
  8. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +29 -29
  9. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +25 -25
  10. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +39 -39
  11. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +20 -20
  12. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +17 -0
  13. package/.docs/organized/changelogs/%40mastra%2Fpg.md +29 -29
  14. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +12 -12
  15. package/.docs/organized/changelogs/%40mastra%2Fserver.md +38 -38
  16. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +29 -29
  17. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +18 -18
  18. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +18 -18
  19. package/.docs/organized/changelogs/create-mastra.md +7 -7
  20. package/.docs/organized/changelogs/mastra.md +32 -32
  21. package/.docs/organized/code-examples/agent.md +93 -3
  22. package/.docs/organized/code-examples/ai-sdk-v5.md +4 -4
  23. package/.docs/raw/agents/input-processors.mdx +268 -0
  24. package/.docs/raw/agents/using-tools-and-mcp.mdx +39 -0
  25. package/.docs/raw/community/contributing-templates.mdx +192 -0
  26. package/.docs/raw/getting-started/installation.mdx +16 -0
  27. package/.docs/raw/getting-started/templates.mdx +95 -0
  28. package/.docs/raw/observability/tracing.mdx +44 -0
  29. package/.docs/raw/reference/agents/agent.mdx +7 -0
  30. package/.docs/raw/reference/agents/generate.mdx +18 -1
  31. package/.docs/raw/reference/agents/stream.mdx +18 -1
  32. package/.docs/raw/reference/cli/dev.mdx +6 -0
  33. package/.docs/raw/reference/client-js/memory.mdx +18 -0
  34. package/.docs/raw/reference/core/mastra-class.mdx +1 -1
  35. package/.docs/raw/reference/memory/Memory.mdx +1 -0
  36. package/.docs/raw/reference/memory/deleteMessages.mdx +95 -0
  37. package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +33 -1
  38. package/.docs/raw/reference/rag/upstash.mdx +112 -5
  39. package/.docs/raw/reference/scorers/answer-relevancy.mdx +114 -0
  40. package/.docs/raw/reference/scorers/bias.mdx +127 -0
  41. package/.docs/raw/reference/scorers/completeness.mdx +89 -0
  42. package/.docs/raw/reference/scorers/content-similarity.mdx +96 -0
  43. package/.docs/raw/reference/scorers/custom-code-scorer.mdx +155 -0
  44. package/.docs/raw/reference/scorers/faithfulness.mdx +122 -0
  45. package/.docs/raw/reference/scorers/hallucination.mdx +133 -0
  46. package/.docs/raw/reference/scorers/keyword-coverage.mdx +92 -0
  47. package/.docs/raw/reference/scorers/llm-scorer.mdx +210 -0
  48. package/.docs/raw/reference/scorers/mastra-scorer.mdx +218 -0
  49. package/.docs/raw/reference/scorers/textual-difference.mdx +76 -0
  50. package/.docs/raw/reference/scorers/tone-consistency.mdx +75 -0
  51. package/.docs/raw/reference/scorers/toxicity.mdx +109 -0
  52. package/.docs/raw/reference/storage/libsql.mdx +7 -4
  53. package/.docs/raw/reference/storage/mssql.mdx +7 -3
  54. package/.docs/raw/reference/storage/postgresql.mdx +7 -3
  55. package/.docs/raw/reference/templates.mdx +228 -0
  56. package/.docs/raw/scorers/custom-scorers.mdx +319 -0
  57. package/.docs/raw/scorers/off-the-shelf-scorers.mdx +30 -0
  58. package/.docs/raw/scorers/overview.mdx +124 -0
  59. package/package.json +4 -4
@@ -61,6 +61,13 @@ constructor(config: AgentConfig<TAgentId, TTools, TMetrics>)
61
61
  description:
62
62
  "Tools that the agent can use. Can be a static object or a function that returns tools.",
63
63
  },
64
+ {
65
+ name: "inputProcessors",
66
+ type: "InputProcessor[] | ({ runtimeContext: RuntimeContext }) => InputProcessor[] | Promise<InputProcessor[]>",
67
+ isOptional: true,
68
+ description:
69
+ "Input processors that run sequentially before messages are sent to the language model. These middleware components can intercept, modify, validate, or filter messages. Each processor receives an array of MastraMessageV2 objects and an abort function for early termination. Can be a static array or a function that returns processors based on runtime context.",
70
+ },
64
71
  {
65
72
  name: "defaultGenerateOptions",
66
73
  type: "AgentGenerateOptions",
@@ -16,16 +16,27 @@ The `messages` parameter can be:
16
16
  - A single string
17
17
  - An array of strings
18
18
  - An array of message objects with `role` and `content` properties
19
+ - An array of `UIMessageWithMetadata` objects (for messages with metadata)
19
20
 
20
- The message object structure:
21
+ The message object structures:
21
22
 
22
23
  ```typescript
23
24
  interface Message {
24
25
  role: "system" | "user" | "assistant";
25
26
  content: string;
26
27
  }
28
+
29
+ // For messages with metadata
30
+ interface UIMessageWithMetadata {
31
+ role: "user" | "assistant";
32
+ content: string;
33
+ parts: Array<{ type: string; text?: string; [key: string]: any }>;
34
+ metadata?: Record<string, unknown>; // Optional metadata field
35
+ }
27
36
  ```
28
37
 
38
+ When using `UIMessageWithMetadata`, the metadata will be preserved throughout the conversation and stored with the messages in memory.
39
+
29
40
  ### `options` (Optional)
30
41
 
31
42
  An optional object that can include configuration for output structure, memory management, tool usage, telemetry, and more.
@@ -175,6 +186,12 @@ An optional object that can include configuration for output structure, memory m
175
186
  description:
176
187
  "Tools that are executed on the 'client' side of the request. These tools do not have execute functions in the definition.",
177
188
  },
189
+ {
190
+ name: "savePerStep",
191
+ type: "boolean",
192
+ isOptional: true,
193
+ description: "Save messages incrementally after each stream step completes (default: false).",
194
+ }
178
195
  ]}
179
196
  />
180
197
 
@@ -16,16 +16,27 @@ The `messages` parameter can be:
16
16
  - A single string
17
17
  - An array of strings
18
18
  - An array of message objects with `role` and `content` properties
19
+ - An array of `UIMessageWithMetadata` objects (for messages with metadata)
19
20
 
20
- The message object structure:
21
+ The message object structures:
21
22
 
22
23
  ```typescript
23
24
  interface Message {
24
25
  role: "system" | "user" | "assistant";
25
26
  content: string;
26
27
  }
28
+
29
+ // For messages with metadata
30
+ interface UIMessageWithMetadata {
31
+ role: "user" | "assistant";
32
+ content: string;
33
+ parts: Array<{ type: string; text?: string; [key: string]: any }>;
34
+ metadata?: Record<string, unknown>; // Optional metadata field
35
+ }
27
36
  ```
28
37
 
38
+ When using `UIMessageWithMetadata`, the metadata will be preserved throughout the conversation and stored with the messages in memory.
39
+
29
40
  ### `options` (Optional)
30
41
 
31
42
  An optional object that can include configuration for output structure, memory management, tool usage, telemetry, and more.
@@ -181,6 +192,12 @@ An optional object that can include configuration for output structure, memory m
181
192
  description:
182
193
  "Tools that are executed on the 'client' side of the request. These tools do not have execute functions in the definition.",
183
194
  },
195
+ {
196
+ name: "savePerStep",
197
+ type: "boolean",
198
+ isOptional: true,
199
+ description: "Save messages incrementally after each generation step completes (default: false)",
200
+ }
184
201
  ]}
185
202
  />
186
203
 
@@ -60,6 +60,12 @@ mastra dev [options]
60
60
  description: "Start the dev server in inspect mode and break at the beginning of the script (cannot be used with --inspect)",
61
61
  isOptional: true,
62
62
  },
63
+ {
64
+ name: "--custom-args",
65
+ type: "string",
66
+ description: "Comma-separated list of custom arguments to pass to the dev server. IE: --experimental-transform-types",
67
+ isOptional: true,
68
+ },
63
69
  {
64
70
  name: "--help",
65
71
  type: "boolean",
@@ -103,6 +103,24 @@ const { messages } = await thread.getMessages();
103
103
  const { messages } = await thread.getMessages({ limit: 10 });
104
104
  ```
105
105
 
106
+ ### Delete a Message
107
+
108
+ Delete a specific message from a thread:
109
+
110
+ ```typescript
111
+ const result = await thread.deleteMessage("message-id");
112
+ // Returns: { success: true, message: "Message deleted successfully" }
113
+ ```
114
+
115
+ ### Delete Multiple Messages
116
+
117
+ Delete multiple messages from a thread in a single operation:
118
+
119
+ ```typescript
120
+ const result = await thread.deleteMessages(["message-1", "message-2", "message-3"]);
121
+ // Returns: { success: true, message: "3 messages deleted successfully" }
122
+ ```
123
+
106
124
  ### Get Memory Status
107
125
 
108
126
  Check the status of the memory system:
@@ -126,7 +126,7 @@ The constructor accepts an optional `Config` object to customize its behavior an
126
126
  "Server configuration including port, host, timeout, API routes, middleware, CORS settings, and build options for Swagger UI, API request logging, and OpenAPI docs.",
127
127
  isOptional: true,
128
128
  defaultValue:
129
- "{ port: 4111, host: localhost, cors: { origin: '*', allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], allowHeaders: ['Content-Type', 'Authorization', 'x-mastra-client-type'], exposeHeaders: ['Content-Length', 'X-Requested-With'], credentials: false } }",
129
+ "{ port: 4111, host: localhost, cors: { origin: '*', allowMethods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], allowHeaders: ['Content-Type', 'Authorization', 'x-mastra-client-type'], exposeHeaders: ['Content-Length', 'X-Requested-With'], credentials: false } }",
130
130
  },
131
131
  {
132
132
  name: "mcpServers",
@@ -310,3 +310,4 @@ Mastra supports many embedding models through the [Vercel AI SDK](https://sdk.ve
310
310
  - [query](/reference/memory/query.mdx)
311
311
  - [getThreadById](/reference/memory/getThreadById.mdx)
312
312
  - [getThreadsByResourceId](/reference/memory/getThreadsByResourceId.mdx)
313
+ - [deleteMessages](/reference/memory/deleteMessages.mdx)
@@ -0,0 +1,95 @@
1
+ ---
2
+ section: Memory
3
+ title: deleteMessages
4
+ slug: reference/memory/deleteMessages
5
+ categorySlug: reference
6
+ layout: guide
7
+ ---
8
+
9
+ # `deleteMessages`
10
+
11
+ Deletes one or more messages from the memory storage. This method accepts arrays to delete multiple messages in a single operation.
12
+
13
+ ## Syntax
14
+
15
+ ```typescript
16
+ memory.deleteMessages(input: MessageDeleteInput): Promise<void>
17
+
18
+ type MessageDeleteInput =
19
+ | string[] // Array of message IDs
20
+ | { id: string }[] // Array of message objects
21
+ ```
22
+
23
+ ## Parameters
24
+
25
+ - `input` (required): An array of messages to delete. Must be either:
26
+ - An array of message IDs (strings)
27
+ - An array of message objects with `id` properties
28
+
29
+ ## Returns
30
+
31
+ A Promise that resolves when all messages have been successfully deleted.
32
+
33
+ ## Examples
34
+
35
+ ### Delete a single message
36
+
37
+ ```typescript
38
+ // Using an array with a single string ID
39
+ await memory.deleteMessages(['msg-123']);
40
+
41
+ // Using an array with a single message object
42
+ await memory.deleteMessages([{ id: 'msg-123' }]);
43
+ ```
44
+
45
+ ### Delete multiple messages
46
+
47
+ ```typescript
48
+ // Using an array of string IDs
49
+ await memory.deleteMessages(['msg-1', 'msg-2', 'msg-3']);
50
+
51
+ // Using an array of message objects
52
+ await memory.deleteMessages([
53
+ { id: 'msg-1' },
54
+ { id: 'msg-2' },
55
+ { id: 'msg-3' }
56
+ ]);
57
+ ```
58
+
59
+ ### Using with client SDK
60
+
61
+ ```typescript
62
+ // Get a thread instance
63
+ const thread = client.getAgent('my-agent').getThread('thread-123');
64
+
65
+ // Delete a single message
66
+ await thread.deleteMessages(['msg-123']);
67
+
68
+ // Delete multiple messages
69
+ await thread.deleteMessages(['msg-1', 'msg-2', 'msg-3']);
70
+
71
+ // Delete using message objects (useful when you have message data)
72
+ const messagesToDelete = messages.map(msg => ({ id: msg.id }));
73
+ await thread.deleteMessages(messagesToDelete);
74
+ ```
75
+
76
+ ### Error handling
77
+
78
+ ```typescript
79
+ try {
80
+ await memory.deleteMessages(['msg-1', 'msg-2', 'msg-3']);
81
+ console.log('Messages deleted successfully');
82
+ } catch (error) {
83
+ console.error('Failed to delete messages:', error);
84
+ }
85
+ ```
86
+
87
+ ## Notes
88
+
89
+ - This method requires an array as input, even when deleting a single message
90
+ - Thread timestamps are automatically updated when messages are deleted
91
+ - The method automatically extracts message IDs from message objects
92
+ - All message IDs must be non-empty strings
93
+ - An empty array will result in no operation (no error thrown)
94
+ - Messages from different threads can be deleted in the same operation
95
+ - When using message objects, only the `id` property is required
@@ -1,6 +1,6 @@
1
1
  # getThreadsByResourceId Reference
2
2
 
3
- The `getThreadsByResourceId` function retrieves all threads associated with a specific resource ID from storage.
3
+ The `getThreadsByResourceId` function retrieves all threads associated with a specific resource ID from storage. Threads can be sorted by creation or modification time in ascending or descending order.
4
4
 
5
5
  ## Usage Example
6
6
 
@@ -9,9 +9,17 @@ import { Memory } from "@mastra/core/memory";
9
9
 
10
10
  const memory = new Memory(config);
11
11
 
12
+ // Basic usage - returns threads sorted by createdAt DESC (default)
12
13
  const threads = await memory.getThreadsByResourceId({
13
14
  resourceId: "resource-123",
14
15
  });
16
+
17
+ // Custom sorting by updatedAt in ascending order
18
+ const threadsByUpdate = await memory.getThreadsByResourceId({
19
+ resourceId: "resource-123",
20
+ orderBy: "updatedAt",
21
+ sortDirection: "ASC",
22
+ });
15
23
  ```
16
24
 
17
25
  ## Parameters
@@ -24,9 +32,33 @@ const threads = await memory.getThreadsByResourceId({
24
32
  description: "The ID of the resource whose threads are to be retrieved.",
25
33
  isOptional: false,
26
34
  },
35
+ {
36
+ name: "orderBy",
37
+ type: "ThreadOrderBy",
38
+ description: "Field to sort threads by. Accepts 'createdAt' or 'updatedAt'. Default: 'createdAt'",
39
+ isOptional: true,
40
+ },
41
+ {
42
+ name: "sortDirection",
43
+ type: "ThreadSortDirection",
44
+ description: "Sort order direction. Accepts 'ASC' or 'DESC'. Default: 'DESC'",
45
+ isOptional: true,
46
+ },
27
47
  ]}
28
48
  />
29
49
 
50
+ ## Type Definitions
51
+
52
+ ```typescript
53
+ type ThreadOrderBy = 'createdAt' | 'updatedAt';
54
+ type ThreadSortDirection = 'ASC' | 'DESC';
55
+
56
+ interface ThreadSortOptions {
57
+ orderBy?: ThreadOrderBy;
58
+ sortDirection?: ThreadSortDirection;
59
+ }
60
+ ```
61
+
30
62
  ## Returns
31
63
 
32
64
  <PropertiesTable
@@ -5,7 +5,7 @@ description: Documentation for the UpstashVector class in Mastra, which provides
5
5
 
6
6
  # Upstash Vector Store
7
7
 
8
- The UpstashVector class provides vector search using [Upstash Vector](https://upstash.com/vector), a serverless vector database service that provides vector similarity search with metadata filtering capabilities.
8
+ The UpstashVector class provides vector search using [Upstash Vector](https://upstash.com/vector), a serverless vector database service that provides vector similarity search with metadata filtering capabilities and hybrid search support.
9
9
 
10
10
  ## Constructor Options
11
11
 
@@ -66,6 +66,12 @@ Note: This method is a no-op for Upstash as indexes are created automatically.
66
66
  type: "number[][]",
67
67
  description: "Array of embedding vectors",
68
68
  },
69
+ {
70
+ name: "sparseVectors",
71
+ type: "{ indices: number[], values: number[] }[]",
72
+ isOptional: true,
73
+ description: "Array of sparse vectors for hybrid search. Each sparse vector must have matching indices and values arrays.",
74
+ },
69
75
  {
70
76
  name: "metadata",
71
77
  type: "Record<string, any>[]",
@@ -95,6 +101,12 @@ Note: This method is a no-op for Upstash as indexes are created automatically.
95
101
  type: "number[]",
96
102
  description: "Query vector to find similar vectors",
97
103
  },
104
+ {
105
+ name: "sparseVector",
106
+ type: "{ indices: number[], values: number[] }",
107
+ isOptional: true,
108
+ description: "Optional sparse vector for hybrid search. Must have matching indices and values arrays.",
109
+ },
98
110
  {
99
111
  name: "topK",
100
112
  type: "number",
@@ -115,6 +127,18 @@ Note: This method is a no-op for Upstash as indexes are created automatically.
115
127
  defaultValue: "false",
116
128
  description: "Whether to include vectors in the results",
117
129
  },
130
+ {
131
+ name: "fusionAlgorithm",
132
+ type: "FusionAlgorithm",
133
+ isOptional: true,
134
+ description: "Algorithm used to combine dense and sparse search results in hybrid search (e.g., RRF - Reciprocal Rank Fusion)",
135
+ },
136
+ {
137
+ name: "queryMode",
138
+ type: "QueryMode",
139
+ isOptional: true,
140
+ description: "Search mode: 'DENSE' for dense-only, 'SPARSE' for sparse-only, or 'HYBRID' for combined search",
141
+ },
118
142
  ]}
119
143
  />
120
144
 
@@ -173,18 +197,17 @@ interface IndexStats {
173
197
  {
174
198
  name: "update",
175
199
  type: "object",
176
- description: "Update object containing vector and/or metadata",
200
+ description: "Update object containing vector, sparse vector, and/or metadata",
177
201
  },
178
202
  ]}
179
203
  />
180
204
 
181
205
  The `update` object can have the following properties:
182
206
 
183
- - `vector` (optional): An array of numbers representing the new vector.
207
+ - `vector` (optional): An array of numbers representing the new dense vector.
208
+ - `sparseVector` (optional): A sparse vector object with `indices` and `values` arrays for hybrid indexes.
184
209
  - `metadata` (optional): A record of key-value pairs for metadata.
185
210
 
186
- Throws an error if neither `vector` nor `metadata` is provided, or if only `metadata` is provided.
187
-
188
211
  ### deleteVector()
189
212
 
190
213
  <PropertiesTable
@@ -204,6 +227,90 @@ Throws an error if neither `vector` nor `metadata` is provided, or if only `meta
204
227
 
205
228
  Attempts to delete an item by its ID from the specified index. Logs an error message if the deletion fails.
206
229
 
230
+ ## Hybrid Vector Search
231
+
232
+ Upstash Vector supports hybrid search that combines semantic search (dense vectors) with keyword-based search (sparse vectors) for improved relevance and accuracy.
233
+
234
+ ### Basic Hybrid Usage
235
+
236
+ ```typescript copy
237
+ import { UpstashVector } from '@mastra/upstash';
238
+
239
+ const vectorStore = new UpstashVector({
240
+ url: process.env.UPSTASH_VECTOR_URL,
241
+ token: process.env.UPSTASH_VECTOR_TOKEN
242
+ });
243
+
244
+ // Upsert vectors with both dense and sparse components
245
+ const denseVectors = [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]];
246
+ const sparseVectors = [
247
+ { indices: [1, 5, 10], values: [0.8, 0.6, 0.4] },
248
+ { indices: [2, 6, 11], values: [0.7, 0.5, 0.3] }
249
+ ];
250
+
251
+ await vectorStore.upsert({
252
+ indexName: 'hybrid-index',
253
+ vectors: denseVectors,
254
+ sparseVectors: sparseVectors,
255
+ metadata: [{ title: 'Document 1' }, { title: 'Document 2' }]
256
+ });
257
+
258
+ // Query with hybrid search
259
+ const results = await vectorStore.query({
260
+ indexName: 'hybrid-index',
261
+ queryVector: [0.1, 0.2, 0.3],
262
+ sparseVector: { indices: [1, 5], values: [0.9, 0.7] },
263
+ topK: 10
264
+ });
265
+ ```
266
+
267
+ ### Advanced Hybrid Search Options
268
+
269
+ ```typescript copy
270
+ import { FusionAlgorithm, QueryMode } from '@upstash/vector';
271
+
272
+ // Query with specific fusion algorithm
273
+ const fusionResults = await vectorStore.query({
274
+ indexName: 'hybrid-index',
275
+ queryVector: [0.1, 0.2, 0.3],
276
+ sparseVector: { indices: [1, 5], values: [0.9, 0.7] },
277
+ fusionAlgorithm: FusionAlgorithm.RRF,
278
+ topK: 10
279
+ });
280
+
281
+ // Dense-only search
282
+ const denseResults = await vectorStore.query({
283
+ indexName: 'hybrid-index',
284
+ queryVector: [0.1, 0.2, 0.3],
285
+ queryMode: QueryMode.DENSE,
286
+ topK: 10
287
+ });
288
+
289
+ // Sparse-only search
290
+ const sparseResults = await vectorStore.query({
291
+ indexName: 'hybrid-index',
292
+ queryVector: [0.1, 0.2, 0.3], // Still required for index structure
293
+ sparseVector: { indices: [1, 5], values: [0.9, 0.7] },
294
+ queryMode: QueryMode.SPARSE,
295
+ topK: 10
296
+ });
297
+ ```
298
+
299
+ ### Updating Hybrid Vectors
300
+
301
+ ```typescript copy
302
+ // Update both dense and sparse components
303
+ await vectorStore.updateVector({
304
+ indexName: 'hybrid-index',
305
+ id: 'vector-id',
306
+ update: {
307
+ vector: [0.2, 0.3, 0.4],
308
+ sparseVector: { indices: [2, 7, 12], values: [0.9, 0.8, 0.6] },
309
+ metadata: { title: 'Updated Document' }
310
+ }
311
+ });
312
+ ```
313
+
207
314
  ## Response Types
208
315
 
209
316
  Query results are returned in this format:
@@ -0,0 +1,114 @@
1
+ ---
2
+ title: "Reference: Answer Relevancy | Scorers | Mastra Docs"
3
+ description: Documentation for the Answer Relevancy Scorer in Mastra, which evaluates how well LLM outputs address the input query.
4
+ ---
5
+
6
+ # Answer Relevancy Scorer
7
+
8
+ The `createAnswerRelevancyScorer()` function accepts a single options object with the following properties:
9
+
10
+ For usage example, see the [Answer Relevancy Examples](/examples/scorers/answer-relevancy).
11
+
12
+ ## Parameters
13
+
14
+ <PropertiesTable
15
+ content={[
16
+ {
17
+ name: "model",
18
+ type: "LanguageModel",
19
+ required: true,
20
+ description: "Configuration for the model used to evaluate relevancy.",
21
+ },
22
+ {
23
+ name: "uncertaintyWeight",
24
+ type: "number",
25
+ required: false,
26
+ defaultValue: "0.3",
27
+ description: "Weight given to 'unsure' verdicts in scoring (0-1).",
28
+ },
29
+ {
30
+ name: "scale",
31
+ type: "number",
32
+ required: false,
33
+ defaultValue: "1",
34
+ description: "Maximum score value.",
35
+ },
36
+ ]}
37
+ />
38
+
39
+ This function returns an instance of the MastraScorer class. The `.run()` method accepts the same input as other scorers (see the [MastraScorer reference](./mastra-scorer)), but the return value includes LLM-specific fields as documented below.
40
+
41
+ ## .run() Returns
42
+
43
+ <PropertiesTable
44
+ content={[
45
+ {
46
+ name: "runId",
47
+ type: "string",
48
+ description: "The id of the run (optional).",
49
+ },
50
+ {
51
+ name: "score",
52
+ type: "number",
53
+ description: "Relevancy score (0 to scale, default 0-1)",
54
+ },
55
+ {
56
+ name: "extractPrompt",
57
+ type: "string",
58
+ description: "The prompt sent to the LLM for the extract step (optional).",
59
+ },
60
+ {
61
+ name: "extractStepResult",
62
+ type: "object",
63
+ description: "Object with extracted statements: { statements: string[] }",
64
+ },
65
+ {
66
+ name: "analyzePrompt",
67
+ type: "string",
68
+ description: "The prompt sent to the LLM for the analyze step (optional).",
69
+ },
70
+ {
71
+ name: "analyzeStepResult",
72
+ type: "object",
73
+ description: "Object with results: { results: Array<{ result: 'yes' | 'unsure' | 'no', reason: string }> }",
74
+ },
75
+ {
76
+ name: "reasonPrompt",
77
+ type: "string",
78
+ description: "The prompt sent to the LLM for the reason step (optional).",
79
+ },
80
+ {
81
+ name: "reason",
82
+ type: "string",
83
+ description: "Explanation of the score.",
84
+ },
85
+ ]}
86
+ />
87
+
88
+ ## Scoring Details
89
+
90
+ The scorer evaluates relevancy through query-answer alignment, considering completeness and detail level, but not factual correctness.
91
+
92
+ ### Scoring Process
93
+
94
+ 1. **Statement Extraction:**
95
+ - Breaks output into meaningful statements while preserving context.
96
+ 2. **Relevance Analysis:**
97
+ - Each statement is evaluated as:
98
+ - "yes": Full weight for direct matches
99
+ - "unsure": Partial weight (default: 0.3) for approximate matches
100
+ - "no": Zero weight for irrelevant content
101
+ 3. **Score Calculation:**
102
+ - `((direct + uncertainty * partial) / total_statements) * scale`
103
+
104
+ ### Score Interpretation
105
+
106
+ - 1.0: Perfect relevance - complete and accurate
107
+ - 0.7-0.9: High relevance - minor gaps or imprecisions
108
+ - 0.4-0.6: Moderate relevance - significant gaps
109
+ - 0.1-0.3: Low relevance - major issues
110
+ - 0.0: No relevance - incorrect or off-topic
111
+
112
+ ## Related
113
+
114
+ - [Faithfulness Scorer](./faithfulness)