Skip to content

3zcurdia/chroma

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chroma

A ChromaDB client for Elixir.

Installation

If available in Hex, the package can be installed by adding chroma to your list of dependencies in mix.exs:

def deps do
  [
    {:chroma, "~> 0.1.2"}
  ]
end

Configuration

In your config file you can setup the following:

config :chroma, 
  host: "http:https://localhost:8000",
  api_base: "api",
  api_version: "v1"

By default the config is set to api/v1

Usage

To verify that the client is connected to the server, you can use the version function from the Chroma.Database module:

Chroma.Database.version

To handle all collection actions, you can use the Chroma.Collection module:

  {:ok, collection} = Chroma.Collection.create("my_collection", %{name: "string", age: "int"})
  {:ok, collection} = Chroma.Collection.get_or_create("my_collection", %{name: "string", age: "int"})
  {:ok, collection} = Chroma.Collection.get("my_collection")
  Chroma.Collection.delete("my_collection")

The client does not generate embeddings, but you can generate embeddings using bumblebee with the TextEmbedding module, you can find an example on this livebook.

Once you get the embeddings for your documents, you can index them using the add function from the Chroma.Collection module:

  {:ok, collection} = Chroma.Collection.get_or_create("my_collection", %{type: "Text"})
  Chroma.Collection.add(collection, 
    %{
      embeddings: embeddings,
      documents: documents,
      metadata: metadata,
      ids: ids
    }
  )

This will add the documents, embeddings and metadata to the collection. Now you can query using a query embeddings list:

  Chroma.Collection.query(collection, 
    %{
      embeddings: query_embeddings,
        query_embeddings: query_embeddings,
        where: %{"metadata_field": "is_equal_to_this"},
        where_document: %{"$contains" => "search_string"}
    }
  )

To understand better how to query, you can check the ChromaDB usage guide. You can also check the livebook where you can find a full example of how to use the client.

License

Chroma is released under the MIT License.