[help] how to force a filter on a createVectorQueryTool (pgVector)

hello, I have a context with some variables and I would like to force a filter on the query tool in the context, I set a clientId var and in the pgVector table, I also have a clientId field in metadata col maybe I'm going in the wrong way and one table / client is a better option ?
export const vectorQueryTool = createVectorQueryTool({
vectorStoreName: "pgvector",
indexName: "deliverable_embedding",
model: ollama.textEmbeddingModel("bge-m3"),
vectorStore: pgVectorStore,
includeSources: true,
enableFilter: true,
databaseConfig: {
pgvector: {
minScore: 0.1,
ef: 100,

},
},
});
export const vectorQueryTool = createVectorQueryTool({
vectorStoreName: "pgvector",
indexName: "deliverable_embedding",
model: ollama.textEmbeddingModel("bge-m3"),
vectorStore: pgVectorStore,
includeSources: true,
enableFilter: true,
databaseConfig: {
pgvector: {
minScore: 0.1,
ef: 100,

},
},
});
how to do it ? I tried to adapt the doc here https://mastra.ai/en/reference/tools/vector-query-tool#example-using-runtime-context without success.
Reference: createVectorQueryTool() | RAG | Mastra Tools Docs
Documentation for the Vector Query Tool in Mastra, which facilitates semantic search over vector stores with filtering and reranking capabilities.
3 Replies
Mastra Triager
GitHub
[DISCORD:1428698675420332042] [help] how to force a filter on a cre...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1428698675420332042 hello, I have a context with some variables and I would like to force a filter on the ...
Abhi Aiyer
Abhi Aiyer3d ago
Is this dynamic? Do you want to always filter on clientId? You can set the filter field in RuntimeContext and if passed to your vectoryQueryTool will use that as the filter, otherwise it is what the agent has decided to call. @mastra/rag also exports vector prompts that help your agent query the store and provide accurate filters https://github.com/mastra-ai/mastra/blob/main/stores/pg/src/vector/prompt.ts
GitHub
mastra/stores/pg/src/vector/prompt.ts at main · mastra-ai/mastra
The TypeScript AI agent framework. ⚡ Assistants, RAG, observability. Supports any LLM: GPT-4, Claude, Gemini, Llama. - mastra-ai/mastra
altab
altabOP3d ago
it's dynamic, and yes I want to filter on clientId does filter runtimeContext works with pgvector? my tests were not succesful is relying entirely on the LLM with the pgvector prompt with an instruction passed in the prompt (eg. "always apply filter + runtime context) ok ?

Did you find this page helpful?