Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langchain ai Langchain Chroma Constructor

From Leeroopedia
Knowledge Sources
Domains Vector_Search, Database
Last Updated 2026-02-11 00:00 GMT

Overview

Concrete tool for initializing a Chroma vector store provided by the LangChain Chroma integration.

Description

The Chroma class wraps the chromadb client library and implements the VectorStore interface. It supports local persistence (via persist_directory), client-server mode (via host/port), and Chroma Cloud. The embedding function from the initialization step is stored and used automatically for all add/search operations.

Usage

Use the Chroma class for development, testing, and small-to-medium production deployments. For large-scale production, consider Qdrant or other dedicated vector databases.

Code Reference

Source Location

  • Repository: langchain
  • File: libs/partners/chroma/langchain_chroma/vectorstores.py
  • Lines: L155-420 (class), L302-348 (__init__)

Signature

class Chroma(VectorStore):
    def __init__(
        self,
        collection_name: str = "_langchain_default_collection_name",
        embedding_function: Embeddings | None = None,
        persist_directory: str | None = None,
        host: str | None = None,
        port: int | None = None,
        headers: dict[str, str] | None = None,
        client_settings: chromadb.config.Settings | None = None,
        collection_metadata: dict | None = None,
        client: chromadb.ClientAPI | None = None,
        relevance_score_fn: Callable[[float], float] | None = None,
        create_collection_if_not_exists: bool | None = True,
        *,
        ssl: bool = False,
    ) -> None:

Import

from langchain_chroma import Chroma

I/O Contract

Inputs

Name Type Required Description
collection_name str No (default: "_langchain_default_collection_name") Chroma collection name
embedding_function Embeddings or None No Embedding model from initialization step
persist_directory str or None No Local path for persistent storage
client chromadb.ClientAPI or None No Pre-configured Chroma client

Outputs

Name Type Description
instance Chroma Initialized vector store ready for document operations

Usage Examples

In-Memory Store

from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings

embeddings = OpenAIEmbeddings(model="text-embedding-3-small")

# In-memory (ephemeral)
vectorstore = Chroma(
    collection_name="my_docs",
    embedding_function=embeddings,
)

Persistent Store

vectorstore = Chroma(
    collection_name="my_docs",
    embedding_function=embeddings,
    persist_directory="./chroma_db",
)

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment