6 releases

0.1.8 Mar 28, 2024
0.1.6 Mar 28, 2024

#531 in Database interfaces

Download history 470/week @ 2024-03-27 56/week @ 2024-04-03

526 downloads per month

MIT license

23KB
420 lines

Chroma Rust Library

This is a Rust library for interacting with the ChromaDB vector database. It's intended for learning and educational purposes. For a more advanced library, please check out chromadb.

The asynchronous example uses Tokio crate.

1. Running the Backend

Here's how to run the ChromaDB backend using Docker:

default configuration:

docker pull chromadb/chroma
docker run -p 8000:8000 chromadb/chroma

with auth using token & persistant storage:

docker pull chromadb/chroma
docker run \
	-p 8000:8000 \
	-e chroma_server_auth_credentials_provider="chromadb.auth.token.tokenconfigserverauthcredentialsprovider" \
	-e chroma_server_auth_provider="chromadb.auth.token.tokenauthserverprovider" \
	-e chroma_server_auth_token_transport_header="x_chroma_token" \
	-e chroma_server_auth_credentials="pilou2024" \
	-v /path/to/persistent/storage/:/chroma/chroma \
	chromadb/chroma

2. Default Client

Here's a basic example of how to create a default client:

use chromadb_rs::client::{ChromaClient, ChromaClientParams};

let client = ChromaClient::new(ChromaClientParams::default());

3. Advanced Client

For more advanced usage, you can create a client with custom parameters:

let mut hmap = HeaderMap::new();
hmap.insert("X-Chroma-Token", "test-token".parse().unwrap());

let settings = Settings {
    tenant: "my-tenant".to_string(),
    database: "my-database".to_string(),
}

let client = ChromaClient::new(ChromaClientParams {
    host: "localhost".to_string(),
    port: "8000".to_string(),
    ssl: false,
    headers: Some(hmap),
    settings: Some(settings), // Some(Settings::default()) for default settings
});

4. Chroma client methods

  • Heartbeat:
let hb = client.heartbeat().await?;
  • Get all collections:
let collections = client.list_collections().await?;
  • Create a collection without metadata:
let new_collection = client.create_collection("test-name", None).await?;
  • Create a collection with metadata:
let mut metadata = HashMap::new();
metadata.insert("key1", "value1");
metadata.insert("key2", "value2");

let new_collection = client
    .create_collection("test-name", Some(metadata)).await?;
  • Create a collection using get or create:
let new_collection = client.get_or_create_collection("test-name", None).await?;
  • Get a collection:
let collection = client.get_collection("test-name").await?;
  • Delete a collection:
let deleted_collection = client.delete_collection("test-name").await?;

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Dependencies

~6–19MB
~267K SLoC