The Chroma provider for Microsoft.Extensions.VectorData is now in the AI Community Toolkit, the .NET Foundation project that brings together the providers for the vector abstractions of .NET. The package is CommunityToolkit.VectorData.Chroma, version 1.0.0-preview.

I wrote it in ChromaDotNet.VectorData and proposed it to the toolkit, where it was accepted after review. Since 9 October it has been developed there.

What the AI Community Toolkit is

The AI Community Toolkit is the .NET Foundation project where the providers of Microsoft.Extensions.VectorData live: the .NET abstractions for vector stores used by Semantic Kernel and Microsoft Agent Framework. With these abstractions the same code stores and searches records on different databases: to change database, you change the provider.

The providers used to be part of Semantic Kernel. They moved to the toolkit to give them a neutral home, not tied to a single product. The toolkit has Qdrant, Redis, PostgreSQL, SQL Server, Azure AI Search, Cosmos DB and the others. Reviews and releases are done by the Microsoft maintainers of Microsoft.Extensions.VectorData.

Now Chroma is there too.

How to use it

Docker starts Chroma:

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

Then the package:

dotnet add package CommunityToolkit.VectorData.Chroma

A model, a collection, a search with a filter:

using ChromaDB.Client;
using CommunityToolkit.VectorData.Chroma;
using Microsoft.Extensions.VectorData;

using var httpClient = new HttpClient();
var client = new ChromaClient(new ChromaConfigurationOptions("http://localhost:8000"), httpClient);
using var vectorStore = new ChromaVectorStore(client, ownsClient: false);

var hotels = vectorStore.GetCollection<string, Hotel>("hotels");
await hotels.EnsureCollectionExistsAsync();

await hotels.UpsertAsync(new Hotel { Id = "h1", Name = "Grand", Rating = 5, Embedding = new float[] { 0.1f, 0.2f, 0.3f, 0.4f } });

await foreach (var result in hotels.SearchAsync(new float[] { 0.1f, 0.2f, 0.3f, 0.4f }, top: 3, new() { Filter = h => h.Rating >= 4 }))
{
    Console.WriteLine($"{result.Record.Name}: {result.Score}");
}

public sealed class Hotel
{
    [VectorStoreKey]
    public string Id { get; set; } = "";

    [VectorStoreData(IsFullTextIndexed = true)]
    public string? Name { get; set; }

    [VectorStoreData]
    public int Rating { get; set; }

    [VectorStoreVector(4)]
    public ReadOnlyMemory<float> Embedding { get; set; }
}

The embeddings are written by hand to keep the example short. In a real project they come from a model, for example through Microsoft.Extensions.AI.

With dependency injection it takes one line:

services.AddChromaVectorStore("http://localhost:8000");

What is underneath

The provider is built on ChromaDotNet.Client, a client for the whole Chroma v2 API, Chroma Cloud included. The client is tested on nine Chroma versions, from 0.4.10 to 1.5.9, and the known defects of the servers are documented in the compatibility table.

On Chroma Cloud the provider also does hybrid search, vectors and keywords together, with HybridSearchAsync.

In the CI of the toolkit, the provider runs the conformance tests of Microsoft.Extensions.VectorData against a real Chroma, like the other providers.

The client and the other ChromaDotNet libraries are introduced in an earlier article.

Thanks

Links