Skip to Content
ReferenceRAGChromaVector

Chroma Vector Store

The ChromaVector class provides vector search using ChromaDB, an open-source embedding database. It offers efficient vector search with metadata filtering and hybrid search capabilities.

Constructor Options

path:

string
URL path to ChromaDB instance

auth?:

object
Authentication configuration

auth

provider:

string
Authentication provider

credentials:

string
Authentication credentials

Methods

createIndex()

indexName:

string
Name of the index to create

dimension:

number
Vector dimension (must match your embedding model)

metric?:

'cosine' | 'euclidean' | 'dotproduct'
= cosine
Distance metric for similarity search

upsert()

indexName:

string
Name of the index to upsert into

vectors:

number[][]
Array of embedding vectors

metadata?:

Record<string, any>[]
Metadata for each vector

ids?:

string[]
Optional vector IDs (auto-generated if not provided)

documents?:

string[]
Chroma-specific: Original text documents associated with the vectors

query()

indexName:

string
Name of the index to query

queryVector:

number[]
Query vector to find similar vectors

topK?:

number
= 10
Number of results to return

filter?:

Record<string, any>
Metadata filters for the query

includeVector?:

boolean
= false
Whether to include vectors in the results

documentFilter?:

Record<string, any>
Chroma-specific: Filter to apply on the document content

listIndexes()

Returns an array of index names as strings.

describeIndex()

indexName:

string
Name of the index to describe

Returns:

interface IndexStats { dimension: number; count: number; metric: "cosine" | "euclidean" | "dotproduct"; }

deleteIndex()

indexName:

string
Name of the index to delete

updateIndexById()

indexName:

string
Name of the index containing the vector to update

id:

string
ID of the vector to update

update:

object
Update parameters

The update object can contain:

vector?:

number[]
New vector to replace the existing one

metadata?:

Record<string, any>
New metadata to replace the existing metadata

deleteIndexById()

indexName:

string
Name of the index containing the vector to delete

id:

string
ID of the vector to delete

Response Types

Query results are returned in this format:

interface QueryResult { id: string; score: number; metadata: Record<string, any>; document?: string; // Chroma-specific: Original document if it was stored vector?: number[]; // Only included if includeVector is true }

Error Handling

The store throws typed errors that can be caught:

try { await store.query({ indexName: "index_name", queryVector: queryVector, }); } catch (error) { if (error instanceof VectorStoreError) { console.log(error.code); // 'connection_failed' | 'invalid_dimension' | etc console.log(error.details); // Additional error context } }