.NET Aspire Qdrant integration
In this article, you learn how to use the .NET Aspire Qdrant integration. Use this integration to register a QdrantClient in the DI container for connecting to a Qdrant server.
Get started
To get started with the .NET Aspire Qdrant integration, install the 📦 Aspire.Qdrant.Client NuGet package in the client-consuming project, i.e., the project for the application that uses the Qdrant client.
dotnet add package Aspire.Qdrant.Client
For more information, see dotnet add package or Manage package dependencies in .NET applications.
Example usage
In the Program.cs file of your client-consuming project, call the AddQdrantClient
extension method to register a QdrantClient
for use via the dependency injection container. The method takes a connection name parameter.
builder.AddQdrantClient("qdrant");
To retrieve your QdrantClient
object consider the following example service:
public class ExampleService(QdrantClient client)
{
// Use client...
}
App host usage
To model the Qdrant server resource in the app host, install the 📦 Aspire.Hosting.Qdrant) NuGet package in the [app host](xref:dotnet/aspire/app-host NuGet package in the app host project.
dotnet add package Aspire.Hosting.Qdrant
In your app host project, register a Qdrant server and consume the connection using the following methods:
var builder = DistributedApplication.CreateBuilder(args);
var qdrant = builder.AddQdrant("qdrant");
var myService = builder.AddProject<Projects.MyService>()
.WithReference(qdrant);
When you want to explicitly provide the API key, you can provide it as a parameter. Consider the following alternative example:
var apiKey = builder.AddParameter("apikey", secret: true);
var qdrant = builder.AddQdrant("qdrant", apiKey);
var myService = builder.AddProject<Projects.MyService>()
.WithReference(qdrant);
For more information, see External parameters.
Configuration
The .NET Aspire Qdrant Client integration provides multiple options to configure the server connection based on the requirements and conventions of your project.
Use a connection string
When using a connection string from the ConnectionStrings
configuration section, you can provide the name of the connection string when calling builder.AddQdrantClient()
:
builder.AddQdrantClient("qdrant");
And then the connection string will be retrieved from the ConnectionStrings
configuration section:
{
"ConnectionStrings": {
"qdrant": "Endpoint=http://localhost:6334;Key=123456!@#$%"
}
}
By default the QdrantClient
uses the gRPC API endpoint.
Use configuration providers
The .NET Aspire Qdrant Client integration supports Microsoft.Extensions.Configuration. It loads the QdrantClientSettings
from configuration by using the Aspire:Qdrant:Client
key. Example appsettings.json
that configures some of the options:
{
"Aspire": {
"Qdrant": {
"Client": {
"Key": "123456!@#$%"
}
}
}
}
Use inline delegates
You can also pass the Action<QdrantClientSettings> configureSettings
delegate to set up some or all the options inline, for example to set the API key from code:
builder.AddQdrantClient("qdrant", settings => settings.ApiKey = "12345!@#$%");
Observability and telemetry
.NET Aspire integrations automatically set up Logging, Tracing, and Metrics configurations, which are sometimes known as the pillars of observability. For more information about integration observability and telemetry, see .NET Aspire integrations overview. 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 .NET Aspire Qdrant integration uses the following logging categories:
- "Qdrant.Client"