FastEmbed + Qdrant — 벡터 검색 구성

FastEmbed + Qdrant — 벡터 검색 구성

FastEmbed를 Qdrant 클라이언트와 함께 쓰면 벡터 검색을 이주 쉽게 구성할 수 있어요. Qdrant 클라이언트의 인메모리 모드를 쓰면 로컬에서 바로 의미 검색을 시험해 볼 수 있어요.

설치

pip install "qdrant-client[fastembed]>=1.14.2"

클라이언트 초기화

from qdrant_client import QdrantClient, models

client = QdrantClient(":memory:")  # Qdrant가 RAM에서 동작

데이터 추가

docs = [
    "Qdrant has a LangChain integration for chatbots.",
    "Qdrant has a LlamaIndex integration for agents.",
]
metadata = [{"source": "langchain-docs"}, {"source": "llamaindex-docs"}]
ids = [42, 2]

컬렉션 생성

Qdrant는 벡터와 메타데이터를 컬렉션에 저장해요. BAAI/bge-small-en 모델로 임베딩을 계산한다고 가정해요.

model_name = "BAAI/bge-small-en"
client.create_collection(
    collection_name="test_collection",
    vectors_config=models.VectorParams(
        size=client.get_embedding_size(model_name),
        distance=models.Distance.COSINE,
    ),
)

문서 업서트

Qdrant 클라이언트는 FastEmbed 통합 덕분에 메서드 안에서 암묵적으로 임베딩 추론을 수행해요. 데이터를 models.Document(또는 이미지면 models.Image)로 감싸면 돼요.

이렇게 하면 텍스트 임베딩 생성과 벡터 인덱싱, 의미 유사도 검색이 하나의 파이프라인으로 이어져요.

더 알아보기 (Learn more)

출처: Qdrant FastEmbed 문서