@mastra/mcp-docs-server 1.0.0-beta.5 → 1.0.0-beta.6
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%2Fagent-builder.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +67 -67
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +53 -53
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +29 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +274 -274
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +65 -65
- package/.docs/organized/changelogs/%40mastra%2Fduckdb.md +42 -0
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Felasticsearch.md +52 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Flance.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +84 -84
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +36 -36
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +47 -47
- package/.docs/organized/changelogs/%40mastra%2Frag.md +43 -43
- package/.docs/organized/changelogs/%40mastra%2Freact.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +56 -56
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +19 -19
- package/.docs/organized/changelogs/create-mastra.md +9 -9
- package/.docs/organized/changelogs/mastra.md +17 -17
- package/.docs/organized/code-examples/agui.md +1 -0
- package/.docs/organized/code-examples/ai-sdk-v5.md +1 -0
- package/.docs/organized/code-examples/mcp-server-adapters.md +721 -0
- package/.docs/organized/code-examples/server-app-access.md +342 -0
- package/.docs/raw/agents/agent-approval.mdx +189 -0
- package/.docs/raw/agents/guardrails.mdx +13 -9
- package/.docs/raw/agents/networks.mdx +1 -0
- package/.docs/raw/agents/overview.mdx +23 -58
- package/.docs/raw/agents/processors.mdx +279 -0
- package/.docs/raw/deployment/cloud-providers/index.mdx +19 -26
- package/.docs/raw/deployment/cloud-providers/netlify-deployer.mdx +44 -13
- package/.docs/raw/evals/running-in-ci.mdx +0 -2
- package/.docs/raw/{guides/getting-started → getting-started}/manual-install.mdx +2 -2
- package/.docs/raw/getting-started/start.mdx +1 -1
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +8 -0
- package/.docs/raw/guides/getting-started/quickstart.mdx +1 -1
- package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +421 -0
- package/.docs/raw/guides/index.mdx +3 -35
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +11 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +29 -0
- package/.docs/raw/index.mdx +1 -1
- package/.docs/raw/memory/memory-processors.mdx +265 -79
- package/.docs/raw/memory/working-memory.mdx +10 -2
- package/.docs/raw/observability/overview.mdx +0 -1
- package/.docs/raw/observability/tracing/bridges/otel.mdx +176 -0
- package/.docs/raw/observability/tracing/exporters/arize.mdx +17 -0
- package/.docs/raw/observability/tracing/exporters/braintrust.mdx +19 -0
- package/.docs/raw/observability/tracing/exporters/langfuse.mdx +20 -0
- package/.docs/raw/observability/tracing/exporters/langsmith.mdx +12 -0
- package/.docs/raw/observability/tracing/exporters/otel.mdx +5 -4
- package/.docs/raw/observability/tracing/overview.mdx +71 -6
- package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +0 -1
- package/.docs/raw/rag/retrieval.mdx +23 -6
- package/.docs/raw/rag/vector-databases.mdx +93 -2
- package/.docs/raw/reference/agents/generate.mdx +55 -6
- package/.docs/raw/reference/agents/network.mdx +44 -0
- package/.docs/raw/reference/client-js/memory.mdx +43 -0
- package/.docs/raw/reference/client-js/workflows.mdx +92 -63
- package/.docs/raw/reference/deployer/netlify.mdx +1 -2
- package/.docs/raw/reference/evals/scorer-utils.mdx +362 -0
- package/.docs/raw/reference/index.mdx +1 -0
- package/.docs/raw/reference/observability/tracing/bridges/otel.mdx +150 -0
- package/.docs/raw/reference/observability/tracing/configuration.mdx +0 -4
- package/.docs/raw/reference/observability/tracing/exporters/arize.mdx +4 -0
- package/.docs/raw/reference/observability/tracing/exporters/langsmith.mdx +17 -1
- package/.docs/raw/reference/observability/tracing/exporters/otel.mdx +6 -0
- package/.docs/raw/reference/observability/tracing/instances.mdx +0 -4
- package/.docs/raw/reference/observability/tracing/interfaces.mdx +29 -4
- package/.docs/raw/reference/observability/tracing/spans.mdx +0 -4
- package/.docs/raw/reference/processors/language-detector.mdx +9 -2
- package/.docs/raw/reference/processors/message-history-processor.mdx +131 -0
- package/.docs/raw/reference/processors/moderation-processor.mdx +10 -3
- package/.docs/raw/reference/processors/pii-detector.mdx +10 -3
- package/.docs/raw/reference/processors/processor-interface.mdx +502 -0
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +9 -2
- package/.docs/raw/reference/processors/semantic-recall-processor.mdx +197 -0
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -2
- package/.docs/raw/reference/processors/tool-call-filter.mdx +125 -0
- package/.docs/raw/reference/processors/working-memory-processor.mdx +221 -0
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +37 -0
- package/.docs/raw/reference/storage/convex.mdx +164 -0
- package/.docs/raw/reference/storage/lance.mdx +33 -0
- package/.docs/raw/reference/storage/libsql.mdx +37 -0
- package/.docs/raw/reference/storage/mongodb.mdx +39 -0
- package/.docs/raw/reference/storage/mssql.mdx +37 -0
- package/.docs/raw/reference/storage/postgresql.mdx +37 -0
- package/.docs/raw/reference/streaming/ChunkType.mdx +1 -1
- package/.docs/raw/reference/streaming/agents/stream.mdx +56 -1
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +7 -9
- package/.docs/raw/reference/streaming/workflows/{resumeStreamVNext.mdx → resumeStream.mdx} +51 -11
- package/.docs/raw/reference/streaming/workflows/stream.mdx +83 -24
- package/.docs/raw/reference/tools/mcp-client.mdx +74 -17
- package/.docs/raw/reference/vectors/convex.mdx +429 -0
- package/.docs/raw/reference/vectors/duckdb.mdx +462 -0
- package/.docs/raw/reference/vectors/elasticsearch.mdx +310 -0
- package/.docs/raw/reference/voice/google.mdx +159 -20
- package/.docs/raw/reference/workflows/run-methods/restart.mdx +142 -0
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +44 -0
- package/.docs/raw/reference/workflows/run-methods/start.mdx +44 -0
- package/.docs/raw/reference/workflows/run.mdx +13 -5
- package/.docs/raw/reference/workflows/step.mdx +13 -0
- package/.docs/raw/reference/workflows/workflow.mdx +19 -0
- package/.docs/raw/server-db/mastra-server.mdx +30 -1
- package/.docs/raw/server-db/request-context.mdx +0 -1
- package/.docs/raw/server-db/storage.mdx +11 -0
- package/.docs/raw/streaming/overview.mdx +6 -6
- package/.docs/raw/streaming/tool-streaming.mdx +2 -2
- package/.docs/raw/streaming/workflow-streaming.mdx +5 -11
- package/.docs/raw/workflows/error-handling.mdx +1 -0
- package/.docs/raw/workflows/human-in-the-loop.mdx +4 -4
- package/.docs/raw/workflows/overview.mdx +56 -44
- package/.docs/raw/workflows/snapshots.mdx +1 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +85 -16
- package/.docs/raw/workflows/time-travel.mdx +313 -0
- package/.docs/raw/workflows/workflow-state.mdx +191 -0
- package/CHANGELOG.md +8 -0
- package/package.json +4 -4
- package/.docs/raw/agents/human-in-the-loop-with-tools.mdx +0 -91
- package/.docs/raw/reference/streaming/workflows/observeStreamVNext.mdx +0 -47
- package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +0 -153
|
@@ -107,6 +107,26 @@ new LangfuseExporter({
|
|
|
107
107
|
});
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
+
## Using Tags
|
|
111
|
+
|
|
112
|
+
Tags help you categorize and filter traces in the Langfuse dashboard. Add tags when executing agents or workflows:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
const result = await agent.generate({
|
|
116
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
117
|
+
tracingOptions: {
|
|
118
|
+
tags: ["production", "experiment-v2", "user-request"],
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Tags appear in Langfuse's trace view and can be used to filter and search traces. Common use cases include:
|
|
124
|
+
|
|
125
|
+
- Environment labels: `"production"`, `"staging"`
|
|
126
|
+
- Experiment tracking: `"experiment-v1"`, `"control-group"`
|
|
127
|
+
- Priority levels: `"priority-high"`, `"batch-job"`
|
|
128
|
+
- User segments: `"beta-user"`, `"enterprise"`
|
|
129
|
+
|
|
110
130
|
## Related
|
|
111
131
|
|
|
112
132
|
- [Tracing Overview](/docs/v1/observability/tracing/overview)
|
|
@@ -23,6 +23,7 @@ npm install @mastra/langsmith@beta
|
|
|
23
23
|
|
|
24
24
|
```bash title=".env"
|
|
25
25
|
LANGSMITH_API_KEY=ls-xxxxxxxxxxxx
|
|
26
|
+
LANGCHAIN_PROJECT=my-project # Optional: default project for traces
|
|
26
27
|
LANGSMITH_BASE_URL=https://api.smith.langchain.com # Optional for self-hosted
|
|
27
28
|
```
|
|
28
29
|
|
|
@@ -60,6 +61,7 @@ new LangSmithExporter({
|
|
|
60
61
|
|
|
61
62
|
// Optional settings
|
|
62
63
|
apiUrl: process.env.LANGSMITH_BASE_URL, // Default: https://api.smith.langchain.com
|
|
64
|
+
projectName: "my-project", // Project to send traces to (overrides LANGCHAIN_PROJECT env var)
|
|
63
65
|
callerOptions: {
|
|
64
66
|
// HTTP client options
|
|
65
67
|
timeout: 30000, // Request timeout in ms
|
|
@@ -73,6 +75,16 @@ new LangSmithExporter({
|
|
|
73
75
|
});
|
|
74
76
|
```
|
|
75
77
|
|
|
78
|
+
### Environment Variables
|
|
79
|
+
|
|
80
|
+
| Variable | Description |
|
|
81
|
+
|----------|-------------|
|
|
82
|
+
| `LANGSMITH_API_KEY` | Your LangSmith API key (required) |
|
|
83
|
+
| `LANGCHAIN_PROJECT` | Default project name for traces (optional, defaults to "default") |
|
|
84
|
+
| `LANGSMITH_BASE_URL` | API URL for self-hosted instances (optional) |
|
|
85
|
+
|
|
86
|
+
The `projectName` config option takes precedence over the `LANGCHAIN_PROJECT` environment variable, allowing you to programmatically route traces to different projects.
|
|
87
|
+
|
|
76
88
|
## Related
|
|
77
89
|
|
|
78
90
|
- [Tracing Overview](/docs/v1/observability/tracing/overview)
|
|
@@ -5,13 +5,13 @@ description: "Send traces to any OpenTelemetry-compatible observability platform
|
|
|
5
5
|
|
|
6
6
|
# OpenTelemetry Exporter
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
The OpenTelemetry (OTEL) exporter sends your traces to any OTEL-compatible observability platform using standardized [OpenTelemetry Semantic Conventions for GenAI](https://opentelemetry.io/docs/specs/semconv/gen-ai/). This ensures broad compatibility with platforms like Datadog, New Relic, SigNoz, MLflow, Dash0, Traceloop, Laminar, and more.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
:::info Looking for bidirectional OTEL integration?
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
If you have existing OpenTelemetry instrumentation and want Mastra traces to inherit context from active OTEL spans, see the [OpenTelemetry Bridge](/docs/v1/observability/tracing/bridges/otel) instead.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
:::
|
|
15
15
|
|
|
16
16
|
## Installation
|
|
17
17
|
|
|
@@ -269,5 +269,6 @@ Install the suggested package for your provider.
|
|
|
269
269
|
## Related
|
|
270
270
|
|
|
271
271
|
- [Tracing Overview](/docs/v1/observability/tracing/overview)
|
|
272
|
+
- [OpenTelemetry Bridge](/docs/v1/observability/tracing/bridges/otel) - For bidirectional OTEL context integration
|
|
272
273
|
- [OpenTelemetry GenAI Conventions](https://opentelemetry.io/docs/specs/semconv/gen-ai/)
|
|
273
274
|
- [OTEL Exporter Reference](/reference/v1/observability/tracing/exporters/otel)
|
|
@@ -99,6 +99,23 @@ In addition to the internal exporters, Mastra supports integration with popular
|
|
|
99
99
|
- **[OpenTelemetry](/docs/v1/observability/tracing/exporters/otel)** - Deliver traces to any OpenTelemetry-compatible observability system
|
|
100
100
|
- Supports: Dash0, MLflow, Laminar, New Relic, SigNoz, Traceloop, Zipkin, and others!
|
|
101
101
|
|
|
102
|
+
## Bridges
|
|
103
|
+
|
|
104
|
+
Bridges provide bidirectional integration with external tracing systems. Unlike exporters that send trace data to external platforms, bridges create native spans in external systems and inherit context from them. This enables Mastra operations to participate in existing distributed traces.
|
|
105
|
+
|
|
106
|
+
- **[OpenTelemetry Bridge](/docs/v1/observability/tracing/bridges/otel)** - Integrate with existing OpenTelemetry infrastructure
|
|
107
|
+
|
|
108
|
+
### Bridges vs Exporters
|
|
109
|
+
|
|
110
|
+
| Feature | Bridges | Exporters |
|
|
111
|
+
| --- | --- | --- |
|
|
112
|
+
| Creates native spans in external systems | Yes | No |
|
|
113
|
+
| Inherits context from external systems | Yes | No |
|
|
114
|
+
| Sends data to backends | Via external SDK | Directly |
|
|
115
|
+
| Use case | Existing distributed tracing | Standalone Mastra tracing |
|
|
116
|
+
|
|
117
|
+
You can use both together — a bridge for context propagation and exporters to send traces to additional destinations.
|
|
118
|
+
|
|
102
119
|
## Sampling Strategies
|
|
103
120
|
|
|
104
121
|
Sampling allows you to control which traces are collected, helping you balance between observability needs and resource costs. In production environments with high traffic, collecting every trace can be expensive and unnecessary. Sampling strategies let you capture a representative subset of traces while ensuring you don't miss critical information about errors or important operations.
|
|
@@ -200,7 +217,6 @@ Use `configSelector` to choose the appropriate tracing configuration based on re
|
|
|
200
217
|
```ts title="src/mastra/index.ts" showLineNumbers copy
|
|
201
218
|
export const mastra = new Mastra({
|
|
202
219
|
observability: new Observability({
|
|
203
|
-
default: { enabled: true }, // Provides 'default' instance
|
|
204
220
|
configs: {
|
|
205
221
|
langfuse: {
|
|
206
222
|
serviceName: "langfuse-service",
|
|
@@ -233,7 +249,7 @@ export const mastra = new Mastra({
|
|
|
233
249
|
return "langfuse";
|
|
234
250
|
}
|
|
235
251
|
|
|
236
|
-
|
|
252
|
+
throw new Error('no config found')
|
|
237
253
|
},
|
|
238
254
|
}),
|
|
239
255
|
});
|
|
@@ -448,6 +464,55 @@ requestContext.set("session", { data: { experimentId: "exp-999" } });
|
|
|
448
464
|
3. **Child Span Extraction**: Child spans can also extract metadata if you pass `requestContext` when creating them
|
|
449
465
|
4. **Metadata Precedence**: Explicit metadata passed to span options always takes precedence over extracted metadata
|
|
450
466
|
|
|
467
|
+
### Adding Tags to Traces
|
|
468
|
+
|
|
469
|
+
Tags are string labels that help you categorize and filter traces. Unlike metadata (which contains structured key-value data), tags are simple strings designed for quick filtering and organization.
|
|
470
|
+
|
|
471
|
+
Use `tracingOptions.tags` to add tags when executing agents or workflows:
|
|
472
|
+
|
|
473
|
+
```ts showLineNumbers copy
|
|
474
|
+
// With agents
|
|
475
|
+
const result = await agent.generate({
|
|
476
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
477
|
+
tracingOptions: {
|
|
478
|
+
tags: ["production", "experiment-v2", "user-request"],
|
|
479
|
+
},
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
// With workflows
|
|
483
|
+
const run = await mastra.getWorkflow("myWorkflow").createRun();
|
|
484
|
+
const result = await run.start({
|
|
485
|
+
inputData: { data: "process this" },
|
|
486
|
+
tracingOptions: {
|
|
487
|
+
tags: ["batch-processing", "priority-high"],
|
|
488
|
+
},
|
|
489
|
+
});
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
#### How Tags Work
|
|
493
|
+
|
|
494
|
+
- **Root span only**: Tags are applied only to the root span of a trace (the agent run or workflow run span)
|
|
495
|
+
- **Platform-specific**: Tags appear in Braintrust and Langfuse dashboards for filtering and searching
|
|
496
|
+
- **Combinable with metadata**: You can use both `tags` and `metadata` in the same `tracingOptions`
|
|
497
|
+
|
|
498
|
+
```ts showLineNumbers copy
|
|
499
|
+
const result = await agent.generate({
|
|
500
|
+
messages: [{ role: "user", content: "Analyze this" }],
|
|
501
|
+
tracingOptions: {
|
|
502
|
+
tags: ["production", "analytics"],
|
|
503
|
+
metadata: { userId: "user-123", experimentId: "exp-456" },
|
|
504
|
+
},
|
|
505
|
+
});
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
#### Common Tag Patterns
|
|
509
|
+
|
|
510
|
+
- **Environment**: `"production"`, `"staging"`, `"development"`
|
|
511
|
+
- **Feature flags**: `"feature-x-enabled"`, `"beta-user"`
|
|
512
|
+
- **Request types**: `"user-request"`, `"batch-job"`, `"scheduled-task"`
|
|
513
|
+
- **Priority levels**: `"priority-high"`, `"priority-low"`
|
|
514
|
+
- **Experiments**: `"experiment-v1"`, `"control-group"`, `"treatment-a"`
|
|
515
|
+
|
|
451
516
|
#### Child Spans and Metadata Extraction
|
|
452
517
|
|
|
453
518
|
When creating child spans within tools or workflow steps, you can pass the `requestContext` parameter to enable metadata extraction:
|
|
@@ -751,10 +816,6 @@ Mastra automatically creates spans for:
|
|
|
751
816
|
|
|
752
817
|
## See Also
|
|
753
818
|
|
|
754
|
-
### Examples
|
|
755
|
-
|
|
756
|
-
- [Basic Tracing Example](/examples/v1/observability/basic-ai-tracing) - Working implementation
|
|
757
|
-
|
|
758
819
|
### Reference Documentation
|
|
759
820
|
|
|
760
821
|
- [Configuration API](/reference/v1/observability/tracing/configuration) - ObservabilityConfig details
|
|
@@ -773,6 +834,10 @@ Mastra automatically creates spans for:
|
|
|
773
834
|
- [MLflow](/reference/v1/observability/tracing/exporters/otel#mlflow) - MLflow OTLP endpoint setup
|
|
774
835
|
- [OpenTelemetry](/reference/v1/observability/tracing/exporters/otel) - OTEL-compatible platforms
|
|
775
836
|
|
|
837
|
+
### Bridges
|
|
838
|
+
|
|
839
|
+
- [OpenTelemetry Bridge](/reference/v1/observability/tracing/bridges/otel) - OTEL context integration
|
|
840
|
+
|
|
776
841
|
### Processors
|
|
777
842
|
|
|
778
843
|
- [Sensitive Data Filter](/docs/v1/observability/tracing/processors/sensitive-data-filter) - Data redaction
|
|
@@ -293,4 +293,3 @@ This ensures that processing errors don't prevent traces from being exported or
|
|
|
293
293
|
## Related
|
|
294
294
|
|
|
295
295
|
- [SensitiveDataFilter API](/reference/v1/observability/tracing/processors/sensitive-data-filter)
|
|
296
|
-
- [Basic Tracing Example](/examples/v1/observability/basic-ai-tracing)
|
|
@@ -52,6 +52,8 @@ const results = await pgVector.query({
|
|
|
52
52
|
console.log(results);
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
The `topK` parameter specifies the maximum number of most similar results to return from the vector search.
|
|
56
|
+
|
|
55
57
|
Results include both the text content and a similarity score:
|
|
56
58
|
|
|
57
59
|
```ts showLineNumbers copy
|
|
@@ -70,8 +72,6 @@ Results include both the text content and a similarity score:
|
|
|
70
72
|
];
|
|
71
73
|
```
|
|
72
74
|
|
|
73
|
-
For an example of how to use the basic retrieval method, see the [Retrieve Results](/examples/v1/rag/query/retrieve-results) example.
|
|
74
|
-
|
|
75
75
|
## Advanced Retrieval options
|
|
76
76
|
|
|
77
77
|
### Metadata Filtering
|
|
@@ -170,7 +170,14 @@ This is particularly useful when:
|
|
|
170
170
|
|
|
171
171
|
#### Database-Specific Configurations
|
|
172
172
|
|
|
173
|
-
The Vector Query Tool supports database-specific configurations that enable you to leverage unique features and optimizations of different vector stores
|
|
173
|
+
The Vector Query Tool supports database-specific configurations that enable you to leverage unique features and optimizations of different vector stores.
|
|
174
|
+
|
|
175
|
+
:::note
|
|
176
|
+
These configurations are for **query-time options** like namespaces, performance tuning, and filtering—not for database connection setup.
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
Connection credentials (URLs, auth tokens) are configured when you instantiate the vector store class (e.g., `new LibSQLVector({ connectionUrl: '...' })`).
|
|
180
|
+
:::
|
|
174
181
|
|
|
175
182
|
```ts showLineNumbers copy
|
|
176
183
|
// Pinecone with namespace
|
|
@@ -510,13 +517,25 @@ const relevanceProvider = new MastraAgentRelevanceScorer('relevance-scorer', "op
|
|
|
510
517
|
const rerankedResults = await rerank({
|
|
511
518
|
results: initialResults,
|
|
512
519
|
query,
|
|
513
|
-
|
|
520
|
+
scorer: relevanceProvider,
|
|
514
521
|
options: {
|
|
522
|
+
weights: {
|
|
523
|
+
semantic: 0.5, // How well the content matches the query semantically
|
|
524
|
+
vector: 0.3, // Original vector similarity score
|
|
525
|
+
position: 0.2, // Preserves original result ordering
|
|
526
|
+
},
|
|
515
527
|
topK: 10,
|
|
516
528
|
},
|
|
517
529
|
);
|
|
518
530
|
```
|
|
519
531
|
|
|
532
|
+
The weights control how different factors influence the final ranking:
|
|
533
|
+
|
|
534
|
+
- `semantic`: Higher values prioritize semantic understanding and relevance to the query
|
|
535
|
+
- `vector`: Higher values favor the original vector similarity scores
|
|
536
|
+
- `position`: Higher values help maintain the original ordering of results
|
|
537
|
+
|
|
538
|
+
|
|
520
539
|
> **Note:** For semantic scoring to work properly during re-ranking, each result must include the text content in its `metadata.text` field.
|
|
521
540
|
|
|
522
541
|
You can also use other relevance score providers like Cohere or ZeroEntropy:
|
|
@@ -533,8 +552,6 @@ The re-ranked results combine vector similarity with semantic understanding to i
|
|
|
533
552
|
|
|
534
553
|
For more details about re-ranking, see the [rerank()](/reference/v1/rag/rerankWithScorer) method.
|
|
535
554
|
|
|
536
|
-
For an example of how to use the re-ranking method, see the Re-ranking Results example in the examples section.
|
|
537
|
-
|
|
538
555
|
### Graph-based Retrieval
|
|
539
556
|
|
|
540
557
|
For documents with complex relationships, graph-based retrieval can follow connections between chunks. This helps when:
|
|
@@ -252,6 +252,27 @@ await store.createIndex({
|
|
|
252
252
|
dimension: 1536,
|
|
253
253
|
});
|
|
254
254
|
|
|
255
|
+
await store.upsert({
|
|
256
|
+
indexName: "my-collection",
|
|
257
|
+
vectors: embeddings,
|
|
258
|
+
metadata: chunks.map((chunk) => ({ text: chunk.text })),
|
|
259
|
+
});
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
</TabItem>
|
|
263
|
+
|
|
264
|
+
<TabItem value="elasticsearch" label="ElasticSearch">
|
|
265
|
+
|
|
266
|
+
```ts title="vector-store.ts" showLineNumbers copy
|
|
267
|
+
import { ElasticSearchVector } from "@mastra/elasticsearch";
|
|
268
|
+
|
|
269
|
+
const store = new ElasticSearchVector({ url: process.env.ELASTICSEARCH_URL });
|
|
270
|
+
|
|
271
|
+
await store.createIndex({
|
|
272
|
+
indexName: "my-collection",
|
|
273
|
+
dimension: 1536,
|
|
274
|
+
});
|
|
275
|
+
|
|
255
276
|
await store.upsert({
|
|
256
277
|
indexName: "my-collection",
|
|
257
278
|
vectors: embeddings,
|
|
@@ -459,6 +480,20 @@ Each vector database enforces specific naming conventions for indexes and collec
|
|
|
459
480
|
- Example: `My_Index` is not valid (contains uppercase letters)
|
|
460
481
|
- Example: `_myindex` is not valid (begins with underscore)
|
|
461
482
|
</TabItem>
|
|
483
|
+
<TabItem value="elasticsearch" label="ElasticSearch">
|
|
484
|
+
Index names must:
|
|
485
|
+
- Use only lowercase letters
|
|
486
|
+
- Not exceed 255 bytes (counting multi-byte characters)
|
|
487
|
+
- Not begin with underscores, hyphens, or plus signs
|
|
488
|
+
- Not contain spaces, commas
|
|
489
|
+
- Not contain special characters (e.g. `:`, `"`, `*`, `+`, `/`, `\`, `|`, `?`, `#`, `>`, `<`)
|
|
490
|
+
- Not be "." or ".."
|
|
491
|
+
- Not start with "." (deprecated except for system/hidden indices)
|
|
492
|
+
- Example: `my-index-123` is valid
|
|
493
|
+
- Example: `My_Index` is not valid (contains uppercase letters)
|
|
494
|
+
- Example: `_myindex` is not valid (begins with underscore)
|
|
495
|
+
- Example: `.myindex` is not valid (begins with dot, deprecated)
|
|
496
|
+
</TabItem>
|
|
462
497
|
<TabItem value="s3vectors" label="S3 Vectors">
|
|
463
498
|
Index names must:
|
|
464
499
|
- Be unique within the same vector bucket
|
|
@@ -496,8 +531,6 @@ The upsert operation:
|
|
|
496
531
|
- Creates new vectors if they don't exist
|
|
497
532
|
- Automatically handles batching for large datasets
|
|
498
533
|
|
|
499
|
-
For complete examples of upserting embeddings in different vector stores, see the [Upsert Embeddings](/examples/v1/rag/upsert/upsert-embeddings) guide.
|
|
500
|
-
|
|
501
534
|
## Adding Metadata
|
|
502
535
|
|
|
503
536
|
Vector stores support rich metadata (any JSON-serializable fields) for filtering and organization. Since metadata is stored with no fixed schema, use consistent field naming to avoid unexpected query results.
|
|
@@ -536,6 +569,64 @@ Key metadata considerations:
|
|
|
536
569
|
- Only include fields you plan to filter or sort by - extra fields add overhead
|
|
537
570
|
- Add timestamps (e.g., 'createdAt', 'lastUpdated') to track content freshness
|
|
538
571
|
|
|
572
|
+
## Deleting Vectors
|
|
573
|
+
|
|
574
|
+
When building RAG applications, you often need to clean up stale vectors when documents are deleted or updated. Mastra provides the `deleteVectors` method that supports deleting vectors by metadata filters, making it easy to remove all embeddings associated with a specific document.
|
|
575
|
+
|
|
576
|
+
### Delete by Metadata Filter
|
|
577
|
+
|
|
578
|
+
The most common use case is deleting all vectors for a specific document when a user deletes it:
|
|
579
|
+
|
|
580
|
+
```ts title="delete-vectors.ts" showLineNumbers copy
|
|
581
|
+
// Delete all vectors for a specific document
|
|
582
|
+
await store.deleteVectors({
|
|
583
|
+
indexName: "myCollection",
|
|
584
|
+
filter: { docId: "document-123" },
|
|
585
|
+
});
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
This is particularly useful when:
|
|
589
|
+
- A user deletes a document and you need to remove all its chunks
|
|
590
|
+
- You're re-indexing a document and want to remove old vectors first
|
|
591
|
+
- You need to clean up vectors for a specific user or tenant
|
|
592
|
+
|
|
593
|
+
### Delete Multiple Documents
|
|
594
|
+
|
|
595
|
+
You can also use complex filters to delete vectors matching multiple conditions:
|
|
596
|
+
|
|
597
|
+
```ts title="delete-vectors-advanced.ts" showLineNumbers copy
|
|
598
|
+
// Delete all vectors for multiple documents
|
|
599
|
+
await store.deleteVectors({
|
|
600
|
+
indexName: "myCollection",
|
|
601
|
+
filter: {
|
|
602
|
+
docId: { $in: ["doc-1", "doc-2", "doc-3"] },
|
|
603
|
+
},
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
// Delete vectors for a specific user's documents
|
|
607
|
+
await store.deleteVectors({
|
|
608
|
+
indexName: "myCollection",
|
|
609
|
+
filter: {
|
|
610
|
+
$and: [
|
|
611
|
+
{ userId: "user-123" },
|
|
612
|
+
{ status: "archived" },
|
|
613
|
+
],
|
|
614
|
+
},
|
|
615
|
+
});
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
### Delete by Vector IDs
|
|
619
|
+
|
|
620
|
+
If you have specific vector IDs to delete, you can pass them directly:
|
|
621
|
+
|
|
622
|
+
```ts title="delete-by-ids.ts" showLineNumbers copy
|
|
623
|
+
// Delete specific vectors by their IDs
|
|
624
|
+
await store.deleteVectors({
|
|
625
|
+
indexName: "myCollection",
|
|
626
|
+
ids: ["vec-1", "vec-2", "vec-3"],
|
|
627
|
+
});
|
|
628
|
+
```
|
|
629
|
+
|
|
539
630
|
## Best Practices
|
|
540
631
|
|
|
541
632
|
- Create indexes before bulk insertions
|
|
@@ -124,12 +124,6 @@ const limitedResult = await agent.generate("Write a short poem about coding", {
|
|
|
124
124
|
},
|
|
125
125
|
],
|
|
126
126
|
},
|
|
127
|
-
{
|
|
128
|
-
name: "tracingContext",
|
|
129
|
-
type: "TracingContext",
|
|
130
|
-
isOptional: true,
|
|
131
|
-
description: "Tracing context for span hierarchy and metadata.",
|
|
132
|
-
},
|
|
133
127
|
{
|
|
134
128
|
name: "returnScorerData",
|
|
135
129
|
type: "boolean",
|
|
@@ -253,6 +247,17 @@ const limitedResult = await agent.generate("Write a short poem about coding", {
|
|
|
253
247
|
},
|
|
254
248
|
],
|
|
255
249
|
},
|
|
250
|
+
{
|
|
251
|
+
parameters: [
|
|
252
|
+
{
|
|
253
|
+
name: "providerOptions",
|
|
254
|
+
type: "ProviderOptions",
|
|
255
|
+
isOptional: true,
|
|
256
|
+
description:
|
|
257
|
+
"Provider-specific options passed to the internal structuring agent. Use this to control model behavior like reasoning effort for thinking models (e.g., `{ openai: { reasoningEffort: 'low' } }`).",
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
},
|
|
256
261
|
],
|
|
257
262
|
},
|
|
258
263
|
{
|
|
@@ -576,6 +581,50 @@ const limitedResult = await agent.generate("Write a short poem about coding", {
|
|
|
576
581
|
},
|
|
577
582
|
],
|
|
578
583
|
},
|
|
584
|
+
{
|
|
585
|
+
parameters: [
|
|
586
|
+
{
|
|
587
|
+
name: "requestContextKeys",
|
|
588
|
+
type: "string[]",
|
|
589
|
+
isOptional: true,
|
|
590
|
+
description:
|
|
591
|
+
"Additional RequestContext keys to extract as metadata for this trace. Supports dot notation for nested values (e.g., 'user.id').",
|
|
592
|
+
},
|
|
593
|
+
],
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
parameters: [
|
|
597
|
+
{
|
|
598
|
+
name: "traceId",
|
|
599
|
+
type: "string",
|
|
600
|
+
isOptional: true,
|
|
601
|
+
description:
|
|
602
|
+
"Trace ID to use for this execution (1-32 hexadecimal characters). If provided, this trace will be part of the specified trace.",
|
|
603
|
+
},
|
|
604
|
+
],
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
parameters: [
|
|
608
|
+
{
|
|
609
|
+
name: "parentSpanId",
|
|
610
|
+
type: "string",
|
|
611
|
+
isOptional: true,
|
|
612
|
+
description:
|
|
613
|
+
"Parent span ID to use for this execution (1-16 hexadecimal characters). If provided, the root span will be created as a child of this span.",
|
|
614
|
+
},
|
|
615
|
+
],
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
parameters: [
|
|
619
|
+
{
|
|
620
|
+
name: "tags",
|
|
621
|
+
type: "string[]",
|
|
622
|
+
isOptional: true,
|
|
623
|
+
description:
|
|
624
|
+
"Tags to apply to this trace. String labels for categorizing and filtering traces.",
|
|
625
|
+
},
|
|
626
|
+
],
|
|
627
|
+
},
|
|
579
628
|
],
|
|
580
629
|
},
|
|
581
630
|
]}
|
|
@@ -154,6 +154,50 @@ await agent.network(`
|
|
|
154
154
|
},
|
|
155
155
|
],
|
|
156
156
|
},
|
|
157
|
+
{
|
|
158
|
+
parameters: [
|
|
159
|
+
{
|
|
160
|
+
name: "requestContextKeys",
|
|
161
|
+
type: "string[]",
|
|
162
|
+
isOptional: true,
|
|
163
|
+
description:
|
|
164
|
+
"Additional RequestContext keys to extract as metadata for this trace. Supports dot notation for nested values (e.g., 'user.id').",
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
parameters: [
|
|
170
|
+
{
|
|
171
|
+
name: "traceId",
|
|
172
|
+
type: "string",
|
|
173
|
+
isOptional: true,
|
|
174
|
+
description:
|
|
175
|
+
"Trace ID to use for this execution (1-32 hexadecimal characters). If provided, this trace will be part of the specified trace.",
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
parameters: [
|
|
181
|
+
{
|
|
182
|
+
name: "parentSpanId",
|
|
183
|
+
type: "string",
|
|
184
|
+
isOptional: true,
|
|
185
|
+
description:
|
|
186
|
+
"Parent span ID to use for this execution (1-16 hexadecimal characters). If provided, the root span will be created as a child of this span.",
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
parameters: [
|
|
192
|
+
{
|
|
193
|
+
name: "tags",
|
|
194
|
+
type: "string[]",
|
|
195
|
+
isOptional: true,
|
|
196
|
+
description:
|
|
197
|
+
"Tags to apply to this trace. String labels for categorizing and filtering traces.",
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
},
|
|
157
201
|
],
|
|
158
202
|
},
|
|
159
203
|
{
|
|
@@ -133,6 +133,49 @@ const result = await thread.deleteMessages([
|
|
|
133
133
|
// Returns: { success: true, message: "Message deleted successfully" }
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
+
## Working Memory
|
|
137
|
+
|
|
138
|
+
Working memory allows agents to maintain persistent information about users across interactions. It can be scoped to either a specific thread or across all threads for a resource (user).
|
|
139
|
+
|
|
140
|
+
### Get Working Memory
|
|
141
|
+
|
|
142
|
+
Retrieve the current working memory for a thread:
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
const workingMemory = await mastraClient.getWorkingMemory({
|
|
146
|
+
agentId: "agent-1",
|
|
147
|
+
threadId: "thread-1",
|
|
148
|
+
resourceId: "user-123", // Optional, required for resource-scoped memory
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The response includes:
|
|
153
|
+
- `workingMemory`: The current working memory content (string or null)
|
|
154
|
+
- `source`: Whether the memory is from `"thread"` or `"resource"` scope
|
|
155
|
+
- `workingMemoryTemplate`: The template used for working memory (if configured)
|
|
156
|
+
- `threadExists`: Whether the thread exists
|
|
157
|
+
|
|
158
|
+
### Update Working Memory
|
|
159
|
+
|
|
160
|
+
Update the working memory content for a thread:
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
await mastraClient.updateWorkingMemory({
|
|
164
|
+
agentId: "agent-1",
|
|
165
|
+
threadId: "thread-1",
|
|
166
|
+
workingMemory: `# User Profile
|
|
167
|
+
- Name: John Doe
|
|
168
|
+
- Location: New York
|
|
169
|
+
- Preferences: Prefers formal communication
|
|
170
|
+
`,
|
|
171
|
+
resourceId: "user-123", // Optional, required for resource-scoped memory
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// Returns: { success: true }
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Note:** For resource-scoped working memory, you must provide the `resourceId` parameter. This allows the memory to persist across all conversation threads for that user.
|
|
178
|
+
|
|
136
179
|
### Get Memory Status
|
|
137
180
|
|
|
138
181
|
Check the status of the memory system:
|