Crate chroma

Crate chroma 

Source
Expand description

Rust client library for the Chroma AI-native database.

This crate provides a comprehensive, production-ready client for interacting with Chroma, an AI-native open-source embedding database. Chroma transforms embeddings into queryable databases, enabling similarity search, filtering, and retrieval operations over high-dimensional vector data.

§Features

  • Automatic retries - Configurable exponential backoff with jitter for resilient network operations
  • OpenTelemetry support - Optional metrics collection for observability (enable opentelemetry feature)
  • TLS flexibility - Support for both native-tls and rustls backends

§Core Types

§Quick Start

§Connecting to Chroma Cloud

use chroma::{ChromaHttpClient, client::ChromaHttpClientOptions, client::ChromaAuthMethod};


let client = ChromaHttpClient::cloud()?;

let heartbeat = client.heartbeat().await?;
println!("Connected! Heartbeat: {}", heartbeat.nanosecond_heartbeat);

§Managing Databases

client.create_database("my_database".to_string()).await?;

let databases = client.list_databases().await?;
for db in databases {
    println!("Found database: {}", db.name);
}

client.delete_database("my_database".to_string()).await?;

§Working with Collections

let collections = client
    .list_collections(100, None)
    .await?;

for collection in collections {
    println!("Collection: {}", collection.name());
}

§Authentication

The client supports multiple authentication methods:

  • Cloud API Key - For Chroma Cloud deployments using ChromaAuthMethod::cloud_api_key
  • Custom Headers - For self-hosted instances with custom auth via ChromaAuthMethod::HeaderAuth
  • No Auth - For local development with ChromaAuthMethod::None

§Error Handling

All operations return Result<T, ChromaHttpClientError> where ChromaHttpClientError captures network errors, serialization failures, and validation errors.

match client.heartbeat().await {
    Ok(response) => println!("Heartbeat: {}", response.nanosecond_heartbeat),
    Err(ChromaHttpClientError::RequestError(e)) => eprintln!("Network error: {}", e),
    Err(e) => eprintln!("Other error: {}", e),
}

§Feature Flags

  • default - Enables native-tls for TLS support
  • native-tls - Use native system TLS (OpenSSL on Linux, Secure Transport on macOS)
  • rustls - Use pure-Rust TLS implementation
  • opentelemetry - Enable metrics collection for request latency and retry counts

Re-exports§

pub use client::ChromaHttpClient;
pub use client::ChromaHttpClientOptions;

Modules§

client
Client configuration and connection management for Chroma.
embed
Embedding function abstractions for converting text to vector representations.
types
Type definitions and re-exports for client requests and responses.

Structs§

ChromaCollection
A handle to a specific collection within a Chroma database.