Set up Qdrant in the AppHost
This article is the reference for the Aspire Qdrant Hosting integration. It enumerates the AppHost APIs — with examples for both AppHost.cs and apphost.mts — that you use to model a Qdrant resource in your AppHost project.
If you’re new to the Qdrant integration, start with the Get started with Qdrant integrations guide. For how consuming apps read the connection information this page exposes, see Connect to Qdrant.
Installation
Section titled “Installation”To start building an Aspire app that uses Qdrant, install the 📦 Aspire.Hosting.Qdrant NuGet package:
aspire add qdrantLearn more about aspire add in the command reference.
Or, choose a manual installation approach:
#:package Aspire.Hosting.Qdrant@*<PackageReference Include="Aspire.Hosting.Qdrant" Version="*" />aspire add qdrantLearn more about aspire add in the command reference.
This updates your aspire.config.json with the Qdrant hosting integration package:
{ "packages": { "Aspire.Hosting.Qdrant": "13.3.0" }}Add Qdrant resource
Section titled “Add Qdrant resource”Once you’ve installed the hosting integration in your AppHost project, you can add a Qdrant resource as shown in the following examples:
var builder = DistributedApplication.CreateBuilder(args);
var qdrant = builder.AddQdrant("qdrant") .WithLifetime(ContainerLifetime.Persistent);
var exampleProject = builder.AddProject<Projects.ExampleProject>("apiservice") .WithReference(qdrant) .WaitFor(qdrant);
// After adding all resources, run the app...import { createBuilder, ContainerLifetime } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const qdrant = await builder.addQdrant("qdrant");await qdrant.withLifetime(ContainerLifetime.Persistent);
await builder.addNodeApp("api", "./api", "index.js") .withReference(qdrant) .waitFor(qdrant);
// After adding all resources, run the app...-
When Aspire adds a container image to the AppHost, as shown in the preceding example with the
qdrant/qdrantimage, it creates a new Qdrant instance on your local machine. -
The Qdrant resource is configured with a randomly generated API key by default. To set an explicit API key, see Add Qdrant resource with API key parameter.
-
The AppHost reference call configures a connection in the consuming project named after the referenced Qdrant resource, such as
qdrantin the preceding example.
Add Qdrant resource with API key parameter
Section titled “Add Qdrant resource with API key parameter”The Qdrant resource includes a randomly generated API key by default. To provide an explicit API key, pass it as a parameter:
var builder = DistributedApplication.CreateBuilder(args);
var apiKey = builder.AddParameter("apiKey", secret: true);
var qdrant = builder.AddQdrant("qdrant", apiKey) .WithLifetime(ContainerLifetime.Persistent);
builder.AddProject<Projects.ExampleProject>("apiservice") .WithReference(qdrant) .WaitFor(qdrant);
// After adding all resources, run the app...import { createBuilder, ContainerLifetime } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const apiKey = await builder.addParameter("apiKey", { secret: true });
const qdrant = await builder.addQdrant("qdrant", { apiKey });await qdrant.withLifetime(ContainerLifetime.Persistent);
await builder.addNodeApp("api", "./api", "index.js") .withReference(qdrant) .waitFor(qdrant);
// After adding all resources, run the app...The apiKey parameter is usually specified as a user secret:
{ "Parameters": { "apiKey": "your-secure-api-key" }}For more information, see External parameters.
Add Qdrant resource with data volume
Section titled “Add Qdrant resource with data volume”Add a data volume to the Qdrant resource as shown in the following examples:
var builder = DistributedApplication.CreateBuilder(args);
var qdrant = builder.AddQdrant("qdrant") .WithDataVolume() .WithLifetime(ContainerLifetime.Persistent);
builder.AddProject<Projects.ExampleProject>("apiservice") .WithReference(qdrant) .WaitFor(qdrant);
// After adding all resources, run the app...import { createBuilder, ContainerLifetime } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const qdrant = await builder.addQdrant("qdrant");await qdrant.withDataVolume();await qdrant.withLifetime(ContainerLifetime.Persistent);
await builder.addNodeApp("api", "./api", "index.js") .withReference(qdrant) .waitFor(qdrant);
// After adding all resources, run the app...The data volume is used to persist Qdrant data outside the lifecycle of its container. The data volume is mounted at the /qdrant/storage path in the Qdrant container, and when a name parameter isn’t provided, the name is generated at random. For more information on data volumes and details on why they’re preferred over bind mounts, see Docker docs: Volumes.
Add Qdrant resource with data bind mount
Section titled “Add Qdrant resource with data bind mount”Add a data bind mount to the Qdrant resource as shown in the following examples:
var builder = DistributedApplication.CreateBuilder(args);
var qdrant = builder.AddQdrant("qdrant") .WithDataBindMount(source: @"C:\Qdrant\Data") .WithLifetime(ContainerLifetime.Persistent);
builder.AddProject<Projects.ExampleProject>("apiservice") .WithReference(qdrant) .WaitFor(qdrant);
// After adding all resources, run the app...import { createBuilder, ContainerLifetime } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const qdrant = await builder.addQdrant("qdrant");await qdrant.withDataBindMount("C:\\Qdrant\\Data");await qdrant.withLifetime(ContainerLifetime.Persistent);
await builder.addNodeApp("api", "./api", "index.js") .withReference(qdrant) .waitFor(qdrant);
// After adding all resources, run the app...Data bind mounts rely on the host machine’s filesystem to persist Qdrant data across container restarts. The data bind mount is mounted at the C:\Qdrant\Data on Windows (or /Qdrant/Data on Unix) path on the host machine in the Qdrant container. For more information on data bind mounts, see Docker docs: Bind mounts.
Connection properties
Section titled “Connection properties”For the full reference of Qdrant connection properties — and how consuming apps in C#, TypeScript, Python, and Go read them — see Connect to Qdrant.
Hosting integration health checks
Section titled “Hosting integration health checks”The Qdrant hosting integration automatically adds a health check for the Qdrant resource. The health check verifies that the Qdrant server is running and that a connection can be established to it.