DatabaseConfig
The DatabaseConfig type allows you to specify database-specific configurations when using vector query tools. These configurations enable you to use features and optimizations offered by different vector stores.
Type definitionDirect link to Type definition
export type DatabaseConfig = {
pinecone?: PineconeConfig
pgvector?: PgVectorConfig
chroma?: ChromaConfig
turbopuffer?: TurbopufferConfig
[key: string]: any // Extensible for future databases
}
Database-specific typesDirect link to Database-specific types
PineconeConfigDirect link to pineconeconfig
Configuration options specific to Pinecone vector store.
namespace?:
sparseVector?:
indices:
values:
Use Cases:
- Multi-tenant applications (separate namespaces per tenant)
- Environment isolation (dev/staging/prod namespaces)
- Hybrid search combining semantic and keyword matching
PgVectorConfigDirect link to pgvectorconfig
Configuration options specific to PostgreSQL with pgvector extension.
minScore?:
ef?:
probes?:
Performance Guidelines:
- ef: Start with 2-4x your topK value, increase for better accuracy
- probes: Start with 1-10, increase for better recall
- minScore: Use values between 0.5-0.9 depending on your quality requirements
Use Cases:
- Performance optimization for high-load scenarios
- Quality filtering to remove irrelevant results
- Fine-tuning search accuracy vs speed tradeoffs
ChromaConfigDirect link to chromaconfig
Configuration options specific to Chroma vector store.
where?:
whereDocument?:
Filter Syntax Examples:
// Simple equality
where: { "category": "technical" }
// Operators
where: { "price": { "$gt": 100 } }
// Multiple conditions
where: {
"category": "electronics",
"inStock": true
}
// Document content filtering
whereDocument: { "$contains": "API documentation" }
Use Cases:
- Advanced metadata filtering
- Content-based document filtering
- Complex query combinations
TurbopufferConfigDirect link to turbopufferconfig
Configuration options specific to Turbopuffer vector store.
consistency?:
Use Cases:
- Latency-sensitive queries where slightly stale data is acceptable (
eventual) - Read-your-writes workflows that must see the latest data (
strong)
Usage examplesDirect link to Usage examples
- Basic Usage
- Runtime Override
- Multi-Database
- Performance Tuning
Basic Database ConfigurationDirect link to Basic Database Configuration
import { createVectorQueryTool } from '@mastra/rag'
const vectorTool = createVectorQueryTool({
vectorStoreName: 'pinecone',
indexName: 'documents',
model: embedModel,
databaseConfig: {
pinecone: {
namespace: 'production',
},
},
})
Runtime Configuration OverrideDirect link to Runtime Configuration Override
import { RequestContext } from '@mastra/core/request-context'
// Initial configuration
const vectorTool = createVectorQueryTool({
vectorStoreName: 'pinecone',
indexName: 'documents',
model: embedModel,
databaseConfig: {
pinecone: {
namespace: 'development',
},
},
})
// Override at runtime
const requestContext = new RequestContext()
requestContext.set('databaseConfig', {
pinecone: {
namespace: 'production',
},
})
await vectorTool.execute({ queryText: 'search query' }, { mastra, requestContext })
Multi-Database ConfigurationDirect link to Multi-Database Configuration
const vectorTool = createVectorQueryTool({
vectorStoreName: 'dynamic', // Will be determined at runtime
indexName: 'documents',
model: embedModel,
databaseConfig: {
pinecone: {
namespace: 'default',
},
pgvector: {
minScore: 0.8,
ef: 150,
},
chroma: {
where: { type: 'documentation' },
},
},
})
Multi-Database Support: When you configure multiple databases, only the configuration matching the actual vector store being used will be applied.
Performance TuningDirect link to Performance Tuning
// High accuracy configuration
const highAccuracyTool = createVectorQueryTool({
vectorStoreName: 'postgres',
indexName: 'embeddings',
model: embedModel,
databaseConfig: {
pgvector: {
ef: 400, // High accuracy
probes: 20, // High recall
minScore: 0.85, // High quality threshold
},
},
})
// High speed configuration
const highSpeedTool = createVectorQueryTool({
vectorStoreName: 'postgres',
indexName: 'embeddings',
model: embedModel,
databaseConfig: {
pgvector: {
ef: 50, // Lower accuracy, faster
probes: 3, // Lower recall, faster
minScore: 0.6, // Lower quality threshold
},
},
})
ExtensibilityDirect link to Extensibility
The DatabaseConfig type is designed to be extensible. To add support for a new vector database:
// 1. Define the configuration interface
export interface NewDatabaseConfig {
customParam1?: string
customParam2?: number
}
// 2. Extend DatabaseConfig type
export type DatabaseConfig = {
pinecone?: PineconeConfig
pgvector?: PgVectorConfig
chroma?: ChromaConfig
newdatabase?: NewDatabaseConfig
[key: string]: any
}
// 3. Use in vector query tool
const vectorTool = createVectorQueryTool({
vectorStoreName: 'newdatabase',
indexName: 'documents',
model: embedModel,
databaseConfig: {
newdatabase: {
customParam1: 'value',
customParam2: 42,
},
},
})
Best practicesDirect link to Best practices
- Environment Configuration: Use different namespaces or configurations for different environments
- Performance Tuning: Start with default values and adjust based on your specific needs
- Quality Filtering: Use minScore to filter out low-quality results
- Runtime Flexibility: Override configurations at runtime for runtime-defined scenarios
- Documentation: Document your specific configuration choices for team members
Migration guideDirect link to Migration guide
Existing vector query tools continue to work without changes. To add database configurations:
const vectorTool = createVectorQueryTool({
vectorStoreName: 'pinecone',
indexName: 'documents',
model: embedModel,
+ databaseConfig: {
+ pinecone: {
+ namespace: 'production'
+ }
+ }
});