@mastra/mcp-docs-server 0.13.39 → 1.0.0-beta.0
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/%40internal%2Fai-sdk-v4.md +1 -0
- package/.docs/organized/changelogs/%40internal%2Fchangeset-cli.md +0 -10
- package/.docs/organized/changelogs/%40internal%2Fexternal-types.md +0 -10
- package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +36 -36
- package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +0 -10
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +70 -70
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +40 -40
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fauth.md +4 -14
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +18 -18
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +199 -199
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +223 -223
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +190 -190
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +199 -199
- package/.docs/organized/changelogs/%40mastra%2Fcodemod.md +7 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +214 -214
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +74 -74
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +67 -67
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +70 -70
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +67 -67
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +209 -209
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +191 -191
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +34 -34
- package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +5 -13
- package/.docs/organized/changelogs/%40mastra%2Flance.md +182 -182
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +199 -199
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +58 -58
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +65 -65
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +228 -228
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +199 -199
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +206 -206
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +197 -197
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +217 -217
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Frag.md +61 -61
- package/.docs/organized/changelogs/%40mastra%2Freact.md +70 -70
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -17
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -30
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +206 -206
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +190 -190
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +18 -18
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +56 -56
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +56 -56
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +20 -20
- package/.docs/organized/changelogs/create-mastra.md +33 -33
- package/.docs/organized/changelogs/mastra.md +86 -86
- package/.docs/organized/code-examples/a2a.md +4 -2
- package/.docs/organized/code-examples/agui.md +12 -9
- package/.docs/organized/code-examples/ai-sdk-useChat.md +12 -18
- package/.docs/organized/code-examples/ai-sdk-v5.md +4 -2
- package/.docs/organized/code-examples/bird-checker-with-express.md +5 -4
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +4 -3
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +4 -3
- package/.docs/organized/code-examples/client-side-tools.md +1 -0
- package/.docs/organized/code-examples/crypto-chatbot.md +1 -1
- package/.docs/organized/code-examples/experimental-auth-weather-agent.md +8 -177
- package/.docs/organized/code-examples/fireworks-r1.md +2 -2
- package/.docs/organized/code-examples/heads-up-game.md +10 -7
- package/.docs/organized/code-examples/mcp-configuration.md +5 -3
- package/.docs/organized/code-examples/mcp-registry-registry.md +3 -2
- package/.docs/organized/code-examples/memory-per-resource-example.md +4 -2
- package/.docs/organized/code-examples/memory-todo-agent.md +1 -0
- package/.docs/organized/code-examples/memory-with-context.md +2 -1
- package/.docs/organized/code-examples/memory-with-libsql.md +4 -2
- package/.docs/organized/code-examples/memory-with-mongodb.md +4 -2
- package/.docs/organized/code-examples/memory-with-pg.md +4 -2
- package/.docs/organized/code-examples/memory-with-processors.md +13 -8
- package/.docs/organized/code-examples/memory-with-upstash.md +5 -3
- package/.docs/organized/code-examples/openapi-spec-writer.md +32 -41
- package/.docs/organized/code-examples/quick-start.md +5 -32
- package/.docs/organized/code-examples/stock-price-tool.md +6 -5
- package/.docs/organized/code-examples/weather-agent.md +21 -16
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +3 -2
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +9 -12
- package/.docs/organized/code-examples/workflow-with-memory.md +16 -15
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +2 -2
- package/.docs/organized/code-examples/workflow-with-suspend-resume.md +3 -2
- package/.docs/raw/agents/adding-voice.mdx +27 -22
- package/.docs/raw/agents/agent-memory.mdx +23 -15
- package/.docs/raw/agents/guardrails.mdx +33 -12
- package/.docs/raw/agents/networks.mdx +8 -4
- package/.docs/raw/agents/overview.mdx +21 -15
- package/.docs/raw/agents/using-tools.mdx +11 -8
- package/.docs/raw/auth/auth0.mdx +8 -8
- package/.docs/raw/auth/clerk.mdx +6 -6
- package/.docs/raw/auth/firebase.mdx +8 -8
- package/.docs/raw/auth/index.mdx +6 -6
- package/.docs/raw/auth/jwt.mdx +6 -6
- package/.docs/raw/auth/supabase.mdx +7 -7
- package/.docs/raw/auth/workos.mdx +8 -8
- package/.docs/raw/community/contributing-templates.mdx +3 -3
- package/.docs/raw/community/discord.mdx +1 -1
- package/.docs/raw/course/01-first-agent/08-exporting-your-agent.md +2 -1
- package/.docs/raw/course/01-first-agent/16-adding-memory-to-agent.md +2 -1
- package/.docs/raw/course/02-agent-tools-mcp/31-enhancing-memory-configuration.md +2 -0
- package/.docs/raw/course/03-agent-memory/04-creating-basic-memory-agent.md +1 -0
- package/.docs/raw/course/03-agent-memory/10-storage-configuration.md +2 -3
- package/.docs/raw/course/03-agent-memory/13-vector-store-configuration.md +2 -0
- package/.docs/raw/course/03-agent-memory/16-configuring-semantic-recall.md +2 -0
- package/.docs/raw/course/03-agent-memory/18-advanced-configuration-semantic-recall.md +1 -0
- package/.docs/raw/course/03-agent-memory/21-configuring-working-memory.md +2 -0
- package/.docs/raw/course/03-agent-memory/22-custom-working-memory-templates.md +1 -0
- package/.docs/raw/course/03-agent-memory/25-combining-memory-features.md +1 -0
- package/.docs/raw/course/03-agent-memory/27-creating-learning-assistant.md +1 -0
- package/.docs/raw/course/04-workflows/08-running-workflows-programmatically.md +2 -2
- package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +5 -5
- package/.docs/raw/deployment/cloud-providers/aws-lambda.mdx +7 -5
- package/.docs/raw/deployment/cloud-providers/azure-app-services.mdx +3 -3
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +4 -4
- package/.docs/raw/deployment/cloud-providers/index.mdx +11 -8
- package/.docs/raw/deployment/monorepo.mdx +2 -2
- package/.docs/raw/deployment/overview.mdx +2 -2
- package/.docs/raw/deployment/server-deployment.mdx +2 -10
- package/.docs/raw/deployment/serverless-platforms/cloudflare-deployer.mdx +4 -4
- package/.docs/raw/deployment/serverless-platforms/index.mdx +10 -7
- package/.docs/raw/deployment/serverless-platforms/netlify-deployer.mdx +4 -4
- package/.docs/raw/deployment/serverless-platforms/vercel-deployer.mdx +4 -4
- package/.docs/raw/deployment/web-framework.mdx +8 -8
- package/.docs/raw/{scorers → evals}/custom-scorers.mdx +6 -6
- package/.docs/raw/evals/off-the-shelf-scorers.mdx +50 -0
- package/.docs/raw/{scorers → evals}/overview.mdx +8 -8
- package/.docs/raw/evals/running-in-ci.mdx +113 -0
- package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +22 -21
- package/.docs/raw/frameworks/agentic-uis/copilotkit.mdx +8 -8
- package/.docs/raw/frameworks/agentic-uis/openrouter.mdx +3 -0
- package/.docs/raw/frameworks/servers/express.mdx +10 -9
- package/.docs/raw/frameworks/web-frameworks/astro.mdx +6 -6
- package/.docs/raw/frameworks/web-frameworks/next-js.mdx +3 -3
- package/.docs/raw/frameworks/web-frameworks/sveltekit.mdx +4 -4
- package/.docs/raw/frameworks/web-frameworks/vite-react.mdx +2 -2
- package/.docs/raw/getting-started/installation.mdx +13 -12
- package/.docs/raw/getting-started/mcp-docs-server.mdx +1 -1
- package/.docs/raw/getting-started/project-structure.mdx +4 -4
- package/.docs/raw/getting-started/studio.mdx +8 -8
- package/.docs/raw/getting-started/templates.mdx +1 -1
- package/.docs/raw/guides/guide/ai-recruiter.mdx +264 -0
- package/.docs/raw/guides/guide/chef-michel.mdx +271 -0
- package/.docs/raw/guides/guide/notes-mcp-server.mdx +450 -0
- package/.docs/raw/guides/guide/research-assistant.mdx +389 -0
- package/.docs/raw/guides/guide/stock-agent.mdx +185 -0
- package/.docs/raw/guides/guide/web-search.mdx +291 -0
- package/.docs/raw/guides/index.mdx +43 -0
- package/.docs/raw/guides/migrations/agentnetwork.mdx +114 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/_template.mdx +50 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +265 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/cli.mdx +48 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/client.mdx +153 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/evals.mdx +230 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/mastra.mdx +171 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/mcp.mdx +114 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/memory.mdx +241 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/overview.mdx +83 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/processors.mdx +62 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/storage.mdx +270 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/tools.mdx +115 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/tracing.mdx +280 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/vectors.mdx +23 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/voice.mdx +39 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +178 -0
- package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +367 -0
- package/.docs/raw/index.mdx +9 -9
- package/.docs/raw/{observability/logging.mdx → logging.mdx} +4 -4
- package/.docs/raw/mastra-cloud/dashboard.mdx +2 -2
- package/.docs/raw/mastra-cloud/observability.mdx +6 -6
- package/.docs/raw/mastra-cloud/overview.mdx +2 -2
- package/.docs/raw/mastra-cloud/setting-up.mdx +4 -4
- package/.docs/raw/memory/conversation-history.mdx +1 -0
- package/.docs/raw/memory/memory-processors.mdx +4 -3
- package/.docs/raw/memory/overview.mdx +9 -5
- package/.docs/raw/memory/semantic-recall.mdx +12 -7
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +10 -5
- package/.docs/raw/memory/storage/memory-with-pg.mdx +9 -4
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +9 -4
- package/.docs/raw/memory/threads-and-resources.mdx +11 -13
- package/.docs/raw/memory/working-memory.mdx +30 -14
- package/.docs/raw/observability/overview.mdx +13 -30
- package/.docs/raw/observability/{ai-tracing → tracing}/exporters/arize.mdx +10 -18
- package/.docs/raw/observability/{ai-tracing → tracing}/exporters/braintrust.mdx +7 -16
- package/.docs/raw/observability/{ai-tracing → tracing}/exporters/cloud.mdx +11 -17
- package/.docs/raw/observability/{ai-tracing → tracing}/exporters/default.mdx +16 -20
- package/.docs/raw/observability/{ai-tracing → tracing}/exporters/langfuse.mdx +7 -16
- package/.docs/raw/observability/{ai-tracing → tracing}/exporters/langsmith.mdx +7 -16
- package/.docs/raw/observability/{ai-tracing → tracing}/exporters/otel.mdx +9 -18
- package/.docs/raw/observability/{ai-tracing → tracing}/overview.mdx +107 -142
- package/.docs/raw/observability/{ai-tracing → tracing}/processors/sensitive-data-filter.mdx +14 -13
- package/.docs/raw/rag/chunking-and-embedding.mdx +5 -5
- package/.docs/raw/rag/overview.mdx +3 -13
- package/.docs/raw/rag/retrieval.mdx +24 -12
- package/.docs/raw/rag/vector-databases.mdx +7 -1
- package/.docs/raw/reference/agents/agent.mdx +33 -28
- package/.docs/raw/reference/agents/generate.mdx +10 -10
- package/.docs/raw/reference/agents/generateLegacy.mdx +8 -8
- package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +21 -15
- package/.docs/raw/reference/agents/getDefaultOptions.mdx +69 -0
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +22 -16
- package/.docs/raw/reference/agents/getDescription.mdx +1 -1
- package/.docs/raw/reference/agents/getInstructions.mdx +8 -8
- package/.docs/raw/reference/agents/getLLM.mdx +9 -9
- package/.docs/raw/reference/agents/getMemory.mdx +9 -9
- package/.docs/raw/reference/agents/getModel.mdx +10 -10
- package/.docs/raw/reference/agents/getVoice.mdx +8 -8
- package/.docs/raw/reference/agents/listAgents.mdx +9 -9
- package/.docs/raw/reference/agents/listScorers.mdx +7 -7
- package/.docs/raw/reference/agents/listTools.mdx +7 -7
- package/.docs/raw/reference/agents/listWorkflows.mdx +7 -7
- package/.docs/raw/reference/agents/network.mdx +11 -10
- package/.docs/raw/reference/auth/auth0.mdx +4 -4
- package/.docs/raw/reference/auth/clerk.mdx +4 -4
- package/.docs/raw/reference/auth/firebase.mdx +6 -6
- package/.docs/raw/reference/auth/jwt.mdx +4 -4
- package/.docs/raw/reference/auth/supabase.mdx +4 -4
- package/.docs/raw/reference/auth/workos.mdx +4 -4
- package/.docs/raw/reference/cli/mastra.mdx +7 -7
- package/.docs/raw/reference/client-js/agents.mdx +6 -2
- package/.docs/raw/reference/client-js/mastra-client.mdx +7 -7
- package/.docs/raw/reference/client-js/memory.mdx +24 -16
- package/.docs/raw/reference/client-js/observability.mdx +11 -11
- package/.docs/raw/reference/client-js/workflows.mdx +6 -34
- package/.docs/raw/reference/core/getAgent.mdx +1 -1
- package/.docs/raw/reference/core/getAgentById.mdx +1 -1
- package/.docs/raw/reference/core/getDeployer.mdx +2 -2
- package/.docs/raw/reference/core/getLogger.mdx +2 -2
- package/.docs/raw/reference/core/getMCPServer.mdx +31 -15
- package/.docs/raw/reference/core/getMCPServerById.mdx +81 -0
- package/.docs/raw/reference/core/getScorer.mdx +3 -3
- package/.docs/raw/reference/core/getScorerById.mdx +79 -0
- package/.docs/raw/reference/core/getServer.mdx +2 -2
- package/.docs/raw/reference/core/getStorage.mdx +2 -2
- package/.docs/raw/reference/core/getTelemetry.mdx +2 -2
- package/.docs/raw/reference/core/getVector.mdx +2 -2
- package/.docs/raw/reference/core/getWorkflow.mdx +1 -1
- package/.docs/raw/reference/core/listAgents.mdx +1 -1
- package/.docs/raw/reference/core/listLogs.mdx +2 -2
- package/.docs/raw/reference/core/listLogsByRunId.mdx +2 -2
- package/.docs/raw/reference/core/listMCPServers.mdx +65 -0
- package/.docs/raw/reference/core/listScorers.mdx +3 -3
- package/.docs/raw/reference/core/listVectors.mdx +36 -0
- package/.docs/raw/reference/core/listWorkflows.mdx +6 -6
- package/.docs/raw/reference/core/mastra-class.mdx +3 -2
- package/.docs/raw/reference/core/setLogger.mdx +2 -2
- package/.docs/raw/reference/core/setStorage.mdx +3 -2
- package/.docs/raw/reference/core/setTelemetry.mdx +2 -2
- package/.docs/raw/reference/deployer/cloudflare.mdx +2 -2
- package/.docs/raw/reference/deployer/deployer.mdx +0 -6
- package/.docs/raw/reference/deployer/netlify.mdx +2 -2
- package/.docs/raw/reference/deployer/vercel.mdx +3 -3
- package/.docs/raw/reference/evals/answer-relevancy.mdx +164 -126
- package/.docs/raw/reference/{scorers → evals}/answer-similarity.mdx +27 -27
- package/.docs/raw/reference/evals/bias.mdx +149 -115
- package/.docs/raw/reference/evals/completeness.mdx +148 -117
- package/.docs/raw/reference/evals/content-similarity.mdx +126 -113
- package/.docs/raw/reference/evals/context-precision.mdx +290 -133
- package/.docs/raw/reference/{scorers → evals}/context-relevance.mdx +6 -6
- package/.docs/raw/reference/{scorers → evals}/create-scorer.mdx +11 -11
- package/.docs/raw/reference/evals/faithfulness.mdx +163 -121
- package/.docs/raw/reference/evals/hallucination.mdx +159 -132
- package/.docs/raw/reference/evals/keyword-coverage.mdx +169 -125
- package/.docs/raw/reference/{scorers → evals}/mastra-scorer.mdx +5 -5
- package/.docs/raw/reference/{scorers → evals}/noise-sensitivity.mdx +9 -9
- package/.docs/raw/reference/evals/prompt-alignment.mdx +604 -182
- package/.docs/raw/reference/{scorers/run-experiment.mdx → evals/run-evals.mdx} +17 -18
- package/.docs/raw/reference/evals/textual-difference.mdx +149 -117
- package/.docs/raw/reference/evals/tone-consistency.mdx +149 -125
- package/.docs/raw/reference/{scorers → evals}/tool-call-accuracy.mdx +8 -6
- package/.docs/raw/reference/evals/toxicity.mdx +152 -96
- package/.docs/raw/reference/{observability/logging → logging}/pino-logger.mdx +2 -2
- package/.docs/raw/reference/memory/createThread.mdx +5 -5
- package/.docs/raw/reference/memory/deleteMessages.mdx +7 -7
- package/.docs/raw/reference/memory/getThreadById.mdx +4 -4
- package/.docs/raw/reference/memory/listThreadsByResourceId.mdx +110 -0
- package/.docs/raw/reference/memory/memory-class.mdx +13 -9
- package/.docs/raw/reference/memory/query.mdx +58 -57
- package/.docs/raw/reference/memory/recall.mdx +185 -0
- package/.docs/raw/reference/observability/tracing/configuration.mdx +245 -0
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/arize.mdx +13 -13
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/braintrust.mdx +11 -8
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/cloud-exporter.mdx +21 -19
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/console-exporter.mdx +49 -17
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/default-exporter.mdx +42 -41
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/langfuse.mdx +10 -7
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/langsmith.mdx +10 -7
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/otel.mdx +5 -5
- package/.docs/raw/reference/observability/tracing/instances.mdx +168 -0
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/interfaces.mdx +115 -89
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/processors/sensitive-data-filter.mdx +3 -3
- package/.docs/raw/reference/observability/{ai-tracing/span.mdx → tracing/spans.mdx} +59 -41
- package/.docs/raw/reference/processors/batch-parts-processor.mdx +1 -1
- package/.docs/raw/reference/processors/language-detector.mdx +1 -1
- package/.docs/raw/reference/processors/moderation-processor.mdx +1 -1
- package/.docs/raw/reference/processors/pii-detector.mdx +1 -1
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +1 -1
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +1 -1
- package/.docs/raw/reference/processors/token-limiter-processor.mdx +1 -1
- package/.docs/raw/reference/processors/unicode-normalizer.mdx +1 -1
- package/.docs/raw/reference/rag/chunk.mdx +1 -8
- package/.docs/raw/reference/rag/database-config.mdx +7 -7
- package/.docs/raw/reference/rag/metadata-filters.mdx +14 -11
- package/.docs/raw/reference/storage/libsql.mdx +2 -0
- package/.docs/raw/reference/storage/mssql.mdx +5 -0
- package/.docs/raw/reference/storage/postgresql.mdx +6 -0
- package/.docs/raw/reference/storage/upstash.mdx +1 -0
- package/.docs/raw/reference/streaming/agents/stream.mdx +12 -12
- package/.docs/raw/reference/streaming/agents/streamLegacy.mdx +8 -8
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +3 -3
- package/.docs/raw/reference/streaming/workflows/observeStreamVNext.mdx +3 -3
- package/.docs/raw/reference/streaming/workflows/resumeStreamVNext.mdx +6 -6
- package/.docs/raw/reference/streaming/workflows/stream.mdx +10 -10
- package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +11 -11
- package/.docs/raw/reference/templates/overview.mdx +2 -2
- package/.docs/raw/reference/tools/create-tool.mdx +52 -35
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +15 -15
- package/.docs/raw/reference/tools/mcp-client.mdx +1 -1
- package/.docs/raw/reference/tools/mcp-server.mdx +119 -35
- package/.docs/raw/reference/tools/vector-query-tool.mdx +27 -26
- package/.docs/raw/reference/vectors/libsql.mdx +1 -0
- package/.docs/raw/reference/vectors/pg.mdx +3 -0
- package/.docs/raw/reference/vectors/upstash.mdx +1 -0
- package/.docs/raw/reference/voice/google-gemini-live.mdx +1 -1
- package/.docs/raw/reference/voice/voice.addTools.mdx +3 -3
- package/.docs/raw/reference/workflows/run-methods/cancel.mdx +4 -4
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +14 -14
- package/.docs/raw/reference/workflows/run-methods/start.mdx +17 -17
- package/.docs/raw/reference/workflows/run.mdx +1 -8
- package/.docs/raw/reference/workflows/step.mdx +5 -5
- package/.docs/raw/reference/workflows/workflow-methods/branch.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/commit.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/create-run.mdx +7 -13
- package/.docs/raw/reference/workflows/workflow-methods/dountil.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/dowhile.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/foreach.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/map.mdx +5 -0
- package/.docs/raw/reference/workflows/workflow-methods/parallel.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/sendEvent.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/sleep.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/sleepUntil.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/then.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/waitForEvent.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow.mdx +1 -1
- package/.docs/raw/server-db/custom-api-routes.mdx +2 -2
- package/.docs/raw/server-db/mastra-client.mdx +19 -18
- package/.docs/raw/server-db/middleware.mdx +7 -7
- package/.docs/raw/server-db/production-server.mdx +4 -4
- package/.docs/raw/server-db/{runtime-context.mdx → request-context.mdx} +46 -45
- package/.docs/raw/server-db/storage.mdx +29 -21
- package/.docs/raw/streaming/events.mdx +3 -3
- package/.docs/raw/streaming/overview.mdx +5 -5
- package/.docs/raw/streaming/tool-streaming.mdx +18 -17
- package/.docs/raw/streaming/workflow-streaming.mdx +1 -1
- package/.docs/raw/tools-mcp/advanced-usage.mdx +5 -4
- package/.docs/raw/tools-mcp/mcp-overview.mdx +32 -19
- package/.docs/raw/tools-mcp/overview.mdx +11 -11
- package/.docs/raw/voice/overview.mdx +63 -43
- package/.docs/raw/voice/speech-to-speech.mdx +5 -3
- package/.docs/raw/voice/speech-to-text.mdx +9 -8
- package/.docs/raw/voice/text-to-speech.mdx +12 -11
- package/.docs/raw/workflows/agents-and-tools.mdx +9 -5
- package/.docs/raw/workflows/control-flow.mdx +3 -3
- package/.docs/raw/workflows/error-handling.mdx +2 -21
- package/.docs/raw/workflows/human-in-the-loop.mdx +7 -4
- package/.docs/raw/workflows/inngest-workflow.mdx +2 -2
- package/.docs/raw/workflows/input-data-mapping.mdx +107 -0
- package/.docs/raw/workflows/overview.mdx +17 -16
- package/.docs/raw/workflows/snapshots.mdx +13 -11
- package/.docs/raw/workflows/suspend-and-resume.mdx +23 -15
- package/CHANGELOG.md +52 -57
- package/README.md +11 -2
- package/dist/{chunk-TUAHUTTB.js → chunk-5NJC7NRO.js} +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/prepare-docs/copy-raw.d.ts.map +1 -1
- package/dist/prepare-docs/prepare.js +1 -1
- package/dist/prompts/migration.d.ts +6 -0
- package/dist/prompts/migration.d.ts.map +1 -0
- package/dist/stdio.js +402 -30
- package/dist/tools/migration.d.ts +40 -0
- package/dist/tools/migration.d.ts.map +1 -0
- package/package.json +8 -12
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +0 -302
- package/.docs/raw/observability/nextjs-tracing.mdx +0 -109
- package/.docs/raw/observability/otel-tracing.mdx +0 -189
- package/.docs/raw/reference/agents/getScorers.mdx +0 -69
- package/.docs/raw/reference/agents/getTools.mdx +0 -69
- package/.docs/raw/reference/agents/getWorkflows.mdx +0 -69
- package/.docs/raw/reference/client-js/workflows-legacy.mdx +0 -143
- package/.docs/raw/reference/core/getAgents.mdx +0 -35
- package/.docs/raw/reference/core/getLogs.mdx +0 -96
- package/.docs/raw/reference/core/getLogsByRunId.mdx +0 -87
- package/.docs/raw/reference/core/getMCPServers.mdx +0 -36
- package/.docs/raw/reference/core/getMemory.mdx +0 -36
- package/.docs/raw/reference/core/getScorerByName.mdx +0 -78
- package/.docs/raw/reference/core/getScorers.mdx +0 -43
- package/.docs/raw/reference/core/getVectors.mdx +0 -36
- package/.docs/raw/reference/core/getWorkflows.mdx +0 -45
- package/.docs/raw/reference/evals/context-position.mdx +0 -197
- package/.docs/raw/reference/evals/context-relevancy.mdx +0 -196
- package/.docs/raw/reference/evals/contextual-recall.mdx +0 -196
- package/.docs/raw/reference/evals/summarization.mdx +0 -212
- package/.docs/raw/reference/legacyWorkflows/after.mdx +0 -89
- package/.docs/raw/reference/legacyWorkflows/afterEvent.mdx +0 -79
- package/.docs/raw/reference/legacyWorkflows/commit.mdx +0 -33
- package/.docs/raw/reference/legacyWorkflows/createRun.mdx +0 -76
- package/.docs/raw/reference/legacyWorkflows/else.mdx +0 -68
- package/.docs/raw/reference/legacyWorkflows/events.mdx +0 -305
- package/.docs/raw/reference/legacyWorkflows/execute.mdx +0 -110
- package/.docs/raw/reference/legacyWorkflows/if.mdx +0 -108
- package/.docs/raw/reference/legacyWorkflows/resume.mdx +0 -158
- package/.docs/raw/reference/legacyWorkflows/resumeWithEvent.mdx +0 -133
- package/.docs/raw/reference/legacyWorkflows/snapshots.mdx +0 -207
- package/.docs/raw/reference/legacyWorkflows/start.mdx +0 -87
- package/.docs/raw/reference/legacyWorkflows/step-class.mdx +0 -100
- package/.docs/raw/reference/legacyWorkflows/step-condition.mdx +0 -137
- package/.docs/raw/reference/legacyWorkflows/step-function.mdx +0 -93
- package/.docs/raw/reference/legacyWorkflows/step-options.mdx +0 -69
- package/.docs/raw/reference/legacyWorkflows/step-retries.mdx +0 -196
- package/.docs/raw/reference/legacyWorkflows/suspend.mdx +0 -70
- package/.docs/raw/reference/legacyWorkflows/then.mdx +0 -72
- package/.docs/raw/reference/legacyWorkflows/until.mdx +0 -168
- package/.docs/raw/reference/legacyWorkflows/watch.mdx +0 -124
- package/.docs/raw/reference/legacyWorkflows/while.mdx +0 -168
- package/.docs/raw/reference/legacyWorkflows/workflow.mdx +0 -234
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +0 -79
- package/.docs/raw/reference/memory/getThreadsByResourceIdPaginated.mdx +0 -110
- package/.docs/raw/reference/observability/ai-tracing/ai-tracing.mdx +0 -185
- package/.docs/raw/reference/observability/ai-tracing/configuration.mdx +0 -238
- package/.docs/raw/reference/observability/otel-tracing/otel-config.mdx +0 -117
- package/.docs/raw/reference/observability/otel-tracing/providers/arize-ax.mdx +0 -81
- package/.docs/raw/reference/observability/otel-tracing/providers/arize-phoenix.mdx +0 -121
- package/.docs/raw/reference/observability/otel-tracing/providers/braintrust.mdx +0 -40
- package/.docs/raw/reference/observability/otel-tracing/providers/dash0.mdx +0 -40
- package/.docs/raw/reference/observability/otel-tracing/providers/index.mdx +0 -20
- package/.docs/raw/reference/observability/otel-tracing/providers/keywordsai.mdx +0 -73
- package/.docs/raw/reference/observability/otel-tracing/providers/laminar.mdx +0 -41
- package/.docs/raw/reference/observability/otel-tracing/providers/langfuse.mdx +0 -84
- package/.docs/raw/reference/observability/otel-tracing/providers/langsmith.mdx +0 -48
- package/.docs/raw/reference/observability/otel-tracing/providers/langwatch.mdx +0 -43
- package/.docs/raw/reference/observability/otel-tracing/providers/new-relic.mdx +0 -40
- package/.docs/raw/reference/observability/otel-tracing/providers/signoz.mdx +0 -40
- package/.docs/raw/reference/observability/otel-tracing/providers/traceloop.mdx +0 -40
- package/.docs/raw/reference/scorers/answer-relevancy.mdx +0 -227
- package/.docs/raw/reference/scorers/bias.mdx +0 -228
- package/.docs/raw/reference/scorers/completeness.mdx +0 -214
- package/.docs/raw/reference/scorers/content-similarity.mdx +0 -197
- package/.docs/raw/reference/scorers/context-precision.mdx +0 -352
- package/.docs/raw/reference/scorers/faithfulness.mdx +0 -241
- package/.docs/raw/reference/scorers/hallucination.mdx +0 -252
- package/.docs/raw/reference/scorers/keyword-coverage.mdx +0 -229
- package/.docs/raw/reference/scorers/prompt-alignment.mdx +0 -668
- package/.docs/raw/reference/scorers/textual-difference.mdx +0 -203
- package/.docs/raw/reference/scorers/tone-consistency.mdx +0 -211
- package/.docs/raw/reference/scorers/toxicity.mdx +0 -228
- package/.docs/raw/reference/workflows/run-methods/watch.mdx +0 -73
- package/.docs/raw/scorers/evals-old-api/custom-eval.mdx +0 -24
- package/.docs/raw/scorers/evals-old-api/overview.mdx +0 -106
- package/.docs/raw/scorers/evals-old-api/running-in-ci.mdx +0 -85
- package/.docs/raw/scorers/evals-old-api/textual-evals.mdx +0 -58
- package/.docs/raw/scorers/off-the-shelf-scorers.mdx +0 -50
- package/.docs/raw/workflows-legacy/control-flow.mdx +0 -774
- package/.docs/raw/workflows-legacy/dynamic-workflows.mdx +0 -239
- package/.docs/raw/workflows-legacy/error-handling.mdx +0 -187
- package/.docs/raw/workflows-legacy/nested-workflows.mdx +0 -360
- package/.docs/raw/workflows-legacy/overview.mdx +0 -182
- package/.docs/raw/workflows-legacy/runtime-variables.mdx +0 -156
- package/.docs/raw/workflows-legacy/steps.mdx +0 -115
- package/.docs/raw/workflows-legacy/suspend-and-resume.mdx +0 -406
- package/.docs/raw/workflows-legacy/variables.mdx +0 -318
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Guide: Building a Research Paper Assistant with RAG | Mastra RAG Guides"
|
|
3
|
+
description: Guide on creating an AI research assistant that can analyze and answer questions about academic papers using RAG.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import Steps from "@site/src/components/Steps";
|
|
7
|
+
import StepItem from "@site/src/components/StepItem";
|
|
8
|
+
|
|
9
|
+
# Building a Research Paper Assistant with RAG
|
|
10
|
+
|
|
11
|
+
In this guide, you'll create an AI research assistant that can analyze academic papers and answer specific questions about their content using Retrieval Augmented Generation (RAG).
|
|
12
|
+
|
|
13
|
+
You'll use the foundational Transformer paper ["Attention Is All You Need"](https://arxiv.org/html/1706.03762) as your example. As a database you'll use a local LibSQL database.
|
|
14
|
+
|
|
15
|
+
## Prerequisites
|
|
16
|
+
|
|
17
|
+
- Node.js `v22.13.0` or later installed
|
|
18
|
+
- An API key from a supported [Model Provider](/models/v1)
|
|
19
|
+
- An existing Mastra project (Follow the [installation guide](/docs/v1/getting-started/installation) to set up a new project)
|
|
20
|
+
|
|
21
|
+
## How RAG works
|
|
22
|
+
|
|
23
|
+
Let's understand how RAG works and how you'll implement each component.
|
|
24
|
+
|
|
25
|
+
### Knowledge Store/Index
|
|
26
|
+
|
|
27
|
+
- Converting text into vector representations
|
|
28
|
+
- Creating numerical representations of content
|
|
29
|
+
- **Implementation**: You'll use OpenAI's `text-embedding-3-small` to create embeddings and store them in LibSQLVector
|
|
30
|
+
|
|
31
|
+
### Retriever
|
|
32
|
+
|
|
33
|
+
- Finding relevant content via similarity search
|
|
34
|
+
- Matching query embeddings with stored vectors
|
|
35
|
+
- **Implementation**: You'll use LibSQLVector to perform similarity searches on the stored embeddings
|
|
36
|
+
|
|
37
|
+
### Generator
|
|
38
|
+
|
|
39
|
+
- Processing retrieved content with an LLM
|
|
40
|
+
- Creating contextually informed responses
|
|
41
|
+
- **Implementation**: You'll use GPT-4o-mini to generate answers based on retrieved content
|
|
42
|
+
|
|
43
|
+
Your implementation will:
|
|
44
|
+
|
|
45
|
+
1. Process the Transformer paper into embeddings
|
|
46
|
+
2. Store them in LibSQLVector for quick retrieval
|
|
47
|
+
3. Use similarity search to find relevant sections
|
|
48
|
+
4. Generate accurate responses using retrieved context
|
|
49
|
+
|
|
50
|
+
## Creating the Agent
|
|
51
|
+
|
|
52
|
+
Let's define the agent's behavior, connect it to your Mastra project, and create the vector store.
|
|
53
|
+
|
|
54
|
+
<Steps>
|
|
55
|
+
|
|
56
|
+
<StepItem title="Install additional dependencies">
|
|
57
|
+
|
|
58
|
+
Install additional dependencies
|
|
59
|
+
|
|
60
|
+
After running the [installation guide](/docs/v1/getting-started/installation) you'll need to install additional dependencies:
|
|
61
|
+
|
|
62
|
+
```bash copy
|
|
63
|
+
npm install @mastra/rag@latest ai@^4.0.0
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
:::info
|
|
67
|
+
|
|
68
|
+
Mastra currently does not support v5 of the AI SDK (see [support
|
|
69
|
+
thread](https://github.com/mastra-ai/mastra/issues/5470)). For this guide
|
|
70
|
+
you'll need to use v4.
|
|
71
|
+
|
|
72
|
+
:::
|
|
73
|
+
|
|
74
|
+
</StepItem>
|
|
75
|
+
|
|
76
|
+
<StepItem title="Define the Agent">
|
|
77
|
+
|
|
78
|
+
Now you'll create your RAG-enabled research assistant. The agent uses:
|
|
79
|
+
|
|
80
|
+
- A [Vector Query Tool](/reference/v1/tools/vector-query-tool) for performing semantic search over the vector store to find relevant content in papers
|
|
81
|
+
- GPT-4o-mini for understanding queries and generating responses
|
|
82
|
+
- Custom instructions that guide the agent on how to analyze papers, use retrieved content effectively, and acknowledge limitations
|
|
83
|
+
|
|
84
|
+
Create a new file `src/mastra/agents/researchAgent.ts` and define your agent:
|
|
85
|
+
|
|
86
|
+
```ts copy title="src/mastra/agents/researchAgent.ts"
|
|
87
|
+
import { Agent } from "@mastra/core/agent";
|
|
88
|
+
import { openai } from "@ai-sdk/openai";
|
|
89
|
+
import { createVectorQueryTool } from "@mastra/rag";
|
|
90
|
+
|
|
91
|
+
// Create a tool for semantic search over the paper embeddings
|
|
92
|
+
const vectorQueryTool = createVectorQueryTool({
|
|
93
|
+
vectorStoreName: "libSqlVector",
|
|
94
|
+
indexName: "papers",
|
|
95
|
+
model: openai.embedding("text-embedding-3-small"),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export const researchAgent = new Agent({
|
|
99
|
+
id: "research-agent",
|
|
100
|
+
name: "Research Assistant",
|
|
101
|
+
instructions: `You are a helpful research assistant that analyzes academic papers and technical documents.
|
|
102
|
+
Use the provided vector query tool to find relevant information from your knowledge base,
|
|
103
|
+
and provide accurate, well-supported answers based on the retrieved content.
|
|
104
|
+
Focus on the specific content available in the tool and acknowledge if you cannot find sufficient information to answer a question.
|
|
105
|
+
Base your responses only on the content provided, not on general knowledge.`,
|
|
106
|
+
model: openai("gpt-4o-mini"),
|
|
107
|
+
tools: {
|
|
108
|
+
vectorQueryTool,
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
</StepItem>
|
|
114
|
+
|
|
115
|
+
<StepItem title="Create the Vector Store">
|
|
116
|
+
|
|
117
|
+
In the root of your project, grab the absolute path with the `pwd` command. The path might be similar to this:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
> pwd
|
|
121
|
+
/Users/your-name/guides/research-assistant
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
In your `src/mastra/index.ts` file, add the following to your existing file and configuration:
|
|
125
|
+
|
|
126
|
+
```ts copy title="src/mastra/index.ts" {2, 4-6, 9}
|
|
127
|
+
import { Mastra } from "@mastra/core";
|
|
128
|
+
import { LibSQLVector } from "@mastra/libsql";
|
|
129
|
+
|
|
130
|
+
const libSqlVector = new LibSQLVector({
|
|
131
|
+
id: 'research-vectors',
|
|
132
|
+
connectionUrl: "file:/Users/your-name/guides/research-assistant/vector.db",
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
export const mastra = new Mastra({
|
|
136
|
+
vectors: { libSqlVector },
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
For the `connectionUrl` use the absolute path you got from the `pwd` command. This way the `vector.db` file is created at the root of your project.
|
|
141
|
+
|
|
142
|
+
:::note
|
|
143
|
+
|
|
144
|
+
For the purpose of this guide you are using a hardcoded absolute path to your
|
|
145
|
+
local LibSQL file, however for production usage this won't work. You should
|
|
146
|
+
use a remote persistent database then.
|
|
147
|
+
|
|
148
|
+
:::
|
|
149
|
+
|
|
150
|
+
</StepItem>
|
|
151
|
+
|
|
152
|
+
<StepItem title="Register the Agent with Mastra">
|
|
153
|
+
|
|
154
|
+
In the `src/mastra/index.ts` file, add the agent to Mastra:
|
|
155
|
+
|
|
156
|
+
```ts copy title="src/mastra/index.ts" {3, 10}
|
|
157
|
+
import { Mastra } from "@mastra/core";
|
|
158
|
+
import { LibSQLVector } from "@mastra/libsql";
|
|
159
|
+
import { researchAgent } from "./agents/researchAgent";
|
|
160
|
+
|
|
161
|
+
const libSqlVector = new LibSQLVector({
|
|
162
|
+
id: 'research-vectors',
|
|
163
|
+
connectionUrl: "file:/Users/your-name/guides/research-assistant/vector.db",
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
export const mastra = new Mastra({
|
|
167
|
+
agents: { researchAgent },
|
|
168
|
+
vectors: { libSqlVector },
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
</StepItem>
|
|
173
|
+
|
|
174
|
+
</Steps>
|
|
175
|
+
|
|
176
|
+
## Processing documents
|
|
177
|
+
|
|
178
|
+
In the following steps you'll fetch the research paper, split it into smaller chunks, generate embeddings for them, and store these chunks of information into the vector database.
|
|
179
|
+
|
|
180
|
+
<Steps>
|
|
181
|
+
|
|
182
|
+
<StepItem title="Load and Process the Paper">
|
|
183
|
+
|
|
184
|
+
In this step the research paper is retrieved by providing an URL, then converted to a document object, and split into smaller, manageable chunks. By splitting into chunks the processing is faster and more efficient.
|
|
185
|
+
|
|
186
|
+
Create a new file `src/store.ts` and add the following:
|
|
187
|
+
|
|
188
|
+
```ts copy title="src/store.ts"
|
|
189
|
+
import { MDocument } from "@mastra/rag";
|
|
190
|
+
|
|
191
|
+
// Load the paper
|
|
192
|
+
const paperUrl = "https://arxiv.org/html/1706.03762";
|
|
193
|
+
const response = await fetch(paperUrl);
|
|
194
|
+
const paperText = await response.text();
|
|
195
|
+
|
|
196
|
+
// Create document and chunk it
|
|
197
|
+
const doc = MDocument.fromText(paperText);
|
|
198
|
+
const chunks = await doc.chunk({
|
|
199
|
+
strategy: "recursive",
|
|
200
|
+
maxSize: 512,
|
|
201
|
+
overlap: 50,
|
|
202
|
+
separators: ["\n\n", "\n", " "],
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
console.log("Number of chunks:", chunks.length);
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Run the file in your terminal:
|
|
209
|
+
|
|
210
|
+
```bash copy
|
|
211
|
+
npx bun src/store.ts
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
You should get back this response:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
Number of chunks: 892
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
</StepItem>
|
|
221
|
+
|
|
222
|
+
<StepItem title="Create and Store Embeddings">
|
|
223
|
+
|
|
224
|
+
Finally, you'll prepare the content for RAG by:
|
|
225
|
+
|
|
226
|
+
1. Generating embeddings for each chunk of text
|
|
227
|
+
2. Creating a vector store index to hold the embeddings
|
|
228
|
+
3. Storing both the embeddings and metadata (original text and source information) in the vector database
|
|
229
|
+
|
|
230
|
+
:::note
|
|
231
|
+
|
|
232
|
+
This metadata is crucial as it allows for returning the actual content when
|
|
233
|
+
the vector store finds relevant matches.
|
|
234
|
+
|
|
235
|
+
:::
|
|
236
|
+
|
|
237
|
+
This allows the agent to efficiently search and retrieve relevant information.
|
|
238
|
+
|
|
239
|
+
Open the `src/store.ts` file and add the following:
|
|
240
|
+
|
|
241
|
+
```ts copy title="src/store.ts" {2-4, 20-99}
|
|
242
|
+
import { MDocument } from "@mastra/rag";
|
|
243
|
+
import { openai } from "@ai-sdk/openai";
|
|
244
|
+
import { embedMany } from "ai";
|
|
245
|
+
import { mastra } from "./mastra";
|
|
246
|
+
|
|
247
|
+
// Load the paper
|
|
248
|
+
const paperUrl = "https://arxiv.org/html/1706.03762";
|
|
249
|
+
const response = await fetch(paperUrl);
|
|
250
|
+
const paperText = await response.text();
|
|
251
|
+
|
|
252
|
+
// Create document and chunk it
|
|
253
|
+
const doc = MDocument.fromText(paperText);
|
|
254
|
+
const chunks = await doc.chunk({
|
|
255
|
+
strategy: "recursive",
|
|
256
|
+
maxSize: 512,
|
|
257
|
+
overlap: 50,
|
|
258
|
+
separators: ["\n\n", "\n", " "],
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// Generate embeddings
|
|
262
|
+
const { embeddings } = await embedMany({
|
|
263
|
+
model: openai.embedding("text-embedding-3-small"),
|
|
264
|
+
values: chunks.map((chunk) => chunk.text),
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// Get the vector store instance from Mastra
|
|
268
|
+
const vectorStore = mastra.getVector("libSqlVector");
|
|
269
|
+
|
|
270
|
+
// Create an index for paper chunks
|
|
271
|
+
await vectorStore.createIndex({
|
|
272
|
+
indexName: "papers",
|
|
273
|
+
dimension: 1536,
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
// Store embeddings
|
|
277
|
+
await vectorStore.upsert({
|
|
278
|
+
indexName: "papers",
|
|
279
|
+
vectors: embeddings,
|
|
280
|
+
metadata: chunks.map((chunk) => ({
|
|
281
|
+
text: chunk.text,
|
|
282
|
+
source: "transformer-paper",
|
|
283
|
+
})),
|
|
284
|
+
});
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Lastly, you'll now need to store the embeddings by running the script again:
|
|
288
|
+
|
|
289
|
+
```bash copy
|
|
290
|
+
npx bun src/store.ts
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
If the operation was successful you should see no output/errors in your terminal.
|
|
294
|
+
|
|
295
|
+
</StepItem>
|
|
296
|
+
|
|
297
|
+
</Steps>
|
|
298
|
+
|
|
299
|
+
## Test the Assistant
|
|
300
|
+
|
|
301
|
+
Now that the vector database has all embeddings, you can test the research assistant with different types of queries.
|
|
302
|
+
|
|
303
|
+
Create a new file `src/ask-agent.ts` and add different types of queries:
|
|
304
|
+
|
|
305
|
+
```ts title="src/ask-agent.ts" copy
|
|
306
|
+
import { mastra } from "./mastra";
|
|
307
|
+
const agent = mastra.getAgent("researchAgent");
|
|
308
|
+
|
|
309
|
+
// Basic query about concepts
|
|
310
|
+
const query1 =
|
|
311
|
+
"What problems does sequence modeling face with neural networks?";
|
|
312
|
+
const response1 = await agent.generate(query1);
|
|
313
|
+
console.log("\nQuery:", query1);
|
|
314
|
+
console.log("Response:", response1.text);
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
Run the script:
|
|
318
|
+
|
|
319
|
+
```bash copy
|
|
320
|
+
npx bun src/ask-agent.ts
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
You should see output like:
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
Query: What problems does sequence modeling face with neural networks?
|
|
327
|
+
Response: Sequence modeling with neural networks faces several key challenges:
|
|
328
|
+
1. Vanishing and exploding gradients during training, especially with long sequences
|
|
329
|
+
2. Difficulty handling long-term dependencies in the input
|
|
330
|
+
3. Limited computational efficiency due to sequential processing
|
|
331
|
+
4. Challenges in parallelizing computations, resulting in longer training times
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Try another question:
|
|
335
|
+
|
|
336
|
+
```ts title="src/ask-agent.ts" copy
|
|
337
|
+
import { mastra } from "./mastra";
|
|
338
|
+
const agent = mastra.getAgent("researchAgent");
|
|
339
|
+
|
|
340
|
+
// Query about specific findings
|
|
341
|
+
const query2 = "What improvements were achieved in translation quality?";
|
|
342
|
+
const response2 = await agent.generate(query2);
|
|
343
|
+
console.log("\nQuery:", query2);
|
|
344
|
+
console.log("Response:", response2.text);
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Output:
|
|
348
|
+
|
|
349
|
+
```
|
|
350
|
+
Query: What improvements were achieved in translation quality?
|
|
351
|
+
Response: The model showed significant improvements in translation quality, achieving more than 2.0
|
|
352
|
+
BLEU points improvement over previously reported models on the WMT 2014 English-to-German translation
|
|
353
|
+
task, while also reducing training costs.
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### Serve the Application
|
|
357
|
+
|
|
358
|
+
Start the Mastra server to expose your research assistant via API:
|
|
359
|
+
|
|
360
|
+
```bash
|
|
361
|
+
mastra dev
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
Your research assistant will be available at:
|
|
365
|
+
|
|
366
|
+
```
|
|
367
|
+
http://localhost:4111/api/agents/researchAgent/generate
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
Test with curl:
|
|
371
|
+
|
|
372
|
+
```bash
|
|
373
|
+
curl -X POST http://localhost:4111/api/agents/researchAgent/generate \
|
|
374
|
+
-H "Content-Type: application/json" \
|
|
375
|
+
-d '{
|
|
376
|
+
"messages": [
|
|
377
|
+
{ "role": "user", "content": "What were the main findings about model parallelization?" }
|
|
378
|
+
]
|
|
379
|
+
}'
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
## Advanced RAG Examples
|
|
383
|
+
|
|
384
|
+
Explore these examples for more advanced RAG techniques:
|
|
385
|
+
|
|
386
|
+
- [Filter RAG](/examples/v1/rag/usage/filter-rag) for filtering results using metadata
|
|
387
|
+
- [Cleanup RAG](/examples/v1/rag/usage/cleanup-rag) for optimizing information density
|
|
388
|
+
- [Chain of Thought RAG](/examples/v1/rag/usage/cot-rag) for complex reasoning queries using workflows
|
|
389
|
+
- [Rerank RAG](/examples/v1/rag/usage/cleanup-rag) for improved result relevance
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Guide: Building an AI Stock Agent | Mastra Agents | Guides"
|
|
3
|
+
description: Guide on creating a simple stock agent in Mastra to fetch the last day's closing stock price for a given symbol.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import Steps from "@site/src/components/Steps";
|
|
7
|
+
import StepItem from "@site/src/components/StepItem";
|
|
8
|
+
import YouTube from "@site/src/components/YouTube-player";
|
|
9
|
+
|
|
10
|
+
# Building an AI Stock Agent
|
|
11
|
+
|
|
12
|
+
In this guide, you're going to create a simple agent that fetches the last day's closing stock price for a given symbol. You'll learn how to create a tool, add it to an agent, and use the agent to fetch stock prices.
|
|
13
|
+
|
|
14
|
+
<YouTube id="rIaZ4l7y9wo" />
|
|
15
|
+
|
|
16
|
+
## Prerequisites
|
|
17
|
+
|
|
18
|
+
- Node.js `v22.13.0` or later installed
|
|
19
|
+
- An API key from a supported [Model Provider](/models/v1)
|
|
20
|
+
- An existing Mastra project (Follow the [installation guide](/docs/v1/getting-started/installation) to set up a new project)
|
|
21
|
+
|
|
22
|
+
## Creating the Agent
|
|
23
|
+
|
|
24
|
+
To create an agent in Mastra use the `Agent` class to define it and then register it with Mastra.
|
|
25
|
+
|
|
26
|
+
<Steps>
|
|
27
|
+
|
|
28
|
+
<StepItem>
|
|
29
|
+
|
|
30
|
+
Create a new file `src/mastra/agents/stockAgent.ts` and define your agent:
|
|
31
|
+
|
|
32
|
+
```ts copy title="src/mastra/agents/stockAgent.ts"
|
|
33
|
+
import { openai } from "@ai-sdk/openai";
|
|
34
|
+
import { Agent } from "@mastra/core/agent";
|
|
35
|
+
|
|
36
|
+
export const stockAgent = new Agent({
|
|
37
|
+
id: "stock-agent",
|
|
38
|
+
name: "Stock Agent",
|
|
39
|
+
instructions:
|
|
40
|
+
"You are a helpful assistant that provides current stock prices. When asked about a stock, use the stock price tool to fetch the stock price.",
|
|
41
|
+
model: openai("gpt-4o-mini"),
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
</StepItem>
|
|
46
|
+
|
|
47
|
+
<StepItem>
|
|
48
|
+
|
|
49
|
+
In your `src/mastra/index.ts` file, register the agent:
|
|
50
|
+
|
|
51
|
+
```ts copy title="src/mastra/index.ts" {2, 5}
|
|
52
|
+
import { Mastra } from "@mastra/core";
|
|
53
|
+
import { stockAgent } from "./agents/stockAgent";
|
|
54
|
+
|
|
55
|
+
export const mastra = new Mastra({
|
|
56
|
+
agents: { stockAgent },
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
</StepItem>
|
|
61
|
+
|
|
62
|
+
</Steps>
|
|
63
|
+
|
|
64
|
+
## Creating the Stock Price Tool
|
|
65
|
+
|
|
66
|
+
So far the Stock Agent doesn't know anything about the current stock prices. To change this, create a tool and add it to the agent.
|
|
67
|
+
|
|
68
|
+
<Steps>
|
|
69
|
+
|
|
70
|
+
<StepItem>
|
|
71
|
+
|
|
72
|
+
Create a new file `src/mastra/tools/stockPrices.ts`. Inside, add a `stockPrices` tool that will fetch the last day's closing stock price for a given symbol:
|
|
73
|
+
|
|
74
|
+
```ts title="src/mastra/tools/stockPrices.ts"
|
|
75
|
+
import { createTool } from "@mastra/core/tools";
|
|
76
|
+
import { z } from "zod";
|
|
77
|
+
|
|
78
|
+
const getStockPrice = async (symbol: string) => {
|
|
79
|
+
const data = await fetch(
|
|
80
|
+
`https://mastra-stock-data.vercel.app/api/stock-data?symbol=${symbol}`,
|
|
81
|
+
).then((r) => r.json());
|
|
82
|
+
return data.prices["4. close"];
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const stockPrices = createTool({
|
|
86
|
+
id: "Get Stock Price",
|
|
87
|
+
inputSchema: z.object({
|
|
88
|
+
symbol: z.string(),
|
|
89
|
+
}),
|
|
90
|
+
description: `Fetches the last day's closing stock price for a given symbol`,
|
|
91
|
+
execute: async (inputData) => {
|
|
92
|
+
console.log("Using tool to fetch stock price for", inputData.symbol);
|
|
93
|
+
return {
|
|
94
|
+
symbol: inputData.symbol,
|
|
95
|
+
currentPrice: await getStockPrice(inputData.symbol),
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
</StepItem>
|
|
102
|
+
|
|
103
|
+
<StepItem>
|
|
104
|
+
|
|
105
|
+
Inside `src/mastra/agents/stockAgent.ts` import your newly created `stockPrices` tool and add it to the agent.
|
|
106
|
+
|
|
107
|
+
```ts copy title="src/mastra/agents/stockAgent.ts" {3, 10-12}
|
|
108
|
+
import { openai } from "@ai-sdk/openai";
|
|
109
|
+
import { Agent } from "@mastra/core/agent";
|
|
110
|
+
import { stockPrices } from "../tools/stockPrices";
|
|
111
|
+
|
|
112
|
+
export const stockAgent = new Agent({
|
|
113
|
+
id: "stock-agent",
|
|
114
|
+
name: "Stock Agent",
|
|
115
|
+
instructions:
|
|
116
|
+
"You are a helpful assistant that provides current stock prices. When asked about a stock, use the stock price tool to fetch the stock price.",
|
|
117
|
+
model: openai("gpt-4o-mini"),
|
|
118
|
+
tools: {
|
|
119
|
+
stockPrices,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
</StepItem>
|
|
125
|
+
|
|
126
|
+
</Steps>
|
|
127
|
+
|
|
128
|
+
## Running the Agent Server
|
|
129
|
+
|
|
130
|
+
Learn how to interact with your agent through Mastra's API.
|
|
131
|
+
|
|
132
|
+
<Steps>
|
|
133
|
+
|
|
134
|
+
<StepItem>
|
|
135
|
+
|
|
136
|
+
You can run your agent as a service using the `mastra dev` command:
|
|
137
|
+
|
|
138
|
+
```bash copy
|
|
139
|
+
mastra dev
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
This will start a server exposing endpoints to interact with your registered agents. Within [Studio](/docs/v1/getting-started/studio) you can test your `stockAgent` and `stockPrices` tool through a UI.
|
|
143
|
+
|
|
144
|
+
</StepItem>
|
|
145
|
+
|
|
146
|
+
<StepItem>
|
|
147
|
+
|
|
148
|
+
By default, `mastra dev` runs on `http://localhost:4111`. Your Stock agent will be available at:
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
POST http://localhost:4111/api/agents/stockAgent/generate
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
</StepItem>
|
|
155
|
+
|
|
156
|
+
<StepItem>
|
|
157
|
+
|
|
158
|
+
You can interact with the agent using `curl` from the command line:
|
|
159
|
+
|
|
160
|
+
```bash copy
|
|
161
|
+
curl -X POST http://localhost:4111/api/agents/stockAgent/generate \
|
|
162
|
+
-H "Content-Type: application/json" \
|
|
163
|
+
-d '{
|
|
164
|
+
"messages": [
|
|
165
|
+
{ "role": "user", "content": "What is the current stock price of Apple (AAPL)?" }
|
|
166
|
+
]
|
|
167
|
+
}'
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**Expected Response:**
|
|
171
|
+
|
|
172
|
+
You should receive a JSON response similar to:
|
|
173
|
+
|
|
174
|
+
```json
|
|
175
|
+
{
|
|
176
|
+
"text": "The current price of Apple (AAPL) is $174.55.",
|
|
177
|
+
"agent": "Stock Agent"
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
This indicates that your agent successfully processed the request, used the `stockPrices` tool to fetch the stock price, and returned the result.
|
|
182
|
+
|
|
183
|
+
</StepItem>
|
|
184
|
+
|
|
185
|
+
</Steps>
|