इसे छोड़कर कंटेंट पर जाएं

Qdrant Client integration reference

यह कंटेंट अभी तक आपकी भाषा में उपलब्ध नहीं है।

Qdrant logo

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

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

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

.NET CLI — Add Aspire.Qdrant.Client package
dotnet add package Aspire.Qdrant.Client

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

C# — Program.cs
builder.AddQdrantClient(connectionName: "qdrant");

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

C# — ExampleService.cs
public class ExampleService(QdrantClient client)
{
// Use Qdrant client...
}

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

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

C# — Program.cs
builder.AddKeyedQdrantClient(name: "mainQdrant");
builder.AddKeyedQdrantClient(name: "loggingQdrant");

Then retrieve the instances using dependency injection:

C# — ExampleService.cs
public class ExampleService(
[FromKeyedServices("mainQdrant")] QdrantClient mainQdrantClient,
[FromKeyedServices("loggingQdrant")] QdrantClient loggingQdrantClient)
{
// Use clients...
}

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

When you use the WithReference method to pass a Qdrant server 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 qdrant becomes QDRANT_URI.

The Qdrant server resource exposes the following connection properties:

Property NameDescription
GrpcHostThe gRPC hostname of the Qdrant server
GrpcPortThe gRPC port of the Qdrant server
HttpHostThe HTTP hostname of the Qdrant server
HttpPortThe HTTP port of the Qdrant server
ApiKeyThe API key for authentication
UriThe gRPC connection URI, with the format http://{GrpcHost}:{GrpcPort}
HttpUriThe HTTP connection URI, with the format http://{HttpHost}:{HttpPort}

Example connection strings:

Uri: http://localhost:6334
HttpUri: http://localhost:6333

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

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

C# — Program.cs
builder.AddQdrantClient("qdrant");

The connection string is retrieved from the ConnectionStrings configuration section. By default the QdrantClient uses the gRPC API endpoint:

JSON — appsettings.json
{
"ConnectionStrings": {
"qdrant": "Endpoint=http://localhost:6334;Key=123456!@#$%"
}
}

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

The Aspire Qdrant client integration supports Microsoft.Extensions.Configuration from configuration files such as appsettings.json by using the Aspire:Qdrant:Client key. If you have set up your configurations in the Aspire:Qdrant: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:

JSON — appsettings.json
{
"Aspire": {
"Qdrant": {
"Client": {
"Endpoint": "http://localhost:6334/",
"Key": "123456!@#$%"
}
}
}
}

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

C# — Program.cs
builder.AddQdrantClient(
"qdrant",
settings => settings.Key = "12345!@#$%");

Here are the configurable options with corresponding default values:

NameDescription
EndpointThe endpoint URI of the Qdrant server to connect to.
KeyThe API key used for authentication.
DisableHealthChecksA boolean value that indicates whether the health check is disabled or not.
DisableTracingA boolean value that indicates whether the OpenTelemetry tracing is disabled or not.

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

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

  • Checks if the QdrantSettings.DisableHealthChecks is true.
  • If not disabled, adds a health check that verifies the Qdrant server is reachable.

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.

The Aspire Qdrant client integration uses the following log categories:

  • Qdrant.Client

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