Milvus Client integration reference

Milvus logo

To get started with the Aspire Milvus integrations, follow the Get started with Milvus integrations guide.

This article includes full details about the Aspire Milvus Client integration, which allows you to connect to and interact with Milvus vector databases from your Aspire consuming projects.

Installation

Caution

The client integration is currently in preview.

You need a Milvus server and connection information for accessing the server. To get started with the Aspire Milvus client integration, install the 📦 Aspire.Milvus.Client NuGet package in the client-consuming project, that is, the project for the application that uses the Milvus client. The Milvus client integration registers a MilvusClient instance that you can use to interact with Milvus.

Install the NuGet package
dotnet add package Aspire.Milvus.Client

Add Milvus client

In the Program.cs file of your client-consuming project, call the AddMilvusClient extension method on any IHostApplicationBuilder to register a MilvusClient for use via the dependency injection container. The method takes a connection name parameter.

builder.AddMilvusClient(connectionName: "milvusdb");

Tip

The connectionName parameter must match the name used when adding the Milvus database resource in the AppHost project. For more information, see Add Milvus server and database resources.

You can then retrieve the MilvusClient instance using dependency injection. For example, to retrieve the connection from an example service:

public class ExampleService(MilvusClient client)
{
    // Use the Milvus Client...
}

For more information on dependency injection, see .NET dependency injection.

Add keyed Milvus client

There might be situations where you want to register multiple MilvusClient instances with different connection strings. To register keyed Milvus clients, call the AddKeyedMilvusClient method:

builder.AddKeyedMilvusClient(name: "mainDb");
builder.AddKeyedMilvusClient(name: "loggingDb");

Then retrieve the instances using dependency injection:

public class ExampleService(
    [FromKeyedServices("mainDb")] MilvusClient mainDbClient,
    [FromKeyedServices("loggingDb")] MilvusClient loggingDbClient)
{
    // Use clients...
}

For more information on keyed services, see .NET dependency injection: Keyed services.

Properties of the Milvus resources

When you use the WithReference method to pass a Milvus server or database resource from the AppHost project to a consuming client project, several properties are available to use in the consuming project.

Aspire exposes each property as an environment variable named [RESOURCE]_[PROPERTY]. For instance, the Uri property of a resource called vectordb becomes VECTORDB_URI.

Milvus server

The Milvus server resource exposes the following connection properties:

Property Name Description
Host The hostname or IP address of the Milvus server
Port The gRPC port exposed by the Milvus server
Token The authentication token, with the format root:{ApiKey}
Uri The gRPC endpoint URI, with the format http://{Host}:{Port}

Example connection strings:

Uri: http://localhost:19530
Token: root:Milvus

Milvus database

The Milvus database resource inherits all properties from its parent MilvusServerResource and adds:

Property Name Description
DatabaseName The Milvus database name

Configuration

The Aspire Milvus client integration provides multiple configuration approaches and options to meet the requirements and conventions of your project.

Use a connection string

When using a connection string from the ConnectionStrings configuration section, you provide the name of the connection string when calling builder.AddMilvusClient():

builder.AddMilvusClient("milvus");

The connection string is retrieved from the ConnectionStrings configuration section:

{
  "ConnectionStrings": {
    "milvus": "Endpoint=http://localhost:19530/;Key=root:Non-default-P@ssw0rd"
  }
}

For more information about the Milvus connection string format, see the Milvus documentation.

Use configuration providers

The Aspire Milvus client integration supports Microsoft.Extensions.Configuration from configuration files such as appsettings.json by using the Aspire:Milvus:Client key. If you have set up your configurations in the Aspire:Milvus:Client section you can just call the method without passing any parameter.

The following is an example of an appsettings.json that configures some of the available options:

{
  "Aspire": {
    "Milvus": {
      "Client": {
        "Endpoint": "http://localhost:19530/",
        "Database": "milvusdb",
        "Key": "root:Non-default-P@ssw0rd",
        "DisableHealthChecks": false
      }
    }
  }
}

Use inline delegates

You can also pass the Action<MilvusSettings> delegate to set up some or all the options inline, for example to set the API key from code:

builder.AddMilvusClient(
    "milvus",
    static settings => settings.Key = "root:Non-default-P@ssw0rd");

Configuration options

Here are the available configurable options:

Name Description
Endpoint The endpoint URI of the Milvus server to connect to.
Database The name of the Milvus database.
Key The authentication key used for authentication (format: root:{password}).
DisableHealthChecks A boolean value that indicates whether the health check is disabled or not.

Client integration health checks

By default, Aspire integrations enable health checks for all services. For more information, see Aspire integrations overview.

By default, the Aspire Milvus client integration handles the following:

  • Checks if the MilvusSettings.DisableHealthChecks is true.
  • If not disabled, adds a health check that verifies the Milvus server is reachable and a connection can be established.

Observability and telemetry

Aspire integrations automatically set up Logging, Tracing, and Metrics configurations, which are sometimes known as the pillars of observability. Depending on the backing service, some integrations may only support some of these features. For example, some integrations support logging and tracing, but not metrics. Telemetry features can also be disabled using the techniques presented in the Configuration section.

Logging

The Aspire Milvus client integration uses the following log categories:

  • Milvus.Client

Tracing and Metrics

The Milvus integration doesn't currently emit tracing activities or metrics because they are not supported by the Milvus.Client library.

See also