ChromaDB client library for Rust.
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 chromadb::v1::client::{ChromaClient, ChromaClientOptions};
use chromadb::v1::collection::{ChromaCollection, GetResult};
use serde_json::json;
# async fn doc_client_demo() -> anyhow::Result<()> {
let client: ChromaClient = ChromaClient::new(Default::default());
let client: ChromaClient = ChromaClient::new(ChromaClientOptions { url: "<CHROMADB_URL>".into() });
# Ok(())
# }
Now that a client is instantiated, we can interface with the ChromaDB server and execute queries.
A collection can be retrieved with the create_collection, get_or_create_collection, get_collection methods.
# use chromadb::v1::ChromaClient;
# use chromadb::v1::collection::{ChromaCollection, GetResult};
# use serde_json::json;
# async fn doc_client_create_collection(client: &ChromaClient) -> anyhow::Result<()> {
let collection: ChromaCollection = client.get_or_create_collection("my_collection", None).await?;
let collection_uuid = collection.id();
println!("Collection UUID: {}", collection_uuid);
let result: bool = collection.upsert(
vec!["demo-id-1", "demo-id-1", "demo-id-1"],
Some(vec![vec![0.0_f64; 768]]),
None,
Some(vec![
"Some document about 9 octopus recipies".into(),
"Some other document about DCEU Superman Vs CW Superman".into()
]),
None).await?;
let where_document = json!({
"$contains": "Superman"
});
let get_result: GetResult = collection.get(
vec![],
None,
Some(1),
None,
Some(where_document),
Some(vec![
"documents",
"embeddings"
])).await?;
println!("Get result: {:?}", get_result);
# Ok(())
# }
Find more information about on the available filters and options in the get() documentation.