DocsReferenceRAGVector Query Tool

createVectorQueryTool()

The createVectorQueryTool() function creates a tool for semantic search over vector stores. It supports filtering, reranking, and integrates with various vector store backends.

Basic Usage

import { createVectorQueryTool } from "@mastra/rag";
 
const queryTool = createVectorQueryTool({
  vectorStoreName: "pinecone",
  indexName: "docs",
  options: {
    provider: "OPEN_AI",
    model: "text-embedding-ada-002",
    maxRetries: 3
  }
});

Parameters

vectorStoreName:

string
Name of the vector store to query (must be configured in Mastra)

indexName:

string
Name of the index within the vector store

options:

EmbeddingOptions
Configuration for embedding generation

topK?:

number
Maximum number of results to retrieve

vectorFilterType?:

'pg' | 'astra' | 'qdrant' | 'upstash' | 'pinecone' | 'chroma' | ''
Type of vector store for filter formatting

rerankOptions?:

RerankerOptions
Options for reranking results

Returns

The tool returns an object with:

relevantContext:

string
Combined text from the most relevant document chunks

Example with Filters

// Pinecone/PG/Astra
const queryTool = createVectorQueryTool({
  vectorStoreName: "pinecone",
  indexName: "docs",
  options: {
    provider: "OPEN_AI",
    model: "text-embedding-ada-002",
    maxRetries: 3
  },
  vectorFilterType: "pinecone",
  topK: 5
});

Filter Formats:

  • Pinecone/PG/Astra: { category: { eq: "technical" } }

Example with Reranking

const queryTool = createVectorQueryTool({
  vectorStoreName: "milvus",
  indexName: "documentation",
  options: {
    provider: "OPEN_AI",
    model: "text-embedding-ada-002",
    maxRetries: 3
  },
  topK: 5,
  rerankOptions: {
    model: "cross-encoder",
    threshold: 0.7
  }
});

Tool Details

The tool is created with:

  • ID: VectorQuery {vectorStoreName} {indexName} Tool
  • Description: Fetches and combines the top {topK} relevant chunks from the {vectorStoreName} vector store using the {indexName} index
  • Input Schema: Requires queryText and filter objects
  • Output Schema: Returns relevantContext string

MIT 2025 © Nextra.