Create an in-memory client for local use.This client stores all data in memory and does not persist to disk.
It is intended for testing and development.
Optional[Settings]
Optional settings to override defaults.
str
Tenant name to use for requests. Defaults to the default tenant.
str
Database name to use for requests. Defaults to the default database.
PersistentClient
Create a persistent client that stores data on disk.This client is intended for local development and testing. For production,
prefer a server-backed Chroma instance.
Union[str, Path]
Directory to store persisted data.
Optional[Settings]
Optional settings to override defaults.
str
Tenant name to use for requests.
str
Database name to use for requests.
HttpClient
Create a client that connects to a Chroma server.
str
Hostname of the Chroma server.
int
HTTP port of the Chroma server.
bool
Whether to enable SSL for the connection.
Optional[Dict[str, str]]
Optional headers to send with each request.
Optional[Settings]
Optional settings to override defaults.
str
Tenant name to use for requests.
str
Database name to use for requests.
AsyncHttpClient
Create an async client that connects to a Chroma HTTP server.This supports multiple clients connecting to the same server and is the
recommended production configuration.
str
Hostname of the Chroma server.
int
HTTP port of the Chroma server.
bool
Whether to enable SSL for the connection.
Optional[Dict[str, str]]
Optional headers to send with each request.
Optional[Settings]
Optional settings to override defaults.
str
Tenant name to use for requests.
str
Database name to use for requests.
CloudClient
Create a client for Chroma Cloud.If not provided, tenant, database, and api_key will be inferred from the environment variables CHROMA_TENANT, CHROMA_DATABASE, and CHROMA_API_KEY.
Optional[str]
Tenant name to use, or None to infer from credentials.
Optional[str]
Database name to use, or None to infer from credentials.
Optional[str]
API key for Chroma Cloud.
Optional[Settings]
Optional settings to override defaults.
str
int
bool
AdminClient
Create an admin client for tenant and database management.
Settings
Client Methods
heartbeat
Get the current time in nanoseconds since epoch.Used to check if the server is alive.Returns: The current time in nanoseconds since epoch
list_collections
List all collections.
Optional[int]
The maximum number of entries to return. Defaults to None.
Optional[int]
The number of entries to skip before returning. Defaults to None.
Returns: A list of collections
count_collections
Count the number of collections.Returns: The number of collections.
create_collection
Create a new collection with the given name and metadata.
str
required
The name of the collection to create.
Optional[Schema]
Optional[CreateCollectionConfiguration]
Optional[Dict[str, Any]]
Optional metadata to associate with the collection.
Optional[EmbeddingFunction[Optional[Embeddings]]]
Optional function to use to embed documents.
Uses the default embedding function if not provided.
Optional[DataLoader[Optional[Embeddings]]]
Optional function to use to load records (documents, images, etc.)
bool
If True, return the existing collection if it exists.
Returns: The newly created collection.Raises:
ValueError: If the collection already exists and get_or_create is False.
ValueError: If the collection name is invalid.
get_collection
Get a collection with the given name.
str
required
The name of the collection to get
Optional[EmbeddingFunction[Optional[Embeddings]]]
Optional function to use to embed documents.
Uses the default embedding function if not provided.
Optional[DataLoader[Optional[Embeddings]]]
Optional function to use to load records (documents, images, etc.)
Returns: The collectionRaises:
ValueError: If the collection does not exist
get_or_create_collection
Get or create a collection with the given name and metadata.Args:
name: The name of the collection to get or create
metadata: Optional metadata to associate with the collection. If
the collection already exists, the metadata provided is ignored.
If the collection does not exist, the new collection will be created
with the provided metadata.
embedding_function: Optional function to use to embed documents
data_loader: Optional function to use to load records (documents, images, etc.)Returns:
The collectionExamples: