### Install a Chroma Sample App Source: https://docs.trychroma.com/docs/cli/sample-apps Use this command to install a specific sample application. The CLI will guide you through any necessary customizations and environment setup. ```bash chroma install [app_name] ``` -------------------------------- ### Full Example: Setup, Add, and Query Source: https://docs.trychroma.com/docs/overview/getting-started A complete example demonstrating ChromaDB setup, including client initialization, collection creation/retrieval, document upsertion, and querying. Use get_or_create_collection and upsert for idempotent operations. ```python import chromadb chroma_client = chromadb.Client() # switch `create_collection` to `get_or_create_collection` to avoid creating a new collection every time collection = chroma_client.get_or_create_collection(name="my_collection") # switch `add` to `upsert` to avoid adding the same documents every time collection.upsert( documents=[ "This is a document about pineapple", "This is a document about oranges" ], ids=["id1", "id2"] ) results = collection.query( query_texts=["This is a query document about florida"], # Chroma will embed this for you n_results=2 # how many results to return ) print(results) ``` -------------------------------- ### Full Example: Querying with TypeScript Source: https://docs.trychroma.com/docs/overview/getting-started A complete TypeScript example demonstrating how to set up a Chroma client, create or get a collection, upsert documents, and perform a query. ```typescript import { ChromaClient } from "chromadb"; const client = new ChromaClient(); // switch `createCollection` to `getOrCreateCollection` to avoid creating a new collection every time const collection = await client.getOrCreateCollection({ name: "my_collection", }); // switch `addRecords` to `upsertRecords` to avoid adding the same documents every time await collection.upsert({ documents: [ "This is a document about pineapple", "This is a document about oranges", ], ids: ["id1", "id2"], }); const results = await collection.query({ queryTexts: ["This is a query document about florida"], nResults: 2, // how many results to return }); console.log(results); ``` -------------------------------- ### Start Chroma Server Source: https://docs.trychroma.com/docs/run-chroma/client-server Run this command in your terminal to start the Chroma server. Specify the desired path for your database. ```bash chroma run --path /db_path ``` -------------------------------- ### Install ChromaDB with bun Source: https://docs.trychroma.com/docs/overview/getting-started Install the chromadb package and the default embedding model using bun. ```bash bun add chromadb @chroma-core/default-embed ``` -------------------------------- ### Install Chroma JavaScript CLI with bun Source: https://docs.trychroma.com/docs/cli/install Install the Chroma JavaScript package globally using bun. ```bash bun add -g chromadb ``` -------------------------------- ### List Available Chroma Sample Apps Source: https://docs.trychroma.com/docs/cli/sample-apps Run this command to view a comprehensive list of all available sample applications that can be installed. ```bash chroma install --list ``` -------------------------------- ### Install and Run ChromaDB Migration CLI Source: https://docs.trychroma.com/docs/overview/migration Install the chroma-migrate package using pip and then run the command to migrate your existing ChromaDB data. ```bash pip install chroma-migrate chroma-migrate ``` -------------------------------- ### Install Chroma with pipx Source: https://docs.trychroma.com/docs/cli/install If global pip installs are not permitted, use pipx to install the Chroma CLI as a standalone program. ```bash pipx install chromadb ``` -------------------------------- ### Example Query and Get JSON Results Source: https://docs.trychroma.com/docs/querying-collections/query-and-get Illustrates the JSON output format for both query and get operations, showing the column-major structure for fields like IDs, embeddings, documents, metadatas, and distances. ```json // Query result { "ids": [["doc_1", "doc_7"]], "embeddings": [[[1, 2, 3, 4], [1, 2, 3, 4]]], "documents": [["Chroma stores vectors.", "Embeddings power semantic search."]], "metadatas": [[ {"source": "docs", "topic": "intro"}, {"source": "blog", "topic": "search"} ]], "distances": [[0.12, 0.21]], "included": ["embeddings", "documents", "metadatas", "distances"] } // Get result { "ids": ["doc_1", "doc_7"], "embeddings": [[1, 2, 3, 4], [1, 2, 3, 4]], "documents": ["Chroma stores vectors.", "Embeddings power semantic search."], "metadatas": [ {"source": "docs", "topic": "intro"}, {"source": "blog", "topic": "search"} ], "included": ["documents", "metadatas"] } ``` -------------------------------- ### Install ChromaDB with yarn Source: https://docs.trychroma.com/docs/overview/getting-started Install the chromadb package and the default embedding model using yarn. ```bash yarn add chromadb @chroma-core/default-embed ``` -------------------------------- ### Install Chroma JavaScript CLI with npm Source: https://docs.trychroma.com/docs/cli/install Install the Chroma JavaScript package globally using npm. ```bash npm install -g chromadb ``` -------------------------------- ### Install ChromaDB with pnpm Source: https://docs.trychroma.com/docs/overview/getting-started Install the chromadb package and the default embedding model using pnpm. ```bash pnpm add chromadb @chroma-core/default-embed ``` -------------------------------- ### Install and Run Chroma Server (TypeScript) Source: https://docs.trychroma.com/docs/run-chroma/clients To use the JS/TS client, you need a Chroma server. Install Chroma via npm and run the server using the CLI, specifying a path for data persistence. Alternatively, use the official Docker image. ```terminal npm install chromadb ``` ```terminal npx chroma run --path ./getting-started ``` ```terminal docker pull chromadb/chroma docker run -p 8000:8000 chromadb/chroma ``` -------------------------------- ### Run Chroma Backend Source: https://docs.trychroma.com/docs/overview/getting-started Start the Chroma backend server locally. The `--path` argument specifies where to store data. ```bash chroma run --path ./getting-started ``` -------------------------------- ### Install ChromaDB with npm Source: https://docs.trychroma.com/docs/overview/getting-started Install the chromadb package and the default embedding model using npm. ```bash npm install chromadb @chroma-core/default-embed ``` -------------------------------- ### Install Chroma JavaScript CLI with yarn Source: https://docs.trychroma.com/docs/cli/install Install the Chroma JavaScript package globally using yarn. ```bash yarn global add chromadb ``` -------------------------------- ### Install Chroma using uv Source: https://docs.trychroma.com/docs/overview/getting-started Install the Chroma Python package using uv, a fast Python package installer. This is an alternative to pip for managing dependencies. ```bash uv pip install chromadb ``` -------------------------------- ### Run Local Chroma Server with bun Source: https://docs.trychroma.com/docs/overview/getting-started Start a local Chroma server using bunx. Ensure the --path argument points to your desired data directory. ```bash bunx chroma run --path ./getting-started ``` -------------------------------- ### Install Chroma with pip Source: https://docs.trychroma.com/docs/cli/install Use this command to install the Chroma Python package, which includes the CLI. ```bash pip install chromadb ``` -------------------------------- ### Install Chroma JavaScript CLI with pnpm Source: https://docs.trychroma.com/docs/cli/install Install the Chroma JavaScript package globally using pnpm. ```bash pnpm add -g chromadb ``` -------------------------------- ### Create a Chroma Client Source: https://docs.trychroma.com/docs/overview/getting-started Instantiate a Chroma client to interact with the Chroma database. This example shows how to create a default client, which typically connects to an in-memory instance. ```python import chromadb chroma_client = chromadb.Client() ``` -------------------------------- ### Run Local Chroma Server with npm Source: https://docs.trychroma.com/docs/overview/getting-started Start a local Chroma server using npx. Ensure the --path argument points to your desired data directory. ```bash npx chroma run --path ./getting-started ``` -------------------------------- ### Run Chroma Server Locally Source: https://docs.trychroma.com/docs/cli/run Use this command to start a Chroma server on your local machine. Data will be persisted to the specified path, or to the 'chroma' directory by default. ```bash chroma run --path [/path/to/persist/data] ``` -------------------------------- ### Get and List Chroma Collections Source: https://docs.trychroma.com/docs/collections/manage-collections Use the client to retrieve a specific collection by name, get or create a collection, or list collections with pagination. Ensure the client is properly initialized before use. ```rust let collection = client.get_collection("my-collection").await?; ``` ```rust let collection = client .get_or_create_collection("my-collection", None, None) .await?; ``` ```rust let collections = client.list_collections(100, Some(0)).await?; ``` -------------------------------- ### Install OpenAI Package Source: https://docs.trychroma.com/docs/collections/manage-collections Install the necessary package for using the OpenAI embedding function. ```bash pip install openai ``` ```bash poetry add openai ``` ```bash uv pip install openai ``` -------------------------------- ### Install Chroma CLI on Windows Source: https://docs.trychroma.com/docs/cli/install Use this PowerShell command to install the Chroma CLI as a standalone program on Windows. ```powershell iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/chroma-core/chroma/main/rust/cli/install/install.ps1')) ``` -------------------------------- ### Old Basic Auth Client Configuration Source: https://docs.trychroma.com/docs/overview/migration Example of the previous client configuration for 'Basic' authentication, specifying the auth provider and credentials. ```yaml CHROMA_CLIENT_AUTH_PROVIDER="chromadb.auth.token.TokenAuthClientProvider" CHROMA_CLIENT_AUTH_CREDENTIALS="admin:admin" ``` -------------------------------- ### Basic Chroma Browse Command Source: https://docs.trychroma.com/docs/cli/browse Use this command to start browsing a specific collection. The collection name is a required argument. ```bash chroma browse [collection_name] [--local] ``` -------------------------------- ### Old Basic Auth Server Configuration Source: https://docs.trychroma.com/docs/overview/migration Example of the previous server configuration for 'Basic' authentication, including credentials and provider settings. ```yaml CHROMA_SERVER_AUTH_CREDENTIALS="admin:admin" CHROMA_SERVER_AUTH_CREDENTIALS_FILE="./example_file" CHROMA_SERVER_AUTH_CREDENTIALS_PROVIDER="chromadb.auth.providers.HtpasswdConfigurationServerAuthCredentialsProvider" CHROMA_SERVER_AUTH_PROVIDER="chromadb.auth.basic.BasicAuthServerProvider" ``` -------------------------------- ### Run Local Chroma Server with pnpm Source: https://docs.trychroma.com/docs/overview/getting-started Start a local Chroma server using pnpm exec. Ensure the --path argument points to your desired data directory. ```bash pnpm exec chroma run --path ./getting-started ``` -------------------------------- ### Prompt for AI to set up Chroma OSS project Source: https://docs.trychroma.com/docs/overview/getting-started Use this prompt with AI agents to set up a Python project with Chroma's in-memory client. It guides the AI to create a virtual environment, add and query data, and display the results. ```text In this directory create a new Python project with Chroma set up. Use a virtual environment. Write a small example that adds some data to a collection and queries it. Do not delete the data from the collection when it's complete. Run the script when you are done setting up the environment and writing the script. The output should show what data was ingested, what was the query, and the results. Your own summary should include this output so the user can see it. Use Chroma's in-memory client: `chromadb.Client()` ``` -------------------------------- ### Install Chroma CLI with cURL Source: https://docs.trychroma.com/docs/cli/install Use this cURL command to install the Chroma CLI as a standalone program on Unix-like systems. ```bash curl -sSL https://raw.githubusercontent.com/chroma-core/chroma/main/rust/cli/install/install.sh | bash ``` -------------------------------- ### Update Docker Container Start Command Source: https://docs.trychroma.com/docs/overview/migration Illustrates the updated Docker command to start a Chroma container, reflecting the change in default data location. Use this if you previously ran Chroma using a Docker container. ```bash docker run -p 8000:8000 -v ./chroma:/data chroma-core/chroma ``` -------------------------------- ### Install Chroma with Rust Source: https://docs.trychroma.com/docs/overview/getting-started Add the Chroma Rust client library to your project dependencies using Cargo. ```bash cargo add chroma ``` -------------------------------- ### Run Local Chroma Server with yarn Source: https://docs.trychroma.com/docs/overview/getting-started Start a local Chroma server using yarn. Ensure the --path argument points to your desired data directory. ```bash yarn chroma run --path ./getting-started ``` -------------------------------- ### Install Python Embedding Packages Source: https://docs.trychroma.com/docs/collections/configure Install the necessary Python packages for OpenAI and Cohere embedding functions using pip, poetry, or uv. ```bash pip install openai cohere ``` ```bash poetry add openai cohere ``` ```bash uv pip install openai cohere ``` -------------------------------- ### Install TypeScript Embedding Packages Source: https://docs.trychroma.com/docs/collections/configure Install the necessary TypeScript packages for OpenAI and Cohere embedding functions using npm, pnpm, bun, or yarn. ```bash npm install @chroma-core/openai @chroma-core/cohere ``` ```bash pnpm add @chroma-core/openai @chroma-core/cohere ``` ```bash bun add @chroma-core/openai @chroma-core/cohere ``` ```bash yarn add @chroma-core/openai @chroma-core/cohere ``` -------------------------------- ### Async Chroma Client (Python) Source: https://docs.trychroma.com/docs/run-chroma/client-server Use the AsyncHttpClient for non-blocking operations. All methods are async and require awaiting. This example demonstrates creating a collection and adding documents. ```python import asyncio import chromadb async def main(): client = await chromadb.AsyncHttpClient() collection = await client.create_collection(name="my_collection") await collection.add( documents=["hello world"], ids=["id1"] ) asyncio.run(main()) ``` -------------------------------- ### Prompt for AI to set up Chroma Cloud project Source: https://docs.trychroma.com/docs/overview/getting-started Use this prompt with AI agents like Claude Code, Cursor, or Codex to automatically set up a Python project with Chroma Cloud. It includes instructions for virtual environment setup, adding data, querying, and running the script. ```prompt In this directory create a new Python project with Chroma set up. Use a virtual environment. Write a small example that adds some data to a collection and queries it. Do not delete the data from the collection when it's complete. Run the script when you are done setting up the environment and writing the script. The output should show what data was ingested, what was the query, and the results. Your own summary should include this output so the user can see it. First, install `chromadb`. The project should be set up with Chroma Cloud. When you install `chromadb`, you get access to the Chroma CLI. You can run `chroma login` to authenticate. This will open a browser for authentication and save a connection profile locally. You can also use `chroma profile show` to see if the user already has an active profile saved locally. If so, you can skip the login step. Then create a DB using the CLI with `chroma db create chroma-getting-started`. This will create a DB with this name. Then use the CLI command `chroma db connect chroma-getting-started --env-file`. This will create a .env file in the current directory with the connection variables for this DB and account, so the CloudClient can be instantiated with chromadb.CloudClient(api_key=os.getenv("CHROMA_API_KEY"), ...). ``` -------------------------------- ### Browse Local Collection using Data Path Source: https://docs.trychroma.com/docs/cli/browse Browse a collection by providing the path to your local Chroma data. The CLI will start a local server at an available port. ```bash chroma browse my-local-collection --path ~/Developer/my-app/chroma ``` -------------------------------- ### Install Chroma using Poetry Source: https://docs.trychroma.com/docs/overview/getting-started Add Chroma to your project's dependencies using Poetry. This is useful for projects managed with the Poetry build system. ```bash poetry add chromadb ``` -------------------------------- ### Get records by author using $in Source: https://docs.trychroma.com/docs/querying-collections/metadata-filtering Example of filtering records to find those where the 'author' metadata field is one of the specified values. ```python collection.get( where={ "author": {"$in": ["Rowling", "Fitzgerald", "Herbert"]} } ) ``` ```typescript await collection.get({ where: { author: { $in: ["Rowling", "Fitzgerald", "Herbert"] }, }, }); ``` ```rust let where_clause = Where::Metadata(MetadataExpression { key: "author".to_string(), comparison: MetadataComparison::Set( SetOperator::In, MetadataSetValue::Str(vec![ "Rowling".to_string(), "Fitzgerald".to_string(), "Herbert".to_string(), ]), ), }); let results = collection .get(None, Some(where_clause), None, None, None) .await?; ``` -------------------------------- ### Initialize Chroma Clients Source: https://docs.trychroma.com/docs/overview/migration Demonstrates how to initialize different types of Chroma clients for in-process use. Applicable when using Chroma via Python. ```python import chromadb client = chromadb.Client() # or client = chromadb.EphemeralClient() # or client = chromadb.PersistentClient() ``` -------------------------------- ### List All Collections (Python) Source: https://docs.trychroma.com/docs/collections/manage-collections Use `list_collections` to get a list of all collections in your Chroma database, ordered by creation time. By default, it returns up to 100 collections. ```python collections = client.list_collections() ``` -------------------------------- ### Get or Create a Collection (Python) Source: https://docs.trychroma.com/docs/collections/manage-collections Use `get_or_create_collection` to retrieve a collection by name, creating it if it does not exist. You can provide arguments like metadata, which will be used only if the collection is created. ```python collection = client.get_or_create_collection( name="my-collection", metadata={"description": "..."} ) ``` -------------------------------- ### Initialize Persistent Python Client Source: https://docs.trychroma.com/docs/run-chroma/clients Use `PersistentClient` to configure Chroma to save and load the database from your local machine. Data is persisted automatically and loaded on start. The `path` argument specifies where database files are stored; defaults to `.chroma`. ```python import chromadb client = chromadb.PersistentClient(path="/path/to/save/to") ``` -------------------------------- ### List Collections with Limit and Offset (Python) Source: https://docs.trychroma.com/docs/collections/manage-collections Control the number of collections returned and the starting point using `limit` and `offset` arguments with `list_collections`. This is useful for pagination or retrieving specific subsets. ```python first_collections_batch = client.list_collections(limit=100) # get the first 100 collections ``` ```python second_collections_batch = client.list_collections(limit=100, offset=100) # get the next 100 collections ``` ```python collections_subset = client.list_collections(limit=20, offset=50) # get 20 collections starting from the 50th ``` -------------------------------- ### Run Chroma CLI with Configuration Source: https://docs.trychroma.com/docs/overview/migration Shows how to run the Chroma server using the CLI with a specified configuration file. This is relevant for users running a Chroma server via the CLI. ```bash chroma run --config ./config.yaml ``` -------------------------------- ### Connect to Chroma DB and create .env file Source: https://docs.trychroma.com/docs/cli/db Connects to a Chroma Cloud database and adds Chroma environment variables (CHROMA_API_KEY, CHROMA_TENANT, CHROMA_DATABASE) to a .env file in the current directory. Creates the .env file if it does not exist. ```bash chroma db connect [db_name] --env-file ``` -------------------------------- ### Install OpenAI Embedding Package (TypeScript) Source: https://docs.trychroma.com/docs/embeddings/embedding-functions Install the necessary package for using OpenAI embedding functions in your TypeScript project. ```bash npm install @chroma-core/openai ``` ```bash pnpm add @chroma-core/openai ``` ```bash bun add @chroma-core/openai ``` ```bash yarn add @chroma-core/openai ``` -------------------------------- ### Create Persistent Client (Before) Source: https://docs.trychroma.com/docs/overview/migration Instantiate a persistent ChromaDB client using the older Client class and Settings. ```python import chromadb from chromadb.config import Settings client = chromadb.Client(Settings( chroma_db_impl="duckdb+parquet", persist_directory="/path/to/persist/directory" # Optional, defaults to .chromadb/ in the current directory )) ``` -------------------------------- ### Connect to Chroma Server (Python) Source: https://docs.trychroma.com/docs/run-chroma/client-server Instantiate the HttpClient to connect to a running Chroma server. Ensure the host and port match your server configuration. ```python import chromadb chroma_client = chromadb.HttpClient(host='localhost', port=8000) ``` -------------------------------- ### Install Chroma using pip Source: https://docs.trychroma.com/docs/overview/getting-started Install the Chroma Python package using pip. This is a common method for adding Chroma to your Python project. ```bash pip install chromadb ``` -------------------------------- ### Install Default Embedding Package - Bash Source: https://docs.trychroma.com/docs/embeddings/embedding-functions Installs the default embedding package for ChromaDB using various package managers. This is required if you don't specify an embedding function during collection creation. ```bash npm install @chroma-core/default-embed ``` ```bash pnpm add @chroma-core/default-embed ``` ```bash bun add @chroma-core/default-embed ``` ```bash yarn add @chroma-core/default-embed ``` -------------------------------- ### Create Collection with Metadata (Python) Source: https://docs.trychroma.com/docs/collections/manage-collections Create a collection and attach metadata, such as a description and creation timestamp. ```python from datetime import datetime collection = client.create_collection( name="my_collection", embedding_function=emb_fn, metadata={ "description": "my first Chroma collection", "created": str(datetime.now()) } ) ``` -------------------------------- ### Instantiate Chroma Cloud Client Source: https://docs.trychroma.com/docs/run-chroma/clients Use the CloudClient to connect to Chroma Cloud. Provide tenant, database, and API key for authentication. Environment variables can also be used. ```python import chromadb client = chromadb.CloudClient( tenant='Tenant ID', database='Database name', api_key='Chroma Cloud API key' ) ``` ```typescript import { CloudClient } from "chromadb"; const client = new CloudClient({ tenant: "Tenant ID", database: "Database name", apiKey: "Chroma Cloud API key", }); ``` ```rust use chroma::{ChromaHttpClient, ChromaHttpClientOptions}; let options = ChromaHttpClientOptions::cloud( "ck-...", "Database name", )?; let client = ChromaHttpClient::new(options); ``` -------------------------------- ### Connect to Chroma DB and output environment variables Source: https://docs.trychroma.com/docs/cli/db Connects to a Chroma Cloud database and outputs the Chroma environment variables (CHROMA_API_KEY, CHROMA_TENANT, CHROMA_DATABASE) to the terminal. ```bash chroma db connect [db_name] --env-vars ``` -------------------------------- ### Run Local Chroma Server with Docker Source: https://docs.trychroma.com/docs/overview/getting-started Pull the Chroma Docker image and run a local Chroma server on port 8000. ```bash docker pull chromadb/chroma docker run -p 8000:8000 chromadb/chroma ``` -------------------------------- ### Get Collections by Names Source: https://docs.trychroma.com/docs/collections/manage-collections Retrieves multiple collections by their names. ```APIDOC ## Get Collections by Names (TypeScript) ### Description Retrieves multiple collections by their names. If an embedding function was used during creation and is not provided here, Chroma will resolve it automatically on recent versions. For older versions, you must provide the embedding function. ### Method ```typescript client.getCollections(names: Array<{ name: string, embeddingFunction?: EmbeddingFunction }> | string[]): Promise ``` ### Parameters #### Request Body - **names** (Array<{ name: string, embeddingFunction?: EmbeddingFunction }> | string[]) - Required - An array of collection names or objects containing names and optional embedding functions. ### Request Example ```typescript const [col1, col2] = client.getCollections(["col1", "col2"]); const [colA, colB] = client.getCollections([ { name: "colA", embeddingFunction: openaiEF }, { name: "colB", embeddingFunction: defaultEF }, ]); ``` ### Response #### Success Response (200) - **collections** (array) - An array of collection objects. ### Response Example ```json [ { "name": "col1", "metadata": { ... }, "configuration": { ... }, "embeddingFunction": { ... } }, { "name": "col2", "metadata": { ... }, "configuration": { ... }, "embeddingFunction": { ... } } ] ``` ``` -------------------------------- ### Connect to Chroma Server with HttpClient Source: https://docs.trychroma.com/docs/cli/run Instantiate the Chroma client to connect to a running Chroma server. Ensure the host and port match your server's configuration. ```python import chromadb chroma_client = chromadb.HttpClient(host='localhost', port=8000) ``` ```typescript import { ChromaClient } from "chromadb"; const client = new ChromaClient(); ``` -------------------------------- ### Get Records by IDs Source: https://docs.trychroma.com/docs/querying-collections/query-and-get Use `.get` to retrieve records by their IDs. This method does not perform similarity ranking. ```typescript await collection.get({ ids: ["id1", "id2"] }); // By IDs ``` -------------------------------- ### Initialize TypeScript Client (Custom Configuration) Source: https://docs.trychroma.com/docs/run-chroma/clients Configure the `ChromaClient` with custom settings for SSL, host, port, database, and headers to connect to a Chroma server with non-standard configurations. ```typescript const client = new ChromaClient({ ssl: false, host: "localhost", port: 9000, // non-standard port based on your server config database: "my-db", headers: {}, }); ``` -------------------------------- ### Get or Create Collection Source: https://docs.trychroma.com/docs/collections/manage-collections Retrieves a collection by name, or creates it if it does not exist. Existing collection parameters are ignored. ```APIDOC ## Get or Create Collection ### Description Retrieves a collection by name, or creates it if it does not exist. Existing collection parameters are ignored. ### Method ```python client.get_or_create_collection(name: str, metadata: Optional[Dict] = None, ...) ``` ### Parameters #### Path Parameters - **name** (str) - Required - The name of the collection to get or create. - **metadata** (Optional[Dict]) - Optional - Metadata to associate with the collection if it is created. ### Request Example ```python collection = client.get_or_create_collection( name="my-collection", metadata={"description": "..."} ) ``` ### Response #### Success Response (200) - **Collection** (object) - An object representing the collection. ### Response Example ```json { "name": "my-collection", "metadata": {"description": "..."}, "configuration": { ... }, "embedding_function": { ... } } ``` ``` ```APIDOC ## Get or Create Collection (TypeScript) ### Description Retrieves a collection by name, or creates it if it does not exist. Existing collection parameters are ignored. ### Method ```typescript client.getOrCreateCollection({ name: string, metadata?: Record }): Promise ``` ### Parameters #### Request Body - **name** (string) - Required - The name of the collection to get or create. - **metadata** (Record) - Optional - Metadata to associate with the collection if it is created. ### Request Example ```typescript const collection = await client.getOrCreateCollection({ name: "my-collection", metadata: { description: "..." }, }); ``` ### Response #### Success Response (200) - **Collection** (object) - An object representing the collection. ### Response Example ```json { "name": "my-collection", "metadata": {"description": "..."}, "configuration": { ... }, "embeddingFunction": { ... } } ``` ``` -------------------------------- ### Get Records from Collection Source: https://docs.trychroma.com/docs/querying-collections/query-and-get Retrieve records from a collection by their IDs or using pagination. This method does not perform similarity ranking. ```APIDOC ## Get Use `.get` to retrieve records by ID and/or filters without similarity ranking: ```python collection.get(ids=["id1", "id2"]) # by IDs collection.get(limit=100, offset=0) # with pagination ``` ``` -------------------------------- ### Get Records by IDs Source: https://docs.trychroma.com/docs/querying-collections/query-and-get Retrieve specific records from a collection using their IDs. This method does not perform similarity search. ```python collection.get(ids=["id1", "id2"]) ``` -------------------------------- ### Create In-Memory Ephemeral Client (Before) Source: https://docs.trychroma.com/docs/overview/migration Instantiate an in-memory ephemeral ChromaDB client using the older Client class. ```python import chromadb client = chromadb.Client() ``` -------------------------------- ### Create Persistent Client (After) Source: https://docs.trychroma.com/docs/overview/migration Instantiate a persistent ChromaDB client using the new PersistentClient class. ```python import chromadb client = chromadb.PersistentClient(path="/path/to/persist/directory") ``` -------------------------------- ### Get Collection Records (TypeScript) Source: https://docs.trychroma.com/docs/querying-collections/query-and-get Retrieves records by ID and/or filters without similarity ranking. Supports pagination. ```APIDOC ## Get Collection Records (TypeScript) Use `.get` to retrieve records by ID and/or filters without similarity ranking: ```typescript await collection.get({ ids: ["id1", "id2"] }); // By IDs await collection.get({ limit: 100, offset: 0 }); // With pagination ``` ``` -------------------------------- ### Get Records with Pagination Source: https://docs.trychroma.com/docs/querying-collections/query-and-get Use `.get` with `limit` and `offset` parameters for paginating through records. This method does not perform similarity ranking. ```typescript await collection.get({ limit: 100, offset: 0 }); // With pagination ``` -------------------------------- ### Browse Local Collection using Default Host Source: https://docs.trychroma.com/docs/cli/browse Use the `--local` flag to browse a collection from a local Chroma server running at the default host and port. ```bash chroma browse my-local-collection --local ``` -------------------------------- ### Count and Peek Records in Collection Source: https://docs.trychroma.com/docs/collections/manage-collections Utilize convenience methods to get the total number of records or the first few records in a collection. ```python collection.count() collection.peek() ``` ```typescript await collection.count(); await collection.peek(); ``` -------------------------------- ### Get Multiple Collections (TypeScript) Source: https://docs.trychroma.com/docs/collections/manage-collections Retrieve multiple collections at once using the `getCollections` function, passing an array of collection names. ```typescript const [col1, col2] = client.getCollections(["col1", "col2"]); ``` -------------------------------- ### Instantiate Chroma Cloud Client with Environment Variables Source: https://docs.trychroma.com/docs/run-chroma/clients If CHROMA_API_KEY, CHROMA_TENANT, and CHROMA_DATABASE environment variables are set, you can instantiate a CloudClient with no arguments. ```python client = chromadb.CloudClient() ``` ```typescript const client = new CloudClient(); ``` ```rust use chroma::ChromaHttpClient; let client = ChromaHttpClient::cloud()?; ``` -------------------------------- ### Query Records with $and Filter (Rust) Source: https://docs.trychroma.com/docs/querying-collections/metadata-filtering Example of querying records where the 'page' metadata field is between 5 and 10, using the $and operator in Rust. ```rust let where_clause = Where::Composite(CompositeExpression { operator: BooleanOperator::And, children: vec![ Where::Metadata(MetadataExpression { key: "page".to_string(), comparison: MetadataComparison::Primitive( PrimitiveOperator::GreaterThanOrEqual, MetadataValue::Int(5), ), }), Where::Metadata(MetadataExpression { key: "page".to_string(), comparison: MetadataComparison::Primitive( PrimitiveOperator::LessThanOrEqual, MetadataValue::Int(10), ), }), ], }); let results = collection .query(vec![vec![0.1, 0.2, 0.3]], Some(10), Some(where_clause), None, None) .await?; ``` -------------------------------- ### Query Records with $and Filter (TypeScript) Source: https://docs.trychroma.com/docs/querying-collections/metadata-filtering Example of querying records where the 'page' metadata field is between 5 and 10, using the $and operator in TypeScript. ```typescript await collection.query({ queryTexts: ["first query", "second query"], where: { $and: [{ page: { $gte: 5 } }, { page: { $lte: 10 } }], }, }); ``` -------------------------------- ### Query Records with $and Filter (Python) Source: https://docs.trychroma.com/docs/querying-collections/metadata-filtering Example of querying records where the 'page' metadata field is between 5 and 10, using the $and operator in Python. ```python collection.query( query_texts=["first query", "second query"], where={ "$and": [ {"page": {"$gte": 5 } }, {"page": {"$lte": 10 } }, ] } ) ``` -------------------------------- ### Get a Collection by Name (TypeScript) Source: https://docs.trychroma.com/docs/collections/manage-collections Use `getCollection` to retrieve an existing collection by its name. If an embedding function was not provided during creation, it can be supplied here. ```typescript const collection = await client.getCollection({ name: "my-collection " }); ``` -------------------------------- ### Query Records with $or Filter (Rust) Source: https://docs.trychroma.com/docs/querying-collections/metadata-filtering Example of querying records where the 'color' metadata field is either 'red' or 'blue', using the $or operator in Rust. ```rust let where_clause = Where::Composite(CompositeExpression { operator: BooleanOperator::Or, children: vec![ Where::Metadata(MetadataExpression { key: "color".to_string(), comparison: MetadataComparison::Primitive( ``` -------------------------------- ### Create Chroma Client in Rust Source: https://docs.trychroma.com/docs/overview/getting-started Initialize a Chroma HTTP client to connect to the running Chroma backend. ```rust use chroma::ChromaHttpClient; let client = ChromaHttpClient::new(Default::default()); ``` -------------------------------- ### Query Records with $or Filter (TypeScript) Source: https://docs.trychroma.com/docs/querying-collections/metadata-filtering Example of querying records where the 'color' metadata field is either 'red' or 'blue', using the $or operator in TypeScript. ```typescript await collection.get({ where: { "$or": [{ "color": "red" }, { "color": "blue" }], }, }); ``` -------------------------------- ### Query Records with $or Filter (Python) Source: https://docs.trychroma.com/docs/querying-collections/metadata-filtering Example of querying records where the 'color' metadata field is either 'red' or 'blue', using the $or operator in Python. ```python collection.get( where={ "$or": [ {"color": "red"}, {"color": "blue"}, ] } ) ``` -------------------------------- ### Create In-Memory Ephemeral Client (After) Source: https://docs.trychroma.com/docs/overview/migration Instantiate an in-memory ephemeral ChromaDB client using the new EphemeralClient class. ```python import chromadb client = chromadb.EphemeralClient() ``` -------------------------------- ### Query Chroma Collection Source: https://docs.trychroma.com/docs/overview/getting-started Query a Chroma collection with a list of query texts to retrieve the most similar results. This is a basic example; further customization is possible. ```typescript const results = await collection.query({ ``` -------------------------------- ### Iterating Get Results Source: https://docs.trychroma.com/docs/querying-collections/query-and-get Demonstrates how to iterate through the results of a .get() operation in Python, TypeScript, and Rust, accessing individual documents and their associated metadata. ```python result = collection.get(include=["documents", "metadatas"]) for id, document, metadata in zip(result["ids"], result["documents"], result["metadatas"]): print(id, document, metadata) ``` ```typescript const result = await collection.get(); const first_document = { id: result["ids"][0], document: result["documents"][0], metadatas: result["metadatas"][0] } // Use the .rows() function for easy iteration for (const row of result.rows()) { console.log(row.id, row.document, row.metadata); } ``` ```rust let result = collection.get(None, None, None, None, None).await?; if let (Some(documents), Some(metadatas)) = (&result.documents, &result.metadatas) { for i in 0..result.ids.len() { let id = &result.ids[i]; let document = &documents[i]; let metadata = &metadatas[i]; println!("{id:?} {document:?} {metadata:?}"); } } ``` -------------------------------- ### Vacuum Chroma Database Source: https://docs.trychroma.com/docs/cli/vacuum Run this command to shrink and optimize your Chroma database. Replace `` with the actual path to your Chroma data. ```bash chroma utils vacuum --path ``` -------------------------------- ### Get Collection Records (Rust) Source: https://docs.trychroma.com/docs/querying-collections/query-and-get Retrieves records by ID and/or filters without similarity ranking. Supports pagination and include options. ```APIDOC ## Get Collection Records (Rust) Use `.get` to retrieve records by ID and/or filters without similarity ranking: ```rust let response = collection .get( Some(vec!["id1".to_string(), "id2".to_string()]), None, Some(10), Some(0), Some(IncludeList::default_get()), ) .await?; ``` ``` -------------------------------- ### Get Records with Pagination Source: https://docs.trychroma.com/docs/querying-collections/query-and-get Retrieve records from a collection with pagination controls using `limit` and `offset`. Useful for fetching large datasets in chunks. ```python collection.get(limit=100, offset=0) ``` -------------------------------- ### Browse Local Collection with Custom Host Source: https://docs.trychroma.com/docs/cli/browse Specify a custom host for your local Chroma server when browsing a collection. This overrides the default. ```bash chroma browse my-local-collection --host http://localhost:8050 ``` -------------------------------- ### Login in Headless Environment with API Key Source: https://docs.trychroma.com/docs/cli/login Use this command for environments without a browser. You must first create an API key in the Chroma Cloud dashboard. ```bash chroma login --profile my_profile_name --api-key ck-... ``` -------------------------------- ### Create a new Chroma DB Source: https://docs.trychroma.com/docs/cli/db Creates a new database on Chroma Cloud. Errors if a database with the specified name already exists. Prompts for a name if not provided. ```bash chroma db create my-new-db ``` -------------------------------- ### Query and Get Result Types Source: https://docs.trychroma.com/docs/querying-collections/query-and-get Defines the structure of QueryResult and GetResult for Python, TypeScript, and Rust. These types specify the fields and their expected data formats. ```python class QueryResult(TypedDict): ids: List[IDs] embeddings: Optional[List[Embeddings]] documents: Optional[List[List[Document]]] uris: Optional[List[List[URI]]] metadatas: Optional[List[List[Metadata]]] distances: Optional[List[List[float]]] included: Include class GetResult(TypedDict): ids: List[ID] embeddings: Optional[Embeddings] documents: Optional[List[Document]] uris: Optional[URIs] metadatas: Optional[List[Metadata]] included: Include ``` ```typescript class QueryResult { public readonly ids: string[][]; public readonly distances: (number | null)[][]; public readonly documents: (string | null)[][]; public readonly embeddings: (number[] | null)[][]; public readonly metadatas: (Record | null)[][]; public readonly uris: (string | null)[][]; public readonly include: Include[]; } class GetResult { public readonly ids: string[]; public readonly documents: (string | null)[]; public readonly embeddings: number[][]; public readonly metadatas: (Record | null)[]; public readonly uris: (string | null)[]; public readonly include: Include[]; } ``` ```rust pub struct QueryResponse { pub ids: Vec>, pub embeddings: Option>>>>, pub documents: Option>>>, pub uris: Option>>>, pub metadatas: Option>>>>, pub distances: Option>>>, pub include: Vec, } pub struct GetResponse { pub ids: Vec, pub embeddings: Option> >, pub documents: Option>>, pub uris: Option>>, pub metadatas: Option>>>, pub include: Vec, } ``` -------------------------------- ### Get Collection with ID Filtering Only Source: https://docs.trychroma.com/docs/overview/migration Shows the correct way to call `collection.get` when metadata filtering is not required. Previously, empty dictionaries for metadata were not supported. ```python collection.get(ids=["id1", "id2", "id3", ...]) ``` -------------------------------- ### Get Multiple Collections with Embedding Functions (TypeScript) Source: https://docs.trychroma.com/docs/collections/manage-collections When retrieving multiple collections with `getCollections` in older versions, you can specify the `embeddingFunction` for each collection individually if needed. ```typescript const [col1, col2] = client.getCollections([ { name: "col1", embeddingFunction: openaiEF }, { name: "col2", embeddingFunction: defaultEF }, ]); ```