From e266bd364e406c516672c014aad50d94542b6009 Mon Sep 17 00:00:00 2001 From: Laurianti Date: Wed, 21 Oct 2026 15:36:57 +0200 Subject: [PATCH] Docs: ChromaDotNet.Embeddings, the embeddings of the Python client docs/embeddings.md starts with ChromaDotNet.Embeddings and a short example, run against the packages of nuget.org on Chroma 1.5.9, with its limits and the SearchByText sample of ChromaDotNet.Local; the README links it next to ChromaDotNet.Local. --- README.md | 2 ++ docs/embeddings.md | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/README.md b/README.md index 9dc3d3c..d20bc25 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ dotnet add package ChromaDotNet.Client To run Chroma on your machine without Docker: [ChromaDotNet.Local](https://www.nuget.org/packages/ChromaDotNet.Local). +To compute the embeddings as the Python client does: [ChromaDotNet.Embeddings](https://www.nuget.org/packages/ChromaDotNet.Embeddings), see [Embeddings](https://github.com/ChromaDotNet/ChromaDB.Client/blob/main/docs/embeddings.md). + ## Example The models, like `ChromaRecords`, `ChromaQuery` and `ChromaCollectionDefinition`, are in `ChromaDB.Client.Models`. `AddChromaClient` is in `ChromaDB.Client.DependencyInjection`. diff --git a/docs/embeddings.md b/docs/embeddings.md index fc2331a..5c970f9 100644 --- a/docs/embeddings.md +++ b/docs/embeddings.md @@ -1,5 +1,30 @@ # Embeddings +## The embeddings of the Python client + +[ChromaDotNet.Embeddings](https://www.nuget.org/packages/ChromaDotNet.Embeddings) computes the vectors of the default embedding function of Chroma, the one the Python client uses when a collection has no other: the model all-MiniLM-L6-v2, with 384 dimensions. So .NET and Python read the same collection with the same embeddings. + +``` +dotnet add package ChromaDotNet.Embeddings --prerelease +``` + +```csharp +using ChromaDB.Client; +using ChromaDB.Client.Models; +using ChromaDotNet.Embeddings; + +using var embeddings = await ChromaDefaultEmbeddingGenerator.CreateAsync(); +var collection = await client.GetOrCreateCollectionAsync(new ChromaCollectionDefinition("fruits") { EmbeddingGenerator = embeddings }); +var fruits = client.GetCollectionClient(collection).WithEmbeddingGenerator(embeddings); + +await fruits.AddAsync(["apple", "lemon"], documents: ["A crunchy apple", "A sour lemon"]); +var nearest = await fruits.QueryAsync("something sour", nResults: 1); +``` + +The first `CreateAsync` downloads the model into the cache of the Python client, or uses the one Python downloaded. The definition declares the function `default`, as the Python client does. The package is a preview, and runs in 64-bit processes only, not on Intel Macs: see its [repository](https://github.com/ChromaDotNet/ChromaDB.Embeddings). + +The [SearchByText](https://github.com/ChromaDotNet/ChromaDB.Local/tree/main/samples/SearchByText) sample of ChromaDotNet.Local stores and searches texts this way, on a Chroma started without Docker. [Open it in a Codespace](https://codespaces.new/ChromaDotNet/ChromaDB.Local?quickstart=1). + ## Embeddings from a generator ```csharp