title | description | ms.topic | ms.date |
---|---|---|---|
.NET Aspire Qdrant integration |
This article describes the .NET Aspire Qdrant integration. |
how-to |
08/12/2024 |
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.
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
<PackageReference Include="Aspire.Qdrant.Client"
Version="*" />
For more information, see dotnet add package or Manage package dependencies in .NET applications.
In the :::no-loc text="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...
}
To model the Qdrant server resource in the app host, install the 📦 Aspire.Hosting.Qdrant NuGet package in the app host project.
dotnet add package Aspire.Hosting.Qdrant
<PackageReference Include="Aspire.Hosting.Qdrant"
Version="*" />
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.
The .NET Aspire Qdrant Client integration provides multiple options to configure the server connection based on the requirements and conventions of your project.
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.
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!@#$%"
}
}
}
}
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!@#$%");
[!INCLUDE integration-observability-and-telemetry]
The .NET Aspire Qdrant integration uses the following logging categories:
- "Qdrant.Client"