Chroma plugin
The Chroma plugin provides indexer and retriever implementations that use the Chroma vector database in client/server mode.
Installation
npm install genkitx-chromadb
Configuration
To use this plugin, specify it when you initialize Genkit:
import { genkit } from 'genkit';import { chroma } from 'genkitx-chromadb';
const ai = genkit({ plugins: [ chroma([ { collectionName: 'bob_collection', embedder: textEmbedding004, }, ]), ],});
You must specify a Chroma collection and the embedding model you want to use. In addition, there are two optional parameters:
-
clientParams
: If you’re not running your Chroma server on the same machine as your Genkit flow, you need to specify auth options, or you’re otherwise not running a default Chroma server configuration, you can specify a ChromaChromaClientParams
object to pass to the Chroma client:clientParams: {path: "http://192.168.10.42:8000",} -
embedderOptions
: Use this parameter to pass options to the embedder:embedderOptions: { taskType: 'RETRIEVAL_DOCUMENT' },
Usage
Import retriever and indexer references like so:
import { chromaRetrieverRef } from 'genkitx-chromadb';import { chromaIndexerRef } from 'genkitx-chromadb';
Then, use the references with ai.retrieve()
and ai.index()
:
// To use the index you configured when you loaded the plugin:let docs = await ai.retrieve({ retriever: chromaRetrieverRef, query });
// To specify an index:export const bobFactsRetriever = chromaRetrieverRef({ collectionName: 'bob-facts',});docs = await ai.retrieve({ retriever: bobFactsRetriever, query });
// To use the index you configured when you loaded the plugin:await ai.index({ indexer: chromaIndexerRef, documents });
// To specify an index:export const bobFactsIndexer = chromaIndexerRef({ collectionName: 'bob-facts',});await ai.index({ indexer: bobFactsIndexer, documents });
See the Retrieval-augmented generation page for a general discussion on indexers and retrievers.