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
Functions
add(collection, data)
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
count(collection)
Counts all embeddings from a collection.
Examples
iex> Chroma.Collection.count(%Chroma.Collection{id: "123"})
100
create(name, metadata \\ %{})
Creates a collection.
Examples
iex> Chroma.Collection.create("my_collection", metadata: %{type: "test"})
{:ok, %Chroma.Collection{id: "123", name: "my_collection", metadata: %{type: "test"}}}
create!(name, metadata \\ %{})
Creates a collection.
Examples
iex> Chroma.Collection.create!("my_collection", metadata: %{type: "test"})
%Chroma.Collection{id: "123", name: "my_collection", metadata: %{type: "test"}}
delete(collection)
Deletes a collection by name.
Examples
iex> Chroma.Collection.delete("my_collection")
nil
get(name)
Gets a collection by name.
Examples
iex> Chroma.Collection.get("my_collection")
{:ok, %Chroma.Collection{id: "123", name: "my_collection", metadata: %{}}}
get!(name)
Gets a collection by name.
Examples
iex> Chroma.Collection.get!("my_collection")
%Chroma.Collection{id: "123", name: "my_collection", metadata: %{}}
get_or_create(name, metadata \\ %{})
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"})}}
get_or_create!(name, metadata \\ %{})
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"}}
list()
Lists all stored collections in the database.
Examples
iex> Chroma.Collection.list()
{:ok, [%Chroma.Collection{id: "123", name: "my_collection", metadata: %{}}]}
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"}}}
new(map)
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: %{}}
query(collection, kargs)
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: %{}}]}
update(collection, data)
Updates a batch of embeddings in the database.
upsert(collection, data)
Upserts a batch of embeddings in the database