Chroma.Collection (chroma v0.1.3)

Basic operations to intereact with collections.

Summary

Functions

Adds a batch of embeddings in the database.

Counts all embeddings from a collection.

Creates a collection.

Creates a collection.

Deletes a collection by name.

Gets a collection by name.

Gets a collection by name.

Gets or create a collection by name.

Gets or create a collection by name.

Lists all stored collections in the database.

It updates the name and metadata of a collection.

Creates a new Chroma.Collection struct.

It allows to query the database for similar embeddings.

Updates a batch of embeddings in the database.

Upserts a batch of embeddings in the database

Types

@type t() :: %Chroma.Collection{id: String.t(), metadata: map(), name: String.t()}

Functions

Link to this function

add(collection, data)

@spec add(t(), map()) :: any()

Adds a batch of embeddings in the database.

Examples

  iex> Chroma.Collection.add(%Chroma.Collection{id: "123"}, %{embeddings: [[1, 2, 3], [4, 5, 6]]})
  nil

  iex> Chroma.Collection.add(%Chroma.Collection{id: "123",{ documents: documents, embeddings: embeddings, metadata: metadata, ids: pages})
  nil
Link to this function

count(collection)

@spec count(t()) :: any()

Counts all embeddings from a collection.

Examples

iex> Chroma.Collection.count(%Chroma.Collection{id: "123"})
100
Link to this function

create(name, metadata \\ %{})

@spec create(String.t(), map()) :: {:error, any()} | {:ok, t()}

Creates a collection.

Examples

iex> Chroma.Collection.create("my_collection", metadata: %{type: "test"})
{:ok, %Chroma.Collection{id: "123", name: "my_collection", metadata: %{type: "test"}}}
Link to this function

create!(name, metadata \\ %{})

@spec create!(binary(), map()) :: t()

Creates a collection.

Examples

iex> Chroma.Collection.create!("my_collection", metadata: %{type: "test"})
%Chroma.Collection{id: "123", name: "my_collection", metadata: %{type: "test"}}
Link to this function

delete(collection)

@spec delete(t()) :: any()

Deletes a collection by name.

Examples

iex> Chroma.Collection.delete("my_collection")
nil
@spec get(String.t()) :: {:error, any()} | {:ok, t()}

Gets a collection by name.

Examples

iex> Chroma.Collection.get("my_collection")
{:ok, %Chroma.Collection{id: "123", name: "my_collection", metadata: %{}}}
@spec get!(String.t()) :: t()

Gets a collection by name.

Examples

iex> Chroma.Collection.get!("my_collection")
%Chroma.Collection{id: "123", name: "my_collection", metadata: %{}}
Link to this function

get_or_create(name, metadata \\ %{})

@spec get_or_create(String.t(), map()) :: {:error, any()} | {:ok, t()}

Gets or create a collection by name.

Examples

iex> Chroma.Collection.get_or_create("my_collection", metadata: %{type: "test"})
{:ok, %Chroma.Collection{id: "123", name: "my_collection", metadata: %{type: "test"})}}
Link to this function

get_or_create!(name, metadata \\ %{})

@spec get_or_create!(String.t(), map()) :: t()

Gets or create a collection by name.

Examples

iex> Chroma.Collection.get_or_create!("my_collection", metadata: %{type: "test"})
%Chroma.Collection{id: "123", name: "my_collection", metadata: %{type: "test"}}
@spec list() :: {:error, any()} | {:ok, [t()]}

Lists all stored collections in the database.

Examples

iex> Chroma.Collection.list()
{:ok, [%Chroma.Collection{id: "123", name: "my_collection", metadata: %{}}]}
Link to this function

modify(collection, kwargs)

@spec modify(t(), maybe_improper_list() | map()) :: {:error, any()} | {:ok, any()}

It updates the name and metadata of a collection.

Parameters

  • name: The new name of the collection.
  • metadata: The new metadata of the collection.

Examples

iex> Chroma.Collection.modify(%Chroma.Collection{id: "123"}, name: "new_name")
{:ok, %Chroma.Collection{id: "123", name: "new_name", metadata: %{}}}

iex> Chroma.Collection.modify(%Chroma.Collection{id: "123"}, metadata: %{type: "test"})
{:ok, %Chroma.Collection{id: "123", name: "new_name", metadata: %{type: "test"}}}

iex> Chroma.Collection.modify(%Chroma.Collection{id: "123"}, %{name: "new_name", metadata: %{type: "test"}})
{:ok, %Chroma.Collection{id: "123", name: "new_name", metadata: %{type: "test"}}}
@spec new(map()) :: t()

Creates a new Chroma.Collection struct.

Examples

iex> Chroma.Collection.new(%{"id" => "123", "name" => "my_collection", "metadata" => %{}})
%Chroma.Collection{id: "123", name: "my_collection", metadata: %{}}
Link to this function

query(collection, kargs)

@spec query(t(), list()) :: {:error, any()} | {:ok, any()}

It allows to query the database for similar embeddings.

Parameters

  • query_embeddings: A list of embeddings to query.
  • results: The number of results to return.
  • where: A map of metadata fields to filter by.
  • where_document: A map of document fields to filter by.

Examples

iex> Chroma.Collection.query(
  %Chroma.Collection{id: "123"},
  query_embeddings: [[11.1, 12.1, 13.1],[1.1, 2.3, 3.2], ...],
  where: %{"metadata_field": "is_equal_to_this"},
  where_document: %{"$contains" => "search_string"}
)
{:ok, [%Chroma.Embedding{embedding: [1, 2, 3], id: "123", metadata: %{}}]}
Link to this function

update(collection, data)

@spec update(t(), map()) :: {:error, any()} | {:ok, any()}

Updates a batch of embeddings in the database.

Link to this function

upsert(collection, data)

@spec upsert(t(), map()) :: {:error, any()} | {:ok, any()}

Upserts a batch of embeddings in the database