Qdrant Hosting integration reference
Цей контент ще не доступний вашою мовою.
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 Hosting integration, which models Qdrant server resources as the QdrantServerResource type.
Installation
Section titled “Installation”The Aspire Qdrant hosting integration models the Qdrant vector database server as the QdrantServerResource type.
To access these types and APIs for expressing them as resources in your AppHost project, install the 📦 Aspire.Hosting.Qdrant NuGet package:
aspire add qdrantAspire CLI інтерактивний; оберіть відповідний результат пошуку:
Select an integration to add:
> qdrant (Aspire.Hosting.Qdrant)> Other results listed as selectable options...#:package Aspire.Hosting.Qdrant@*<PackageReference Include="Aspire.Hosting.Qdrant" Version="*" />Add Qdrant resource
Section titled “Add Qdrant resource”In the AppHost project, call AddQdrant to add and return a Qdrant server resource builder:
var builder = DistributedApplication.CreateBuilder(args);
var qdrant = builder.AddQdrant("qdrant") .WithLifetime(ContainerLifetime.Persistent);
builder.AddProject<Projects.ExampleProject>() .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/qdrant image, it creates a new Qdrant server on your local machine. A reference to your Qdrant resource builder (the qdrant variable) is used to connect your application.
The WithReference method configures a connection in the ExampleProject named "qdrant". For more information, see Container resource lifecycle.
Add Qdrant resource with API key parameter
Section titled “Add Qdrant resource with API key parameter”The Qdrant resource includes a default, randomly generated API key. Qdrant supports configuration-based API keys. When you want to provide an API key explicitly, you can provide 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);
var myService = builder.AddProject<Projects.ExampleProject>() .WithReference(qdrant) .WaitFor(qdrant);The preceding code gets a parameter to pass to the AddQdrant API, and internally assigns the parameter to the Qdrant container configuration. 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”To add a data volume to the Qdrant resource, call the WithDataVolume method:
var builder = DistributedApplication.CreateBuilder(args);
var qdrant = builder.AddQdrant("qdrant") .WithDataVolume() .WithLifetime(ContainerLifetime.Persistent);
builder.AddProject<Projects.ExampleProject>() .WithReference(qdrant) .WaitFor(qdrant);
// After adding all resources, run the app...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 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”To add a data bind mount to the Qdrant resource, call the WithDataBindMount method:
var builder = DistributedApplication.CreateBuilder(args);
var qdrant = builder.AddQdrant("qdrant") .WithDataBindMount(source: @"C:\Qdrant\Data") .WithLifetime(ContainerLifetime.Persistent);
builder.AddProject<Projects.ExampleProject>() .WithReference(qdrant) .WaitFor(qdrant);
// After adding all resources, run the app...Using with non-.NET applications
Section titled “Using with non-.NET applications”When you use the WithReference method to pass a Qdrant resource to a non-.NET application (such as Python or JavaScript), Aspire automatically injects environment variables that describe the connection information.
For example, if you reference a Qdrant resource named qdrant:
var qdrant = builder.AddQdrant("qdrant");
var pythonApp = builder.AddUvicornApp("api", "./api", "main.app") .WithReference(qdrant);The following environment variables are available in the Python application:
ConnectionStrings__qdrant- The connection string for the Qdrant serverQDRANT_GRPCHOST- The gRPC hostname of the Qdrant serverQDRANT_GRPCPORT- The gRPC port numberQDRANT_HTTPHOST- The HTTP hostname of the Qdrant serverQDRANT_HTTPPORT- The HTTP port numberQDRANT_APIKEY- The API key for authenticationQDRANT_URI- The gRPC connection URIQDRANT_HTTPURI- The HTTP connection URI
You can access these environment variables in your application code:
from qdrant_client import QdrantClientimport os
# Get connection propertiesgrpc_host = os.getenv("QDRANT_GRPCHOST")grpc_port = os.getenv("QDRANT_GRPCPORT")api_key = os.getenv("QDRANT_APIKEY")
# Create Qdrant clientclient = QdrantClient( host=grpc_host, port=int(grpc_port), api_key=api_key, prefer_grpc=True)const { QdrantClient } = require('@qdrant/js-client-rest');
// Get connection propertiesconst httpHost = process.env.QDRANT_HTTPHOST;const httpPort = process.env.QDRANT_HTTPPORT;const apiKey = process.env.QDRANT_APIKEY;
// Create Qdrant clientconst client = new QdrantClient({ url: `http://${httpHost}:${httpPort}`, apiKey: apiKey});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.