A Testcontainers for .NET module for Chroma, published as the ChromaDotNet.Testcontainers package: start a throwaway Chroma container in your tests.
This is a community project. It is not affiliated with or endorsed by Testcontainers or Chroma.
Website: chromadotnet.org
dotnet add package ChromaDotNet.Testcontainersusing Testcontainers.Chroma;
await using var chroma = new ChromaBuilder("chromadb/chroma:1.5.9").Build();
await chroma.StartAsync();
// The base address of the Chroma API, like http://localhost:32768/
var address = chroma.GetConnectionString();GetBaseAddress() returns the same address; ChromaBuilder.ChromaHttpPort is the port of the API in the container, 8000.
With ChromaDB.Client, the ChromaDotNet.Client package:
using ChromaDB.Client;
using var httpClient = new HttpClient();
var options = new ChromaConfigurationOptions(chroma.GetConnectionString());
var client = new ChromaClient(options, httpClient);
var collection = await client.CreateCollectionAsync("documents");The container is ready when the heartbeat of the Chroma API answers: the v2 API from Chroma 0.5.16, and the v1 API on the earlier releases, so the module works with any Chroma image, whatever its tag.
dotnet build ChromaDB.Testcontainers.slnx
dotnet test tests/Testcontainers.Chroma.Tests
CHROMA_IMAGE=chromadb/chroma:0.4.10 dotnet test tests/Testcontainers.Chroma.ImageTestsThe tests start Chroma in containers, so they need Docker. tests/Testcontainers.Chroma.ImageTests runs on the image in CHROMA_IMAGE, which the CI sets to each Chroma release it tests.
The module follows the structure and conventions of the modules of Testcontainers for .NET, so that it can become one of them: the code and the tests started as a copy of its Qdrant module, under the MIT license, and docs/modules/chroma.md is the page proposed for its documentation site: it names the package Testcontainers.Chroma that Testcontainers for .NET would publish, and its --8<-- lines include the code when that site is built. Here the package is ChromaDotNet.Testcontainers.
It is proposed to Testcontainers for .NET in testcontainers/testcontainers-dotnet#1784. This repository publishes it until Testcontainers for .NET ships Testcontainers.Chroma; then it will be archived and the package deprecated in its favor. The namespace and the API are the same, so moving there changes only the package reference.
Every change to the module is made first in that pull request; eng/sync-from-upstream.sh copies src/Testcontainers.Chroma, tests/Testcontainers.Chroma.Tests and docs/modules/chroma.md here. The rest, like the build files, the CI and tests/Testcontainers.Chroma.ImageTests, belongs to this repository.
