💾 Installing the library
cargo add chromadb
📖 Documentation
The library reference can be found here.
🔍 Overview
The library provides 2 modules to interact with the ChromaDB server via API V1
client- To interface with the ChromaDB server.collection- To interface with an associated ChromaDB collection.
You can connect to ChromaDB by instantiating a ChromaClient
use ;
use ;
// With default ChromaClientOptions
// Defaults to http://localhost:8000
let client: ChromaClient = new;
// With custom ChromaClientOptions
let auth = TokenAuth ;
let client: ChromaClient = new;
Now that a client is instantiated, we can interface with the ChromaDB server
use json;
// Get or create a collection with the given name and no metadata.
let collection: ChromaCollection = client.get_or_create_collection.await?;
// Get the UUID of the collection
let collection_uuid = collection.id;
println!;
With a collection instance, we can perform queries on the database
// Upsert some embeddings with documents and no metadata.
let collection_entries = CollectionEntries ;
let result: bool = collection.upsert.await?;
// Create a filter object to filter by document content.
let where_document = json!;
// Get embeddings from a collection with filters and limit set to 1.
// An empty IDs vec will return all embeddings.
let get_query = GetQuery ;
let get_result: GetResult = collection.get.await?;
println!;
Find more information about the available filters and options in the get() documentation.
Performing a similarity search
//Instantiate QueryOptions to perform a similarity search on the collection
//Alternatively, an embedding_function can also be provided with query_texts to perform the search
let query = QueryOptions ;
let query_result: QueryResult = collection.query.await?;
println!;
Support for Embedding providers
This crate has built-in support for OpenAI and SBERT embeddings.
To use OpenAI embeddings, enable the openai feature in your Cargo.toml.
let collection: ChromaCollection = client.get_or_create_collection.await?;
let collection_entries = CollectionEntries ;
// Use OpenAI embeddings
let openai_embeddings = new;
collection.upsert.await?;
Sponsors
OpenSauced provides insights into open source projects by using data science in git commits.
