@mastra/mcp-docs-server 0.0.0-default-storage-virtual-file-20250410035748
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +131 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +80 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +166 -0
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +220 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +220 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +299 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
- package/.docs/organized/changelogs/create-mastra.md +302 -0
- package/.docs/organized/changelogs/mastra.md +302 -0
- package/.docs/organized/code-examples/agent-network.md +282 -0
- package/.docs/organized/code-examples/agent.md +390 -0
- package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
- package/.docs/organized/code-examples/assistant-ui.md +37 -0
- package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
- package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
- package/.docs/organized/code-examples/fireworks-r1.md +159 -0
- package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
- package/.docs/organized/code-examples/memory-with-context.md +167 -0
- package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
- package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
- package/.docs/organized/code-examples/memory-with-pg.md +224 -0
- package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
- package/.docs/organized/code-examples/quick-start.md +129 -0
- package/.docs/organized/code-examples/stock-price-tool.md +124 -0
- package/.docs/organized/code-examples/weather-agent.md +353 -0
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
- package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
- package/.docs/raw/agents/adding-tools.mdx +239 -0
- package/.docs/raw/agents/adding-voice.mdx +175 -0
- package/.docs/raw/agents/agent-memory.mdx +62 -0
- package/.docs/raw/agents/mcp-guide.mdx +192 -0
- package/.docs/raw/agents/overview.mdx +303 -0
- package/.docs/raw/community/discord.mdx +12 -0
- package/.docs/raw/community/licensing.mdx +63 -0
- package/.docs/raw/deployment/client.mdx +120 -0
- package/.docs/raw/deployment/deployment.mdx +119 -0
- package/.docs/raw/deployment/server.mdx +276 -0
- package/.docs/raw/evals/custom-eval.mdx +22 -0
- package/.docs/raw/evals/overview.mdx +95 -0
- package/.docs/raw/evals/running-in-ci.mdx +81 -0
- package/.docs/raw/evals/textual-evals.mdx +54 -0
- package/.docs/raw/faq/index.mdx +63 -0
- package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
- package/.docs/raw/frameworks/next-js.mdx +238 -0
- package/.docs/raw/getting-started/installation.mdx +436 -0
- package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
- package/.docs/raw/getting-started/project-structure.mdx +80 -0
- package/.docs/raw/index.mdx +22 -0
- package/.docs/raw/integrations/index.mdx +213 -0
- package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
- package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
- package/.docs/raw/local-dev/mastra-dev.mdx +108 -0
- package/.docs/raw/memory/memory-processors.mdx +131 -0
- package/.docs/raw/memory/overview.mdx +119 -0
- package/.docs/raw/memory/semantic-recall.mdx +122 -0
- package/.docs/raw/memory/working-memory.mdx +87 -0
- package/.docs/raw/observability/logging.mdx +38 -0
- package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
- package/.docs/raw/observability/tracing.mdx +115 -0
- package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
- package/.docs/raw/rag/overview.mdx +85 -0
- package/.docs/raw/rag/retrieval.mdx +365 -0
- package/.docs/raw/rag/vector-databases.mdx +340 -0
- package/.docs/raw/reference/agents/createTool.mdx +229 -0
- package/.docs/raw/reference/agents/generate.mdx +327 -0
- package/.docs/raw/reference/agents/getAgent.mdx +54 -0
- package/.docs/raw/reference/agents/stream.mdx +362 -0
- package/.docs/raw/reference/cli/build.mdx +48 -0
- package/.docs/raw/reference/cli/deploy.mdx +22 -0
- package/.docs/raw/reference/cli/dev.mdx +134 -0
- package/.docs/raw/reference/cli/init.mdx +43 -0
- package/.docs/raw/reference/client-js/agents.mdx +107 -0
- package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
- package/.docs/raw/reference/client-js/logs.mdx +24 -0
- package/.docs/raw/reference/client-js/memory.mdx +97 -0
- package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
- package/.docs/raw/reference/client-js/tools.mdx +44 -0
- package/.docs/raw/reference/client-js/vectors.mdx +79 -0
- package/.docs/raw/reference/client-js/workflows.mdx +136 -0
- package/.docs/raw/reference/core/mastra-class.mdx +232 -0
- package/.docs/raw/reference/deployer/cloudflare.mdx +176 -0
- package/.docs/raw/reference/deployer/deployer.mdx +159 -0
- package/.docs/raw/reference/deployer/netlify.mdx +88 -0
- package/.docs/raw/reference/deployer/vercel.mdx +97 -0
- package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
- package/.docs/raw/reference/evals/bias.mdx +186 -0
- package/.docs/raw/reference/evals/completeness.mdx +174 -0
- package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
- package/.docs/raw/reference/evals/context-position.mdx +190 -0
- package/.docs/raw/reference/evals/context-precision.mdx +189 -0
- package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
- package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
- package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
- package/.docs/raw/reference/evals/hallucination.mdx +219 -0
- package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
- package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
- package/.docs/raw/reference/evals/summarization.mdx +205 -0
- package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
- package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
- package/.docs/raw/reference/evals/toxicity.mdx +165 -0
- package/.docs/raw/reference/index.mdx +8 -0
- package/.docs/raw/reference/memory/Memory.mdx +212 -0
- package/.docs/raw/reference/memory/createThread.mdx +95 -0
- package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
- package/.docs/raw/reference/memory/query.mdx +167 -0
- package/.docs/raw/reference/networks/agent-network.mdx +159 -0
- package/.docs/raw/reference/observability/create-logger.mdx +106 -0
- package/.docs/raw/reference/observability/logger.mdx +55 -0
- package/.docs/raw/reference/observability/otel-config.mdx +120 -0
- package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
- package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
- package/.docs/raw/reference/observability/providers/index.mdx +16 -0
- package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
- package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
- package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
- package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
- package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
- package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
- package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
- package/.docs/raw/reference/rag/astra.mdx +258 -0
- package/.docs/raw/reference/rag/chroma.mdx +281 -0
- package/.docs/raw/reference/rag/chunk.mdx +235 -0
- package/.docs/raw/reference/rag/document.mdx +127 -0
- package/.docs/raw/reference/rag/embeddings.mdx +160 -0
- package/.docs/raw/reference/rag/extract-params.mdx +226 -0
- package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
- package/.docs/raw/reference/rag/libsql.mdx +357 -0
- package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
- package/.docs/raw/reference/rag/pg.mdx +477 -0
- package/.docs/raw/reference/rag/pinecone.mdx +281 -0
- package/.docs/raw/reference/rag/qdrant.mdx +236 -0
- package/.docs/raw/reference/rag/rerank.mdx +212 -0
- package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
- package/.docs/raw/reference/rag/upstash.mdx +247 -0
- package/.docs/raw/reference/rag/vectorize.mdx +298 -0
- package/.docs/raw/reference/storage/libsql.mdx +74 -0
- package/.docs/raw/reference/storage/postgresql.mdx +48 -0
- package/.docs/raw/reference/storage/upstash.mdx +86 -0
- package/.docs/raw/reference/tools/client.mdx +188 -0
- package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
- package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
- package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
- package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
- package/.docs/raw/reference/voice/deepgram.mdx +164 -0
- package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
- package/.docs/raw/reference/voice/google.mdx +198 -0
- package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
- package/.docs/raw/reference/voice/murf.mdx +251 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
- package/.docs/raw/reference/voice/openai.mdx +168 -0
- package/.docs/raw/reference/voice/playai.mdx +159 -0
- package/.docs/raw/reference/voice/sarvam.mdx +260 -0
- package/.docs/raw/reference/voice/speechify.mdx +145 -0
- package/.docs/raw/reference/voice/voice.answer.mdx +122 -0
- package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
- package/.docs/raw/reference/voice/voice.listen.mdx +195 -0
- package/.docs/raw/reference/voice/voice.on.mdx +189 -0
- package/.docs/raw/reference/voice/voice.send.mdx +118 -0
- package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
- package/.docs/raw/reference/workflows/after.mdx +88 -0
- package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
- package/.docs/raw/reference/workflows/commit.mdx +37 -0
- package/.docs/raw/reference/workflows/createRun.mdx +77 -0
- package/.docs/raw/reference/workflows/else.mdx +72 -0
- package/.docs/raw/reference/workflows/events.mdx +305 -0
- package/.docs/raw/reference/workflows/execute.mdx +110 -0
- package/.docs/raw/reference/workflows/if.mdx +107 -0
- package/.docs/raw/reference/workflows/resume.mdx +155 -0
- package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
- package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
- package/.docs/raw/reference/workflows/start.mdx +84 -0
- package/.docs/raw/reference/workflows/step-class.mdx +100 -0
- package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
- package/.docs/raw/reference/workflows/step-function.mdx +92 -0
- package/.docs/raw/reference/workflows/step-options.mdx +69 -0
- package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
- package/.docs/raw/reference/workflows/suspend.mdx +70 -0
- package/.docs/raw/reference/workflows/then.mdx +74 -0
- package/.docs/raw/reference/workflows/until.mdx +165 -0
- package/.docs/raw/reference/workflows/watch.mdx +118 -0
- package/.docs/raw/reference/workflows/while.mdx +168 -0
- package/.docs/raw/reference/workflows/workflow.mdx +233 -0
- package/.docs/raw/storage/overview.mdx +378 -0
- package/.docs/raw/voice/overview.mdx +135 -0
- package/.docs/raw/voice/speech-to-text.mdx +45 -0
- package/.docs/raw/voice/text-to-speech.mdx +52 -0
- package/.docs/raw/voice/voice-to-voice.mdx +310 -0
- package/.docs/raw/workflows/control-flow.mdx +778 -0
- package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
- package/.docs/raw/workflows/error-handling.mdx +183 -0
- package/.docs/raw/workflows/nested-workflows.mdx +352 -0
- package/.docs/raw/workflows/overview.mdx +167 -0
- package/.docs/raw/workflows/steps.mdx +108 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
- package/.docs/raw/workflows/variables.mdx +313 -0
- package/LICENSE +44 -0
- package/README.md +129 -0
- package/dist/_tsup-dts-rollup.d.ts +149 -0
- package/dist/chunk-QWYMT5LP.js +194 -0
- package/dist/prepare-docs/prepare.d.ts +1 -0
- package/dist/prepare-docs/prepare.js +1 -0
- package/dist/stdio.d.ts +1 -0
- package/dist/stdio.js +518 -0
- package/package.json +60 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Storing Embeddings in A Vector Database | Mastra Docs"
|
|
3
|
+
description: Guide on vector storage options in Mastra, including embedded and dedicated vector databases for similarity search.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { Tabs } from "nextra/components";
|
|
7
|
+
|
|
8
|
+
## Storing Embeddings in A Vector Database
|
|
9
|
+
|
|
10
|
+
After generating embeddings, you need to store them in a database that supports vector similarity search. Mastra provides a consistent interface for storing and querying embeddings across different vector databases.
|
|
11
|
+
|
|
12
|
+
## Supported Databases
|
|
13
|
+
|
|
14
|
+
<Tabs items={['Pg Vector', 'Pinecone', 'Qdrant', 'Chroma', 'Astra', 'LibSQL', 'Upstash', 'Cloudflare']}>
|
|
15
|
+
<Tabs.Tab>
|
|
16
|
+
```ts filename="vector-store.ts" showLineNumbers copy
|
|
17
|
+
import { PgVector } from '@mastra/pg';
|
|
18
|
+
|
|
19
|
+
const store = new PgVector(process.env.POSTGRES_CONNECTION_STRING)
|
|
20
|
+
await store.createIndex({
|
|
21
|
+
indexName: "myCollection",
|
|
22
|
+
dimension: 1536,
|
|
23
|
+
});
|
|
24
|
+
await store.upsert({
|
|
25
|
+
indexName: "myCollection",
|
|
26
|
+
vectors: embeddings,
|
|
27
|
+
metadata: chunks.map(chunk => ({ text: chunk.text })),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Using PostgreSQL with pgvector
|
|
33
|
+
|
|
34
|
+
PostgreSQL with the pgvector extension is a good solution for teams already using PostgreSQL who want to minimize infrastructure complexity.
|
|
35
|
+
For detailed setup instructions and best practices, see the [official pgvector repository](https://github.com/pgvector/pgvector).
|
|
36
|
+
</Tabs.Tab>
|
|
37
|
+
<Tabs.Tab>
|
|
38
|
+
```ts filename="vector-store.ts" showLineNumbers copy
|
|
39
|
+
import { PineconeVector } from '@mastra/pinecone'
|
|
40
|
+
|
|
41
|
+
const store = new PineconeVector(process.env.PINECONE_API_KEY)
|
|
42
|
+
await store.createIndex({
|
|
43
|
+
indexName: "myCollection",
|
|
44
|
+
dimension: 1536,
|
|
45
|
+
});
|
|
46
|
+
await store.upsert({
|
|
47
|
+
indexName: "myCollection",
|
|
48
|
+
vectors: embeddings,
|
|
49
|
+
metadata: chunks.map(chunk => ({ text: chunk.text })),
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
</Tabs.Tab>
|
|
53
|
+
<Tabs.Tab>
|
|
54
|
+
```ts filename="vector-store.ts" showLineNumbers copy
|
|
55
|
+
import { QdrantVector } from '@mastra/qdrant'
|
|
56
|
+
|
|
57
|
+
const store = new QdrantVector({
|
|
58
|
+
url: process.env.QDRANT_URL,
|
|
59
|
+
apiKey: process.env.QDRANT_API_KEY
|
|
60
|
+
})
|
|
61
|
+
await store.createIndex({
|
|
62
|
+
indexName: "myCollection",
|
|
63
|
+
dimension: 1536,
|
|
64
|
+
});
|
|
65
|
+
await store.upsert({
|
|
66
|
+
indexName: "myCollection",
|
|
67
|
+
vectors: embeddings,
|
|
68
|
+
metadata: chunks.map(chunk => ({ text: chunk.text })),
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
</Tabs.Tab>
|
|
72
|
+
<Tabs.Tab>
|
|
73
|
+
```ts filename="vector-store.ts" showLineNumbers copy
|
|
74
|
+
import { ChromaVector } from '@mastra/chroma'
|
|
75
|
+
|
|
76
|
+
const store = new ChromaVector()
|
|
77
|
+
await store.createIndex({
|
|
78
|
+
indexName: "myCollection",
|
|
79
|
+
dimension: 1536,
|
|
80
|
+
});
|
|
81
|
+
await store.upsert({
|
|
82
|
+
indexName: "myCollection",
|
|
83
|
+
vectors: embeddings,
|
|
84
|
+
metadata: chunks.map(chunk => ({ text: chunk.text })),
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
</Tabs.Tab>
|
|
88
|
+
<Tabs.Tab>
|
|
89
|
+
```ts filename="vector-store.ts" showLineNumbers copy
|
|
90
|
+
import { AstraVector } from '@mastra/astra'
|
|
91
|
+
|
|
92
|
+
const store = new AstraVector({
|
|
93
|
+
token: process.env.ASTRA_DB_TOKEN,
|
|
94
|
+
endpoint: process.env.ASTRA_DB_ENDPOINT,
|
|
95
|
+
keyspace: process.env.ASTRA_DB_KEYSPACE
|
|
96
|
+
})
|
|
97
|
+
await store.createIndex({
|
|
98
|
+
indexName: "myCollection",
|
|
99
|
+
dimension: 1536,
|
|
100
|
+
});
|
|
101
|
+
await store.upsert({
|
|
102
|
+
indexName: "myCollection",
|
|
103
|
+
vectors: embeddings,
|
|
104
|
+
metadata: chunks.map(chunk => ({ text: chunk.text })),
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
</Tabs.Tab>
|
|
108
|
+
<Tabs.Tab>
|
|
109
|
+
```ts filename="vector-store.ts" showLineNumbers copy
|
|
110
|
+
import { LibSQLVector } from "@mastra/core/vector/libsql";
|
|
111
|
+
|
|
112
|
+
const store = new LibSQLVector({
|
|
113
|
+
connectionUrl: process.env.DATABASE_URL,
|
|
114
|
+
authToken: process.env.DATABASE_AUTH_TOKEN // Optional: for Turso cloud databases
|
|
115
|
+
})
|
|
116
|
+
await store.createIndex({
|
|
117
|
+
indexName: "myCollection",
|
|
118
|
+
dimension: 1536,
|
|
119
|
+
});
|
|
120
|
+
await store.upsert({
|
|
121
|
+
indexName: "myCollection",
|
|
122
|
+
vectors: embeddings,
|
|
123
|
+
metadata: chunks.map(chunk => ({ text: chunk.text })),
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
</Tabs.Tab>
|
|
127
|
+
<Tabs.Tab>
|
|
128
|
+
```ts filename="vector-store.ts" showLineNumbers copy
|
|
129
|
+
import { UpstashVector } from '@mastra/upstash'
|
|
130
|
+
|
|
131
|
+
const store = new UpstashVector({
|
|
132
|
+
url: process.env.UPSTASH_URL,
|
|
133
|
+
token: process.env.UPSTASH_TOKEN
|
|
134
|
+
})
|
|
135
|
+
await store.createIndex({
|
|
136
|
+
indexName: "myCollection",
|
|
137
|
+
dimension: 1536,
|
|
138
|
+
});
|
|
139
|
+
await store.upsert({
|
|
140
|
+
indexName: "myCollection",
|
|
141
|
+
vectors: embeddings,
|
|
142
|
+
metadata: chunks.map(chunk => ({ text: chunk.text })),
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
</Tabs.Tab>
|
|
146
|
+
<Tabs.Tab>
|
|
147
|
+
```ts filename="vector-store.ts" showLineNumbers copy
|
|
148
|
+
import { CloudflareVector } from '@mastra/vectorize'
|
|
149
|
+
|
|
150
|
+
const store = new CloudflareVector({
|
|
151
|
+
accountId: process.env.CF_ACCOUNT_ID,
|
|
152
|
+
apiToken: process.env.CF_API_TOKEN
|
|
153
|
+
})
|
|
154
|
+
await store.createIndex({
|
|
155
|
+
indexName: "myCollection",
|
|
156
|
+
dimension: 1536,
|
|
157
|
+
});
|
|
158
|
+
await store.upsert({
|
|
159
|
+
indexName: "myCollection",
|
|
160
|
+
vectors: embeddings,
|
|
161
|
+
metadata: chunks.map(chunk => ({ text: chunk.text })),
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
</Tabs.Tab>
|
|
165
|
+
</Tabs>
|
|
166
|
+
|
|
167
|
+
## Using Vector Storage
|
|
168
|
+
|
|
169
|
+
Once initialized, all vector stores share the same interface for creating indexes, upserting embeddings, and querying.
|
|
170
|
+
|
|
171
|
+
### Creating Indexes
|
|
172
|
+
|
|
173
|
+
Before storing embeddings, you need to create an index with the appropriate dimension size for your embedding model:
|
|
174
|
+
|
|
175
|
+
```ts filename="store-embeddings.ts" showLineNumbers copy
|
|
176
|
+
// Create an index with dimension 1536 (for text-embedding-3-small)
|
|
177
|
+
await store.createIndex({
|
|
178
|
+
indexName: 'myCollection',
|
|
179
|
+
dimension: 1536,
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// For other models, use their corresponding dimensions:
|
|
183
|
+
// - text-embedding-3-large: 3072
|
|
184
|
+
// - text-embedding-ada-002: 1536
|
|
185
|
+
// - cohere-embed-multilingual-v3: 1024
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
The dimension size must match the output dimension of your chosen embedding model. Common dimension sizes are:
|
|
189
|
+
- OpenAI text-embedding-3-small: 1536 dimensions
|
|
190
|
+
- OpenAI text-embedding-3-large: 3072 dimensions
|
|
191
|
+
- Cohere embed-multilingual-v3: 1024 dimensions
|
|
192
|
+
|
|
193
|
+
> **Important**: Index dimensions cannot be changed after creation. To use a different model, delete and recreate the index with the new dimension size.
|
|
194
|
+
|
|
195
|
+
### Naming Rules for Databases
|
|
196
|
+
|
|
197
|
+
Each vector database enforces specific naming conventions for indexes and collections to ensure compatibility and prevent conflicts.
|
|
198
|
+
|
|
199
|
+
<Tabs items={['Pg Vector', 'Pinecone', 'Qdrant', 'Chroma', 'Astra', 'LibSQL', 'Upstash', 'Cloudflare']}>
|
|
200
|
+
<Tabs.Tab>
|
|
201
|
+
Index names must:
|
|
202
|
+
- Start with a letter or underscore
|
|
203
|
+
- Contain only letters, numbers, and underscores
|
|
204
|
+
- Example: `my_index_123` is valid
|
|
205
|
+
- Example: `my-index` is not valid (contains hyphen)
|
|
206
|
+
</Tabs.Tab>
|
|
207
|
+
<Tabs.Tab>
|
|
208
|
+
Index names must:
|
|
209
|
+
- Use only lowercase letters, numbers, and dashes
|
|
210
|
+
- Not contain dots (used for DNS routing)
|
|
211
|
+
- Not use non-Latin characters or emojis
|
|
212
|
+
- Have a combined length (with project ID) under 52 characters
|
|
213
|
+
- Example: `my-index-123` is valid
|
|
214
|
+
- Example: `my.index` is not valid (contains dot)
|
|
215
|
+
</Tabs.Tab>
|
|
216
|
+
<Tabs.Tab>
|
|
217
|
+
Collection names must:
|
|
218
|
+
- Be 1-255 characters long
|
|
219
|
+
- Not contain any of these special characters:
|
|
220
|
+
- `< > : " / \ | ? *`
|
|
221
|
+
- Null character (`\0`)
|
|
222
|
+
- Unit separator (`\u{1F}`)
|
|
223
|
+
- Example: `my_collection_123` is valid
|
|
224
|
+
- Example: `my/collection` is not valid (contains slash)
|
|
225
|
+
</Tabs.Tab>
|
|
226
|
+
<Tabs.Tab>
|
|
227
|
+
Collection names must:
|
|
228
|
+
- Be 3-63 characters long
|
|
229
|
+
- Start and end with a letter or number
|
|
230
|
+
- Contain only letters, numbers, underscores, or hyphens
|
|
231
|
+
- Not contain consecutive periods (..)
|
|
232
|
+
- Not be a valid IPv4 address
|
|
233
|
+
- Example: `my-collection-123` is valid
|
|
234
|
+
- Example: `my..collection` is not valid (consecutive periods)
|
|
235
|
+
</Tabs.Tab>
|
|
236
|
+
<Tabs.Tab>
|
|
237
|
+
Collection names must:
|
|
238
|
+
- Not be empty
|
|
239
|
+
- Be 48 characters or less
|
|
240
|
+
- Contain only letters, numbers, and underscores
|
|
241
|
+
- Example: `my_collection_123` is valid
|
|
242
|
+
- Example: `my-collection` is not valid (contains hyphen)
|
|
243
|
+
</Tabs.Tab>
|
|
244
|
+
<Tabs.Tab>
|
|
245
|
+
Index names must:
|
|
246
|
+
- Start with a letter or underscore
|
|
247
|
+
- Contain only letters, numbers, and underscores
|
|
248
|
+
- Example: `my_index_123` is valid
|
|
249
|
+
- Example: `my-index` is not valid (contains hyphen)
|
|
250
|
+
</Tabs.Tab>
|
|
251
|
+
<Tabs.Tab>
|
|
252
|
+
Namespace names must:
|
|
253
|
+
- Be 2-100 characters long
|
|
254
|
+
- Contain only:
|
|
255
|
+
- Alphanumeric characters (a-z, A-Z, 0-9)
|
|
256
|
+
- Underscores, hyphens, dots
|
|
257
|
+
- Not start or end with special characters (_, -, .)
|
|
258
|
+
- Can be case-sensitive
|
|
259
|
+
- Example: `MyNamespace123` is valid
|
|
260
|
+
- Example: `_namespace` is not valid (starts with underscore)
|
|
261
|
+
</Tabs.Tab>
|
|
262
|
+
<Tabs.Tab>
|
|
263
|
+
Index names must:
|
|
264
|
+
- Start with a letter
|
|
265
|
+
- Be shorter than 32 characters
|
|
266
|
+
- Contain only lowercase ASCII letters, numbers, and dashes
|
|
267
|
+
- Use dashes instead of spaces
|
|
268
|
+
- Example: `my-index-123` is valid
|
|
269
|
+
- Example: `My_Index` is not valid (uppercase and underscore)
|
|
270
|
+
</Tabs.Tab>
|
|
271
|
+
</Tabs>
|
|
272
|
+
|
|
273
|
+
### Upserting Embeddings
|
|
274
|
+
|
|
275
|
+
After creating an index, you can store embeddings along with their basic metadata:
|
|
276
|
+
|
|
277
|
+
```ts filename="store-embeddings.ts" showLineNumbers copy
|
|
278
|
+
// Store embeddings with their corresponding metadata
|
|
279
|
+
await store.upsert({
|
|
280
|
+
indexName: 'myCollection', // index name
|
|
281
|
+
vectors: embeddings, // array of embedding vectors
|
|
282
|
+
metadata: chunks.map(chunk => ({
|
|
283
|
+
text: chunk.text, // The original text content
|
|
284
|
+
id: chunk.id // Optional unique identifier
|
|
285
|
+
}))
|
|
286
|
+
});
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
The upsert operation:
|
|
290
|
+
- Takes an array of embedding vectors and their corresponding metadata
|
|
291
|
+
- Updates existing vectors if they share the same ID
|
|
292
|
+
- Creates new vectors if they don't exist
|
|
293
|
+
- Automatically handles batching for large datasets
|
|
294
|
+
|
|
295
|
+
For complete examples of upserting embeddings in different vector stores, see the [Upsert Embeddings](../../examples/rag/upsert/upsert-embeddings.mdx) guide.
|
|
296
|
+
|
|
297
|
+
## Adding Metadata
|
|
298
|
+
|
|
299
|
+
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.
|
|
300
|
+
|
|
301
|
+
**Important**: Metadata is crucial for vector storage - without it, you'd only have numerical embeddings with no way to return the original text or filter results. Always store at least the source text as metadata.
|
|
302
|
+
|
|
303
|
+
```ts showLineNumbers copy
|
|
304
|
+
// Store embeddings with rich metadata for better organization and filtering
|
|
305
|
+
await store.upsert({
|
|
306
|
+
indexName: "myCollection",
|
|
307
|
+
vectors: embeddings,
|
|
308
|
+
metadata: chunks.map((chunk) => ({
|
|
309
|
+
// Basic content
|
|
310
|
+
text: chunk.text,
|
|
311
|
+
id: chunk.id,
|
|
312
|
+
|
|
313
|
+
// Document organization
|
|
314
|
+
source: chunk.source,
|
|
315
|
+
category: chunk.category,
|
|
316
|
+
|
|
317
|
+
// Temporal metadata
|
|
318
|
+
createdAt: new Date().toISOString(),
|
|
319
|
+
version: "1.0",
|
|
320
|
+
|
|
321
|
+
// Custom fields
|
|
322
|
+
language: chunk.language,
|
|
323
|
+
author: chunk.author,
|
|
324
|
+
confidenceScore: chunk.score,
|
|
325
|
+
})),
|
|
326
|
+
});
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Key metadata considerations:
|
|
330
|
+
- Be strict with field naming - inconsistencies like 'category' vs 'Category' will affect queries
|
|
331
|
+
- Only include fields you plan to filter or sort by - extra fields add overhead
|
|
332
|
+
- Add timestamps (e.g., 'createdAt', 'lastUpdated') to track content freshness
|
|
333
|
+
|
|
334
|
+
## Best Practices
|
|
335
|
+
|
|
336
|
+
- Create indexes before bulk insertions
|
|
337
|
+
- Use batch operations for large insertions (the upsert method handles batching automatically)
|
|
338
|
+
- Only store metadata you'll query against
|
|
339
|
+
- Match embedding dimensions to your model (e.g., 1536 for `text-embedding-3-small`)
|
|
340
|
+
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: createTool() | Tools | Agents | Mastra Docs"
|
|
3
|
+
description: Documentation for the createTool function in Mastra, which creates custom tools for agents and workflows.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# `createTool()`
|
|
7
|
+
|
|
8
|
+
The `createTool()` function creates typed tools that can be executed by agents or workflows. Tools have built-in schema validation, execution context, and integration with the Mastra ecosystem.
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
Tools are a fundamental building block in Mastra that allow agents to interact with external systems, perform computations, and access data. Each tool has:
|
|
13
|
+
|
|
14
|
+
- A unique identifier
|
|
15
|
+
- A description that helps the AI understand when and how to use the tool
|
|
16
|
+
- Optional input and output schemas for validation
|
|
17
|
+
- An execution function that implements the tool's logic
|
|
18
|
+
|
|
19
|
+
## Example Usage
|
|
20
|
+
|
|
21
|
+
```ts filename="src/tools/stock-tools.ts" showLineNumbers copy
|
|
22
|
+
import { createTool } from "@mastra/core/tools";
|
|
23
|
+
import { z } from "zod";
|
|
24
|
+
|
|
25
|
+
// Helper function to fetch stock data
|
|
26
|
+
const getStockPrice = async (symbol: string) => {
|
|
27
|
+
const response = await fetch(
|
|
28
|
+
`https://mastra-stock-data.vercel.app/api/stock-data?symbol=${symbol}`
|
|
29
|
+
);
|
|
30
|
+
const data = await response.json();
|
|
31
|
+
return data.prices["4. close"];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Create a tool to get stock prices
|
|
35
|
+
export const stockPriceTool = createTool({
|
|
36
|
+
id: "getStockPrice",
|
|
37
|
+
description: "Fetches the current stock price for a given ticker symbol",
|
|
38
|
+
inputSchema: z.object({
|
|
39
|
+
symbol: z.string().describe("The stock ticker symbol (e.g., AAPL, MSFT)")
|
|
40
|
+
}),
|
|
41
|
+
outputSchema: z.object({
|
|
42
|
+
symbol: z.string(),
|
|
43
|
+
price: z.number(),
|
|
44
|
+
currency: z.string(),
|
|
45
|
+
timestamp: z.string()
|
|
46
|
+
}),
|
|
47
|
+
execute: async ({ context }) => {
|
|
48
|
+
const price = await getStockPrice(context.symbol);
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
symbol: context.symbol,
|
|
52
|
+
price: parseFloat(price),
|
|
53
|
+
currency: "USD",
|
|
54
|
+
timestamp: new Date().toISOString()
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Create a tool that uses the thread context
|
|
60
|
+
export const threadInfoTool = createTool({
|
|
61
|
+
id: "getThreadInfo",
|
|
62
|
+
description: "Returns information about the current conversation thread",
|
|
63
|
+
inputSchema: z.object({
|
|
64
|
+
includeResource: z.boolean().optional().default(false)
|
|
65
|
+
}),
|
|
66
|
+
execute: async ({ context, threadId, resourceId }) => {
|
|
67
|
+
return {
|
|
68
|
+
threadId,
|
|
69
|
+
resourceId: context.includeResource ? resourceId : undefined,
|
|
70
|
+
timestamp: new Date().toISOString()
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## API Reference
|
|
77
|
+
|
|
78
|
+
### Parameters
|
|
79
|
+
|
|
80
|
+
`createTool()` accepts a single object with the following properties:
|
|
81
|
+
|
|
82
|
+
<PropertiesTable
|
|
83
|
+
content={[
|
|
84
|
+
{
|
|
85
|
+
name: "id",
|
|
86
|
+
type: "string",
|
|
87
|
+
required: true,
|
|
88
|
+
description: "Unique identifier for the tool. This should be descriptive of the tool's function."
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "description",
|
|
92
|
+
type: "string",
|
|
93
|
+
required: true,
|
|
94
|
+
description: "Detailed description of what the tool does, when it should be used, and what inputs it requires. This helps the AI understand how to use the tool effectively."
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "execute",
|
|
98
|
+
type: "(context: ToolExecutionContext, options?: any) => Promise<any>",
|
|
99
|
+
required: false,
|
|
100
|
+
description: "Async function that implements the tool's logic. Receives the execution context and optional configuration.",
|
|
101
|
+
properties: [
|
|
102
|
+
{
|
|
103
|
+
type: "ToolExecutionContext",
|
|
104
|
+
parameters: [
|
|
105
|
+
{
|
|
106
|
+
name: "context",
|
|
107
|
+
type: "object",
|
|
108
|
+
description: "The validated input data that matches the inputSchema"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: "threadId",
|
|
112
|
+
type: "string",
|
|
113
|
+
isOptional: true,
|
|
114
|
+
description: "Identifier for the conversation thread, if available"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: "resourceId",
|
|
118
|
+
type: "string",
|
|
119
|
+
isOptional: true,
|
|
120
|
+
description: "Identifier for the user or resource interacting with the tool"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: "mastra",
|
|
124
|
+
type: "Mastra",
|
|
125
|
+
isOptional: true,
|
|
126
|
+
description: "Reference to the Mastra instance, if available"
|
|
127
|
+
},
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
type: "ToolOptions",
|
|
132
|
+
parameters: [
|
|
133
|
+
{
|
|
134
|
+
name: "toolCallId",
|
|
135
|
+
type: "string",
|
|
136
|
+
description: "The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data."
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "messages",
|
|
140
|
+
type: "CoreMessage[]",
|
|
141
|
+
description: "Messages that were sent to the language model to initiate the response that contained the tool call. The messages do not include the system prompt nor the assistant response that contained the tool call."
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
name: "abortSignal",
|
|
145
|
+
type: "AbortSignal",
|
|
146
|
+
isOptional: true,
|
|
147
|
+
description: "An optional abort signal that indicates that the overall operation should be aborted."
|
|
148
|
+
},
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
name: "inputSchema",
|
|
155
|
+
type: "ZodSchema",
|
|
156
|
+
required: false,
|
|
157
|
+
description: "Zod schema that defines and validates the tool's input parameters. If not provided, the tool will accept any input."
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
name: "outputSchema",
|
|
161
|
+
type: "ZodSchema",
|
|
162
|
+
required: false,
|
|
163
|
+
description: "Zod schema that defines and validates the tool's output. Helps ensure the tool returns data in the expected format."
|
|
164
|
+
},
|
|
165
|
+
]}
|
|
166
|
+
/>
|
|
167
|
+
|
|
168
|
+
### Returns
|
|
169
|
+
|
|
170
|
+
<PropertiesTable
|
|
171
|
+
content={[
|
|
172
|
+
{
|
|
173
|
+
name: "Tool",
|
|
174
|
+
type: "Tool<TSchemaIn, TSchemaOut>",
|
|
175
|
+
description: "A Tool instance that can be used with agents, workflows, or directly executed.",
|
|
176
|
+
properties: [
|
|
177
|
+
{
|
|
178
|
+
type: "Tool",
|
|
179
|
+
parameters: [
|
|
180
|
+
{
|
|
181
|
+
name: "id",
|
|
182
|
+
type: "string",
|
|
183
|
+
description: "The tool's unique identifier"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
name: "description",
|
|
187
|
+
type: "string",
|
|
188
|
+
description: "Description of the tool's functionality"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
name: "inputSchema",
|
|
192
|
+
type: "ZodSchema | undefined",
|
|
193
|
+
description: "Schema for validating inputs"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
name: "outputSchema",
|
|
197
|
+
type: "ZodSchema | undefined",
|
|
198
|
+
description: "Schema for validating outputs"
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
name: "execute",
|
|
202
|
+
type: "Function",
|
|
203
|
+
description: "The tool's execution function"
|
|
204
|
+
}
|
|
205
|
+
]
|
|
206
|
+
}
|
|
207
|
+
]
|
|
208
|
+
}
|
|
209
|
+
]}
|
|
210
|
+
/>
|
|
211
|
+
|
|
212
|
+
## Type Safety
|
|
213
|
+
|
|
214
|
+
The `createTool()` function provides full type safety through TypeScript generics:
|
|
215
|
+
|
|
216
|
+
- Input types are inferred from the `inputSchema`
|
|
217
|
+
- Output types are inferred from the `outputSchema`
|
|
218
|
+
- The execution context is properly typed based on the input schema
|
|
219
|
+
|
|
220
|
+
This ensures that your tools are type-safe throughout your application.
|
|
221
|
+
|
|
222
|
+
## Best Practices
|
|
223
|
+
|
|
224
|
+
1. **Descriptive IDs**: Use clear, action-oriented IDs like `getWeatherForecast` or `searchDatabase`
|
|
225
|
+
2. **Detailed Descriptions**: Provide comprehensive descriptions that explain when and how to use the tool
|
|
226
|
+
3. **Input Validation**: Use Zod schemas to validate inputs and provide helpful error messages
|
|
227
|
+
4. **Error Handling**: Implement proper error handling in your execute function
|
|
228
|
+
5. **Idempotency**: When possible, make your tools idempotent (same input always produces same output)
|
|
229
|
+
6. **Performance**: Keep tools lightweight and fast to execute
|