Skip to content

Qdrant integration

Qdrant logo

Qdrant is an open-source vector similarity search engine that efficiently stores, indexes, and searches large-scale vector data. It’s commonly used in machine learning, artificial intelligence, and data science applications.

Vector data encodes information as mathematical vectors, which are arrays of numbers or coordinates. Machine learning and AI systems often use vectors to represent unstructured objects like images, text, audio, or video.

The Qdrant hosting integration models the server as the QdrantServerResource type. To access this type and APIs, add the 📦 Aspire.Hosting.Qdrant NuGet package in your AppHost project:

Aspire CLI — Add Aspire.Hosting.Qdrant package
aspire add qdrant

The Aspire CLI is interactive, be sure to select the appropriate search result when prompted:

Aspire CLI — Example output prompt
Select an integration to add:
> qdrant (Aspire.Hosting.Qdrant)
> Other results listed as selectable options...

In your AppHost project, call AddQdrant to add and return a Qdrant resource builder:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var qdrant = builder.AddQdrant("qdrant")
.WithLifetime(ContainerLifetime.Persistent);
var myService = builder.AddProject<Projects.ExampleProject>()
.WithReference(qdrant)
.WaitFor(qdrant);

The WithReference method configures a connection in the ExampleProject named qdrant.

To connect to Qdrant a client must pass the right API key. When Aspire adds a Qdrant resource, it sets the API key to a random string. To use a specific API key, pass it as an apiKey parameter:

var apiKey = builder.AddParameter("apiKey", secret: true);
var qdrant = builder.AddQdrant("qdrant", apiKey);
var myService = builder.AddProject<Projects.ExampleProject>()
.WithReference(qdrant);

For more information, see External parameters.

To add a data volume to the Qdrant resource, call the WithDataVolume extension method:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var qdrant = builder.AddQdrant("qdrant")
.WithLifetime(ContainerLifetime.Persistent)
.WithDataVolume();
var myService = builder.AddProject<Projects.ExampleProject>()
.WithReference(qdrant)
.WaitFor(qdrant);

The data volume is used to persist the Qdrant data outside the lifecycle of its container. The data volume is mounted at the /qdrant/storage path.

To add a data bind mount to the Qdrant resource, call the WithDataBindMount method:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var qdrant = builder.AddQdrant("qdrant")
.WithLifetime(ContainerLifetime.Persistent)
.WithDataBindMount(source: @"C:\Qdrant\Data");
var myService = builder.AddProject<Projects.ExampleProject>()
.WithReference(qdrant)
.WaitFor(qdrant);

The Qdrant hosting integration automatically adds a health check for the Qdrant resource. The health check verifies that Qdrant is running and that a connection can be established to it.

To get started with the Aspire Qdrant client integration, install the 📦 Aspire.Qdrant.Client NuGet package:

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

The Qdrant client integration registers a QdrantClient instance that you can use to interact with Qdrant vector data.

In the Program.cs file, call the AddQdrantClient extension method to register a QdrantClient:

builder.AddQdrantClient("qdrant");

You can then retrieve the QdrantClient instance using dependency injection:

public class ExampleService(QdrantClient client)
{
// Use client...
}

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

builder.AddKeyedQdrantClient(name: "mainQdrant");
builder.AddKeyedQdrantClient(name: "loggingQdrant");

Then retrieve the instances:

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

When using a connection string from the ConnectionStrings configuration section:

builder.AddQdrantClient("qdrant");

Then Aspire retrieves the connection string:

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

By default the QdrantClient uses the gRPC API endpoint.

The Qdrant client integration supports Microsoft.Extensions.Configuration. Example appsettings.json:

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

You can pass the delegate to set up options inline:

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

By default, Aspire integrations enable health checks for all services.

The Qdrant integration uses the Qdrant.Client log category.

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

FAQCollaborateCommunityDiscussWatch