clients/js/packages/chromadb-client/README.md
Chroma is the open-source data infrastructure for AI. Chroma makes it easy to build LLM apps by making knowledge, facts, and skills pluggable for LLMs.
Note: JS client version 3._ is only compatible with chromadb v1.0.6 and newer or Chroma Cloud. For prior version compatiblity, please use JS client version 2._.
This package provides embedding libraries as peer dependencies, allowing you to manage your own versions of embedding libraries and keep your dependency tree lean by not bundling dependencies you don't use. For a thick client with bundled embedding functions, install chromadb.
# npm
npm install chromadb-client
# pnpm
pnpm add chromadb-client
# yarn
yarn add chromadb-client
You'll need to install any required embedding libraries separately. For example:
# For OpenAI embeddings
npm install chromadb-client openai
# For default embeddings
npm install chromadb-client chromadb-default-embed
# For Cohere embeddings
npm install chromadb-client cohere-ai
Chroma needs to be running in order for this client to talk to it. Please see the Usage Guide to learn how to quickly stand this up.
import { ChromaClient } from "chromadb-client";
// Initialize the client
const chroma = new ChromaClient({ path: "http://localhost:8000" });
// Create a collection
const collection = await chroma.createCollection({ name: "my-collection" });
// Add documents to the collection
await collection.add({
ids: ["id1", "id2"],
embeddings: [
[1.1, 2.3, 3.2],
[4.5, 6.9, 4.4],
],
metadatas: [{ source: "doc1" }, { source: "doc2" }],
documents: ["Document 1 content", "Document 2 content"],
});
// Query the collection
const results = await collection.query({
queryEmbeddings: [1.1, 2.3, 3.2],
nResults: 2,
});
Make sure to install the necessary peer dependencies before using embedding functions:
// First install: npm install chromadb-client openai
import { ChromaClient, OpenAIEmbeddingFunction } from "chromadb-client";
const embedder = new OpenAIEmbeddingFunction({
openai_api_key: "your-api-key",
model_name: "text-embedding-ada-002",
});
const chroma = new ChromaClient({ path: "http://localhost:8000" });
const collection = await chroma.createCollection({
name: "my-collection",
embeddingFunction: embedder,
});
// Now you can add documents without providing embeddings
await collection.add({
ids: ["id1"],
documents: ["Document content"],
});
// And query with text
const results = await collection.query({
queryTexts: ["similar document"],
nResults: 2,
});
This package supports multiple embedding providers as peer dependencies:
openai)cohere-ai)chromadb-default-embed)@google/generative-ai)@xenova/transformers)voyageai)ollama)chromadb packageApache 2.0