@mastra/mcp-docs-server 0.0.0-commonjs-20250414101718
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +161 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +110 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +26 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +196 -0
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +250 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +250 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
- package/.docs/organized/changelogs/create-mastra.md +302 -0
- package/.docs/organized/changelogs/mastra.md +302 -0
- package/.docs/organized/code-examples/agent-network.md +282 -0
- package/.docs/organized/code-examples/agent.md +388 -0
- package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
- package/.docs/organized/code-examples/assistant-ui.md +37 -0
- package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
- package/.docs/organized/code-examples/client-side-tools.md +69 -0
- package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
- package/.docs/organized/code-examples/fireworks-r1.md +159 -0
- package/.docs/organized/code-examples/mcp-registry-registry.md +63 -0
- package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
- package/.docs/organized/code-examples/memory-with-context.md +167 -0
- package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
- package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
- package/.docs/organized/code-examples/memory-with-pg.md +224 -0
- package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
- package/.docs/organized/code-examples/quick-start.md +129 -0
- package/.docs/organized/code-examples/stock-price-tool.md +124 -0
- package/.docs/organized/code-examples/weather-agent.md +353 -0
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
- package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
- package/.docs/raw/agents/adding-tools.mdx +317 -0
- package/.docs/raw/agents/adding-voice.mdx +175 -0
- package/.docs/raw/agents/agent-memory.mdx +62 -0
- package/.docs/raw/agents/mcp-guide.mdx +215 -0
- package/.docs/raw/agents/overview.mdx +303 -0
- package/.docs/raw/community/discord.mdx +12 -0
- package/.docs/raw/community/licensing.mdx +63 -0
- package/.docs/raw/deployment/client.mdx +120 -0
- package/.docs/raw/deployment/deployment.mdx +127 -0
- package/.docs/raw/deployment/server.mdx +282 -0
- package/.docs/raw/evals/custom-eval.mdx +22 -0
- package/.docs/raw/evals/overview.mdx +95 -0
- package/.docs/raw/evals/running-in-ci.mdx +81 -0
- package/.docs/raw/evals/textual-evals.mdx +54 -0
- package/.docs/raw/faq/index.mdx +63 -0
- package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
- package/.docs/raw/frameworks/next-js.mdx +238 -0
- package/.docs/raw/getting-started/installation.mdx +442 -0
- package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
- package/.docs/raw/getting-started/project-structure.mdx +80 -0
- package/.docs/raw/index.mdx +22 -0
- package/.docs/raw/integrations/index.mdx +213 -0
- package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
- package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
- package/.docs/raw/local-dev/mastra-dev.mdx +108 -0
- package/.docs/raw/memory/memory-processors.mdx +131 -0
- package/.docs/raw/memory/overview.mdx +119 -0
- package/.docs/raw/memory/semantic-recall.mdx +122 -0
- package/.docs/raw/memory/working-memory.mdx +87 -0
- package/.docs/raw/observability/logging.mdx +38 -0
- package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
- package/.docs/raw/observability/tracing.mdx +115 -0
- package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
- package/.docs/raw/rag/overview.mdx +85 -0
- package/.docs/raw/rag/retrieval.mdx +365 -0
- package/.docs/raw/rag/vector-databases.mdx +340 -0
- package/.docs/raw/reference/agents/createTool.mdx +229 -0
- package/.docs/raw/reference/agents/generate.mdx +334 -0
- package/.docs/raw/reference/agents/getAgent.mdx +54 -0
- package/.docs/raw/reference/agents/stream.mdx +369 -0
- package/.docs/raw/reference/cli/build.mdx +55 -0
- package/.docs/raw/reference/cli/dev.mdx +134 -0
- package/.docs/raw/reference/cli/init.mdx +43 -0
- package/.docs/raw/reference/client-js/agents.mdx +107 -0
- package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
- package/.docs/raw/reference/client-js/logs.mdx +24 -0
- package/.docs/raw/reference/client-js/memory.mdx +97 -0
- package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
- package/.docs/raw/reference/client-js/tools.mdx +44 -0
- package/.docs/raw/reference/client-js/vectors.mdx +79 -0
- package/.docs/raw/reference/client-js/workflows.mdx +136 -0
- package/.docs/raw/reference/core/mastra-class.mdx +232 -0
- package/.docs/raw/reference/deployer/cloudflare.mdx +207 -0
- package/.docs/raw/reference/deployer/deployer.mdx +159 -0
- package/.docs/raw/reference/deployer/netlify.mdx +109 -0
- package/.docs/raw/reference/deployer/vercel.mdx +117 -0
- package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
- package/.docs/raw/reference/evals/bias.mdx +186 -0
- package/.docs/raw/reference/evals/completeness.mdx +174 -0
- package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
- package/.docs/raw/reference/evals/context-position.mdx +190 -0
- package/.docs/raw/reference/evals/context-precision.mdx +189 -0
- package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
- package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
- package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
- package/.docs/raw/reference/evals/hallucination.mdx +219 -0
- package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
- package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
- package/.docs/raw/reference/evals/summarization.mdx +205 -0
- package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
- package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
- package/.docs/raw/reference/evals/toxicity.mdx +165 -0
- package/.docs/raw/reference/index.mdx +12 -0
- package/.docs/raw/reference/memory/Memory.mdx +212 -0
- package/.docs/raw/reference/memory/createThread.mdx +95 -0
- package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
- package/.docs/raw/reference/memory/query.mdx +167 -0
- package/.docs/raw/reference/networks/agent-network.mdx +159 -0
- package/.docs/raw/reference/observability/create-logger.mdx +106 -0
- package/.docs/raw/reference/observability/logger.mdx +55 -0
- package/.docs/raw/reference/observability/otel-config.mdx +120 -0
- package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
- package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
- package/.docs/raw/reference/observability/providers/index.mdx +16 -0
- package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
- package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
- package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
- package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
- package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
- package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
- package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
- package/.docs/raw/reference/rag/astra.mdx +258 -0
- package/.docs/raw/reference/rag/chroma.mdx +281 -0
- package/.docs/raw/reference/rag/chunk.mdx +235 -0
- package/.docs/raw/reference/rag/document.mdx +127 -0
- package/.docs/raw/reference/rag/embeddings.mdx +160 -0
- package/.docs/raw/reference/rag/extract-params.mdx +226 -0
- package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
- package/.docs/raw/reference/rag/libsql.mdx +357 -0
- package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
- package/.docs/raw/reference/rag/pg.mdx +477 -0
- package/.docs/raw/reference/rag/pinecone.mdx +281 -0
- package/.docs/raw/reference/rag/qdrant.mdx +236 -0
- package/.docs/raw/reference/rag/rerank.mdx +212 -0
- package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
- package/.docs/raw/reference/rag/upstash.mdx +247 -0
- package/.docs/raw/reference/rag/vectorize.mdx +298 -0
- package/.docs/raw/reference/storage/libsql.mdx +74 -0
- package/.docs/raw/reference/storage/postgresql.mdx +48 -0
- package/.docs/raw/reference/storage/upstash.mdx +86 -0
- package/.docs/raw/reference/tools/client.mdx +207 -0
- package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
- package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
- package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
- package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
- package/.docs/raw/reference/voice/deepgram.mdx +164 -0
- package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
- package/.docs/raw/reference/voice/google.mdx +198 -0
- package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
- package/.docs/raw/reference/voice/murf.mdx +251 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
- package/.docs/raw/reference/voice/openai.mdx +168 -0
- package/.docs/raw/reference/voice/playai.mdx +159 -0
- package/.docs/raw/reference/voice/sarvam.mdx +260 -0
- package/.docs/raw/reference/voice/speechify.mdx +145 -0
- package/.docs/raw/reference/voice/voice.answer.mdx +122 -0
- package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
- package/.docs/raw/reference/voice/voice.listen.mdx +195 -0
- package/.docs/raw/reference/voice/voice.on.mdx +189 -0
- package/.docs/raw/reference/voice/voice.send.mdx +118 -0
- package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
- package/.docs/raw/reference/workflows/after.mdx +88 -0
- package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
- package/.docs/raw/reference/workflows/commit.mdx +37 -0
- package/.docs/raw/reference/workflows/createRun.mdx +77 -0
- package/.docs/raw/reference/workflows/else.mdx +72 -0
- package/.docs/raw/reference/workflows/events.mdx +305 -0
- package/.docs/raw/reference/workflows/execute.mdx +110 -0
- package/.docs/raw/reference/workflows/if.mdx +107 -0
- package/.docs/raw/reference/workflows/resume.mdx +155 -0
- package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
- package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
- package/.docs/raw/reference/workflows/start.mdx +84 -0
- package/.docs/raw/reference/workflows/step-class.mdx +100 -0
- package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
- package/.docs/raw/reference/workflows/step-function.mdx +92 -0
- package/.docs/raw/reference/workflows/step-options.mdx +69 -0
- package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
- package/.docs/raw/reference/workflows/suspend.mdx +70 -0
- package/.docs/raw/reference/workflows/then.mdx +74 -0
- package/.docs/raw/reference/workflows/until.mdx +165 -0
- package/.docs/raw/reference/workflows/watch.mdx +118 -0
- package/.docs/raw/reference/workflows/while.mdx +168 -0
- package/.docs/raw/reference/workflows/workflow.mdx +233 -0
- package/.docs/raw/storage/overview.mdx +378 -0
- package/.docs/raw/voice/overview.mdx +135 -0
- package/.docs/raw/voice/speech-to-text.mdx +45 -0
- package/.docs/raw/voice/text-to-speech.mdx +52 -0
- package/.docs/raw/voice/voice-to-voice.mdx +310 -0
- package/.docs/raw/workflows/control-flow.mdx +778 -0
- package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
- package/.docs/raw/workflows/error-handling.mdx +183 -0
- package/.docs/raw/workflows/nested-workflows.mdx +352 -0
- package/.docs/raw/workflows/overview.mdx +203 -0
- package/.docs/raw/workflows/steps.mdx +108 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
- package/.docs/raw/workflows/variables.mdx +313 -0
- package/LICENSE.md +46 -0
- package/README.md +129 -0
- package/dist/_tsup-dts-rollup.d.ts +149 -0
- package/dist/chunk-QWYMT5LP.js +194 -0
- package/dist/prepare-docs/prepare.d.ts +1 -0
- package/dist/prepare-docs/prepare.js +1 -0
- package/dist/stdio.d.ts +1 -0
- package/dist/stdio.js +518 -0
- package/package.json +60 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: createDocumentChunkerTool() | Tools | Mastra Docs"
|
|
3
|
+
description: Documentation for the Document Chunker Tool in Mastra, which splits documents into smaller chunks for efficient processing and retrieval.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# createDocumentChunkerTool()
|
|
7
|
+
|
|
8
|
+
The `createDocumentChunkerTool()` function creates a tool for splitting documents into smaller chunks for efficient processing and retrieval. It supports different chunking strategies and configurable parameters.
|
|
9
|
+
|
|
10
|
+
## Basic Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { createDocumentChunkerTool, MDocument } from "@mastra/rag";
|
|
14
|
+
|
|
15
|
+
const document = new MDocument({
|
|
16
|
+
text: "Your document content here...",
|
|
17
|
+
metadata: { source: "user-manual" }
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const chunker = createDocumentChunkerTool({
|
|
21
|
+
doc: document,
|
|
22
|
+
params: {
|
|
23
|
+
strategy: "recursive",
|
|
24
|
+
size: 512,
|
|
25
|
+
overlap: 50,
|
|
26
|
+
separator: "\n"
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const { chunks } = await chunker.execute();
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Parameters
|
|
34
|
+
|
|
35
|
+
<PropertiesTable
|
|
36
|
+
content={[
|
|
37
|
+
{
|
|
38
|
+
name: "doc",
|
|
39
|
+
type: "MDocument",
|
|
40
|
+
description: "The document to be chunked",
|
|
41
|
+
isOptional: false,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "params",
|
|
45
|
+
type: "ChunkParams",
|
|
46
|
+
description: "Configuration parameters for chunking",
|
|
47
|
+
isOptional: true,
|
|
48
|
+
defaultValue: "Default chunking parameters",
|
|
49
|
+
}
|
|
50
|
+
]}
|
|
51
|
+
/>
|
|
52
|
+
|
|
53
|
+
### ChunkParams
|
|
54
|
+
|
|
55
|
+
<PropertiesTable
|
|
56
|
+
content={[
|
|
57
|
+
{
|
|
58
|
+
name: "strategy",
|
|
59
|
+
type: "'recursive'",
|
|
60
|
+
description: "The chunking strategy to use",
|
|
61
|
+
isOptional: true,
|
|
62
|
+
defaultValue: "'recursive'",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "size",
|
|
66
|
+
type: "number",
|
|
67
|
+
description: "Target size of each chunk in tokens/characters",
|
|
68
|
+
isOptional: true,
|
|
69
|
+
defaultValue: "512",
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: "overlap",
|
|
73
|
+
type: "number",
|
|
74
|
+
description: "Number of overlapping tokens/characters between chunks",
|
|
75
|
+
isOptional: true,
|
|
76
|
+
defaultValue: "50",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "separator",
|
|
80
|
+
type: "string",
|
|
81
|
+
description: "Character(s) to use as chunk separator",
|
|
82
|
+
isOptional: true,
|
|
83
|
+
defaultValue: "'\\n'",
|
|
84
|
+
}
|
|
85
|
+
]}
|
|
86
|
+
/>
|
|
87
|
+
|
|
88
|
+
## Returns
|
|
89
|
+
|
|
90
|
+
<PropertiesTable
|
|
91
|
+
content={[
|
|
92
|
+
{
|
|
93
|
+
name: "chunks",
|
|
94
|
+
type: "DocumentChunk[]",
|
|
95
|
+
description: "Array of document chunks with their content and metadata",
|
|
96
|
+
}
|
|
97
|
+
]}
|
|
98
|
+
/>
|
|
99
|
+
|
|
100
|
+
## Example with Custom Parameters
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
const technicalDoc = new MDocument({
|
|
104
|
+
text: longDocumentContent,
|
|
105
|
+
metadata: {
|
|
106
|
+
type: "technical",
|
|
107
|
+
version: "1.0"
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const chunker = createDocumentChunkerTool({
|
|
112
|
+
doc: technicalDoc,
|
|
113
|
+
params: {
|
|
114
|
+
strategy: "recursive",
|
|
115
|
+
size: 1024, // Larger chunks
|
|
116
|
+
overlap: 100, // More overlap
|
|
117
|
+
separator: "\n\n" // Split on double newlines
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const { chunks } = await chunker.execute();
|
|
122
|
+
|
|
123
|
+
// Process the chunks
|
|
124
|
+
chunks.forEach((chunk, index) => {
|
|
125
|
+
console.log(`Chunk ${index + 1} length: ${chunk.content.length}`);
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Tool Details
|
|
130
|
+
|
|
131
|
+
The chunker is created as a Mastra tool with the following properties:
|
|
132
|
+
|
|
133
|
+
- **Tool ID**: `Document Chunker {strategy} {size}`
|
|
134
|
+
- **Description**: `Chunks document using {strategy} strategy with size {size} and {overlap} overlap`
|
|
135
|
+
- **Input Schema**: Empty object (no additional inputs required)
|
|
136
|
+
- **Output Schema**: Object containing the chunks array
|
|
137
|
+
|
|
138
|
+
## Related
|
|
139
|
+
|
|
140
|
+
- [MDocument](../rag/document.mdx)
|
|
141
|
+
- [createVectorQueryTool](./vector-query-tool)
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: createGraphRAGTool() | RAG | Mastra Tools Docs"
|
|
3
|
+
description: Documentation for the Graph RAG Tool in Mastra, which enhances RAG by building a graph of semantic relationships between documents.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# createGraphRAGTool()
|
|
7
|
+
|
|
8
|
+
The `createGraphRAGTool()` creates a tool that enhances RAG by building a graph of semantic relationships between documents. It uses the `GraphRAG` system under the hood to provide graph-based retrieval, finding relevant content through both direct similarity and connected relationships.
|
|
9
|
+
|
|
10
|
+
## Usage Example
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { openai } from "@ai-sdk/openai";
|
|
14
|
+
import { createGraphRAGTool } from "@mastra/rag";
|
|
15
|
+
|
|
16
|
+
const graphTool = createGraphRAGTool({
|
|
17
|
+
vectorStoreName: "pinecone",
|
|
18
|
+
indexName: "docs",
|
|
19
|
+
model: openai.embedding('text-embedding-3-small'),
|
|
20
|
+
graphOptions: {
|
|
21
|
+
dimension: 1536,
|
|
22
|
+
threshold: 0.7,
|
|
23
|
+
randomWalkSteps: 100,
|
|
24
|
+
restartProb: 0.15
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Parameters
|
|
30
|
+
|
|
31
|
+
<PropertiesTable
|
|
32
|
+
content={[
|
|
33
|
+
{
|
|
34
|
+
name: "vectorStoreName",
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "Name of the vector store to query",
|
|
37
|
+
isOptional: false,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "indexName",
|
|
41
|
+
type: "string",
|
|
42
|
+
description: "Name of the index within the vector store",
|
|
43
|
+
isOptional: false,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "model",
|
|
47
|
+
type: "EmbeddingModel",
|
|
48
|
+
description: "Embedding model to use for vector search",
|
|
49
|
+
isOptional: false,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: "graphOptions",
|
|
53
|
+
type: "GraphOptions",
|
|
54
|
+
description: "Configuration for the graph-based retrieval",
|
|
55
|
+
isOptional: true,
|
|
56
|
+
defaultValue: "Default graph options",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "description",
|
|
60
|
+
type: "string",
|
|
61
|
+
description: "Custom description for the tool. By default: 'Access and analyze relationships between information in the knowledge base to answer complex questions about connections and patterns'",
|
|
62
|
+
isOptional: true,
|
|
63
|
+
}
|
|
64
|
+
]}
|
|
65
|
+
/>
|
|
66
|
+
|
|
67
|
+
### GraphOptions
|
|
68
|
+
|
|
69
|
+
<PropertiesTable
|
|
70
|
+
content={[
|
|
71
|
+
{
|
|
72
|
+
name: "dimension",
|
|
73
|
+
type: "number",
|
|
74
|
+
description: "Dimension of the embedding vectors",
|
|
75
|
+
isOptional: true,
|
|
76
|
+
defaultValue: "1536",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "threshold",
|
|
80
|
+
type: "number",
|
|
81
|
+
description: "Similarity threshold for creating edges between nodes (0-1)",
|
|
82
|
+
isOptional: true,
|
|
83
|
+
defaultValue: "0.7",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "randomWalkSteps",
|
|
87
|
+
type: "number",
|
|
88
|
+
description: "Number of steps in random walk for graph traversal",
|
|
89
|
+
isOptional: true,
|
|
90
|
+
defaultValue: "100",
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "restartProb",
|
|
94
|
+
type: "number",
|
|
95
|
+
description: "Probability of restarting random walk from query node",
|
|
96
|
+
isOptional: true,
|
|
97
|
+
defaultValue: "0.15",
|
|
98
|
+
}
|
|
99
|
+
]}
|
|
100
|
+
/>
|
|
101
|
+
|
|
102
|
+
## Returns
|
|
103
|
+
The tool returns an object with:
|
|
104
|
+
|
|
105
|
+
<PropertiesTable
|
|
106
|
+
content={[
|
|
107
|
+
{
|
|
108
|
+
name: "relevantContext",
|
|
109
|
+
type: "string",
|
|
110
|
+
description: "Combined text from the most relevant document chunks, retrieved using graph-based ranking",
|
|
111
|
+
}
|
|
112
|
+
]}
|
|
113
|
+
/>
|
|
114
|
+
|
|
115
|
+
## Default Tool Description
|
|
116
|
+
|
|
117
|
+
The default description focuses on:
|
|
118
|
+
- Analyzing relationships between documents
|
|
119
|
+
- Finding patterns and connections
|
|
120
|
+
- Answering complex queries
|
|
121
|
+
|
|
122
|
+
## Advanced Example
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
const graphTool = createGraphRAGTool({
|
|
126
|
+
vectorStoreName: "pinecone",
|
|
127
|
+
indexName: "docs",
|
|
128
|
+
model: openai.embedding('text-embedding-3-small'),
|
|
129
|
+
graphOptions: {
|
|
130
|
+
dimension: 1536,
|
|
131
|
+
threshold: 0.8, // Higher similarity threshold
|
|
132
|
+
randomWalkSteps: 200, // More exploration steps
|
|
133
|
+
restartProb: 0.2 // Higher restart probability
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Example with Custom Description
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
const graphTool = createGraphRAGTool({
|
|
142
|
+
vectorStoreName: "pinecone",
|
|
143
|
+
indexName: "docs",
|
|
144
|
+
model: openai.embedding('text-embedding-3-small'),
|
|
145
|
+
description: "Analyze document relationships to find complex patterns and connections in our company's historical data"
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
This example shows how to customize the tool description for a specific use case while maintaining its core purpose of relationship analysis.
|
|
150
|
+
|
|
151
|
+
## Related
|
|
152
|
+
|
|
153
|
+
- [createVectorQueryTool](./vector-query-tool)
|
|
154
|
+
- [GraphRAG](../rag/graph-rag)
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: MCPConfiguration | Tool Management | Mastra Docs"
|
|
3
|
+
description: API Reference for MCPConfiguration - A class for managing multiple Model Context Protocol servers and their tools.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# MCPConfiguration
|
|
7
|
+
|
|
8
|
+
The `MCPConfiguration` class provides a way to manage multiple MCP server connections and their tools in a Mastra application. It handles connection lifecycle, tool namespacing, and provides convenient access to tools across all configured servers.
|
|
9
|
+
|
|
10
|
+
## Constructor
|
|
11
|
+
|
|
12
|
+
Creates a new instance of the MCPConfiguration class.
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
constructor({
|
|
16
|
+
id?: string;
|
|
17
|
+
servers: Record<string, MastraMCPServerDefinition>
|
|
18
|
+
}: {
|
|
19
|
+
servers: {
|
|
20
|
+
[serverName: string]: {
|
|
21
|
+
// For stdio-based servers
|
|
22
|
+
command?: string;
|
|
23
|
+
args?: string[];
|
|
24
|
+
env?: Record<string, string>;
|
|
25
|
+
// For SSE-based servers
|
|
26
|
+
url?: URL;
|
|
27
|
+
requestInit?: RequestInit;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Parameters
|
|
34
|
+
|
|
35
|
+
<PropertiesTable
|
|
36
|
+
content={[
|
|
37
|
+
{
|
|
38
|
+
name: "id",
|
|
39
|
+
type: "string",
|
|
40
|
+
description:
|
|
41
|
+
"Optional unique identifier for the configuration instance. Use this to prevent memory leaks when creating multiple instances with identical configurations.",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "servers",
|
|
45
|
+
type: "Record<string, MastraMCPServerDefinition>",
|
|
46
|
+
description:
|
|
47
|
+
"A map of server configurations, where each key is a unique server identifier and the value is the server configuration.",
|
|
48
|
+
},
|
|
49
|
+
]}
|
|
50
|
+
/>
|
|
51
|
+
|
|
52
|
+
## Methods
|
|
53
|
+
|
|
54
|
+
### getTools()
|
|
55
|
+
|
|
56
|
+
Retrieves all tools from all configured servers, with tool names namespaced by their server name (in the format `serverName_toolName`) to prevent conflicts.
|
|
57
|
+
Intended to be passed onto an Agent definition.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
new Agent({ tools: await mcp.getTools() });
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### getToolsets()
|
|
64
|
+
|
|
65
|
+
Returns an object mapping namespaced tool names (in the format `serverName.toolName`) to their tool implementations.
|
|
66
|
+
Intended to be passed dynamically into the generate or stream method.
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
const res = await agent.stream(prompt, {
|
|
70
|
+
toolsets: await mcp.getToolsets(),
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Examples
|
|
75
|
+
|
|
76
|
+
### Basic Usage
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { MCPConfiguration } from "@mastra/mcp";
|
|
80
|
+
import { Agent } from "@mastra/core/agent";
|
|
81
|
+
import { openai } from "@ai-sdk/openai";
|
|
82
|
+
|
|
83
|
+
const mcp = new MCPConfiguration({
|
|
84
|
+
servers: {
|
|
85
|
+
stockPrice: {
|
|
86
|
+
command: "npx",
|
|
87
|
+
args: ["tsx", "stock-price.ts"],
|
|
88
|
+
env: {
|
|
89
|
+
API_KEY: "your-api-key",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
weather: {
|
|
93
|
+
url: new URL("http://localhost:8080/sse"),
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Create an agent with access to all tools
|
|
99
|
+
const agent = new Agent({
|
|
100
|
+
name: "Multi-tool Agent",
|
|
101
|
+
instructions: "You have access to multiple tool servers.",
|
|
102
|
+
model: openai("gpt-4"),
|
|
103
|
+
tools: await mcp.getTools(),
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Using Toolsets in generate() or stream()
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { Agent } from "@mastra/core/agent";
|
|
111
|
+
import { MCPConfiguration } from "@mastra/mcp";
|
|
112
|
+
import { openai } from "@ai-sdk/openai";
|
|
113
|
+
|
|
114
|
+
// Create the agent first, without any tools
|
|
115
|
+
const agent = new Agent({
|
|
116
|
+
name: "Multi-tool Agent",
|
|
117
|
+
instructions: "You help users check stocks and weather.",
|
|
118
|
+
model: openai("gpt-4"),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Later, configure MCP with user-specific settings
|
|
122
|
+
const mcp = new MCPConfiguration({
|
|
123
|
+
servers: {
|
|
124
|
+
stockPrice: {
|
|
125
|
+
command: "npx",
|
|
126
|
+
args: ["tsx", "stock-price.ts"],
|
|
127
|
+
env: {
|
|
128
|
+
API_KEY: "user-123-api-key",
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
weather: {
|
|
132
|
+
url: new URL("http://localhost:8080/sse"),
|
|
133
|
+
requestInit: {
|
|
134
|
+
headers: {
|
|
135
|
+
Authorization: `Bearer user-123-token`,
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Pass all toolsets to stream() or generate()
|
|
143
|
+
const response = await agent.stream(
|
|
144
|
+
"How is AAPL doing and what is the weather?",
|
|
145
|
+
{
|
|
146
|
+
toolsets: await mcp.getToolsets(),
|
|
147
|
+
},
|
|
148
|
+
);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Resource Management
|
|
152
|
+
|
|
153
|
+
The `MCPConfiguration` class includes built-in memory leak prevention for managing multiple instances:
|
|
154
|
+
|
|
155
|
+
1. Creating multiple instances with identical configurations without an `id` will throw an error to prevent memory leaks
|
|
156
|
+
2. If you need multiple instances with identical configurations, provide a unique `id` for each instance
|
|
157
|
+
3. Call `await configuration.disconnect()` before recreating an instance with the same configuration
|
|
158
|
+
4. If you only need one instance, consider moving the configuration to a higher scope to avoid recreation
|
|
159
|
+
|
|
160
|
+
For example, if you try to create multiple instances with the same configuration without an `id`:
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
// First instance - OK
|
|
164
|
+
const mcp1 = new MCPConfiguration({
|
|
165
|
+
servers: {
|
|
166
|
+
/* ... */
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Second instance with same config - Will throw an error
|
|
171
|
+
const mcp2 = new MCPConfiguration({
|
|
172
|
+
servers: {
|
|
173
|
+
/* ... */
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// To fix, either:
|
|
178
|
+
// 1. Add unique IDs
|
|
179
|
+
const mcp3 = new MCPConfiguration({
|
|
180
|
+
id: "instance-1",
|
|
181
|
+
servers: {
|
|
182
|
+
/* ... */
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// 2. Or disconnect before recreating
|
|
187
|
+
await mcp1.disconnect();
|
|
188
|
+
const mcp4 = new MCPConfiguration({
|
|
189
|
+
servers: {
|
|
190
|
+
/* ... */
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Server Lifecycle
|
|
196
|
+
|
|
197
|
+
MCPConfiguration handles server connections gracefully:
|
|
198
|
+
|
|
199
|
+
1. Automatic connection management for multiple servers
|
|
200
|
+
2. Graceful server shutdown to prevent error messages during development
|
|
201
|
+
3. Proper cleanup of resources when disconnecting
|
|
202
|
+
|
|
203
|
+
## Related Information
|
|
204
|
+
|
|
205
|
+
- For details about individual MCP client configuration, see the [MastraMCPClient documentation](./client)
|
|
206
|
+
- For more about the Model Context Protocol, see the [@modelcontextprotocol/sdk documentation](https://github.com/modelcontextprotocol/typescript-sdk)
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: createVectorQueryTool() | RAG | Mastra Tools Docs"
|
|
3
|
+
description: Documentation for the Vector Query Tool in Mastra, which facilitates semantic search over vector stores with filtering and reranking capabilities.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# createVectorQueryTool()
|
|
7
|
+
|
|
8
|
+
The `createVectorQueryTool()` function creates a tool for semantic search over vector stores. It supports filtering, reranking, and integrates with various vector store backends.
|
|
9
|
+
|
|
10
|
+
## Basic Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { openai } from '@ai-sdk/openai';
|
|
14
|
+
import { createVectorQueryTool } from "@mastra/rag";
|
|
15
|
+
|
|
16
|
+
const queryTool = createVectorQueryTool({
|
|
17
|
+
vectorStoreName: "pinecone",
|
|
18
|
+
indexName: "docs",
|
|
19
|
+
model: openai.embedding('text-embedding-3-small'),
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Parameters
|
|
24
|
+
|
|
25
|
+
<PropertiesTable
|
|
26
|
+
content={[
|
|
27
|
+
{
|
|
28
|
+
name: "vectorStoreName",
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "Name of the vector store to query (must be configured in Mastra)",
|
|
31
|
+
isOptional: false,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "indexName",
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "Name of the index within the vector store",
|
|
37
|
+
isOptional: false,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "model",
|
|
41
|
+
type: "EmbeddingModel",
|
|
42
|
+
description: "Embedding model to use for vector search",
|
|
43
|
+
isOptional: false,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "reranker",
|
|
47
|
+
type: "RerankConfig",
|
|
48
|
+
description: "Options for reranking results",
|
|
49
|
+
isOptional: true,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: "id",
|
|
53
|
+
type: "string",
|
|
54
|
+
description: "Custom ID for the tool (defaults to 'VectorQuery {vectorStoreName} {indexName} Tool')",
|
|
55
|
+
isOptional: true,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "description",
|
|
59
|
+
type: "string",
|
|
60
|
+
description: "Custom description for the tool. By default: 'Access the knowledge base to find information needed to answer user questions'",
|
|
61
|
+
isOptional: true,
|
|
62
|
+
}
|
|
63
|
+
]}
|
|
64
|
+
/>
|
|
65
|
+
|
|
66
|
+
### RerankConfig
|
|
67
|
+
|
|
68
|
+
<PropertiesTable
|
|
69
|
+
content={[
|
|
70
|
+
{
|
|
71
|
+
name: "model",
|
|
72
|
+
type: "MastraLanguageModel",
|
|
73
|
+
description: "Language model to use for reranking",
|
|
74
|
+
isOptional: false,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: "options",
|
|
78
|
+
type: "RerankerOptions",
|
|
79
|
+
description: "Options for the reranking process",
|
|
80
|
+
isOptional: true,
|
|
81
|
+
properties: [
|
|
82
|
+
{
|
|
83
|
+
type: "object",
|
|
84
|
+
parameters: [
|
|
85
|
+
{
|
|
86
|
+
name: "weights",
|
|
87
|
+
description: "Weights for scoring components (semantic: 0.4, vector: 0.4, position: 0.2)",
|
|
88
|
+
isOptional: true,
|
|
89
|
+
type: "WeightConfig",
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "topK",
|
|
93
|
+
description: "Number of top results to return",
|
|
94
|
+
isOptional: true,
|
|
95
|
+
type: "number",
|
|
96
|
+
defaultValue: "3"
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
]}
|
|
103
|
+
/>
|
|
104
|
+
|
|
105
|
+
## Returns
|
|
106
|
+
|
|
107
|
+
The tool returns an object with:
|
|
108
|
+
|
|
109
|
+
<PropertiesTable
|
|
110
|
+
content={[
|
|
111
|
+
{
|
|
112
|
+
name: "relevantContext",
|
|
113
|
+
type: "string",
|
|
114
|
+
description: "Combined text from the most relevant document chunks",
|
|
115
|
+
}
|
|
116
|
+
]}
|
|
117
|
+
/>
|
|
118
|
+
|
|
119
|
+
## Default Tool Description
|
|
120
|
+
|
|
121
|
+
The default description focuses on:
|
|
122
|
+
- Finding relevant information in stored knowledge
|
|
123
|
+
- Answering user questions
|
|
124
|
+
- Retrieving factual content
|
|
125
|
+
|
|
126
|
+
## Result Handling
|
|
127
|
+
|
|
128
|
+
The tool determines the number of results to return based on the user's query, with a default of 10 results. This can be adjusted based on the query requirements.
|
|
129
|
+
|
|
130
|
+
## Example with Filters
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
const queryTool = createVectorQueryTool({
|
|
134
|
+
vectorStoreName: "pinecone",
|
|
135
|
+
indexName: "docs",
|
|
136
|
+
model: openai.embedding('text-embedding-3-small'),
|
|
137
|
+
enableFilters: true,
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
With filtering enabled, the tool processes queries to construct metadata filters that combine with semantic search. The process works as follows:
|
|
142
|
+
|
|
143
|
+
1. A user makes a query with specific filter requirements like "Find content where the 'version' field is greater than 2.0"
|
|
144
|
+
2. The agent analyzes the query and constructs the appropriate filters:
|
|
145
|
+
```typescript
|
|
146
|
+
{
|
|
147
|
+
"version": { "$gt": 2.0 }
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
This agent-driven approach:
|
|
152
|
+
- Processes natural language queries into filter specifications
|
|
153
|
+
- Implements vector store-specific filter syntax
|
|
154
|
+
- Translates query terms to filter operators
|
|
155
|
+
|
|
156
|
+
For detailed filter syntax and store-specific capabilities, see the [Metadata Filters](../rag/metadata-filters) documentation.
|
|
157
|
+
|
|
158
|
+
For an example of how agent-driven filtering works, see the [Agent-Driven Metadata Filtering](../../../examples/rag/usage/filter-rag) example.
|
|
159
|
+
|
|
160
|
+
## Example with Reranking
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
const queryTool = createVectorQueryTool({
|
|
164
|
+
vectorStoreName: "milvus",
|
|
165
|
+
indexName: "documentation",
|
|
166
|
+
model: openai.embedding('text-embedding-3-small'),
|
|
167
|
+
reranker: {
|
|
168
|
+
model: openai('gpt-4o-mini'),
|
|
169
|
+
options: {
|
|
170
|
+
weights: {
|
|
171
|
+
semantic: 0.5, // Semantic relevance weight
|
|
172
|
+
vector: 0.3, // Vector similarity weight
|
|
173
|
+
position: 0.2 // Original position weight
|
|
174
|
+
},
|
|
175
|
+
topK: 5
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Reranking improves result quality by combining:
|
|
182
|
+
- Semantic relevance: Using LLM-based scoring of text similarity
|
|
183
|
+
- Vector similarity: Original vector distance scores
|
|
184
|
+
- Position bias: Consideration of original result ordering
|
|
185
|
+
- Query analysis: Adjustments based on query characteristics
|
|
186
|
+
|
|
187
|
+
The reranker processes the initial vector search results and returns a reordered list optimized for relevance.
|
|
188
|
+
|
|
189
|
+
## Example with Custom Description
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
const queryTool = createVectorQueryTool({
|
|
193
|
+
vectorStoreName: "pinecone",
|
|
194
|
+
indexName: "docs",
|
|
195
|
+
model: openai.embedding('text-embedding-3-small'),
|
|
196
|
+
description: "Search through document archives to find relevant information for answering questions about company policies and procedures"
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
This example shows how to customize the tool description for a specific use case while maintaining its core purpose of information retrieval.
|
|
201
|
+
|
|
202
|
+
## Tool Details
|
|
203
|
+
|
|
204
|
+
The tool is created with:
|
|
205
|
+
- **ID**: `VectorQuery {vectorStoreName} {indexName} Tool`
|
|
206
|
+
- **Input Schema**: Requires queryText and filter objects
|
|
207
|
+
- **Output Schema**: Returns relevantContext string
|
|
208
|
+
|
|
209
|
+
## Related
|
|
210
|
+
|
|
211
|
+
- [rerank()](../rag/rerank)
|
|
212
|
+
- [createGraphRAGTool](./graph-rag-tool)
|