Vector Store Integrations
Relevant source files
The following files were used as context for generating this wiki page:
- packages/core/src/vector/vector.ts
- stores/pinecone/src/vector/index.ts
- stores/chroma/src/vector/index.ts
- stores/qdrant/src/vector/index.ts
- stores/upstash/src/vector/index.ts
- stores/pg/README.md
- stores/astra/README.md
- stores/duckdb/README.md
- stores/s3vectors/README.md
- stores/vectorize/README.md
- stores/couchbase/README.md
- communications/releases/2025-02-09.md
- templates/template-coding-agent/src/mastra/agents/coding-agent.ts
- CLAUDE.md
Vector store integrations are a core component of the Mastra framework, providing a pluggable architecture for persisting and querying vector embeddings. This system is fundamental for enabling advanced AI capabilities such as semantic search, retrieval-augmented generation (RAG), and long-term memory for agents. By abstracting the specific database implementations, Mastra allows developers to switch between different vector databases with minimal code changes.
The architecture is built around a standardized MastraVector interface, which defines a common set of operations for all vector stores. Each integration is a separate package that implements this interface, translating the standard Mastra operations into the native API calls of the specific vector database. This modular design is a key pattern in the Mastra framework, promoting flexibility and extensibility.
Sources: CLAUDE.md, DEVELOPMENT.md
Core Abstraction: MastraVector
The foundation of the vector store system is the MastraVector interface. It defines the contract that all vector store adapters must adhere to, ensuring a consistent API for interacting with vector data regardless of the underlying storage backend.
Sources: packages/core/src/vector/vector.ts
MastraVector Interface Methods
The following table outlines the primary methods defined in the MastraVector interface.
| Method | Description |
|---|---|
createIndex | Creates a new index (or collection/table) in the vector store with a specified dimension and metric. |
upsert | Adds or updates vectors and their associated metadata in the specified index. |
query | Performs a similarity search against an index to find the top K vectors most similar to a query vector. |
updateVector | Updates a single vector entry by its ID with new vector data and/or metadata. |
deleteVector | Deletes a single vector by its ID. |
deleteVectors | Deletes multiple vectors by their IDs or based on a metadata filter. |
listIndexes | Lists all available indexes in the vector store. |
describeIndex | Retrieves statistics for a specific index, such as dimension, metric, and vector count. |
deleteIndex | Deletes an entire index and all its data. |
connect | Establishes a connection to the database. Often handled lazily. |
disconnect | Closes the connection to the database. |
Sources: packages/core/src/vector/vector.ts:10-101
Architecture Diagram
This diagram illustrates how different vector store implementations extend the base MastraVector interface.
Metadata Filtering System
A key feature of the vector store integration is the unified metadata filtering system. It allows developers to use a consistent, MongoDB-like query syntax to filter results during a query operation. Each vector store adapter includes a FilterTranslator component responsible for converting this generic query object into the native filtering language of the specific database.
This abstraction simplifies development, as developers do not need to learn the unique filter syntax for each different vector database they might use.
Sources: communications/releases/2025-02-09.md, stores/pg/README.md, stores/duckdb/README.md
Filter Translation Flow
The diagram below shows how a query with a filter is processed.
Supported Filter Operators
The filtering system supports a rich set of operators for complex queries.
| Operator | Description | Example |
|---|---|---|
$eq | Matches values that are equal to a specified value. | { "category": { "$eq": "technology" } } |
$ne | Matches all values that are not equal to a value. | { "status": { "$ne": "archived" } } |
$gt | Matches values that are greater than a value. | { "price": { "$gt": 100 } } |
$gte | Matches values that are greater than or equal to. | { "year": { "$gte": 2022 } } |
$lt | Matches values that are less than a value. | { "stock": { "$lt": 10 } } |
$lte | Matches values that are less than or equal to. | { "rating": { "$lte": 4.5 } } |
$in | Matches any of the values specified in an array. | { "tags": { "$in": ["A", "B"] } } |
$nin | Matches none of the values specified in an array. | { "tags": { "$nin": ["C", "D"] } } |
$exists | Matches documents that have the specified field. | { "image_url": { "$exists": true } } |
$and | Joins query clauses with a logical AND. | { "$and": [{...}, {...}] } |
$or | Joins query clauses with a logical OR. | { "$or": [{...}, {...}] } |
$not | Inverts the effect of a query expression. | { "field": { "$not": { "$eq": "value" } } } |
$contains | Selects documents where the field is a string that contains the specified substring. | { "text": { "$contains": "Mastra" } } |
Sources: stores/duckdb/README.md, stores/pg/README.md, stores/s3vectors/README.md
Supported Vector Stores
Mastra supports a variety of vector databases through its pluggable store architecture. Each is available as a separate package.
Sources: DEVELOPMENT.md
Pinecone (@mastra/pinecone)
A managed vector database. The implementation uses the Pinecone SDK and supports its unified filter API. Upserts are automatically batched.
| Option | Description |
|---|---|
apiKey | Your Pinecone API key. |
indexName | The name of the Pinecone index to use. |
Sources: stores/pinecone/src/vector/index.ts, communications/releases/2025-02-09.md
Chroma (@mastra/chroma)
An open-source vector database. The implementation uses the chromadb client.
| Option | Description |
|---|---|
collection | The name of the Chroma collection to use. |
path | The URL of the ChromaDB instance. |
Sources: stores/chroma/src/vector/index.ts, communications/releases/2025-02-09.md
Qdrant (@mastra/qdrant)
A vector database with advanced filtering capabilities, including geo-spatial queries.
| Option | Description |
|---|---|
url | The URL of the Qdrant instance. |
apiKey | Optional API key for authentication. |
collectionName | The name of the Qdrant collection to use. |
Sources: stores/qdrant/src/vector/index.ts, communications/releases/2025-02-09.md
Upstash (@mastra/upstash)
A serverless vector database built on Redis.
| Option | Description |
|---|---|
url | Your Upstash database URL. |
token | Your Upstash database read/write token. |
Sources: stores/upstash/src/vector/index.ts, communications/releases/2025-02-09.md
DuckDB (@mastra/duckdb)
An in-process SQL OLAP database with a vector similarity search (VSS) extension. It requires no external server.
| Option | Description |
|---|---|
id | Unique identifier for the vector store instance. |
path | Database file path. Use :memory: for in-memory. |
dimensions | Default dimension for vector embeddings. |
metric | Default distance metric (cosine, euclidean, dotproduct). |
Sources: stores/duckdb/README.md
Amazon S3 Vectors (@mastra/s3vectors)
A preview service from AWS for vector storage and search built on S3.
| Option | Description |
|---|---|
vectorBucketName | The name of the S3 vector bucket. |
clientConfig | AWS SDK v3 S3VectorsClientConfig (region, credentials). |
nonFilterableMetadataKeys | Metadata keys that are stored but not filterable at query time. |
Sources: stores/s3vectors/README.md
Other Integrations
Mastra also provides integrations for:
- PostgreSQL (
@mastra/pg): A unified package for PostgreSQL with PGVector. - DataStax Astra DB (
@mastra/astra): A cloud-native NoSQL database with vector capabilities. - Cloudflare Vectorize (
@mastra/vectorize): A globally distributed vector database. - Couchbase (
@mastra/couchbase): A NoSQL database with vector search features. - LibSQL (
@mastra/libsql): A fork of SQLite, used for local/embedded vector storage.
Sources: stores/pg/README.md, stores/astra/README.md, stores/vectorize/README.md, stores/couchbase/README.md, templates/template-coding-agent/src/mastra/agents/coding-agent.ts:11-12
Common Operations
The following diagrams illustrate the data flow for the two most common vector store operations.
Upsert Operation
This sequence diagram shows how vectors and metadata are added to a store.
Query Operation
This sequence diagram shows how a similarity search is performed, including the filter translation step.
Integration with Mastra Systems
Vector stores are a foundational service layer used by higher-level systems within Mastra.
- Memory System: The
Memoryclass uses a vector store forsemanticRecall, allowing agents to retrieve relevant past messages based on semantic similarity rather than just chronological order. It also uses it forworkingMemory. - RAG (Retrieval-Augmented Generation): RAG tools, such as the
VectorQuerytool, directly use vector stores to fetch relevant document chunks to augment an LLM's context.
Sources: CLAUDE.md, templates/template-coding-agent/src/mastra/agents/coding-agent.ts:110-116, communications/releases/2025-02-09.md
Conclusion
The Mastra vector store integration system provides a robust, flexible, and consistent way to work with vector embeddings. Its pluggable architecture, centered around the MastraVector interface and a powerful filter translation layer, allows developers to leverage a wide range of vector databases without being locked into a specific vendor. This modularity is crucial for building scalable and maintainable AI applications that rely on semantic search and retrieval.