⚙️ Running ChromaDB
ℹ Chroma can be run in-memory in Python (without Docker), but this feature is not yet available in other languages. To use this library you either need a hosted or local version of ChromaDB running.
If you can run docker-compose up -d --build you can run Chroma.
git clone https://github.com/chroma-core/chroma.git
cd chroma
# Run a ChromaDB instance at localhost:8000
docker-compose up -d --build
More information about deploying Chroma to production can be found here.
🚀 Installing the library
cargo add chromadb
The library crate can be found at crates.io.
📖 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 ChromaClient;
use ;
use json;
// With default ChromaClientOptions
// Defaults to http://localhost:8000
let client: ChromaClient = new;
// With custom ChromaClientOptions
let client: ChromaClient = new;
Now that a client is instantiated, we can interface with the ChromaDB server.
// Get or create a collection with the given name and no metadata.
let collection: ChromaCollection = client.get_or_create_collection?;
// 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?;
// 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?;
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?;
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?;
let collection_entries = CollectionEntries ;
// Use OpenAI embeddings
let openai_embeddings = new;
collection.upsert?;
To use SBERT embeddings, enable the bert feature in your Cargo.toml.
let collection_entries = CollectionEntries ;
// Use SBERT embeddings
let sbert_embeddings = remote.create_model?;
collection.upsert?;
Sponsors
OpenSauced provides insights into open source projects by using data science in git commits.
⚖️ LICENSE
MIT © 2023
