@mastra/chroma
Vector store implementation for ChromaDB using the official chromadb client with added dimension validation and collection management.
Installation
npm install @mastra/chroma
Usage
import { ChromaVector } from '@mastra/chroma';
const vectorStore = new ChromaVector({
path: 'http://localhost:8000',
auth: {
provider: 'token',
credentials: 'your-token'
}
});
await vectorStore.createIndex('my-collection', 1536, 'cosine');
const vectors = [[0.1, 0.2, ...], [0.3, 0.4, ...]];
const metadata = [{ text: 'doc1' }, { text: 'doc2' }];
const ids = await vectorStore.upsert('my-collection', vectors, metadata);
const results = await vectorStore.query(
'my-collection',
[0.1, 0.2, ...],
10,
{ text: { $eq: 'doc1' } },
false
);
Configuration
Required:
path
: URL of your ChromaDB server
Optional:
auth
: Authentication configuration
provider
: Authentication providercredentials
: Authentication credentials
Features
- Vector similarity search with cosine, euclidean, and dot product metrics
- Strict vector dimension validation
- Collection-based organization
- Metadata filtering support
- Optional vector inclusion in query results
- Automatic UUID generation for vectors
- Built-in collection caching for performance
- Built on top of chromadb client
Methods
createIndex(indexName, dimension, metric?)
: Create a new collectionupsert(indexName, vectors, metadata?, ids?)
: Add or update vectorsquery(indexName, queryVector, topK?, filter?, includeVector?)
: Search for similar vectorslistIndexes()
: List all collectionsdescribeIndex(indexName)
: Get collection statisticsdeleteIndex(indexName)
: Delete a collection
Query Response Format
Query results include:
id
: Vector IDscore
: Distance/similarity scoremetadata
: Associated metadatavector
: Original vector (if includeVector is true)
Related Links