콘텐츠로 이동

Get started with the Qdrant integrations

이 콘텐츠는 아직 번역되지 않았습니다.

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. The Aspire Qdrant integration enables you to connect to existing Qdrant servers or create new servers from Aspire with the qdrant/qdrant container image.

In this introduction, you’ll see how to install and use the Aspire Qdrant integrations in a simple configuration. If you already have this knowledge, see Qdrant Hosting integration for full reference details.

To begin, install the Aspire Qdrant Hosting integration in your Aspire AppHost project. This integration allows you to create and manage Qdrant vector database instances from your Aspire hosting projects:

Aspire CLI — Aspire.Hosting.Qdrant 패키지 추가
aspire add qdrant

Aspire CLI는 대화형입니다. 프롬프트 시 알맞은 검색 결과 선택:

Aspire CLI — 출력 예시
Select an integration to add:
> qdrant (Aspire.Hosting.Qdrant)
> Other results listed as selectable options...

Next, in the AppHost project, create instances of Qdrant server resources, then pass the server to the consuming client projects:

Select your programming language to get started
C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var qdrant = builder.AddQdrant("qdrant")
.WithLifetime(ContainerLifetime.Persistent);
var exampleProject = builder.AddProject<Projects.ExampleProject>("apiservice")
.WaitFor(qdrant)
.WithReference(qdrant);
C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var qdrant = builder.AddQdrant("qdrant")
.WithLifetime(ContainerLifetime.Persistent);
var exampleProject = builder.AddUvicornApp("api", "./api", "main.app")
.WithExternalHttpEndpoints()
.WaitFor(qdrant)
.WithReference(qdrant);
C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var qdrant = builder.AddQdrant("qdrant")
.WithLifetime(ContainerLifetime.Persistent);
var api = builder.AddNodeApp("api", "./api", scriptPath: "index.js")
.WithExternalHttpEndpoints()
.WaitFor(qdrant)
.WithReference(qdrant);

Now that the hosting integration is ready, the next step is to install and configure the client integration in any projects that need to use it.

In each of these consuming client projects, install the Aspire Qdrant client integration:

.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");

To interact with Qdrant vector databases in your Python consuming projects, you need to include a Qdrant client library. The official option is qdrant-client, which is Qdrant’s Python SDK. You can install this library using pip:

Terminal window
pip install qdrant-client

Ensure that you import the QdrantClient in code files that interact with the vector database. You should also import the os module to access environment variables:

Python - Import qdrant-client
from qdrant_client import QdrantClient
import os

To interact with Qdrant vector databases in your JavaScript consuming projects, you need to include a Qdrant client library. The official option is @qdrant/js-client-rest, which is Qdrant’s JavaScript/TypeScript SDK. You can install this library using npm:

Terminal window
npm install @qdrant/js-client-rest

Ensure that you import the QdrantClient in code files that interact with the vector database:

JavaScript - Import @qdrant/js-client-rest
const { QdrantClient } = require('@qdrant/js-client-rest');

In the AppHost, when you used the WithReference method to pass a Qdrant resource to a consuming client project, Aspire injects several configuration properties that you can 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.

Use the GetValue() method to obtain these environment variables in consuming projects:

C# - Obtain configuration properties
string connectionString = builder.Configuration.GetValue<string>("ConnectionStrings__qdrant");
string apiKey = builder.Configuration.GetValue<string>("QDRANT_APIKEY");

Use the os.getenv() method to obtain these environment variables in consuming projects:

Python - Obtain configuration properties
connection_string = os.getenv("ConnectionStrings__qdrant")
api_key = os.getenv("QDRANT_APIKEY")
grpc_host = os.getenv("QDRANT_GRPCHOST")
grpc_port = os.getenv("QDRANT_GRPCPORT")

Use the process.env property to obtain these environment variables in consuming projects:

JavaScript - Obtain configuration properties
const connectionString = process.env.ConnectionStrings__qdrant;
const apiKey = process.env.QDRANT_APIKEY;
const grpcHost = process.env.QDRANT_GRPCHOST;
const grpcPort = process.env.QDRANT_GRPCPORT;

Now that you’ve added the QdrantClient to the builder in the consuming project, you can use the Qdrant vector database to store and search vector data. Get the QdrantClient instance using dependency injection. For example, to retrieve your client object from an example service, define it as a constructor parameter and ensure the ExampleService class is registered with the dependency injection container:

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

Having obtained the client, you can work with the Qdrant vector database as you would in any other C# application.

Use the information you have obtained about the Qdrant resource to connect to the vector database. Here is an example of how to connect using qdrant-client:

Python - Connect to Qdrant
# Create Qdrant client
client = QdrantClient(
host=grpc_host,
port=int(grpc_port),
api_key=api_key,
prefer_grpc=True
)
# Verify connection
print(client.get_collections())

Having obtained the client, you can work with the Qdrant vector database as you would in any other Python application.

Use the information you have obtained about the Qdrant resource to connect to the vector database. Here is an example of how to connect using @qdrant/js-client-rest:

JavaScript - Connect to Qdrant
// Create Qdrant client
const client = new QdrantClient({
url: `http://${httpHost}:${httpPort}`,
apiKey: apiKey
});
// Verify connection
const collections = await client.getCollections();
console.log('Collections:', collections);

Having obtained the client, you can work with the Qdrant vector database as you would in any other JavaScript application.

Now that you have an Aspire app with Qdrant integrations up and running, you can use the following reference documents to learn how to configure and interact with the Qdrant resources: