From c9bac74d26716af8e4de6890667399043446fc21 Mon Sep 17 00:00:00 2001 From: Ali Hamza Date: Thu, 19 Feb 2026 07:50:12 +0000 Subject: [PATCH 1/7] feat: add ChromaDB hosting and client integrations This contribution adds support for ChromaDB as a .NET Aspire resource, including: - Hosting integration for containerized ChromaDB - Client integration with health checks and keyed service support - Persistence support via volumes and bind mounts - Comprehensive unit tests and documentation --- CommunityToolkit.Aspire.slnx | 4 + Directory.Packages.props | 1 + .../AspireChromaExtensions.cs | 91 +++++++++++++++++ .../ChromaClientSettings.cs | 49 +++++++++ .../ChromaHealthCheck.cs | 22 +++++ .../CommunityToolkit.Aspire.Chroma.csproj | 21 ++++ src/CommunityToolkit.Aspire.Chroma/README.md | 53 ++++++++++ .../api/CommunityToolkit.Aspire.Chroma.cs | 21 ++++ .../ChromaBuilderExtensions.cs | 63 ++++++++++++ .../ChromaContainerImageTags.cs | 13 +++ .../ChromaResource.cs | 54 ++++++++++ ...munityToolkit.Aspire.Hosting.Chroma.csproj | 16 +++ .../README.md | 38 +++++++ .../CommunityToolkit.Aspire.Hosting.Chroma.cs | 31 ++++++ .../ChromaClientExtensionsTests.cs | 79 +++++++++++++++ ...ommunityToolkit.Aspire.Chroma.Tests.csproj | 8 ++ .../AddChromaTests.cs | 99 +++++++++++++++++++ ...Toolkit.Aspire.Hosting.Chroma.Tests.csproj | 13 +++ 18 files changed, 676 insertions(+) create mode 100644 src/CommunityToolkit.Aspire.Chroma/AspireChromaExtensions.cs create mode 100644 src/CommunityToolkit.Aspire.Chroma/ChromaClientSettings.cs create mode 100644 src/CommunityToolkit.Aspire.Chroma/ChromaHealthCheck.cs create mode 100644 src/CommunityToolkit.Aspire.Chroma/CommunityToolkit.Aspire.Chroma.csproj create mode 100644 src/CommunityToolkit.Aspire.Chroma/README.md create mode 100644 src/CommunityToolkit.Aspire.Chroma/api/CommunityToolkit.Aspire.Chroma.cs create mode 100644 src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaBuilderExtensions.cs create mode 100644 src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaContainerImageTags.cs create mode 100644 src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaResource.cs create mode 100644 src/CommunityToolkit.Aspire.Hosting.Chroma/CommunityToolkit.Aspire.Hosting.Chroma.csproj create mode 100644 src/CommunityToolkit.Aspire.Hosting.Chroma/README.md create mode 100644 src/CommunityToolkit.Aspire.Hosting.Chroma/api/CommunityToolkit.Aspire.Hosting.Chroma.cs create mode 100644 tests/CommunityToolkit.Aspire.Chroma.Tests/ChromaClientExtensionsTests.cs create mode 100644 tests/CommunityToolkit.Aspire.Chroma.Tests/CommunityToolkit.Aspire.Chroma.Tests.csproj create mode 100644 tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/AddChromaTests.cs create mode 100644 tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests.csproj diff --git a/CommunityToolkit.Aspire.slnx b/CommunityToolkit.Aspire.slnx index 73ed3e46d..39d147517 100644 --- a/CommunityToolkit.Aspire.slnx +++ b/CommunityToolkit.Aspire.slnx @@ -196,12 +196,14 @@ + + @@ -257,12 +259,14 @@ + + diff --git a/Directory.Packages.props b/Directory.Packages.props index eed710385..232915005 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -95,6 +95,7 @@ + diff --git a/src/CommunityToolkit.Aspire.Chroma/AspireChromaExtensions.cs b/src/CommunityToolkit.Aspire.Chroma/AspireChromaExtensions.cs new file mode 100644 index 000000000..a803aa8a3 --- /dev/null +++ b/src/CommunityToolkit.Aspire.Chroma/AspireChromaExtensions.cs @@ -0,0 +1,91 @@ +using System.Net.Http; +using ChromaDB.Client; +using CommunityToolkit.Aspire.Chroma; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; + +namespace Microsoft.Extensions.Hosting; + +/// +/// Provides extension methods for registering ChromaDB-related services. +/// +public static class AspireChromaExtensions +{ + private const string DefaultConfigSectionName = "Aspire:Chroma"; + + /// + /// Registers as a singleton in the services collection. + /// + public static void AddChromaClient( + this IHostApplicationBuilder builder, + string connectionName, + Action? configureSettings = null) + { + AddChromaClient(builder, serviceKey: null, connectionName, configureSettings); + } + + /// + /// Registers as a keyed singleton in the services collection. + /// + public static void AddKeyedChromaClient( + this IHostApplicationBuilder builder, + string name, + Action? configureSettings = null) + { + AddChromaClient(builder, serviceKey: name, connectionName: name, configureSettings); + } + + private static void AddChromaClient( + IHostApplicationBuilder builder, + object? serviceKey, + string connectionName, + Action? configureSettings = null) + { + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(connectionName); + + var settings = new ChromaClientSettings(); + builder.Configuration.GetSection(DefaultConfigSectionName).Bind(settings); + + if (builder.Configuration.GetConnectionString(connectionName) is string connectionString) + { + settings.ParseConnectionString(connectionString); + } + + configureSettings?.Invoke(settings); + + if (serviceKey is null) + { + builder.Services.AddSingleton(sp => CreateClient(sp, settings, connectionName)); + } + else + { + builder.Services.AddKeyedSingleton(serviceKey, (sp, key) => CreateClient(sp, settings, connectionName)); + } + + if (!settings.DisableHealthChecks) + { + builder.Services.AddHealthChecks() + .Add(new HealthCheckRegistration( + serviceKey is null ? connectionName : $"{connectionName}_check", + sp => new ChromaHealthCheck(serviceKey is null + ? sp.GetRequiredService() + : sp.GetRequiredKeyedService(serviceKey)), + failureStatus: default, + tags: default, + timeout: settings.HealthCheckTimeout.HasValue ? TimeSpan.FromMilliseconds(settings.HealthCheckTimeout.Value) : default)); + } + } + + private static ChromaClient CreateClient(IServiceProvider sp, ChromaClientSettings settings, string connectionName) + { + if (settings.Endpoint == null) + { + throw new InvalidOperationException($"ChromaDB endpoint is not configured for connection name '{connectionName}'."); + } + + var httpClient = sp.GetRequiredService().CreateClient(connectionName); + return new ChromaClient(new ChromaConfigurationOptions(settings.Endpoint.ToString()), httpClient); + } +} diff --git a/src/CommunityToolkit.Aspire.Chroma/ChromaClientSettings.cs b/src/CommunityToolkit.Aspire.Chroma/ChromaClientSettings.cs new file mode 100644 index 000000000..35f7dff4e --- /dev/null +++ b/src/CommunityToolkit.Aspire.Chroma/ChromaClientSettings.cs @@ -0,0 +1,49 @@ +using System.Data.Common; + +namespace CommunityToolkit.Aspire.Chroma; + +/// +/// Provides the client configuration settings for connecting to a ChromaDB server using ChromaClient. +/// +public sealed class ChromaClientSettings +{ + private const string ConnectionStringEndpoint = "Endpoint"; + + /// + /// The endpoint URI string of the ChromaDB server to connect to. + /// + public Uri? Endpoint { get; set; } + + /// + /// Gets or sets a boolean value that indicates whether the ChromaDB health check is disabled or not. + /// + /// + /// The default value is . + /// + public bool DisableHealthChecks { get; set; } + + /// + /// Gets or sets a integer value that indicates the ChromaDB health check timeout in milliseconds. + /// + public int? HealthCheckTimeout { get; set; } + + internal void ParseConnectionString(string? connectionString) + { + if (Uri.TryCreate(connectionString, UriKind.Absolute, out var uri)) + { + Endpoint = uri; + } + else + { + var connectionBuilder = new DbConnectionStringBuilder + { + ConnectionString = connectionString + }; + + if (connectionBuilder.TryGetValue(ConnectionStringEndpoint, out var endpoint) && Uri.TryCreate(endpoint.ToString(), UriKind.Absolute, out var serviceUri)) + { + Endpoint = serviceUri; + } + } + } +} diff --git a/src/CommunityToolkit.Aspire.Chroma/ChromaHealthCheck.cs b/src/CommunityToolkit.Aspire.Chroma/ChromaHealthCheck.cs new file mode 100644 index 000000000..5d62ac800 --- /dev/null +++ b/src/CommunityToolkit.Aspire.Chroma/ChromaHealthCheck.cs @@ -0,0 +1,22 @@ +using ChromaDB.Client; +using Microsoft.Extensions.Diagnostics.HealthChecks; + +namespace CommunityToolkit.Aspire.Chroma; + +internal sealed class ChromaHealthCheck(ChromaClient chromaClient) : IHealthCheck +{ + /// + public async Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) + { + try + { + await chromaClient.GetVersion().ConfigureAwait(false); + + return HealthCheckResult.Healthy(); + } + catch (Exception ex) + { + return new HealthCheckResult(context.Registration.FailureStatus, exception: ex); + } + } +} diff --git a/src/CommunityToolkit.Aspire.Chroma/CommunityToolkit.Aspire.Chroma.csproj b/src/CommunityToolkit.Aspire.Chroma/CommunityToolkit.Aspire.Chroma.csproj new file mode 100644 index 000000000..2ce28eb1d --- /dev/null +++ b/src/CommunityToolkit.Aspire.Chroma/CommunityToolkit.Aspire.Chroma.csproj @@ -0,0 +1,21 @@ + + + + ChromaDB client + A ChromaDB client that integrates with Aspire, including health checks, logging, and telemetry. + + + + + + + + + + + + + + + + diff --git a/src/CommunityToolkit.Aspire.Chroma/README.md b/src/CommunityToolkit.Aspire.Chroma/README.md new file mode 100644 index 000000000..5a5149647 --- /dev/null +++ b/src/CommunityToolkit.Aspire.Chroma/README.md @@ -0,0 +1,53 @@ +# CommunityToolkit.Aspire.Chroma + +Provides extension methods for registering a `ChromaClient` in a .NET application. + +## Installation + +```bash +dotnet add package CommunityToolkit.Aspire.Chroma +``` + +## Usage + +In your application project: + +```csharp +var builder = Host.CreateApplicationBuilder(args); + +builder.AddChromaClient("chroma"); + +// Or using keyed service +builder.AddKeyedChromaClient("chroma"); +``` + +Then resolve the client in your services: + +```csharp +public class MyService(ChromaClient chromaClient) +{ + public async Task QueryAsync() + { + var version = await chromaClient.GetVersion(); + // ... + } +} +``` + +## Configuration + +The client can be configured using connection strings or settings: + +```json +{ + "ConnectionStrings": { + "chroma": "http://localhost:8000" + }, + "Aspire": { + "Chroma": { + "DisableHealthChecks": false, + "HealthCheckTimeout": 5000 + } + } +} +``` diff --git a/src/CommunityToolkit.Aspire.Chroma/api/CommunityToolkit.Aspire.Chroma.cs b/src/CommunityToolkit.Aspire.Chroma/api/CommunityToolkit.Aspire.Chroma.cs new file mode 100644 index 000000000..58daac8fe --- /dev/null +++ b/src/CommunityToolkit.Aspire.Chroma/api/CommunityToolkit.Aspire.Chroma.cs @@ -0,0 +1,21 @@ +namespace CommunityToolkit.Aspire.Chroma +{ + public sealed partial class ChromaClientSettings + { + public bool DisableHealthChecks { get { throw null; } set { } } + + public System.Uri? Endpoint { get { throw null; } set { } } + + public int? HealthCheckTimeout { get { throw null; } set { } } + } +} + +namespace Microsoft.Extensions.Hosting +{ + public static partial class AspireChromaExtensions + { + public static void AddChromaClient(this IHostApplicationBuilder builder, string connectionName, System.Action? configureSettings = null) { } + + public static void AddKeyedChromaClient(this IHostApplicationBuilder builder, string name, System.Action? configureSettings = null) { } + } +} diff --git a/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaBuilderExtensions.cs b/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaBuilderExtensions.cs new file mode 100644 index 000000000..f889b1cf7 --- /dev/null +++ b/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaBuilderExtensions.cs @@ -0,0 +1,63 @@ +using Aspire.Hosting.ApplicationModel; +using CommunityToolkit.Aspire.Hosting.Chroma; + +namespace Aspire.Hosting; + +/// +/// Provides extension methods for adding ChromaDB resources to the application model. +/// +public static class ChromaBuilderExtensions +{ + private const int ChromaPort = 8000; + + /// + /// Adds a ChromaDB container resource to the application model. + /// The default image is and the tag is . + /// + /// The . + /// The name of the resource. This name will be used as the connection string name when referenced in a dependency. + /// The host port to bind the underlying container to. + /// A reference to the . + public static IResourceBuilder AddChroma( + this IDistributedApplicationBuilder builder, + string name, + int? port = null) + { + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(name); + + var chroma = new ChromaResource(name); + + return builder.AddResource(chroma) + .WithImage(ChromaContainerImageTags.Image, ChromaContainerImageTags.Tag) + .WithImageRegistry(ChromaContainerImageTags.Registry) + .WithHttpEndpoint(targetPort: ChromaPort, port: port, name: ChromaResource.PrimaryEndpointName); + } + + /// + /// Adds a named volume for the data folder to a ChromaDB container resource. + /// + /// The resource builder. + /// The name of the volume. Defaults to an auto-generated name based on the application and resource names. + /// The . + public static IResourceBuilder WithDataVolume(this IResourceBuilder builder, string? name = null) + { + ArgumentNullException.ThrowIfNull(builder); + + return builder.WithVolume(name ?? VolumeNameGenerator.Generate(builder, "data"), "/chroma/chroma"); + } + + /// + /// Adds a bind mount for the data folder to a ChromaDB container resource. + /// + /// The resource builder. + /// The source directory on the host to mount into the container. + /// The . + public static IResourceBuilder WithDataBindMount(this IResourceBuilder builder, string source) + { + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(source); + + return builder.WithBindMount(source, "/chroma/chroma"); + } +} diff --git a/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaContainerImageTags.cs b/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaContainerImageTags.cs new file mode 100644 index 000000000..78864755d --- /dev/null +++ b/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaContainerImageTags.cs @@ -0,0 +1,13 @@ +namespace CommunityToolkit.Aspire.Hosting.Chroma; + +internal static class ChromaContainerImageTags +{ + /// docker.io + public const string Registry = "docker.io"; + + /// chromadb/chroma + public const string Image = "chromadb/chroma"; + + /// 0.5.0 + public const string Tag = "0.5.0"; +} diff --git a/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaResource.cs b/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaResource.cs new file mode 100644 index 000000000..a51556a8e --- /dev/null +++ b/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaResource.cs @@ -0,0 +1,54 @@ +using Aspire.Hosting.ApplicationModel; + +namespace CommunityToolkit.Aspire.Hosting.Chroma; + +/// +/// A resource that represents a ChromaDB container. +/// +public class ChromaResource : ContainerResource, IResourceWithConnectionString +{ + internal const string PrimaryEndpointName = "http"; + + /// The name of the resource. + public ChromaResource(string name) : base(name) + { + } + + private EndpointReference? _primaryEndpoint; + + /// + /// Gets the primary endpoint for the ChromaDB. This endpoint is used for all API calls over HTTP. + /// + public EndpointReference PrimaryEndpoint => _primaryEndpoint ??= new(this, PrimaryEndpointName); + + /// + /// Gets the host endpoint reference for this resource. + /// + public EndpointReferenceExpression Host => PrimaryEndpoint.Property(EndpointProperty.Host); + + /// + /// Gets the port endpoint reference for this resource. + /// + public EndpointReferenceExpression Port => PrimaryEndpoint.Property(EndpointProperty.Port); + + /// + /// Gets the connection string expression for the ChromaDB + /// + public ReferenceExpression ConnectionStringExpression => + ReferenceExpression.Create($"Endpoint=http://{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}"); + + /// + /// Gets the connection URI expression for the ChromaDB server. + /// + /// + /// Format: http://{host}:{port}. + /// + public ReferenceExpression UriExpression => ReferenceExpression.Create($"http://{Host}:{Port}"); + + IEnumerable> IResourceWithConnectionString.GetConnectionProperties() + { + yield return new("Host", ReferenceExpression.Create($"{Host}")); + yield return new("Port", ReferenceExpression.Create($"{Port}")); + yield return new("Uri", UriExpression); + } +} diff --git a/src/CommunityToolkit.Aspire.Hosting.Chroma/CommunityToolkit.Aspire.Hosting.Chroma.csproj b/src/CommunityToolkit.Aspire.Hosting.Chroma/CommunityToolkit.Aspire.Hosting.Chroma.csproj new file mode 100644 index 000000000..a3d51a557 --- /dev/null +++ b/src/CommunityToolkit.Aspire.Hosting.Chroma/CommunityToolkit.Aspire.Hosting.Chroma.csproj @@ -0,0 +1,16 @@ + + + + hosting chroma chromadb + ChromaDB hosting support for Aspire. + + + + + + + + + + + diff --git a/src/CommunityToolkit.Aspire.Hosting.Chroma/README.md b/src/CommunityToolkit.Aspire.Hosting.Chroma/README.md new file mode 100644 index 000000000..e8132dc31 --- /dev/null +++ b/src/CommunityToolkit.Aspire.Hosting.Chroma/README.md @@ -0,0 +1,38 @@ +# CommunityToolkit.Aspire.Hosting.Chroma + +Provides extension methods for adding a ChromaDB resource to a .NET Aspire application model. + +## Installation + +```bash +dotnet add package CommunityToolkit.Aspire.Hosting.Chroma +``` + +## Usage + +In your AppHost's `Program.cs`: + +```csharp +var builder = DistributedApplication.CreateBuilder(args); + +var chroma = builder.AddChroma("chroma"); + +builder.AddProject() + .WithReference(chroma); + +builder.Build().Run(); +``` + +## Persistence + +You can configure persistence using either Docker volumes or bind mounts: + +```csharp +// Using a Docker volume +var chroma = builder.AddChroma("chroma") + .WithDataVolume(); + +// Using a bind mount +var chroma = builder.AddChroma("chroma") + .WithDataBindMount("C:/chroma/data"); +``` diff --git a/src/CommunityToolkit.Aspire.Hosting.Chroma/api/CommunityToolkit.Aspire.Hosting.Chroma.cs b/src/CommunityToolkit.Aspire.Hosting.Chroma/api/CommunityToolkit.Aspire.Hosting.Chroma.cs new file mode 100644 index 000000000..a40f7c805 --- /dev/null +++ b/src/CommunityToolkit.Aspire.Hosting.Chroma/api/CommunityToolkit.Aspire.Hosting.Chroma.cs @@ -0,0 +1,31 @@ +namespace Aspire.Hosting +{ + public static partial class ChromaBuilderExtensions + { + public static ApplicationModel.IResourceBuilder AddChroma(this IDistributedApplicationBuilder builder, string name, int? port = null) { throw null; } + + public static ApplicationModel.IResourceBuilder WithDataBindMount(this ApplicationModel.IResourceBuilder builder, string source) { throw null; } + + public static ApplicationModel.IResourceBuilder WithDataVolume(this ApplicationModel.IResourceBuilder builder, string? name = null) { throw null; } + } +} + +namespace Aspire.Hosting.ApplicationModel +{ + public partial class ChromaResource : ContainerResource, IResourceWithConnectionString, IResource, IManifestExpressionProvider, IValueProvider, IValueWithReferences + { + public ChromaResource(string name) : base(default!, default) { } + + public ReferenceExpression ConnectionStringExpression { get { throw null; } } + + public EndpointReferenceExpression Host { get { throw null; } } + + public EndpointReferenceExpression Port { get { throw null; } } + + public EndpointReference PrimaryEndpoint { get { throw null; } } + + public ReferenceExpression UriExpression { get { throw null; } } + + System.Collections.Generic.IEnumerable> IResourceWithConnectionString.GetConnectionProperties() { throw null; } + } +} diff --git a/tests/CommunityToolkit.Aspire.Chroma.Tests/ChromaClientExtensionsTests.cs b/tests/CommunityToolkit.Aspire.Chroma.Tests/ChromaClientExtensionsTests.cs new file mode 100644 index 000000000..5850ed7b0 --- /dev/null +++ b/tests/CommunityToolkit.Aspire.Chroma.Tests/ChromaClientExtensionsTests.cs @@ -0,0 +1,79 @@ +using ChromaDB.Client; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; +using Microsoft.Extensions.Hosting; + +namespace CommunityToolkit.Aspire.Chroma.Tests; + +public class AspireChromaClientExtensionsTests +{ + private const string DefaultConnectionName = "chroma"; + private const string DefaultConnectionString = "http://localhost:8000"; + + [Fact] + public void AddChromaClient_ShouldRegisterClient() + { + var builder = CreateBuilder(); + + builder.AddChromaClient(DefaultConnectionName); + + using var host = builder.Build(); + + var client = host.Services.GetService(); + Assert.NotNull(client); + } + + [Fact] + public void AddKeyedChromaClient_ShouldRegisterKeyedClient() + { + var builder = CreateBuilder(); + + builder.AddKeyedChromaClient(DefaultConnectionName); + + using var host = builder.Build(); + + var client = host.Services.GetKeyedService(DefaultConnectionName); + Assert.NotNull(client); + } + + [Fact] + public void AddChromaClient_HealthCheckShouldBeRegistered() + { + var builder = CreateBuilder(); + + builder.AddChromaClient(DefaultConnectionName); + + using var host = builder.Build(); + + var healthCheckService = host.Services.GetRequiredService(); + // The health check name should match the connection name for non-keyed + var registration = host.Services.GetRequiredService>(); + Assert.Contains(registration, x => x.Name == DefaultConnectionName); + } + + [Fact] + public void AddKeyedChromaClient_HealthCheckShouldBeRegisteredWithSuffix() + { + var builder = CreateBuilder(); + + builder.AddKeyedChromaClient(DefaultConnectionName); + + using var host = builder.Build(); + + var healthCheckService = host.Services.GetRequiredService(); + // The health check name should have _check suffix for keyed + var registration = host.Services.GetRequiredService>(); + Assert.Contains(registration, x => x.Name == $"{DefaultConnectionName}_check"); + } + + private static HostApplicationBuilder CreateBuilder() + { + var builder = Host.CreateApplicationBuilder(); + builder.Configuration.AddInMemoryCollection([ + new KeyValuePair($"ConnectionStrings:{DefaultConnectionName}", DefaultConnectionString) + ]); + builder.Services.AddHttpClient(); + return builder; + } +} diff --git a/tests/CommunityToolkit.Aspire.Chroma.Tests/CommunityToolkit.Aspire.Chroma.Tests.csproj b/tests/CommunityToolkit.Aspire.Chroma.Tests/CommunityToolkit.Aspire.Chroma.Tests.csproj new file mode 100644 index 000000000..08e5bb2b0 --- /dev/null +++ b/tests/CommunityToolkit.Aspire.Chroma.Tests/CommunityToolkit.Aspire.Chroma.Tests.csproj @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/AddChromaTests.cs b/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/AddChromaTests.cs new file mode 100644 index 000000000..39e0ca6dc --- /dev/null +++ b/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/AddChromaTests.cs @@ -0,0 +1,99 @@ +using System.Net.Sockets; +using Aspire.Hosting; +using Aspire.Hosting.ApplicationModel; +using CommunityToolkit.Aspire.Hosting.Chroma; +using Microsoft.Extensions.DependencyInjection; + +namespace CommunityToolkit.Aspire.Hosting.Chroma.Tests; + +public class AddChromaTests +{ + [Fact] + public void AddChromaContainerWithDefaultsAddsAnnotationMetadata() + { + var appBuilder = DistributedApplication.CreateBuilder(); + + appBuilder.AddChroma("chroma"); + + using var app = appBuilder.Build(); + + var appModel = app.Services.GetRequiredService(); + + var containerResource = Assert.Single(appModel.Resources.OfType()); + Assert.Equal("chroma", containerResource.Name); + + var endpoints = containerResource.Annotations.OfType(); + Assert.Single(endpoints); + + var primaryEndpoint = Assert.Single(endpoints, e => e.Name == "http"); + Assert.Equal(8000, primaryEndpoint.TargetPort); + Assert.False(primaryEndpoint.IsExternal); + Assert.Equal("http", primaryEndpoint.Name); + Assert.Null(primaryEndpoint.Port); + Assert.Equal(ProtocolType.Tcp, primaryEndpoint.Protocol); + Assert.Equal("http", primaryEndpoint.Transport); + Assert.Equal("http", primaryEndpoint.UriScheme); + + var containerAnnotation = Assert.Single(containerResource.Annotations.OfType()); + Assert.Equal(ChromaContainerImageTags.Tag, containerAnnotation.Tag); + Assert.Equal(ChromaContainerImageTags.Image, containerAnnotation.Image); + Assert.Equal(ChromaContainerImageTags.Registry, containerAnnotation.Registry); + } + + [Fact] + public async Task ChromaCreatesConnectionString() + { + var appBuilder = DistributedApplication.CreateBuilder(); + appBuilder + .AddChroma("chroma") + .WithEndpoint("http", e => e.AllocatedEndpoint = new AllocatedEndpoint(e, "localhost", 27020)); + + using var app = appBuilder.Build(); + + var appModel = app.Services.GetRequiredService(); + + var connectionStringResource = Assert.Single(appModel.Resources.OfType()) as IResourceWithConnectionString; + var connectionString = await connectionStringResource.GetConnectionStringAsync(); + + Assert.Equal($"Endpoint=http://localhost:27020", connectionString); + Assert.Equal("Endpoint=http://{chroma.bindings.http.host}:{chroma.bindings.http.port}", connectionStringResource.ConnectionStringExpression.ValueExpression); + } + + [Fact] + public void WithDataVolumeAddsAnnotationMetadata() + { + var appBuilder = DistributedApplication.CreateBuilder(); + + appBuilder.AddChroma("chroma") + .WithDataVolume("chroma-data"); + + using var app = appBuilder.Build(); + + var appModel = app.Services.GetRequiredService(); + + var containerResource = Assert.Single(appModel.Resources.OfType()); + var mountAnnotation = Assert.Single(containerResource.Annotations.OfType()); + Assert.Equal("chroma-data", mountAnnotation.Source); + Assert.Equal("/chroma/chroma", mountAnnotation.Target); + Assert.Equal(ContainerMountType.Volume, mountAnnotation.Type); + } + + [Fact] + public void WithDataBindMountAddsAnnotationMetadata() + { + var appBuilder = DistributedApplication.CreateBuilder(); + + appBuilder.AddChroma("chroma") + .WithDataBindMount("C:/chroma/data"); + + using var app = appBuilder.Build(); + + var appModel = app.Services.GetRequiredService(); + + var containerResource = Assert.Single(appModel.Resources.OfType()); + var mountAnnotation = Assert.Single(containerResource.Annotations.OfType()); + Assert.Equal("C:/chroma/data", mountAnnotation.Source); + Assert.Equal("/chroma/chroma", mountAnnotation.Target); + Assert.Equal(ContainerMountType.BindMount, mountAnnotation.Type); + } +} diff --git a/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests.csproj b/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests.csproj new file mode 100644 index 000000000..35524062b --- /dev/null +++ b/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests.csproj @@ -0,0 +1,13 @@ + + + + + + + + + + + + + From 9800960b689487ca11e6a382aeec8c5a2edffa6d Mon Sep 17 00:00:00 2001 From: Ali Hamza Date: Thu, 26 Feb 2026 08:01:53 +0000 Subject: [PATCH 2/7] Address ChromaDB integration feedback - Removed auto-generated api files. - Refactored ChromaResource to use a primary constructor. - Corrected style for null checks (is null). - Added example app with CRUD operations in examples/chromadb. - Added integration tests for health and CRUD verification. - Updated tests.yml workflow to include new tests. --- .github/workflows/tests.yaml | 2 + ...it.Aspire.Hosting.Chroma.ApiService.csproj | 15 +++ .../Program.cs | 77 +++++++++++++ ...olkit.Aspire.Hosting.Chroma.AppHost.csproj | 17 +++ .../Program.cs | 12 ++ ...pire.Hosting.Chroma.ServiceDefaults.csproj | 21 ++++ .../Extensions.cs | 103 ++++++++++++++++++ .../AspireChromaExtensions.cs | 46 +++++--- .../api/CommunityToolkit.Aspire.Chroma.cs | 21 ---- .../ChromaResource.cs | 7 +- .../CommunityToolkit.Aspire.Hosting.Chroma.cs | 31 ------ .../ChromaClientExtensionsTests.cs | 14 +-- .../AppHostTests.cs | 53 +++++++++ ...Toolkit.Aspire.Hosting.Chroma.Tests.csproj | 1 + 14 files changed, 338 insertions(+), 82 deletions(-) create mode 100644 examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ApiService/CommunityToolkit.Aspire.Hosting.Chroma.ApiService.csproj create mode 100644 examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ApiService/Program.cs create mode 100644 examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.AppHost/CommunityToolkit.Aspire.Hosting.Chroma.AppHost.csproj create mode 100644 examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.AppHost/Program.cs create mode 100644 examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ServiceDefaults/CommunityToolkit.Aspire.Hosting.Chroma.ServiceDefaults.csproj create mode 100644 examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ServiceDefaults/Extensions.cs delete mode 100644 src/CommunityToolkit.Aspire.Chroma/api/CommunityToolkit.Aspire.Chroma.cs delete mode 100644 src/CommunityToolkit.Aspire.Hosting.Chroma/api/CommunityToolkit.Aspire.Hosting.Chroma.cs create mode 100644 tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/AppHostTests.cs diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f95435e03..fdf09c7c2 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -27,6 +27,7 @@ jobs: Hosting.Azure.DataApiBuilder.Tests, Hosting.Azure.Extensions.Tests, Hosting.Bun.Tests, + Hosting.Chroma.Tests, Hosting.Dapr.Tests, Hosting.DbGate.Tests, Hosting.Deno.Tests, @@ -68,6 +69,7 @@ jobs: Hosting.Zitadel.Tests, # Client integration tests + Chroma.Tests, GoFeatureFlag.Tests, KurrentDB.Tests, MassTransit.RabbitMQ.Tests, diff --git a/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ApiService/CommunityToolkit.Aspire.Hosting.Chroma.ApiService.csproj b/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ApiService/CommunityToolkit.Aspire.Hosting.Chroma.ApiService.csproj new file mode 100644 index 000000000..9c865df63 --- /dev/null +++ b/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ApiService/CommunityToolkit.Aspire.Hosting.Chroma.ApiService.csproj @@ -0,0 +1,15 @@ + + + + net8.0;net9.0;net10.0 + enable + enable + false + + + + + + + + diff --git a/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ApiService/Program.cs b/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ApiService/Program.cs new file mode 100644 index 000000000..418106176 --- /dev/null +++ b/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ApiService/Program.cs @@ -0,0 +1,77 @@ +using ChromaDB.Client; +using ChromaDB.Client.Models; + +var builder = WebApplication.CreateBuilder(args); + +builder.AddServiceDefaults(); + +builder.AddChromaClient("chroma"); + +var app = builder.Build(); + +app.MapDefaultEndpoints(); + +app.MapPost("/create", async (ChromaClient chroma, IConfiguration config, IHttpClientFactory factory) => +{ + var collectionName = $"movies_{Guid.NewGuid():N}"; + var collection = await chroma.CreateCollection(collectionName); + + var endpoint = GetChromaEndpoint(config, "chroma"); + var httpClient = factory.CreateClient("chroma"); + var options = new ChromaConfigurationOptions(endpoint); + var collectionClient = new ChromaCollectionClient(collection, options, httpClient); + + await collectionClient.Add( + ids: ["1", "2"], + embeddings: [new ReadOnlyMemory([0.1f, 0.2f, 0.3f]), new ReadOnlyMemory([0.4f, 0.5f, 0.6f])], + metadatas: [ + new Dictionary { { "title", "Inception" } }, + new Dictionary { { "title", "Interstellar" } } + ], + documents: ["A thief who enters the dreams of others.", "A group of explorers travel through a wormhole."] + ); + + return Results.Ok(new { Collection = collectionName, Count = 2 }); +}); + +app.MapGet("/query", async (ChromaClient chroma, IConfiguration config, IHttpClientFactory factory, string collectionName) => +{ + var collection = await chroma.GetCollection(collectionName); + var endpoint = GetChromaEndpoint(config, "chroma"); + var httpClient = factory.CreateClient("chroma"); + var options = new ChromaConfigurationOptions(endpoint); + var collectionClient = new ChromaCollectionClient(collection, options, httpClient); + + var results = await collectionClient.Query( + queryEmbeddings: new ReadOnlyMemory([0.1f, 0.2f, 0.3f]), + nResults: 1 + ); + + return Results.Ok(results); +}); + +static string GetChromaEndpoint(IConfiguration config, string connectionName) +{ + var connectionString = config.GetConnectionString(connectionName); + if (!string.IsNullOrEmpty(connectionString)) + { + if (Uri.TryCreate(connectionString, UriKind.Absolute, out var uri)) + { + return uri.ToString(); + } + + // Handle "Endpoint=..." format + var parts = connectionString.Split(';', StringSplitOptions.RemoveEmptyEntries); + foreach (var part in parts) + { + if (part.StartsWith("Endpoint=", StringComparison.OrdinalIgnoreCase)) + { + return part.Substring("Endpoint=".Length); + } + } + } + + return config["Aspire:Chroma:Endpoint"] ?? throw new InvalidOperationException("ChromaDB endpoint not found."); +} + +app.Run(); diff --git a/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.AppHost/CommunityToolkit.Aspire.Hosting.Chroma.AppHost.csproj b/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.AppHost/CommunityToolkit.Aspire.Hosting.Chroma.AppHost.csproj new file mode 100644 index 000000000..dd809554b --- /dev/null +++ b/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.AppHost/CommunityToolkit.Aspire.Hosting.Chroma.AppHost.csproj @@ -0,0 +1,17 @@ + + + + Exe + net8.0;net9.0;net10.0 + enable + enable + true + false + + + + + + + + diff --git a/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.AppHost/Program.cs b/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.AppHost/Program.cs new file mode 100644 index 000000000..1c472299b --- /dev/null +++ b/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.AppHost/Program.cs @@ -0,0 +1,12 @@ +using Projects; + +var builder = DistributedApplication.CreateBuilder(args); + +var chroma = builder.AddChroma("chroma"); + +builder.AddProject("apiservice") + .WithReference(chroma) + .WaitFor(chroma) + .WithHttpHealthCheck("/health"); + +builder.Build().Run(); diff --git a/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ServiceDefaults/CommunityToolkit.Aspire.Hosting.Chroma.ServiceDefaults.csproj b/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ServiceDefaults/CommunityToolkit.Aspire.Hosting.Chroma.ServiceDefaults.csproj new file mode 100644 index 000000000..1b1971949 --- /dev/null +++ b/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ServiceDefaults/CommunityToolkit.Aspire.Hosting.Chroma.ServiceDefaults.csproj @@ -0,0 +1,21 @@ + + + + net8.0;net9.0;net10.0 + enable + enable + false + + + + + + + + + + + + + + diff --git a/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ServiceDefaults/Extensions.cs b/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ServiceDefaults/Extensions.cs new file mode 100644 index 000000000..8d782e51d --- /dev/null +++ b/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ServiceDefaults/Extensions.cs @@ -0,0 +1,103 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.ServiceDiscovery; +using OpenTelemetry; +using OpenTelemetry.Metrics; +using OpenTelemetry.Trace; + +namespace Microsoft.Extensions.Hosting; + +// Adds common Aspire services: service discovery, resilience, health checks, and OpenTelemetry. +// This project should be referenced by each service project in your solution. +// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults +public static class Extensions +{ + public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBuilder builder) + { + builder.ConfigureOpenTelemetry(); + + builder.AddDefaultHealthChecks(); + + builder.Services.AddServiceDiscovery(); + + builder.Services.ConfigureHttpClientDefaults(http => + { + // Turn on resilience by default + http.AddStandardResilienceHandler(); + + // Turn on service discovery by default + http.AddServiceDiscovery(); + }); + + return builder; + } + + public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicationBuilder builder) + { + builder.Logging.AddOpenTelemetry(logging => + { + logging.IncludeFormattedMessage = true; + logging.IncludeScopes = true; + }); + + builder.Services.AddOpenTelemetry() + .WithMetrics(metrics => + { + metrics.AddAspNetCoreInstrumentation() + .AddHttpClientInstrumentation() + .AddRuntimeInstrumentation(); + }) + .WithTracing(tracing => + { + tracing.AddAspNetCoreInstrumentation() + .AddHttpClientInstrumentation(); + }); + + builder.AddOpenTelemetryExporters(); + + return builder; + } + + private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostApplicationBuilder builder) + { + var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); + + if (useOtlpExporter) + { + builder.Services.AddOpenTelemetry().UseOtlpExporter(); + } + + return builder; + } + + public static IHostApplicationBuilder AddDefaultHealthChecks(this IHostApplicationBuilder builder) + { + builder.Services.AddHealthChecks() + // Add a default liveness check to ensure app is responsive + .AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]); + + return builder; + } + + public static WebApplication MapDefaultEndpoints(this WebApplication app) + { + // Adding health checks endpoints to applications in non-development environments has security implications. + // See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments. + if (app.Environment.IsDevelopment()) + { + // All health checks must pass for app to be considered ready to accept traffic after starting + app.MapHealthChecks("/health"); + + // Only health checks tagged with the "live" tag must pass for app to be considered alive + app.MapHealthChecks("/alive", new HealthCheckOptions + { + Predicate = r => r.Tags.Contains("live") + }); + } + + return app; + } +} diff --git a/src/CommunityToolkit.Aspire.Chroma/AspireChromaExtensions.cs b/src/CommunityToolkit.Aspire.Chroma/AspireChromaExtensions.cs index a803aa8a3..4d70f6710 100644 --- a/src/CommunityToolkit.Aspire.Chroma/AspireChromaExtensions.cs +++ b/src/CommunityToolkit.Aspire.Chroma/AspireChromaExtensions.cs @@ -1,3 +1,4 @@ +using Aspire; using System.Net.Http; using ChromaDB.Client; using CommunityToolkit.Aspire.Chroma; @@ -17,36 +18,48 @@ public static class AspireChromaExtensions /// /// Registers as a singleton in the services collection. /// + /// The to read config from and add services to. + /// The connection name to use to find a connection string. + /// An optional method that can be used for customizing the . It's invoked after the settings are read from the configuration. public static void AddChromaClient( this IHostApplicationBuilder builder, string connectionName, Action? configureSettings = null) { - AddChromaClient(builder, serviceKey: null, connectionName, configureSettings); + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNullOrEmpty(connectionName); + AddChromaClient(builder, DefaultConfigSectionName, configureSettings, connectionName, serviceKey: null); } /// /// Registers as a keyed singleton in the services collection. /// + /// The to read config from and add services to. + /// The connection name to use to find a connection string. + /// An optional method that can be used for customizing the . It's invoked after the settings are read from the configuration. public static void AddKeyedChromaClient( this IHostApplicationBuilder builder, string name, Action? configureSettings = null) { - AddChromaClient(builder, serviceKey: name, connectionName: name, configureSettings); + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNullOrEmpty(name); + AddChromaClient(builder, $"{DefaultConfigSectionName}:{name}", configureSettings, connectionName: name, serviceKey: name); } private static void AddChromaClient( IHostApplicationBuilder builder, - object? serviceKey, + string configurationSectionName, + Action? configureSettings, string connectionName, - Action? configureSettings = null) + object? serviceKey) { ArgumentNullException.ThrowIfNull(builder); - ArgumentNullException.ThrowIfNull(connectionName); + ArgumentNullException.ThrowIfNull(configurationSectionName, nameof(configurationSectionName)); + ArgumentNullException.ThrowIfNull(connectionName, nameof(connectionName)); var settings = new ChromaClientSettings(); - builder.Configuration.GetSection(DefaultConfigSectionName).Bind(settings); + builder.Configuration.GetSection(configurationSectionName).Bind(settings); if (builder.Configuration.GetConnectionString(connectionName) is string connectionString) { @@ -66,21 +79,22 @@ private static void AddChromaClient( if (!settings.DisableHealthChecks) { - builder.Services.AddHealthChecks() - .Add(new HealthCheckRegistration( - serviceKey is null ? connectionName : $"{connectionName}_check", - sp => new ChromaHealthCheck(serviceKey is null - ? sp.GetRequiredService() - : sp.GetRequiredKeyedService(serviceKey)), - failureStatus: default, - tags: default, - timeout: settings.HealthCheckTimeout.HasValue ? TimeSpan.FromMilliseconds(settings.HealthCheckTimeout.Value) : default)); + var healthCheckName = serviceKey is null ? connectionName : $"{connectionName}_check"; + + builder.TryAddHealthCheck(new HealthCheckRegistration( + healthCheckName, + sp => new ChromaHealthCheck(serviceKey is null + ? sp.GetRequiredService() + : sp.GetRequiredKeyedService(serviceKey)), + failureStatus: null, + tags: null, + timeout: settings.HealthCheckTimeout > 0 ? TimeSpan.FromMilliseconds(settings.HealthCheckTimeout.Value) : null)); } } private static ChromaClient CreateClient(IServiceProvider sp, ChromaClientSettings settings, string connectionName) { - if (settings.Endpoint == null) + if (settings.Endpoint is null) { throw new InvalidOperationException($"ChromaDB endpoint is not configured for connection name '{connectionName}'."); } diff --git a/src/CommunityToolkit.Aspire.Chroma/api/CommunityToolkit.Aspire.Chroma.cs b/src/CommunityToolkit.Aspire.Chroma/api/CommunityToolkit.Aspire.Chroma.cs deleted file mode 100644 index 58daac8fe..000000000 --- a/src/CommunityToolkit.Aspire.Chroma/api/CommunityToolkit.Aspire.Chroma.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace CommunityToolkit.Aspire.Chroma -{ - public sealed partial class ChromaClientSettings - { - public bool DisableHealthChecks { get { throw null; } set { } } - - public System.Uri? Endpoint { get { throw null; } set { } } - - public int? HealthCheckTimeout { get { throw null; } set { } } - } -} - -namespace Microsoft.Extensions.Hosting -{ - public static partial class AspireChromaExtensions - { - public static void AddChromaClient(this IHostApplicationBuilder builder, string connectionName, System.Action? configureSettings = null) { } - - public static void AddKeyedChromaClient(this IHostApplicationBuilder builder, string name, System.Action? configureSettings = null) { } - } -} diff --git a/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaResource.cs b/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaResource.cs index a51556a8e..887dbf323 100644 --- a/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaResource.cs +++ b/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaResource.cs @@ -5,15 +5,10 @@ namespace CommunityToolkit.Aspire.Hosting.Chroma; /// /// A resource that represents a ChromaDB container. /// -public class ChromaResource : ContainerResource, IResourceWithConnectionString +public class ChromaResource(string name) : ContainerResource(name), IResourceWithConnectionString { internal const string PrimaryEndpointName = "http"; - /// The name of the resource. - public ChromaResource(string name) : base(name) - { - } - private EndpointReference? _primaryEndpoint; /// diff --git a/src/CommunityToolkit.Aspire.Hosting.Chroma/api/CommunityToolkit.Aspire.Hosting.Chroma.cs b/src/CommunityToolkit.Aspire.Hosting.Chroma/api/CommunityToolkit.Aspire.Hosting.Chroma.cs deleted file mode 100644 index a40f7c805..000000000 --- a/src/CommunityToolkit.Aspire.Hosting.Chroma/api/CommunityToolkit.Aspire.Hosting.Chroma.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace Aspire.Hosting -{ - public static partial class ChromaBuilderExtensions - { - public static ApplicationModel.IResourceBuilder AddChroma(this IDistributedApplicationBuilder builder, string name, int? port = null) { throw null; } - - public static ApplicationModel.IResourceBuilder WithDataBindMount(this ApplicationModel.IResourceBuilder builder, string source) { throw null; } - - public static ApplicationModel.IResourceBuilder WithDataVolume(this ApplicationModel.IResourceBuilder builder, string? name = null) { throw null; } - } -} - -namespace Aspire.Hosting.ApplicationModel -{ - public partial class ChromaResource : ContainerResource, IResourceWithConnectionString, IResource, IManifestExpressionProvider, IValueProvider, IValueWithReferences - { - public ChromaResource(string name) : base(default!, default) { } - - public ReferenceExpression ConnectionStringExpression { get { throw null; } } - - public EndpointReferenceExpression Host { get { throw null; } } - - public EndpointReferenceExpression Port { get { throw null; } } - - public EndpointReference PrimaryEndpoint { get { throw null; } } - - public ReferenceExpression UriExpression { get { throw null; } } - - System.Collections.Generic.IEnumerable> IResourceWithConnectionString.GetConnectionProperties() { throw null; } - } -} diff --git a/tests/CommunityToolkit.Aspire.Chroma.Tests/ChromaClientExtensionsTests.cs b/tests/CommunityToolkit.Aspire.Chroma.Tests/ChromaClientExtensionsTests.cs index 5850ed7b0..366c69d54 100644 --- a/tests/CommunityToolkit.Aspire.Chroma.Tests/ChromaClientExtensionsTests.cs +++ b/tests/CommunityToolkit.Aspire.Chroma.Tests/ChromaClientExtensionsTests.cs @@ -38,7 +38,7 @@ public void AddKeyedChromaClient_ShouldRegisterKeyedClient() } [Fact] - public void AddChromaClient_HealthCheckShouldBeRegistered() + public async Task AddChromaClient_HealthCheckShouldBeRegistered() { var builder = CreateBuilder(); @@ -47,13 +47,12 @@ public void AddChromaClient_HealthCheckShouldBeRegistered() using var host = builder.Build(); var healthCheckService = host.Services.GetRequiredService(); - // The health check name should match the connection name for non-keyed - var registration = host.Services.GetRequiredService>(); - Assert.Contains(registration, x => x.Name == DefaultConnectionName); + var healthCheckReport = await healthCheckService.CheckHealthAsync(); + Assert.Contains(healthCheckReport.Entries, x => x.Key == DefaultConnectionName); } [Fact] - public void AddKeyedChromaClient_HealthCheckShouldBeRegisteredWithSuffix() + public async Task AddKeyedChromaClient_HealthCheckShouldBeRegisteredWithSuffix() { var builder = CreateBuilder(); @@ -62,9 +61,8 @@ public void AddKeyedChromaClient_HealthCheckShouldBeRegisteredWithSuffix() using var host = builder.Build(); var healthCheckService = host.Services.GetRequiredService(); - // The health check name should have _check suffix for keyed - var registration = host.Services.GetRequiredService>(); - Assert.Contains(registration, x => x.Name == $"{DefaultConnectionName}_check"); + var healthCheckReport = await healthCheckService.CheckHealthAsync(); + Assert.Contains(healthCheckReport.Entries, x => x.Key == $"{DefaultConnectionName}_check"); } private static HostApplicationBuilder CreateBuilder() diff --git a/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/AppHostTests.cs b/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/AppHostTests.cs new file mode 100644 index 000000000..30868c4ce --- /dev/null +++ b/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/AppHostTests.cs @@ -0,0 +1,53 @@ +using CommunityToolkit.Aspire.Testing; +using Aspire.Components.Common.Tests; +using System.Net; +using Microsoft.Extensions.DependencyInjection; +using System.Net.Http.Json; +using Aspire.Hosting.ApplicationModel; + +namespace CommunityToolkit.Aspire.Hosting.Chroma.Tests; + +[RequiresDocker] +public class AppHostTests(AspireIntegrationTestFixture fixture) : IClassFixture> +{ + [Fact] + public async Task ChromaResourceStartsAndIsHealthy() + { + var distributedAppModel = fixture.App.Services.GetRequiredService(); + var chromaResource = distributedAppModel.Resources.OfType().Single(); + + var rns = fixture.ResourceNotificationService; + + await rns.WaitForResourceHealthyAsync(chromaResource.Name).WaitAsync(TimeSpan.FromMinutes(5)); + + using var httpClient = fixture.CreateHttpClient(chromaResource.Name); + + var response = await httpClient.GetAsync("/api/v1/heartbeat"); + + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + + [Fact] + public async Task ApiServiceCanCreateAndQueryCollections() + { + var rns = fixture.ResourceNotificationService; + + await rns.WaitForResourceHealthyAsync("apiservice").WaitAsync(TimeSpan.FromMinutes(5)); + + using var httpClient = fixture.CreateHttpClient("apiservice"); + + // Create + var createResponse = await httpClient.PostAsync("/create", null); + Assert.Equal(HttpStatusCode.OK, createResponse.StatusCode); + + var result = await createResponse.Content.ReadFromJsonAsync(); + Assert.NotNull(result); + Assert.NotEmpty(result.Collection); + + // Query + var queryResponse = await httpClient.GetAsync($"/query?collectionName={result.Collection}"); + Assert.Equal(HttpStatusCode.OK, queryResponse.StatusCode); + } + + private record CreateResult(string Collection, int Count); +} diff --git a/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests.csproj b/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests.csproj index 35524062b..95d0b95e9 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests.csproj +++ b/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests.csproj @@ -7,6 +7,7 @@ + From 12273b2f7bee156589cc16f51e6b92a989817d09 Mon Sep 17 00:00:00 2001 From: Ali Hamza Date: Thu, 26 Feb 2026 08:30:00 +0000 Subject: [PATCH 3/7] Address Copilot feedback: fix grammar and rename test class --- src/CommunityToolkit.Aspire.Chroma/ChromaClientSettings.cs | 2 +- .../ChromaClientExtensionsTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CommunityToolkit.Aspire.Chroma/ChromaClientSettings.cs b/src/CommunityToolkit.Aspire.Chroma/ChromaClientSettings.cs index 35f7dff4e..cdd0b1af9 100644 --- a/src/CommunityToolkit.Aspire.Chroma/ChromaClientSettings.cs +++ b/src/CommunityToolkit.Aspire.Chroma/ChromaClientSettings.cs @@ -23,7 +23,7 @@ public sealed class ChromaClientSettings public bool DisableHealthChecks { get; set; } /// - /// Gets or sets a integer value that indicates the ChromaDB health check timeout in milliseconds. + /// Gets or sets an integer value that indicates the ChromaDB health check timeout in milliseconds. /// public int? HealthCheckTimeout { get; set; } diff --git a/tests/CommunityToolkit.Aspire.Chroma.Tests/ChromaClientExtensionsTests.cs b/tests/CommunityToolkit.Aspire.Chroma.Tests/ChromaClientExtensionsTests.cs index 366c69d54..e950e675c 100644 --- a/tests/CommunityToolkit.Aspire.Chroma.Tests/ChromaClientExtensionsTests.cs +++ b/tests/CommunityToolkit.Aspire.Chroma.Tests/ChromaClientExtensionsTests.cs @@ -6,7 +6,7 @@ namespace CommunityToolkit.Aspire.Chroma.Tests; -public class AspireChromaClientExtensionsTests +public class ChromaClientExtensionsTests { private const string DefaultConnectionName = "chroma"; private const string DefaultConnectionString = "http://localhost:8000"; From 1470e0062a5bc6e80893f4ec787c9a38cadaa6d5 Mon Sep 17 00:00:00 2001 From: Ali Hamza Date: Tue, 3 Mar 2026 05:41:21 +0000 Subject: [PATCH 4/7] Fix CI test failures: use relative path for bind mount and add launchSettings.json for ApiService --- .../Properties/launchSettings.json | 23 +++++++++++++++++++ .../AddChromaTests.cs | 5 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ApiService/Properties/launchSettings.json diff --git a/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ApiService/Properties/launchSettings.json b/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ApiService/Properties/launchSettings.json new file mode 100644 index 000000000..841adeaa2 --- /dev/null +++ b/examples/chromadb/CommunityToolkit.Aspire.Hosting.Chroma.ApiService/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/AddChromaTests.cs b/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/AddChromaTests.cs index 39e0ca6dc..5167bc50a 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/AddChromaTests.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.Chroma.Tests/AddChromaTests.cs @@ -84,7 +84,7 @@ public void WithDataBindMountAddsAnnotationMetadata() var appBuilder = DistributedApplication.CreateBuilder(); appBuilder.AddChroma("chroma") - .WithDataBindMount("C:/chroma/data"); + .WithDataBindMount("./chroma-data"); using var app = appBuilder.Build(); @@ -92,7 +92,8 @@ public void WithDataBindMountAddsAnnotationMetadata() var containerResource = Assert.Single(appModel.Resources.OfType()); var mountAnnotation = Assert.Single(containerResource.Annotations.OfType()); - Assert.Equal("C:/chroma/data", mountAnnotation.Source); + Assert.NotNull(mountAnnotation.Source); + Assert.Equal(Path.GetFullPath("./chroma-data").Replace('\\', '/'), mountAnnotation.Source.Replace('\\', '/')); Assert.Equal("/chroma/chroma", mountAnnotation.Target); Assert.Equal(ContainerMountType.BindMount, mountAnnotation.Type); } From d596477e7bff37d8d8d402f67e6025e1392159e6 Mon Sep 17 00:00:00 2001 From: Ali Hamza Date: Wed, 4 Mar 2026 06:18:22 +0000 Subject: [PATCH 5/7] fix(chroma): resolve health check 404 and address review feedback --- .../ChromaHealthCheck.cs | 2 +- src/CommunityToolkit.Aspire.Chroma/README.md | 2 +- tests/tmp_inspect/Program.cs | 10 ++++++++++ tests/tmp_inspect_v2/Program.cs | 10 ++++++++++ tests/tmp_inspect_v3/Program.cs | 11 +++++++++++ tests/tmp_inspect_v3/tmp_inspect_v3.csproj | 14 ++++++++++++++ tests/tmp_inspect_v4/Directory.Build.props | Bin 0 -> 34 bytes tests/tmp_inspect_v4/Directory.Packages.props | Bin 0 -> 34 bytes tests/tmp_inspect_v4/Program.cs | 2 ++ tests/tmp_inspect_v4/tmp_inspect_v4.csproj | 10 ++++++++++ 10 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 tests/tmp_inspect/Program.cs create mode 100644 tests/tmp_inspect_v2/Program.cs create mode 100644 tests/tmp_inspect_v3/Program.cs create mode 100644 tests/tmp_inspect_v3/tmp_inspect_v3.csproj create mode 100644 tests/tmp_inspect_v4/Directory.Build.props create mode 100644 tests/tmp_inspect_v4/Directory.Packages.props create mode 100644 tests/tmp_inspect_v4/Program.cs create mode 100644 tests/tmp_inspect_v4/tmp_inspect_v4.csproj diff --git a/src/CommunityToolkit.Aspire.Chroma/ChromaHealthCheck.cs b/src/CommunityToolkit.Aspire.Chroma/ChromaHealthCheck.cs index 5d62ac800..984703b32 100644 --- a/src/CommunityToolkit.Aspire.Chroma/ChromaHealthCheck.cs +++ b/src/CommunityToolkit.Aspire.Chroma/ChromaHealthCheck.cs @@ -10,7 +10,7 @@ public async Task CheckHealthAsync(HealthCheckContext context { try { - await chromaClient.GetVersion().ConfigureAwait(false); + await chromaClient.Heartbeat().ConfigureAwait(false); return HealthCheckResult.Healthy(); } diff --git a/src/CommunityToolkit.Aspire.Chroma/README.md b/src/CommunityToolkit.Aspire.Chroma/README.md index 5a5149647..2b8bf73a1 100644 --- a/src/CommunityToolkit.Aspire.Chroma/README.md +++ b/src/CommunityToolkit.Aspire.Chroma/README.md @@ -28,7 +28,7 @@ public class MyService(ChromaClient chromaClient) { public async Task QueryAsync() { - var version = await chromaClient.GetVersion(); + await chromaClient.Heartbeat(); // ... } } diff --git a/tests/tmp_inspect/Program.cs b/tests/tmp_inspect/Program.cs new file mode 100644 index 000000000..a587d35d8 --- /dev/null +++ b/tests/tmp_inspect/Program.cs @@ -0,0 +1,10 @@ +using System; +using System.Reflection; +using ChromaDB.Client; + +var type = typeof(ChromaClient); +Console.WriteLine($"Methods in {type.FullName}:"); +foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance)) +{ + Console.WriteLine($"- {method.Name} (Returns: {method.ReturnType.Name})"); +} diff --git a/tests/tmp_inspect_v2/Program.cs b/tests/tmp_inspect_v2/Program.cs new file mode 100644 index 000000000..a587d35d8 --- /dev/null +++ b/tests/tmp_inspect_v2/Program.cs @@ -0,0 +1,10 @@ +using System; +using System.Reflection; +using ChromaDB.Client; + +var type = typeof(ChromaClient); +Console.WriteLine($"Methods in {type.FullName}:"); +foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance)) +{ + Console.WriteLine($"- {method.Name} (Returns: {method.ReturnType.Name})"); +} diff --git a/tests/tmp_inspect_v3/Program.cs b/tests/tmp_inspect_v3/Program.cs new file mode 100644 index 000000000..d887da1f5 --- /dev/null +++ b/tests/tmp_inspect_v3/Program.cs @@ -0,0 +1,11 @@ +using System; +using System.Reflection; +using System.Threading.Tasks; +using ChromaDB.Client; + +var type = typeof(ChromaClient); +Console.WriteLine($"Methods in {type.FullName}:"); +foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance)) +{ + Console.WriteLine($"- {method.Name} (Returns: {method.ReturnType.Name})"); +} diff --git a/tests/tmp_inspect_v3/tmp_inspect_v3.csproj b/tests/tmp_inspect_v3/tmp_inspect_v3.csproj new file mode 100644 index 000000000..f6e61451a --- /dev/null +++ b/tests/tmp_inspect_v3/tmp_inspect_v3.csproj @@ -0,0 +1,14 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + diff --git a/tests/tmp_inspect_v4/Directory.Build.props b/tests/tmp_inspect_v4/Directory.Build.props new file mode 100644 index 0000000000000000000000000000000000000000..c1abec6dd194a03da1fb137d965989f29cdf611a GIT binary patch literal 34 mcmezWFOI>6A%LNXA)g_OA(bJSp@e~#fr~+(A&$Wg%mM(LC6A%LNXA)g_OA(bJSp@e~#fr~+(A&$Wg%mM(LC + + + Exe + net10.0 + enable + enable + + + From 0e284dd511fca321003ab370728a17370f1c66d0 Mon Sep 17 00:00:00 2001 From: Ali Hamza Date: Wed, 4 Mar 2026 06:21:12 +0000 Subject: [PATCH 6/7] fix(chroma): resolve health check 404 and address review feedback --- tests/tmp_inspect/Program.cs | 10 ---------- tests/tmp_inspect_v2/Program.cs | 10 ---------- tests/tmp_inspect_v3/Program.cs | 11 ----------- tests/tmp_inspect_v3/tmp_inspect_v3.csproj | 14 -------------- tests/tmp_inspect_v4/Directory.Build.props | Bin 34 -> 0 bytes tests/tmp_inspect_v4/Directory.Packages.props | Bin 34 -> 0 bytes tests/tmp_inspect_v4/Program.cs | 2 -- tests/tmp_inspect_v4/tmp_inspect_v4.csproj | 10 ---------- 8 files changed, 57 deletions(-) delete mode 100644 tests/tmp_inspect/Program.cs delete mode 100644 tests/tmp_inspect_v2/Program.cs delete mode 100644 tests/tmp_inspect_v3/Program.cs delete mode 100644 tests/tmp_inspect_v3/tmp_inspect_v3.csproj delete mode 100644 tests/tmp_inspect_v4/Directory.Build.props delete mode 100644 tests/tmp_inspect_v4/Directory.Packages.props delete mode 100644 tests/tmp_inspect_v4/Program.cs delete mode 100644 tests/tmp_inspect_v4/tmp_inspect_v4.csproj diff --git a/tests/tmp_inspect/Program.cs b/tests/tmp_inspect/Program.cs deleted file mode 100644 index a587d35d8..000000000 --- a/tests/tmp_inspect/Program.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Reflection; -using ChromaDB.Client; - -var type = typeof(ChromaClient); -Console.WriteLine($"Methods in {type.FullName}:"); -foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance)) -{ - Console.WriteLine($"- {method.Name} (Returns: {method.ReturnType.Name})"); -} diff --git a/tests/tmp_inspect_v2/Program.cs b/tests/tmp_inspect_v2/Program.cs deleted file mode 100644 index a587d35d8..000000000 --- a/tests/tmp_inspect_v2/Program.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Reflection; -using ChromaDB.Client; - -var type = typeof(ChromaClient); -Console.WriteLine($"Methods in {type.FullName}:"); -foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance)) -{ - Console.WriteLine($"- {method.Name} (Returns: {method.ReturnType.Name})"); -} diff --git a/tests/tmp_inspect_v3/Program.cs b/tests/tmp_inspect_v3/Program.cs deleted file mode 100644 index d887da1f5..000000000 --- a/tests/tmp_inspect_v3/Program.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Reflection; -using System.Threading.Tasks; -using ChromaDB.Client; - -var type = typeof(ChromaClient); -Console.WriteLine($"Methods in {type.FullName}:"); -foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance)) -{ - Console.WriteLine($"- {method.Name} (Returns: {method.ReturnType.Name})"); -} diff --git a/tests/tmp_inspect_v3/tmp_inspect_v3.csproj b/tests/tmp_inspect_v3/tmp_inspect_v3.csproj deleted file mode 100644 index f6e61451a..000000000 --- a/tests/tmp_inspect_v3/tmp_inspect_v3.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - Exe - net10.0 - enable - enable - - - - - - - diff --git a/tests/tmp_inspect_v4/Directory.Build.props b/tests/tmp_inspect_v4/Directory.Build.props deleted file mode 100644 index c1abec6dd194a03da1fb137d965989f29cdf611a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 34 mcmezWFOI>6A%LNXA)g_OA(bJSp@e~#fr~+(A&$Wg%mM(LC6A%LNXA)g_OA(bJSp@e~#fr~+(A&$Wg%mM(LC - - - Exe - net10.0 - enable - enable - - - From 05a7cd2f41367ead28bb77708bf6e85fa4c1018b Mon Sep 17 00:00:00 2001 From: Ali Hamza Date: Thu, 12 Mar 2026 05:21:04 +0000 Subject: [PATCH 7/7] feat(chroma): fix health check and base URL construction for CI stability --- .../AspireChromaExtensions.cs | 9 ++++++++- .../ChromaBuilderExtensions.cs | 3 ++- .../ChromaResource.cs | 6 +++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/CommunityToolkit.Aspire.Chroma/AspireChromaExtensions.cs b/src/CommunityToolkit.Aspire.Chroma/AspireChromaExtensions.cs index 4d70f6710..1454664b7 100644 --- a/src/CommunityToolkit.Aspire.Chroma/AspireChromaExtensions.cs +++ b/src/CommunityToolkit.Aspire.Chroma/AspireChromaExtensions.cs @@ -100,6 +100,13 @@ private static ChromaClient CreateClient(IServiceProvider sp, ChromaClientSettin } var httpClient = sp.GetRequiredService().CreateClient(connectionName); - return new ChromaClient(new ChromaConfigurationOptions(settings.Endpoint.ToString()), httpClient); + var endpoint = settings.Endpoint.ToString(); + + if (!endpoint.Contains("/api/v1", StringComparison.OrdinalIgnoreCase)) + { + endpoint = endpoint.TrimEnd('/') + "/api/v1/"; + } + + return new ChromaClient(new ChromaConfigurationOptions(endpoint), httpClient); } } diff --git a/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaBuilderExtensions.cs b/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaBuilderExtensions.cs index f889b1cf7..5692ae84f 100644 --- a/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaBuilderExtensions.cs +++ b/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaBuilderExtensions.cs @@ -31,7 +31,8 @@ public static IResourceBuilder AddChroma( return builder.AddResource(chroma) .WithImage(ChromaContainerImageTags.Image, ChromaContainerImageTags.Tag) .WithImageRegistry(ChromaContainerImageTags.Registry) - .WithHttpEndpoint(targetPort: ChromaPort, port: port, name: ChromaResource.PrimaryEndpointName); + .WithHttpEndpoint(targetPort: ChromaPort, port: port, name: ChromaResource.PrimaryEndpointName) + .WithHttpHealthCheck("/api/v1/heartbeat"); } /// diff --git a/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaResource.cs b/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaResource.cs index 887dbf323..782129675 100644 --- a/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaResource.cs +++ b/src/CommunityToolkit.Aspire.Hosting.Chroma/ChromaResource.cs @@ -30,15 +30,15 @@ public class ChromaResource(string name) : ContainerResource(name), IResourceWit /// Gets the connection string expression for the ChromaDB /// public ReferenceExpression ConnectionStringExpression => - ReferenceExpression.Create($"Endpoint=http://{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}"); + ReferenceExpression.Create($"Endpoint=http://{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}/api/v1/"); /// /// Gets the connection URI expression for the ChromaDB server. /// /// - /// Format: http://{host}:{port}. + /// Format: http://{host}:{port}/api/v1/. /// - public ReferenceExpression UriExpression => ReferenceExpression.Create($"http://{Host}:{Port}"); + public ReferenceExpression UriExpression => ReferenceExpression.Create($"http://{Host}:{Port}/api/v1/"); IEnumerable> IResourceWithConnectionString.GetConnectionProperties() {