@mastra/mcp-docs-server 1.2.13-alpha.4 → 1.2.13-alpha.8
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/docs/agents/agent-approval.md +2 -2
- package/.docs/docs/deployment/workers.md +14 -14
- package/.docs/docs/evals/datasets/running-experiments.md +1 -1
- package/.docs/docs/index.md +1 -1
- package/.docs/docs/long-running-agents/durable-agents.md +2 -2
- package/.docs/docs/mastra-platform/overview.md +1 -1
- package/.docs/docs/mastra-platform/{workspace.md → workspaces.md} +48 -7
- package/.docs/docs/memory/observational-memory.md +30 -13
- package/.docs/docs/memory/overview.md +14 -0
- package/.docs/docs/server/auth/workers.md +7 -5
- package/.docs/docs/server/mastra-client.md +60 -0
- package/.docs/docs/server/pubsub.md +2 -2
- package/.docs/docs/what-is-mastra.md +10 -10
- package/.docs/docs/workflows/overview.md +1 -1
- package/.docs/docs/workflows/scheduled-workflows.md +1 -0
- package/.docs/guides/deployment/kubernetes.md +2 -0
- package/.docs/guides/deployment/mastra-workers.md +350 -6
- package/.docs/guides/deployment/vercel.md +2 -0
- package/.docs/models/gateways/openrouter.md +1 -4
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/hyper.md +2 -1
- package/.docs/models/providers/minimax.md +1 -1
- package/.docs/models/providers/openai.md +2 -2
- package/.docs/models/providers/opencode-go.md +2 -1
- package/.docs/models/providers/opencode.md +1 -1
- package/.docs/models/providers/perplexity-agent.md +3 -1
- package/.docs/reference/agents/durable-agent.md +12 -1
- package/.docs/reference/cli/mastra.md +30 -14
- package/.docs/reference/core/mastra-class.md +1 -1
- package/.docs/reference/evals/summarization.md +203 -0
- package/.docs/reference/index.md +1 -0
- package/.docs/reference/memory/observational-memory.md +74 -24
- package/.docs/reference/observability/tracing/interfaces.md +3 -0
- package/.docs/reference/processors/regex-filter-processor.md +1 -1
- package/.docs/reference/tools/isolated-vm-transport.md +1 -1
- package/.docs/reference/vectors/mongodb.md +13 -13
- package/.docs/reference/workers/overview.md +10 -8
- package/.docs/reference/workspace/platform-filesystem.md +5 -2
- package/.docs/reference/workspace/platform-sandbox.md +80 -4
- package/CHANGELOG.md +15 -0
- package/package.json +5 -5
|
@@ -135,7 +135,7 @@ Visit the [Configuration reference](https://mastra.ai/reference/configuration) f
|
|
|
135
135
|
|
|
136
136
|
Re-drives every orphaned `running` durable-agent run across all registered durable agents. Called automatically on boot when `recovery.durableAgents` is `'auto'`. You can also call it directly for manual recovery or from a scheduled task.
|
|
137
137
|
|
|
138
|
-
Requires persistent storage
|
|
138
|
+
Requires persistent storage. With an in-memory store, there's nothing to recover after a process restart.
|
|
139
139
|
|
|
140
140
|
```typescript
|
|
141
141
|
const result = await mastra.recoverAllDurableAgents()
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
+
|
|
3
|
+
# Summarization scorer
|
|
4
|
+
|
|
5
|
+
The `createSummarizationScorer()` function creates a scorer that evaluates a summary on two axes: whether every claim it makes is supported by the source text, and whether it preserves the information the source states. The final score is the lower of the two, so a summary can't pass by being faithful but empty, or thorough but wrong.
|
|
6
|
+
|
|
7
|
+
The summary is the agent's last message that carries text, and the source text defaults to the first user message of the run input. Pass `source` or `sourceExtractor` when the text being summarized lives somewhere else, such as a tool result.
|
|
8
|
+
|
|
9
|
+
## Usage example
|
|
10
|
+
|
|
11
|
+
Score a summary against the document it condenses.
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createSummarizationScorer } from '@mastra/evals/scorers/prebuilt'
|
|
15
|
+
|
|
16
|
+
const scorer = createSummarizationScorer({
|
|
17
|
+
model: 'openai/gpt-5.6-sol',
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const result = await scorer.run({
|
|
21
|
+
input: {
|
|
22
|
+
inputMessages: [{ id: '1', role: 'user', content: sourceDocument }],
|
|
23
|
+
},
|
|
24
|
+
output: [{ id: '2', role: 'assistant', content: summary }],
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
console.log(result.score)
|
|
28
|
+
console.log(result.reason)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Summarization evaluation
|
|
32
|
+
|
|
33
|
+
Use this scorer when an agent condenses text:
|
|
34
|
+
|
|
35
|
+
- Document and transcript summarization
|
|
36
|
+
- Support thread and email digests
|
|
37
|
+
- Any step that compresses a long input into a short output
|
|
38
|
+
|
|
39
|
+
## Parameters
|
|
40
|
+
|
|
41
|
+
**model** (`MastraModelConfig`): The language model to use for judging claims and coverage questions
|
|
42
|
+
|
|
43
|
+
**options** (`SummarizationMetricOptions`): Configuration options for the scorer
|
|
44
|
+
|
|
45
|
+
**options.source** (`string`): Text the summary is judged against. Defaults to the user message of the run input
|
|
46
|
+
|
|
47
|
+
**options.sourceExtractor** (`(input, output) => string`): Function to derive the source text from the run input and output. Takes precedence over source
|
|
48
|
+
|
|
49
|
+
**options.maxQuestions** (`number`): Upper bound on the coverage questions drawn from the source (default: 10)
|
|
50
|
+
|
|
51
|
+
**options.scale** (`number`): Scale factor to multiply the final score (default: 1)
|
|
52
|
+
|
|
53
|
+
## `.run()` returns
|
|
54
|
+
|
|
55
|
+
**score** (`number`): Summarization score between 0 and scale (default 0-1), the lower of the alignment and coverage scores
|
|
56
|
+
|
|
57
|
+
**reason** (`string`): Human-readable explanation naming the axis that produced the score and the claims or questions behind it. Both axis scores appear in the text
|
|
58
|
+
|
|
59
|
+
**preprocessStepResult** (`object`): The alignment verdicts and the questions drawn from the source
|
|
60
|
+
|
|
61
|
+
**preprocessStepResult.alignment** (`{ claim: string; supported: boolean; reason: string }[]`): One verdict per claim the summary makes
|
|
62
|
+
|
|
63
|
+
**preprocessStepResult.questions** (`string[]`): The coverage questions drawn from the source text
|
|
64
|
+
|
|
65
|
+
**analyzeStepResult** (`object`): The coverage verdicts
|
|
66
|
+
|
|
67
|
+
**analyzeStepResult.coverage** (`{ question: string; answered: boolean; reason: string }[]`): One verdict per question, answered from the summary alone
|
|
68
|
+
|
|
69
|
+
The axis scores are derived from these verdicts rather than stored: alignment is the share of `alignment` entries with `supported: true`, and coverage is the share of `questions` whose `coverage` entry has `answered: true`.
|
|
70
|
+
|
|
71
|
+
## Scoring details
|
|
72
|
+
|
|
73
|
+
### Two-axis evaluation
|
|
74
|
+
|
|
75
|
+
The scorer runs a three-step pipeline:
|
|
76
|
+
|
|
77
|
+
1. **Source judgement**: the claims the summary makes are extracted and checked against the source, and closed-ended questions are drawn from the source. Every question is written so the source answers it "yes".
|
|
78
|
+
2. **Coverage**: each question is answered using the summary alone.
|
|
79
|
+
3. **Scoring**: the two ratios are computed and the lower one becomes the score.
|
|
80
|
+
|
|
81
|
+
The coverage step runs as a separate model call that never receives the source text. A judge that could see the source would answer questions from it rather than from the summary, which would hide the omissions this axis exists to measure.
|
|
82
|
+
|
|
83
|
+
### Scoring formula
|
|
84
|
+
|
|
85
|
+
```text
|
|
86
|
+
Alignment = supported_claims / total_claims
|
|
87
|
+
Coverage = answered_questions / total_questions
|
|
88
|
+
Summarization = min(Alignment, Coverage) × scale
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The score is 0 when the summary yields no claims or the source yields no questions.
|
|
92
|
+
|
|
93
|
+
### Score interpretation
|
|
94
|
+
|
|
95
|
+
These ranges assume the default `scale` of 1. When using a custom scale, multiply accordingly.
|
|
96
|
+
|
|
97
|
+
- **0.9-1.0**: Excellent summary, faithful to the source and covering its main points
|
|
98
|
+
- **0.7-0.8**: Good summary with a small omission or an unsupported detail
|
|
99
|
+
- **0.4-0.6**: Moderate summary, either missing important information or drifting from the source
|
|
100
|
+
- **0.1-0.3**: Poor summary, most of the source is lost or contradicted
|
|
101
|
+
- **0.0**: The summary produced nothing to judge, or it failed to support any claims. A summary that answers no questions also receives this score
|
|
102
|
+
|
|
103
|
+
### Reading the two axes
|
|
104
|
+
|
|
105
|
+
Both axes leave their verdicts on the run result: the alignment verdicts on the preprocess step, and the coverage verdicts on the analyze step. Each verdict carries the claim or question it belongs to and the reason behind it. A low alignment score has a different meaning from a low coverage score:
|
|
106
|
+
|
|
107
|
+
- A low alignment score with high coverage means the summary invents or distorts detail
|
|
108
|
+
- A low coverage score with high alignment means the summary is accurate but leaves too much out
|
|
109
|
+
|
|
110
|
+
The reason field names whichever axis produced the score.
|
|
111
|
+
|
|
112
|
+
### What the score leaves out
|
|
113
|
+
|
|
114
|
+
Length plays no part in the score. A summary that repeats the source word for word supports every claim and answers every question, so it scores 1. Add a length check of your own when compression is part of what you're testing.
|
|
115
|
+
|
|
116
|
+
### Cost
|
|
117
|
+
|
|
118
|
+
Each evaluation makes three model calls. `maxQuestions` bounds the coverage half of the work, which otherwise grows with source length. Raise it for long documents where ten questions can't represent the content.
|
|
119
|
+
|
|
120
|
+
## Scorer configuration
|
|
121
|
+
|
|
122
|
+
### Summarizing the run input
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
const scorer = createSummarizationScorer({
|
|
126
|
+
model: 'openai/gpt-5.6-sol',
|
|
127
|
+
})
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Summarizing a document from elsewhere
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { extractToolResults } from '@mastra/evals/scorers/utils'
|
|
134
|
+
|
|
135
|
+
const scorer = createSummarizationScorer({
|
|
136
|
+
model: 'openai/gpt-5.6-sol',
|
|
137
|
+
options: {
|
|
138
|
+
sourceExtractor: (input, output) => {
|
|
139
|
+
return extractToolResults(output)
|
|
140
|
+
.filter(({ toolName }) => toolName === 'fetchDocument')
|
|
141
|
+
.map(({ result }) => String(result))
|
|
142
|
+
.join('\n\n')
|
|
143
|
+
},
|
|
144
|
+
maxQuestions: 20,
|
|
145
|
+
},
|
|
146
|
+
})
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Example
|
|
150
|
+
|
|
151
|
+
Evaluate a summarization agent against a set of documents:
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
import { runEvals } from '@mastra/core/evals'
|
|
155
|
+
import { createSummarizationScorer } from '@mastra/evals/scorers/prebuilt'
|
|
156
|
+
import { summarizerAgent } from './agent'
|
|
157
|
+
|
|
158
|
+
const scorer = createSummarizationScorer({
|
|
159
|
+
model: 'openai/gpt-5.6-sol',
|
|
160
|
+
options: { maxQuestions: 10 },
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const result = await runEvals({
|
|
164
|
+
target: summarizerAgent,
|
|
165
|
+
scorers: [scorer],
|
|
166
|
+
data: [
|
|
167
|
+
{
|
|
168
|
+
input:
|
|
169
|
+
'The company was founded in 1995 by John Smith. It started with 10 employees and grew to 500 by 2020. The company is based in Seattle.',
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
onItemComplete: ({ scorerResults }) => {
|
|
173
|
+
console.log({
|
|
174
|
+
score: scorerResults[scorer.id].score,
|
|
175
|
+
reason: scorerResults[scorer.id].reason,
|
|
176
|
+
})
|
|
177
|
+
},
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
console.log(result.scores)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
For more details on `runEvals`, see the [runEvals reference](https://mastra.ai/reference/evals/run-evals).
|
|
184
|
+
|
|
185
|
+
To add this scorer to an agent, see the [Scorers overview](https://mastra.ai/docs/evals/overview) guide.
|
|
186
|
+
|
|
187
|
+
## Comparison with faithfulness
|
|
188
|
+
|
|
189
|
+
| Use case | Summarization | Faithfulness |
|
|
190
|
+
| ------------------------- | ------------------------------- | --------------------------------- |
|
|
191
|
+
| **What it measures** | Support and coverage together | Support only |
|
|
192
|
+
| **Judged against** | The source text being condensed | Retrieved context or tool results |
|
|
193
|
+
| **Catches omission** | Yes | No |
|
|
194
|
+
| **Needs the full source** | Yes | No, context alone is enough |
|
|
195
|
+
|
|
196
|
+
Use `faithfulness` when the question is whether an answer stays grounded in retrieved context. Use `summarization` when the output is meant to stand in for a longer text.
|
|
197
|
+
|
|
198
|
+
## Related
|
|
199
|
+
|
|
200
|
+
- [Faithfulness Scorer](https://mastra.ai/reference/evals/faithfulness): Measures answer groundedness in context
|
|
201
|
+
- [Completeness Scorer](https://mastra.ai/reference/evals/completeness): Compares element coverage without a model
|
|
202
|
+
- [Content Similarity Scorer](https://mastra.ai/reference/evals/content-similarity): Compares text similarity without a model
|
|
203
|
+
- [Custom Scorers](https://mastra.ai/docs/evals/custom-scorers): Creating your own evaluation metrics
|
package/.docs/reference/index.md
CHANGED
|
@@ -152,6 +152,7 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
152
152
|
- [Noise Sensitivity Scorer](https://mastra.ai/reference/evals/noise-sensitivity)
|
|
153
153
|
- [Prompt Alignment Scorer](https://mastra.ai/reference/evals/prompt-alignment)
|
|
154
154
|
- [Rubric Scorer](https://mastra.ai/reference/evals/rubric)
|
|
155
|
+
- [Summarization Scorer](https://mastra.ai/reference/evals/summarization)
|
|
155
156
|
- [Textual Difference Scorer](https://mastra.ai/reference/evals/textual-difference)
|
|
156
157
|
- [Tone Consistency Scorer](https://mastra.ai/reference/evals/tone-consistency)
|
|
157
158
|
- [Tool Call Accuracy Scorers](https://mastra.ai/reference/evals/tool-call-accuracy)
|
|
@@ -27,7 +27,7 @@ export const agent = new Agent({
|
|
|
27
27
|
|
|
28
28
|
## Configuration
|
|
29
29
|
|
|
30
|
-
The `observationalMemory` option accepts `true`, a configuration object, or `false`. Setting `true` enables OM with `google/gemini-2.5-flash` as the default model. When passing a config object,
|
|
30
|
+
The `observationalMemory` option accepts `true`, a configuration object, or `false`. Setting `true` enables OM with `google/gemini-2.5-flash` as the default model. When passing a config object, set `model` at the top level or on `observation.model` and/or `reflection.model`; when all model fields are omitted, OM falls back to `google/gemini-2.5-flash`.
|
|
31
31
|
|
|
32
32
|
Observer input is multimodal-aware. OM keeps text placeholders like `[Image #1: screenshot.png]` in the transcript it builds for the Observer, and also sends the underlying image parts when possible. This applies to both single-thread observation and batched multi-thread observation. Non-image files appear as placeholders only.
|
|
33
33
|
|
|
@@ -35,7 +35,7 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
|
|
|
35
35
|
|
|
36
36
|
**enabled** (`boolean`): Enable or disable Observational Memory. When omitted from a config object, defaults to true. Only enabled: false explicitly disables it. (Default: `true`)
|
|
37
37
|
|
|
38
|
-
**model** (`string | LanguageModel | DynamicModel | ModelByInputTokens | ModelWithRetries[]`): Model for both the Observer and Reflector agents. Sets the model for both at once. Cannot be used together with observation.model or reflection.model — an error will be thrown if both are set. When
|
|
38
|
+
**model** (`string | LanguageModel | DynamicModel | ModelByInputTokens | ModelWithRetries[]`): Model for both the Observer and Reflector agents. Sets the model for both at once. Cannot be used together with observation.model or reflection.model — an error will be thrown if both are set. When this and observation.model/reflection.model are all omitted, OM falls back to google/gemini-2.5-flash. Use "default" to explicitly use the default model (google/gemini-2.5-flash). (Default: `'google/gemini-2.5-flash'`)
|
|
39
39
|
|
|
40
40
|
**scope** (`'resource' | 'thread'`): Memory scope for observations. 'thread' keeps observations per-thread. 'resource' (experimental) shares observations across all threads for a resource, enabling cross-conversation memory. (Default: `'thread'`)
|
|
41
41
|
|
|
@@ -47,7 +47,9 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
|
|
|
47
47
|
|
|
48
48
|
**temporalMarkers** (`boolean`): Insert temporal-gap reminder markers before new user messages when the previous message in the thread is at least 10 minutes older. The marker is persisted in memory, emitted as an inline reminder event so clients can render it specially, and shown to the observer so it can anchor observations to when events occurred. (Default: `false`)
|
|
49
49
|
|
|
50
|
-
**retrieval** (`boolean | { vector?: boolean; scope?: 'thread' | 'resource' }`):
|
|
50
|
+
**retrieval** (`boolean | { vector?: boolean; scope?: 'thread' | 'resource' }`): Let the agent look up the raw message history behind its observations. Observation groups keep durable pointers to the original messages, and a recall tool is registered so the agent can browse them. true enables cross-thread browsing by default. { vector: true } also enables semantic search using Memory's vector store and embedder. { scope: 'thread' } restricts the recall tool to the current thread only. Default scope is 'resource'. (Default: `false`)
|
|
51
|
+
|
|
52
|
+
**hooks** (`ObserveHooks`): Lifecycle hooks fired for every observation/reflection cycle — the manual observe()/reflect() APIs, turn-driven synchronous observation, and fire-and-forget async buffering. Callbacks receive threadId/resourceId/trigger call context ('manual' | 'turn-sync' | 'async-buffer'), and the end hooks (onObservationEnd/onReflectionEnd) additionally receive the OM model call's token usage and providerMetadata (where providers such as the AI Gateway report per-call cost), so apps can account for OM model spend without wrapping the observer/reflector models in middleware. Failed async-buffered cycles never throw; they report through the end hook's error field. Errors thrown by these hooks are caught and logged — they never fail the cycle.
|
|
51
53
|
|
|
52
54
|
**observation** (`ObservationalMemoryObservationConfig`): Configuration for the observation step. Controls when the Observer agent runs and how it behaves.
|
|
53
55
|
|
|
@@ -59,29 +61,33 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
|
|
|
59
61
|
|
|
60
62
|
**observation.extract** (`Extractor[]`): Custom values to extract after observation. Schema-less extractors are requested inline in the Observer output. Schema-backed extractors run as a follow-up structured output call and are stored in thread OM metadata.
|
|
61
63
|
|
|
62
|
-
**observation.
|
|
64
|
+
**observation.manageWorkingMemory** (`boolean`): Let the Observer manage working memory through OM extraction. Adds WorkingMemoryExtractor, defaults workingMemory.agentManaged to false, and defaults workingMemory.useStateSignals to true. See Working memory updates.
|
|
65
|
+
|
|
66
|
+
**observation.observeAttachments** (`'auto' | boolean | string[]`): Controls which image/file attachments are forwarded to the Observer model alongside their placeholder text lines. true (default) forwards all attachments. false drops all attachments while keeping placeholders visible. 'auto' uses the provider capabilities registry to decide: attachments are forwarded when the Observer model supports multimodal input, dropped otherwise, and forwarded when no capability data is available for the model. An array is a case-insensitive mimeType allowlist supporting exact matches ('application/pdf'), wildcard subtypes ('image/\*'), and bare '\*' for everything. Useful when the Observer model is text-only (e.g. some DeepSeek endpoints) while the main agent uses a multimodal model. Tool-result attachments are filtered using the same rule.
|
|
63
67
|
|
|
64
68
|
**observation.messageTokens** (`number`): Token count of unobserved messages that triggers observation. When unobserved message tokens exceed this threshold, the Observer agent is called. Text is estimated locally with tokenx. Image parts are included with model-aware heuristics when possible, with deterministic fallbacks when image metadata is incomplete. Image-like file parts are counted the same way when uploads are normalized as files.
|
|
65
69
|
|
|
66
70
|
**observation.maxTokensPerBatch** (`number`): Maximum tokens per batch when observing multiple threads in resource scope. Threads are chunked into batches of this size and processed in parallel. Lower values mean more parallelism but more API calls.
|
|
67
71
|
|
|
68
|
-
**observation.modelSettings** (`ObservationalMemoryModelSettings`): Model settings for the Observer agent.
|
|
72
|
+
**observation.modelSettings** (`ObservationalMemoryModelSettings`): Model settings for the Observer agent. The maxOutputTokens: 100\_000 default is only applied with default model selection (no model set, "default", or a ModelByInputTokens selector). Custom models get no maxOutputTokens default.
|
|
69
73
|
|
|
70
74
|
**observation.modelSettings.temperature** (`number`): Temperature for generation. Lower values produce more consistent output.
|
|
71
75
|
|
|
72
|
-
**observation.modelSettings.maxOutputTokens** (`number`): Maximum output tokens. Set high to prevent truncation of observations.
|
|
76
|
+
**observation.modelSettings.maxOutputTokens** (`number`): Maximum output tokens. Set high to prevent truncation of observations. The 100000 default is only applied with default model selection; custom models get no default.
|
|
73
77
|
|
|
74
|
-
**observation.
|
|
78
|
+
**observation.providerOptions** (`ProviderOptions`): Provider-specific options passed to the Observer agent, such as Google thinking configuration.
|
|
79
|
+
|
|
80
|
+
**observation.bufferTokens** (`number | false`): How often background observation buffering runs. Values between 0 and 1 are fractions of messageTokens: 0.25 buffers every 25% of the threshold (7.5k tokens with the default 30k). Values of 1 or more are absolute token counts: 5000 buffers every 5k tokens. Buffered observations are stored until the messageTokens threshold is reached, then activate instantly without a blocking LLM call. Must resolve to less than messageTokens. Set to false to disable all async buffering (both observation and reflection).
|
|
75
81
|
|
|
76
82
|
**observation.bufferOnIdle** (`boolean`): Run background observation buffering when an agent turn ends and the agent becomes idle. This is separate from bufferTokens, which controls step-time async buffering. Set this to true to buffer short idle turns without waiting for the next turn or the messageTokens threshold.
|
|
77
83
|
|
|
78
|
-
**observation.bufferActivation** (`number`):
|
|
84
|
+
**observation.bufferActivation** (`number`): How much of the message window to clear when buffered observations activate. Values between 0 and 1 are the fraction of messageTokens to remove: 0.8 removes \~80% of the message history and keeps \~20% (6k tokens with the default 30k). Values of 1000 or more are the token count to keep: 4000 keeps \~4k message tokens after activation. Note the direction flips: a higher ratio removes more history, while a higher token count keeps more.
|
|
79
85
|
|
|
80
|
-
**observation.activateAfterIdle** (`number | string | false | "auto"`): Time before buffered observations are forced to activate after inactivity. Accepts milliseconds, a duration string, "auto" for a provider-aware prompt cache TTL, or false. If unset, the top-level activateAfterIdle value is used for observations. Set false to disable the top-level idle setting for observations.
|
|
86
|
+
**observation.activateAfterIdle** (`number | string | false | "auto"`): Time before buffered observations are forced to activate after inactivity. Accepts milliseconds, a duration string, "auto" for a provider-aware prompt cache TTL, or false. If unset, the top-level activateAfterIdle value is used for observations. Set false to disable the top-level idle setting for observations. Currently only applied when using the standalone ObservationalMemory class; new Memory(...) applies the top-level activateAfterIdle only.
|
|
81
87
|
|
|
82
|
-
**observation.activateOnProviderChange** (`boolean`): Force buffered observations to activate when the actor provider or model changes. If unset, the top-level activateOnProviderChange value is used for observations.
|
|
88
|
+
**observation.activateOnProviderChange** (`boolean`): Force buffered observations to activate when the actor provider or model changes. If unset, the top-level activateOnProviderChange value is used for observations. Currently only applied when using the standalone ObservationalMemory class; new Memory(...) applies the top-level activateOnProviderChange only.
|
|
83
89
|
|
|
84
|
-
**observation.blockAfter** (`number`):
|
|
90
|
+
**observation.blockAfter** (`number`): Safety net that forces a synchronous (blocking) observation when background buffering can't keep up. Values from 1 up to (but not including) 100 are multipliers of messageTokens: 1.2 forces a blocking observation at 120% of the threshold (36k tokens with the default 30k). Values of 100 or more are absolute token counts and must be greater than messageTokens. Between messageTokens and blockAfter, only async buffering and activation run; buffered activation still preserves a minimum remaining context (the smaller of 1000 tokens or the retention floor). Only relevant when bufferTokens is set. Defaults to 1.2 when async buffering is enabled.
|
|
85
91
|
|
|
86
92
|
**observation.previousObserverTokens** (`number | false`): Optional token budget for the observer's previous-observations context. When set to a number, the observations passed to the Observer agent are tail-truncated to fit within this budget while keeping the newest observations and preserving highlighted 🔴 items when possible. When a buffered reflection is pending, the already-reflected observation lines are automatically replaced with the reflection summary before truncation. Set to 0 to omit previous observations entirely, or false to disable truncation explicitly.
|
|
87
93
|
|
|
@@ -95,19 +101,21 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
|
|
|
95
101
|
|
|
96
102
|
**reflection.observationTokens** (`number`): Token count of observations that triggers reflection. When observation tokens exceed this threshold, the Reflector agent is called to condense them.
|
|
97
103
|
|
|
98
|
-
**reflection.modelSettings** (`ObservationalMemoryModelSettings`): Model settings for the Reflector agent.
|
|
104
|
+
**reflection.modelSettings** (`ObservationalMemoryModelSettings`): Model settings for the Reflector agent. The maxOutputTokens: 100\_000 default is only applied with default model selection (no model set, "default", or a ModelByInputTokens selector). Custom models get no maxOutputTokens default.
|
|
99
105
|
|
|
100
106
|
**reflection.modelSettings.temperature** (`number`): Temperature for generation. Lower values produce more consistent output.
|
|
101
107
|
|
|
102
|
-
**reflection.modelSettings.maxOutputTokens** (`number`): Maximum output tokens. Set high to prevent truncation of observations.
|
|
108
|
+
**reflection.modelSettings.maxOutputTokens** (`number`): Maximum output tokens. Set high to prevent truncation of observations. The 100000 default is only applied with default model selection; custom models get no default.
|
|
109
|
+
|
|
110
|
+
**reflection.providerOptions** (`ProviderOptions`): Provider-specific options passed to the Reflector agent, such as Google thinking configuration.
|
|
103
111
|
|
|
104
|
-
**reflection.bufferActivation** (`number`):
|
|
112
|
+
**reflection.bufferActivation** (`number`): When background reflection starts, as a ratio (0-1) of observationTokens: 0.5 starts reflecting in the background once observations reach 50% of the threshold (20k tokens with the default 40k). When the full threshold is reached, the buffered reflection replaces the observations it covers, preserving any new observations appended after that range.
|
|
105
113
|
|
|
106
|
-
**reflection.activateAfterIdle** (`number | string | false | "auto"`): Time before buffered reflections are forced to activate after inactivity. Accepts milliseconds, a duration string, "auto" for a provider-aware prompt cache TTL, or false. Reflections do not inherit top-level activateAfterIdle; set this explicitly to opt reflections into idle activation.
|
|
114
|
+
**reflection.activateAfterIdle** (`number | string | false | "auto"`): Time before buffered reflections are forced to activate after inactivity. Accepts milliseconds, a duration string, "auto" for a provider-aware prompt cache TTL, or false. Reflections do not inherit top-level activateAfterIdle; set this explicitly to opt reflections into idle activation. Currently only applied when using the standalone ObservationalMemory class; this setting has no effect through new Memory(...).
|
|
107
115
|
|
|
108
|
-
**reflection.activateOnProviderChange** (`boolean`): Force buffered reflections to activate when the actor provider or model changes. Reflections do not inherit top-level activateOnProviderChange; set this explicitly to opt reflections into provider-change activation.
|
|
116
|
+
**reflection.activateOnProviderChange** (`boolean`): Force buffered reflections to activate when the actor provider or model changes. Reflections do not inherit top-level activateOnProviderChange; set this explicitly to opt reflections into provider-change activation. Currently only applied when using the standalone ObservationalMemory class; this setting has no effect through new Memory(...).
|
|
109
117
|
|
|
110
|
-
**reflection.blockAfter** (`number`):
|
|
118
|
+
**reflection.blockAfter** (`number`): Safety net that forces a synchronous (blocking) reflection when background reflection can't keep up. Values from 1 up to (but not including) 100 are multipliers of observationTokens: 1.2 forces a blocking reflection at 120% of the threshold (48k tokens with the default 40k). Values of 100 or more are absolute token counts and must be greater than observationTokens. Between observationTokens and blockAfter, only async buffering and activation run. Only relevant when bufferActivation is set. Defaults to 1.2 when async reflection is enabled.
|
|
111
119
|
|
|
112
120
|
### Token estimate metadata cache
|
|
113
121
|
|
|
@@ -150,7 +158,7 @@ const memory = new Memory({
|
|
|
150
158
|
|
|
151
159
|
**name** (`string`): Human-readable extractor name. OM slugifies this value into the extractor slug. Names must be unique after slug generation.
|
|
152
160
|
|
|
153
|
-
**slug** (`string`): Generated stable identifier for persisted values and XML tags. Slugs use lowercase letters, numbers, and hyphens. Built-in slugs and reserved XML tags cannot be used by custom extractors.
|
|
161
|
+
**slug** (`string`): Read-only property derived from name — not a constructor option. Generated stable identifier for persisted values and XML tags. Slugs use lowercase letters, numbers, and hyphens. Built-in slugs and reserved XML tags cannot be used by custom extractors.
|
|
154
162
|
|
|
155
163
|
**instructions** (`string | (context) => string`): Instructions for what to extract and when to update the value. Use a function to derive instructions from runtime context.
|
|
156
164
|
|
|
@@ -158,6 +166,8 @@ const memory = new Memory({
|
|
|
158
166
|
|
|
159
167
|
**includePreviousExtraction** (`boolean`): Controls whether the previous extraction is shown to the extractor on future OM runs. Set to false for values that should only come from the current OM run. (Default: `true`)
|
|
160
168
|
|
|
169
|
+
**metadataKeyPath** (`string | false`): Dot-separated OM metadata path used to persist the extracted value. Set to false to skip OM metadata persistence entirely. (Default: `'extracted.<slug>'`)
|
|
170
|
+
|
|
161
171
|
**onExtracted** (`(context) => T | void | Promise<T | void>`): Optional hook called after a custom extractor returns a value and before metadata is persisted. Returning a value replaces the extracted value. Throwing records an extraction failure.
|
|
162
172
|
|
|
163
173
|
### Extraction behavior
|
|
@@ -663,18 +673,45 @@ Emitted when buffered observations or reflections are activated (moved into the
|
|
|
663
673
|
|
|
664
674
|
**observations** (`string`): The activated observations text.
|
|
665
675
|
|
|
676
|
+
**triggeredBy** (`'threshold' | 'ttl' | 'provider_change'`): Whether activation was triggered by threshold crossing, activateAfterIdle expiry, or a model/provider change.
|
|
677
|
+
|
|
678
|
+
**lastActivityAt** (`number`): Unix-ms timestamp of the last assistant message part used for TTL checks.
|
|
679
|
+
|
|
680
|
+
**ttlExpiredMs** (`number`): How long activateAfterIdle had been exceeded when activation fired.
|
|
681
|
+
|
|
682
|
+
**previousModel** (`string`): Previous assistant model identifier that triggered activation (e.g. openai/gpt-4o).
|
|
683
|
+
|
|
684
|
+
**currentModel** (`string`): Current actor model identifier that triggered activation.
|
|
685
|
+
|
|
666
686
|
**recordId** (`string`): The OM record ID.
|
|
667
687
|
|
|
668
688
|
**threadId** (`string`): This thread's ID.
|
|
669
689
|
|
|
670
690
|
**config** (`ObservationMarkerConfig`): Snapshot of config at activation time.
|
|
671
691
|
|
|
692
|
+
### `data-om-thread-update`
|
|
693
|
+
|
|
694
|
+
Emitted when the Observer updates the thread title. Only emitted when `observation.threadTitle` is enabled.
|
|
695
|
+
|
|
696
|
+
**cycleId** (`string`): Unique ID for this observation cycle — shared with observation markers.
|
|
697
|
+
|
|
698
|
+
**threadId** (`string`): The thread ID that was updated.
|
|
699
|
+
|
|
700
|
+
**oldTitle** (`string`): The previous thread title. Undefined if the thread had no title.
|
|
701
|
+
|
|
702
|
+
**newTitle** (`string`): The new thread title.
|
|
703
|
+
|
|
704
|
+
**timestamp** (`string`): When this update occurred.
|
|
705
|
+
|
|
672
706
|
## Standalone usage
|
|
673
707
|
|
|
674
708
|
Most users should use the `Memory` class above. Using `ObservationalMemory` directly is mainly useful for benchmarking, experimentation, or when you need to control processor ordering with other processors (like [guardrails](https://mastra.ai/docs/agents/guardrails)).
|
|
675
709
|
|
|
710
|
+
The `ObservationalMemory` class is the engine; to attach it to an agent, wrap it in an `ObservationalMemoryProcessor`, which needs a `Memory` instance for loading and persisting messages. Note that `stores.memory` is typed as optional on storage adapters, so a non-null assertion (or a runtime check) is needed:
|
|
711
|
+
|
|
676
712
|
```typescript
|
|
677
|
-
import { ObservationalMemory } from '@mastra/memory/processors'
|
|
713
|
+
import { ObservationalMemory, ObservationalMemoryProcessor } from '@mastra/memory/processors'
|
|
714
|
+
import { Memory } from '@mastra/memory'
|
|
678
715
|
import { Agent } from '@mastra/core/agent'
|
|
679
716
|
import { LibSQLStore } from '@mastra/libsql'
|
|
680
717
|
|
|
@@ -683,8 +720,11 @@ const storage = new LibSQLStore({
|
|
|
683
720
|
url: 'file:./memory.db',
|
|
684
721
|
})
|
|
685
722
|
|
|
723
|
+
const memory = new Memory({ storage })
|
|
724
|
+
|
|
686
725
|
const om = new ObservationalMemory({
|
|
687
|
-
storage: storage.stores.memory
|
|
726
|
+
storage: storage.stores.memory!,
|
|
727
|
+
memory,
|
|
688
728
|
model: 'google/gemini-2.5-flash',
|
|
689
729
|
scope: 'resource',
|
|
690
730
|
observation: {
|
|
@@ -695,13 +735,15 @@ const om = new ObservationalMemory({
|
|
|
695
735
|
},
|
|
696
736
|
})
|
|
697
737
|
|
|
738
|
+
const omProcessor = new ObservationalMemoryProcessor(om, memory)
|
|
739
|
+
|
|
698
740
|
export const agent = new Agent({
|
|
699
741
|
id: 'my-agent',
|
|
700
742
|
name: 'my-agent',
|
|
701
743
|
instructions: 'You are a helpful assistant.',
|
|
702
744
|
model: 'openai/gpt-5-mini',
|
|
703
|
-
inputProcessors: [
|
|
704
|
-
outputProcessors: [
|
|
745
|
+
inputProcessors: [omProcessor],
|
|
746
|
+
outputProcessors: [omProcessor],
|
|
705
747
|
})
|
|
706
748
|
```
|
|
707
749
|
|
|
@@ -725,9 +767,11 @@ When `retrieval` is set (any truthy value), a `recall` tool is registered so the
|
|
|
725
767
|
|
|
726
768
|
**query** (`string`): Search query for mode: "search". Finds messages semantically similar to this text across all threads for the current user.
|
|
727
769
|
|
|
728
|
-
**cursor** (`string`): A message ID to anchor the recall query.
|
|
770
|
+
**cursor** (`string`): A message ID to anchor the recall query. Extract the start or end ID from an observation group range (e.g. from \_range: \startId:endId\\\_, use either startId or endId). If a range string is passed directly, the tool returns a hint explaining how to extract the correct ID. When both cursor and threadId are omitted for mode: "messages", the tool browses the current thread from the position set by anchor.
|
|
771
|
+
|
|
772
|
+
**threadId** (`string`): Browse a different thread by its ID, or pass "current" for the active thread. Use mode: "threads" first to discover thread IDs. When provided without a cursor, reading starts from the beginning of the thread.
|
|
729
773
|
|
|
730
|
-
**
|
|
774
|
+
**anchor** (`'start' | 'end'`): For mode: "messages" without a cursor, page from the start (oldest-first) or end (newest-first) of the thread. (Default: `'start'`)
|
|
731
775
|
|
|
732
776
|
**page** (`number`): Pagination offset. For messages: positive values page forward from cursor, negative values page backward. For threads: page number (0-indexed). 0 is treated as 1 for messages. (Default: `1`)
|
|
733
777
|
|
|
@@ -735,6 +779,10 @@ When `retrieval` is set (any truthy value), a `recall` tool is registered so the
|
|
|
735
779
|
|
|
736
780
|
**detail** (`'low' | 'high'`): Controls how much content is shown per message part. 'low' shows truncated text and tool names with positional indices (\[p0], \[p1]). 'high' shows full content including tool arguments and results, clamped to one part per call with continuation hints. (Default: `'low'`)
|
|
737
781
|
|
|
782
|
+
**partType** (`'text' | 'tool-call' | 'tool-result' | 'reasoning' | 'image' | 'file'`): Filter results to only include message parts of this type. Only applies to mode: "messages".
|
|
783
|
+
|
|
784
|
+
**toolName** (`string`): Filter results to only include tool-call and tool-result parts matching this tool name. Only applies to mode: "messages".
|
|
785
|
+
|
|
738
786
|
**partIndex** (`number`): Fetch a single message part at full detail by its positional index. Use this when a low-detail recall shows an interesting part at \[p1] — call again with partIndex: 1 to see the full content without loading every part.
|
|
739
787
|
|
|
740
788
|
**before** (`string`): For mode: "threads" only. Filter to threads created before this date. Accepts ISO 8601 format (e.g. "2026-03-15", "2026-03-10T00:00:00Z").
|
|
@@ -753,6 +801,8 @@ When `retrieval` is set (any truthy value), a `recall` tool is registered so the
|
|
|
753
801
|
|
|
754
802
|
**limit** (`number`): The limit used for this query.
|
|
755
803
|
|
|
804
|
+
**detail** (`'low' | 'high'`): The detail level used for this query.
|
|
805
|
+
|
|
756
806
|
**hasNextPage** (`boolean`): Whether more messages exist after this page.
|
|
757
807
|
|
|
758
808
|
**hasPrevPage** (`boolean`): Whether more messages exist before this page.
|
|
@@ -473,6 +473,7 @@ interface ToolCallAttributes {
|
|
|
473
473
|
toolId?: string
|
|
474
474
|
toolType?: string
|
|
475
475
|
toolDescription?: string
|
|
476
|
+
toolCallId?: string
|
|
476
477
|
success?: boolean
|
|
477
478
|
}
|
|
478
479
|
```
|
|
@@ -495,6 +496,8 @@ interface MCPToolCallAttributes {
|
|
|
495
496
|
/** Tool description */
|
|
496
497
|
toolDescription?: string
|
|
497
498
|
|
|
499
|
+
toolCallId?: string
|
|
500
|
+
|
|
498
501
|
/** Whether tool execution was successful */
|
|
499
502
|
success?: boolean
|
|
500
503
|
}
|
|
@@ -125,7 +125,7 @@ A replacement string can reference capture groups with `$1` or `$&`. Those refer
|
|
|
125
125
|
|
|
126
126
|
## Redaction reporting
|
|
127
127
|
|
|
128
|
-
The `redact` strategy rewrites text in place, so nothing downstream can tell what changed. Assign `onViolation` to record it. The processor calls it once per redacted message, message part, or stream chunk, and offsets are relative to that piece of text. Async callbacks are awaited, and errors are caught so an unavailable audit sink
|
|
128
|
+
The `redact` strategy rewrites text in place, so nothing downstream can tell what changed. Assign `onViolation` to record it. The processor calls it once per redacted message, message part, or stream chunk, and offsets are relative to that piece of text. Async callbacks are awaited, and errors are caught so an unavailable audit sink can't fail the request.
|
|
129
129
|
|
|
130
130
|
```typescript
|
|
131
131
|
import { RegexFilterProcessor, type RegexRedactionDetail } from '@mastra/core/processors'
|
|
@@ -34,7 +34,7 @@ yarn add @mastra/isolated-vm
|
|
|
34
34
|
bun add @mastra/isolated-vm
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
`isolated-vm` is a native addon. It
|
|
37
|
+
`isolated-vm` is a native addon. It provides prebuilt binaries for common platforms, so installation usually needs no extra setup. A C++ toolchain is only needed on platforms without a matching prebuild, where it falls back to compiling from source.
|
|
38
38
|
|
|
39
39
|
On Node.js 20 and later, the host process must be started with the `--no-node-snapshot` flag, otherwise creating an isolate crashes the process. The constructor throws an error when the flag is missing. Pass the flag when starting your server, or set it through `NODE_OPTIONS`:
|
|
40
40
|
|
|
@@ -109,7 +109,7 @@ Waits for an index to become ready after creation. Useful when you need to ensur
|
|
|
109
109
|
|
|
110
110
|
### `upsert()`
|
|
111
111
|
|
|
112
|
-
Adds or updates vectors and their metadata in the collection. On a bring-your-own index this requires `allowWrites: true` at `createIndex()` time
|
|
112
|
+
Adds or updates vectors and their metadata in the collection. On a bring-your-own index, this requires `allowWrites: true` at `createIndex()` time because BYO collections are read-only by default.
|
|
113
113
|
|
|
114
114
|
**indexName** (`string`): Name of the collection to insert into
|
|
115
115
|
|
|
@@ -148,12 +148,12 @@ Provisions an Atlas Search (BM25/full-text) index on the collection backing an i
|
|
|
148
148
|
**Managed vs. bring-your-own collections:**
|
|
149
149
|
|
|
150
150
|
- For a **managed** index (created without `collectionName`), `createIndex()` already provisions a _dynamic_ full-text index named `${collectionName}_search_index` (covering all string fields). `createSearchIndex()` is therefore only needed when you want a **field-restricted** mapping or a **custom index name**.
|
|
151
|
-
- For a **bring-your-own** index (created with `collectionName`), `createIndex()`
|
|
151
|
+
- For a **bring-your-own** index (created with `collectionName`), `createIndex()` doesn't auto-create any full-text index. Enabling `textQuery()`/`hybridQuery()` on a caller-owned operational collection is opt-in. Call `createSearchIndex()` explicitly to provision the (billable) text index. Until you do, `textQuery()`/`hybridQuery()` throw a clear error rather than querying a non-existent index.
|
|
152
152
|
|
|
153
153
|
Naming:
|
|
154
154
|
|
|
155
|
-
- When `fields` is provided **without** an explicit `searchIndexName`, the field-mapped index is created under a **distinct** default name (`${collectionName}_${indexName}_search_fields_index`, unique per logical index) so it
|
|
156
|
-
- When `searchIndexName` is provided, that exact name is used and persisted. `textQuery()`/`hybridQuery()` resolve the persisted name automatically
|
|
155
|
+
- When `fields` is provided **without** an explicit `searchIndexName`, the field-mapped index is created under a **distinct** default name (`${collectionName}_${indexName}_search_fields_index`, unique per logical index) so it doesn't collide with a managed collection's auto-created dynamic index and get silently ignored. This distinct index is persisted as the text-search index, so `textQuery()`/`hybridQuery()` use the restricted mapping automatically.
|
|
156
|
+
- When `searchIndexName` is provided, that exact name is used and persisted. `textQuery()`/`hybridQuery()` resolve the persisted name automatically. You can also override the name per call via their `searchIndexName` / `textSearchIndexName` parameters.
|
|
157
157
|
|
|
158
158
|
**indexName** (`string`): Name of the Mastra index whose collection will have the search index
|
|
159
159
|
|
|
@@ -170,7 +170,7 @@ await store.createSearchIndex({
|
|
|
170
170
|
})
|
|
171
171
|
```
|
|
172
172
|
|
|
173
|
-
|
|
173
|
+
The field-mapped index name includes the logical `indexName`, so two logical indexes on the same collection get distinct text indexes. Recreating the _same_ logical index with different `fields` still requires dropping the existing index first (`IndexAlreadyExists`).
|
|
174
174
|
|
|
175
175
|
### `waitForSearchIndexReady()`
|
|
176
176
|
|
|
@@ -193,7 +193,7 @@ await store.waitForSearchIndexReady({ indexName: 'precedents' })
|
|
|
193
193
|
|
|
194
194
|
Runs a full-text (BM25) search against an Atlas Search index. By default it targets the text-search index recorded for this index (set by `createSearchIndex()`, or the dynamic `${collectionName}_search_index` auto-created by `createIndex()`). Pass `searchIndexName` to target a specific index for this call.
|
|
195
195
|
|
|
196
|
-
|
|
196
|
+
Metadata filters here (like `hybridQuery()`) are applied via a `$match` stage. For the vector branch of `hybridQuery()`, filters on fields not declared via `filterFields` at index creation are transparently materialised as candidate `_id`s (the same fallback `query()` uses), so undeclared-field filters don't error.
|
|
197
197
|
|
|
198
198
|
**indexName** (`string`): Name of the Mastra index to search
|
|
199
199
|
|
|
@@ -220,7 +220,7 @@ const results = await store.textQuery({
|
|
|
220
220
|
|
|
221
221
|
### `hybridQuery()`
|
|
222
222
|
|
|
223
|
-
Runs a hybrid search that fuses vector similarity and full-text results using MongoDB's server-side `$rankFusion
|
|
223
|
+
Runs a hybrid search that fuses vector similarity and full-text results using MongoDB's server-side `$rankFusion`. It requires MongoDB >= 8.0 and is generally available from 8.1. On 8.0.x, it may need a MongoDB support case to enable, and it runs where enabled, such as Atlas 8.0.x. A full-text search index must exist: it's auto-created for managed indexes, but for a bring-your-own collection you must call `createSearchIndex()` first (opt-in).
|
|
224
224
|
|
|
225
225
|
**indexName** (`string`): Name of the Mastra index to search
|
|
226
226
|
|
|
@@ -253,7 +253,7 @@ const results = await store.hybridQuery({
|
|
|
253
253
|
})
|
|
254
254
|
```
|
|
255
255
|
|
|
256
|
-
|
|
256
|
+
`hybridQuery()` requires MongoDB >= 8.0 for the `$rankFusion` stage. The stage is generally available from 8.1. On 8.0.x, it may need a MongoDB support case to enable and runs where enabled, such as Atlas 8.0.x. If you're running an older version, or `$rankFusion` isn't enabled on your 8.0.x deployment, use `query()` and `textQuery()` separately and merge the results client-side.
|
|
257
257
|
|
|
258
258
|
### `describeIndex()`
|
|
259
259
|
|
|
@@ -276,15 +276,15 @@ interface IndexStats {
|
|
|
276
276
|
Deletes a vector index. Behavior depends on how the index was created:
|
|
277
277
|
|
|
278
278
|
- **Managed index** (created without `collectionName`): drops the entire collection and all its data.
|
|
279
|
-
- **Bring-your-own index** (created with `collectionName`): drops the Atlas vectorSearch index
|
|
279
|
+
- **Bring-your-own index** (created with `collectionName`): drops the Atlas vectorSearch index and, if one was provisioned via `createSearchIndex()`, the companion full-text search index. The caller's operational collection and its documents are preserved. This store never drops a collection it didn't create.
|
|
280
280
|
|
|
281
|
-
The BYO classification is recorded durably when the index is created, so it
|
|
281
|
+
The BYO classification is recorded durably when the index is created, so it's applied correctly even by a different process (e.g. an index created by a setup job and later deleted by a long-lived service). Always pass the **logical index name** (the `indexName` used at `createIndex`), not the physical collection name.
|
|
282
282
|
|
|
283
283
|
**indexName** (`string`): Logical name of the index to delete
|
|
284
284
|
|
|
285
285
|
### `listIndexes()`
|
|
286
286
|
|
|
287
|
-
Lists the **logical** Mastra index names (the `indexName` values passed to `createIndex`), not physical collection names. For a bring-your-own index whose data lives in an operational collection, the logical index name is returned
|
|
287
|
+
Lists the **logical** Mastra index names (the `indexName` values passed to `createIndex`), not physical collection names. For a bring-your-own index whose data lives in an operational collection, the logical index name is returned instead of the physical collection name. The value can be passed straight back into `deleteIndex()` / `describeIndex()`. Managed indexes created before durable metadata was introduced are still discovered via their `${name}_vector_index` search index. The internal registry collection is never listed.
|
|
288
288
|
|
|
289
289
|
Returns: `Promise<string[]>`
|
|
290
290
|
|
|
@@ -408,12 +408,12 @@ await store.createSearchIndex({ indexName: 'precedents', fields: ['note'] })
|
|
|
408
408
|
|
|
409
409
|
- The collection must already exist and contain documents with an `embedding` field (or the custom `embeddingFieldPath` you configured)
|
|
410
410
|
- The collection is never created or dropped when using `collectionName`
|
|
411
|
-
- **A BYO index is read-only by default.** `upsert()`, `updateVector()`, `deleteVector()`, and `deleteVectors()` throw a clear error rather than mutating caller-owned operational documents. To let the store write embeddings into (or delete documents from) your collection, opt in explicitly with `createIndex({ ..., allowWrites: true })`. The policy is persisted and survives restarts
|
|
411
|
+
- **A BYO index is read-only by default.** `upsert()`, `updateVector()`, `deleteVector()`, and `deleteVectors()` throw a clear error rather than mutating caller-owned operational documents. To let the store write embeddings into (or delete documents from) your collection, opt in explicitly with `createIndex({ ..., allowWrites: true })`. The policy is persisted and survives restarts. Entries written by older versions without the flag are treated as read-only (fail closed).
|
|
412
412
|
- Use `metadataMode: 'document'` when querying to retrieve the full source document as `metadata`
|
|
413
413
|
- In `'document'` mode the embedding is omitted from `metadata` by default; pass `includeVector: true` to retain it (and also expose it as a top-level `vector`)
|
|
414
414
|
- **Filtering in `'document'` mode operates on root document fields**, not a nested `metadata.` subdocument. `filter: { lane: 'fraud' }` matches the top-level `lane` field of your operational documents (in the default `'field'` mode, bare fields are rewritten to `metadata.<field>` for managed collections). Both the pushdown and `$match` fallback paths honor this.
|
|
415
415
|
- **Native `ObjectId` `_id`s are supported.** Operational collections commonly key on `ObjectId`; query results coerce `_id` to a string (the `QueryResult.id` contract), and `deleteVector()`/`updateVector()`/`deleteVectors()` accept that string and match the underlying `ObjectId` document. Managed collections (string `_id`s) are unaffected.
|
|
416
|
-
- Full-text and hybrid search on a BYO collection are **opt-in**: no full-text index is auto-created, so call `createSearchIndex()` before `textQuery()`/`hybridQuery()`. The full-text index builds asynchronously
|
|
416
|
+
- Full-text and hybrid search on a BYO collection are **opt-in**: no full-text index is auto-created, so call `createSearchIndex()` before `textQuery()`/`hybridQuery()`. The full-text index builds asynchronously. Call `waitForSearchIndexReady()` (or pass `waitUntilReady: true`) before an immediate text/hybrid query.
|
|
417
417
|
- `deleteIndex()` on a BYO index drops the vector index (and the text index if one was created) but **preserves** the collection and its documents
|
|
418
418
|
|
|
419
419
|
## Best practices
|