M
Mastra2mo ago
ahanusek

Using createVectorQueryTool in agent configuration throwing TS Error

Hey, I'm using the latest mastra packages and trying to add a vector tool to the agent, but this is throwing a Zod error:
Type 'RagTool<ZodObject<{ filter: ZodString; queryText: ZodString; topK: ZodNumber; }, "strip", ZodTypeAny, { filter: string; topK: number; queryText: string; }, { ...; }> | ZodObject<...>, any>' is not assignable to type 'ToolAction<any, any, any, any, ToolExecutionContext<any, any, any>> | VercelTool | VercelToolV5'.
[deleted]
Types of property 'inputSchema' are incompatible.
Type 'ZodObject<{ filter: ZodString; queryText: ZodString; topK: ZodNumber; }, "strip", ZodTypeAny, { filter: string; topK: number; queryText: string; }, { ...; }> | ZodObject<...> | undefined' is not assignable to type 'FlexibleSchema<any>'.
Type 'undefined' is not assignable to type 'FlexibleSchema<any>'
Type 'RagTool<ZodObject<{ filter: ZodString; queryText: ZodString; topK: ZodNumber; }, "strip", ZodTypeAny, { filter: string; topK: number; queryText: string; }, { ...; }> | ZodObject<...>, any>' is not assignable to type 'ToolAction<any, any, any, any, ToolExecutionContext<any, any, any>> | VercelTool | VercelToolV5'.
[deleted]
Types of property 'inputSchema' are incompatible.
Type 'ZodObject<{ filter: ZodString; queryText: ZodString; topK: ZodNumber; }, "strip", ZodTypeAny, { filter: string; topK: number; queryText: string; }, { ...; }> | ZodObject<...> | undefined' is not assignable to type 'FlexibleSchema<any>'.
Type 'undefined' is not assignable to type 'FlexibleSchema<any>'
Code:
tools: {
organizationDetailsTool,
searchOrganizationsTool,
pgVectorQueryTool,
},
tools: {
organizationDetailsTool,
searchOrganizationsTool,
pgVectorQueryTool,
},
Tool definition
import { INDEX_NAME, pgVector } from "@/mastra/vectors/db-config";
import { openai } from "@ai-sdk/openai";
import { createVectorQueryTool } from "@mastra/rag";

export const pgVectorQueryTool = createVectorQueryTool({
indexName: INDEX_NAME,
model: openai.embedding("text-embedding-3-small"),
vectorStore: pgVector,
enableFilter: true,
includeSources: true,
databaseConfig: {
pgvector: {
minScore: 0.4, // Filter low-quality results
},
},
});
import { INDEX_NAME, pgVector } from "@/mastra/vectors/db-config";
import { openai } from "@ai-sdk/openai";
import { createVectorQueryTool } from "@mastra/rag";

export const pgVectorQueryTool = createVectorQueryTool({
indexName: INDEX_NAME,
model: openai.embedding("text-embedding-3-small"),
vectorStore: pgVector,
enableFilter: true,
includeSources: true,
databaseConfig: {
pgvector: {
minScore: 0.4, // Filter low-quality results
},
},
});
package.json
"@mastra/ai-sdk": "^0.2.5",
"@mastra/client-js": "^0.16.8",
"@mastra/core": "^0.23.3",
"@mastra/langfuse": "0.2.2",
"@mastra/libsql": "^0.16.1",
"@mastra/loggers": "^0.10.18",
"@mastra/memory": "^0.15.10",
"@mastra/observability": "^0.0.4",
"@mastra/pg": "^0.17.7",
"@mastra/rag": "^1.3.3",
"@mastra/ai-sdk": "^0.2.5",
"@mastra/client-js": "^0.16.8",
"@mastra/core": "^0.23.3",
"@mastra/langfuse": "0.2.2",
"@mastra/libsql": "^0.16.1",
"@mastra/loggers": "^0.10.18",
"@mastra/memory": "^0.15.10",
"@mastra/observability": "^0.0.4",
"@mastra/pg": "^0.17.7",
"@mastra/rag": "^1.3.3",
documentation: https://mastra.ai/en/examples/rag/usage/filter-rag#vector-query-tool-creation
Example: Agent-Driven Metadata Filtering | Retrieval | RAG | Mastra...
Example of using a Mastra agent in a RAG system to construct and apply metadata filters for document retrieval.
4 Replies
Mastra Triager
Mastra Triager2mo ago
GitHub
[DISCORD:1433425201961500712] Using createVectorQueryTool in agent ...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1433425201961500712 Hey, I&#39;m using the latest mastra packages and trying to add a vector tool to the a...
Abhi Aiyer
Abhi Aiyer2w ago
Hi! I do not reproduce this on latest versions!
Edgar
Edgar2w ago
Hey @ahanusek , I fixed this by wrapping a vector tool with a generic tool. Apparently nested tools can loose inputSchema and this is a registered bug here: https://github.com/mastra-ai/mastra/issues/9699
import { createTool } from "@mastra/core/tools";
import { createVectorQueryTool } from '@mastra/rag';
import { openai } from '@ai-sdk/openai';
import { z } from "zod";
import dedent from 'dedent';

const vectorTool = createVectorQueryTool({
id: "vector-tool",
description: dedent`
Query the style guidelines for something.
`,
vectorStoreName: 'someStore',
indexName: 'someIndex',
model: openai.embedding("text-embedding-3-small"),
databaseConfig: {
pgvector: {
minScore: 0.2,
ef: 400,
probes: 75,
},
},
});

export const genericGuidelineTool = createTool({
id: 'get-guidelines-tool',
description:
'Query the style guidelines for something.',
inputSchema: z.object({
queryText: z.string().min(1).describe("Query text"),
topK: z.number().int().min(1).max(20).describe("Number of results"),
}).strict(),
execute: async ({ context, runtimeContext, mastra }) => {
const { queryText, topK } = context;

return vectorTool.execute({
context: { queryText, topK },
runtimeContext: runtimeContext,
mastra: mastra,
});
},
});
import { createTool } from "@mastra/core/tools";
import { createVectorQueryTool } from '@mastra/rag';
import { openai } from '@ai-sdk/openai';
import { z } from "zod";
import dedent from 'dedent';

const vectorTool = createVectorQueryTool({
id: "vector-tool",
description: dedent`
Query the style guidelines for something.
`,
vectorStoreName: 'someStore',
indexName: 'someIndex',
model: openai.embedding("text-embedding-3-small"),
databaseConfig: {
pgvector: {
minScore: 0.2,
ef: 400,
probes: 75,
},
},
});

export const genericGuidelineTool = createTool({
id: 'get-guidelines-tool',
description:
'Query the style guidelines for something.',
inputSchema: z.object({
queryText: z.string().min(1).describe("Query text"),
topK: z.number().int().min(1).max(20).describe("Number of results"),
}).strict(),
execute: async ({ context, runtimeContext, mastra }) => {
const { queryText, topK } = context;

return vectorTool.execute({
context: { queryText, topK },
runtimeContext: runtimeContext,
mastra: mastra,
});
},
});
GitHub
Chaining supervisor agent with agents which own vector tools does n...
This issue was created from Discord post 1435311074948943993: I have created a supervisor agent, which has a tool calling agent B. Agent B has an access to the vector tool and if called directly - ...
Abhi Aiyer
Abhi Aiyer2w ago
I just made a fix for that other issue last night! Vector tool was using Zod.passthrough which adds that additional properties thing

Did you find this page helpful?