๐ป ์์คํ ์ค์น ๋ฐ ์คํ ์๊ตฌ์ฌ์ (System Requirements)
์ต์ Qdrant v1.20.x ๋ฐ ๊ณต์ Python SDK qdrant-client v1.20.0 ๊ธฐ์ค ์๊ตฌ์ฌ์์
๋๋ค.
| ๊ตฌ๋ถ | ์ต์ ์ฌ์ (Minimum) | ๊ถ์ฅ ์ฌ์ (Recommended) |
|---|---|---|
| ์ด์์ฒด์ (OS) | Linux, macOS, Windows (Docker Desktop / WSL2) | Ubuntu 24.04 LTS / Debian 12 (x86_64 AVX2+ ๋๋ ARM64 NEON) |
| CPU | 2 vCPU | 4 ~ 16+ vCPU (SIMD ๋ฒกํฐ ์ ์ฌ๋ ์ฐ์ฐ ๋ฐ HNSW ๋น๋ ๊ฐ์) |
| ๋ฉ๋ชจ๋ฆฌ (RAM) | 2 GB (์๊ท๋ชจ ๊ฐ๋ฐ/ํ ์คํธ์ฉ) | 8 GB ~ 64 GB+ (๋ฒกํฐ ์ธ๋ฑ์ค RAM ์์ฃผ + ์์ํ ์ค์ ์ ์ ๊ฐ) |
| ๋์คํฌ (Storage) | 5 GB ์ฌ์ ๊ณต๊ฐ | NVMe SSD (on_disk payload/mmap ํ์ฉ ์ IOPS ์ค์) |
| ๋ฐํ์ / ํด๋ผ์ด์ธํธ | Docker 24+ ๋๋ Python 3.10+ (qdrant-client>=1.20) | Docker Compose v2 / Kubernetes + qdrant-client[orjson,fastembed] |
์ต์ ๋ฒ์ ์ค์น ๋ฐ ์คํ
# 1. Qdrant ์๋ฒ ์ต์ ์ปจํ
์ด๋ ์คํ (REST 6333, gRPC 6334)
docker run -d --name qdrant \
-p 6333:6333 -p 6334:6334 \
-v "$(pwd)/qdrant_storage:/qdrant/storage:z" \
qdrant/qdrant:latest
# 2. ํฌ์ค์ฒดํฌ ๋ฐ ์น ๋์๋ณด๋ ํ์ธ
curl -s http://localhost:6333/readyz
# ์น UI: http://localhost:6333/dashboard
# 3. Python ๊ฐ์ํ๊ฒฝ ๋ฐ qdrant-client ์ค์น
python -m venv .venv
source .venv/bin/activate # Windows PowerShell: .venv\Scripts\Activate.ps1
pip install -U "qdrant-client[orjson,fastembed]"
๐ง Qdrant ๋ฉํ ๋ชจ๋ธ (Collection ยท Segment ยท HNSW + Payload Filter)
Qdrant๋ ๋จ์ ๋ฒกํฐ ๊ฒ์๊ธฐ๊ฐ ์๋๋ผ **ํํฐ ๊ฐ๋ฅํ HNSW ๊ทธ๋ํ(Filterable HNSW)**์ ๋ค์ดํฐ๋ธ ์คํ์ค/BM25 ํ์ด๋ธ๋ฆฌ๋ ๊ฒ์์ Rust ๋จ์ผ ๋ฐ์ด๋๋ฆฌ๋ก ์ ๊ณตํฉ๋๋ค.
[Client: REST :6333 / gRPC :6334]
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Collection ("docs_rag") โ
โ โโ Dense Vector (e.g. 1536d Cosine, HNSW + Quantize) โ
โ โโ Sparse / Text Vector (BM25 / SPLADE ํค์๋ ๊ฐ์ค์น) โ
โ โโ Payload Index (category: keyword, price: float) โ
โโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโ
โ Shard 0 (Segments) โ Shard 1 (Segments)
โผ โผ
[Immutable Segments (mmap)] [Appendable Segments (RAM)]
- Point = ID + Vector(s) + Payload(JSON): ํ๋์ ๋ ์ฝ๋(Point)์ ์ฌ๋ฌ ๊ฐ์ ์ด๋ฆ ์๋ ๋ฒกํฐ(
dense,sparse)์ JSON ๋ฉํ๋ฐ์ดํฐ(Payload)๋ฅผ ํจ๊ป ์ ์ฅํฉ๋๋ค. - Filterable HNSW: ์กฐ๊ฑด ํํฐ(
category == "backend")์ ๋ฒกํฐ ์ ์ฌ๋ ๊ฒ์์ ํ์ฒ๋ฆฌ๊ฐ ์๋ ๊ทธ๋ํ ํ์ ๋จ๊ณ์์ ํตํฉ ์ํํด ์ ํ๋์ ์๋๋ฅผ ๋์์ ์งํต๋๋ค.
๐ ๋จ๊ณ๋ณ ์ ์ง์ ์ค์ต (Step-by-Step Walkthrough)
[์ด๋ณด์ 1๋จ๊ณ] ์ปฌ๋ ์ ์์ฑ, ํฌ์ธํธ ์ ์ํธ ๋ฐ ๊ธฐ๋ณธ ๋ฒกํฐ ๊ฒ์
from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams, PointStruct
client = QdrantClient(url="http://localhost:6333")
# 1. 4์ฐจ์ ํ
์คํธ ์ปฌ๋ ์
์์ฑ (์ค๋ฌด์์๋ ์๋ฒ ๋ฉ ๋ชจ๋ธ ์ฐจ์: 768, 1024, 1536 ๋ฑ ์ฌ์ฉ)
client.recreate_collection(
collection_name="tech_notes",
vectors_config=VectorParams(size=4, distance=Distance.COSINE),
)
# 2. ํฌ์ธํธ(ID + ๋ฒกํฐ + JSON ํ์ด๋ก๋) ์
์ํธ
client.upsert(
collection_name="tech_notes",
wait=True,
points=[
PointStruct(id=1, vector=[0.91, 0.12, 0.05, 0.30], payload={"topic": "db", "lang": "ko", "title": "PostgreSQL ์ธ๋ฑ์ฑ"}),
PointStruct(id=2, vector=[0.88, 0.15, 0.10, 0.25], payload={"topic": "db", "lang": "en", "title": "Qdrant HNSW Tuning"}),
PointStruct(id=3, vector=[0.10, 0.92, 0.85, 0.04], payload={"topic": "k8s", "lang": "ko", "title": "Kubernetes RBAC"}),
],
)
# 3. ์ ์ฌ ๋ฒกํฐ Top-2 ๊ฒ์
hits = client.query_points(
collection_name="tech_notes",
query=[0.90, 0.14, 0.08, 0.28],
limit=2,
).points
for h in hits:
print(f"id={h.id}, score={h.score:.4f}, title={h.payload['title']}")
# ์์ ์ถ๋ ฅ:
# id=2, score=0.9998, title=Qdrant HNSW Tuning
# id=1, score=0.9993, title=PostgreSQL ์ธ๋ฑ์ฑ
[2๋จ๊ณ] ํ์ด๋ก๋ ์ธ๋ฑ์ค ์์ฑ & ์กฐ๊ฑด ํํฐ ๊ฒ์ (Filter)
์ค๋ฌด RAG์์๋ ํ ๋ํธ ID, ๋ฌธ์ ๊ถํ, ๋ ์ง ๋ฒ์ ๊ฐ์ ๋ฉํ๋ฐ์ดํฐ ํํฐ๋ง์ด ํ์์ ๋๋ค.
from qdrant_client.models import Filter, FieldCondition, MatchValue, PayloadSchemaType
# 1. ์์ฃผ ํํฐ๋งํ๋ ํ๋์ Payload Index ์์ฑ (์๋ ๋ํญ ํฅ์)
client.create_payload_index(
collection_name="tech_notes",
field_name="topic",
field_schema=PayloadSchemaType.KEYWORD,
)
client.create_payload_index(
collection_name="tech_notes",
field_name="lang",
field_schema=PayloadSchemaType.KEYWORD,
)
# 2. topic="db" ์ด๋ฉด์ lang="ko" ์ธ ๋ฌธ์๋ง ํํฐ๋ง ๊ฒ์
filtered = client.query_points(
collection_name="tech_notes",
query=[0.90, 0.14, 0.08, 0.28],
query_filter=Filter(
must=[
FieldCondition(key="topic", match=MatchValue(value="db")),
FieldCondition(key="lang", match=MatchValue(value="ko")),
]
),
limit=3,
).points
print("ํํฐ ๊ฒฐ๊ณผ:", [p.payload["title"] for p in filtered])
# ์์ ์ถ๋ ฅ: ํํฐ ๊ฒฐ๊ณผ: ['PostgreSQL ์ธ๋ฑ์ฑ']
[3๋จ๊ณ] ํ์ด๋ธ๋ฆฌ๋ ๊ฒ์ (Dense + Sparse RRF Fusion) & ๋ฉ๋ชจ๋ฆฌ ์์ํ
Qdrant๋ Prefetch + FusionQuery(Fusion.RRF)๋ฅผ ํตํด ์๋ฏธ ๊ธฐ๋ฐ ๊ฒ์(Dense)๊ณผ ํค์๋ ๊ธฐ๋ฐ ๊ฒ์(Sparse/BM25)์ ์๋ฒ ๋ด๋ถ์์ ํ ๋ฒ์ ๊ฒฐํฉํฉ๋๋ค.
from qdrant_client.models import (
SparseVectorParams, SparseVector, Prefetch, FusionQuery, Fusion,
ScalarQuantization, ScalarQuantizationConfig, ScalarType
)
# 1. Multi-Vector ์ปฌ๋ ์
+ Int8 ์ค์นผ๋ผ ์์ํ(๋ฉ๋ชจ๋ฆฌ 4๋ฐฐ ์ ๊ฐ) ์์ฑ
client.recreate_collection(
collection_name="hybrid_rag",
vectors_config={
"dense": VectorParams(size=4, distance=Distance.COSINE),
},
sparse_vectors_config={
"sparse": SparseVectorParams(),
},
quantization_config=ScalarQuantization(
scalar=ScalarQuantizationConfig(type=ScalarType.INT8, always_ram=True)
),
)
client.upsert(
collection_name="hybrid_rag",
points=[
PointStruct(
id=101,
vector={
"dense": [0.85, 0.20, 0.10, 0.15],
"sparse": SparseVector(indices=[12, 45, 99], values=[0.7, 1.2, 0.5]),
},
payload={"doc": "Qdrant Hybrid Search with RRF"},
)
],
)
# 2. RRF(Reciprocal Rank Fusion) ํ์ด๋ธ๋ฆฌ๋ ์ฟผ๋ฆฌ
res = client.query_points(
collection_name="hybrid_rag",
prefetch=[
Prefetch(query=[0.84, 0.21, 0.11, 0.14], using="dense", limit=10),
Prefetch(query=SparseVector(indices=[12, 45], values=[0.8, 1.0]), using="sparse", limit=10),
],
query=FusionQuery(fusion=Fusion.RRF),
limit=5,
)
print("RRF ๊ฒฐ๊ณผ:", [p.payload["doc"] for p in res.points])
๐ ๏ธ ์ฃผ์ REST / ์ด์ API & ์ค๋ ์ท ๊ด๋ฆฌ
# ์ปฌ๋ ์
์ํ(ํฌ์ธํธ ์, ์ธ๋ฑ์ค ์ํ, ์ธ๊ทธ๋จผํธ ์) ์กฐํ
curl -s http://localhost:6333/collections/tech_notes | jq .result.status
# ์ปฌ๋ ์
์ค๋
์ท ์์ฑ (๋ฌด์ค๋จ ๋ฐฑ์
)
curl -X POST http://localhost:6333/collections/tech_notes/snapshots
# ์ค๋
์ท ๋ชฉ๋ก ์กฐํ
curl -s http://localhost:6333/collections/tech_notes/snapshots | jq .
โ ๏ธ ์ค๋ฌด ์ฃผ์์ฌํญ & ํ๋ก๋์ ์ฒดํฌ๋ฆฌ์คํธ
- gRPC ํฌํธ(
6334) ํ์ฉ: ๋์ฉ๋ ๋ฐฐ์น ์ ์ํธ(10๋ง+ํฌ์ธํธ)๋ ์ด์ ์ง์ฐ ๊ฒ์์๋ REST(6333) ๋์QdrantClient(host="localhost", grpc_port=6334, prefer_grpc=True)๋ฅผ ์ฌ์ฉํ์ธ์. - ํ์ด๋ก๋ ์ธ๋ฑ์ค ์ ์ ์์ฑ: ํํฐ ์กฐ๊ฑด์ ์ฐ์ด๋ ํ๋๋
create_payload_index๋ฅผ ๋ฐ๋์ ๋ฑ๋กํด์ผ HNSW ๊ทธ๋ํ ํ์ ์ ํ ์ค์บ์ ํผํ ์ ์์ต๋๋ค. - ์์ํ +
on_disk์กฐํฉ: ๋ฒกํฐ ์๊ฐ ์๋ฐฑ๋ง ๊ฐ๋ฅผ ๋์ด๊ฐ๋ฉดScalarQuantization(INT8)๋๋BinaryQuantization๊ณผon_disk=True๋ฅผ ์กฐํฉํด RAM ๋น์ฉ์ 4~32๋ฐฐ ์ค์ด๊ณrescore=True๋ก ์ ํ๋๋ฅผ ๋ณด์ ํ์ธ์. - API Key ๋ฐ TLS ํ์ฑํ: ํ๋ก๋์
ํ๊ฒฝ์์๋
QDRANT__SERVICE__API_KEYํ๊ฒฝ ๋ณ์๋ก ์ธ์ฆ์ ํ์ฑํํ๊ณ ๋ฆฌ๋ฒ์ค ํ๋ก์ ๋๋ ๋ด์ฅ TLS๋ฅผ ์ ์ฉํ์ธ์.
์๊ฒฌ ๋ฐ ์ง๋ฌธ
0์์ง ๋ฑ๋ก๋ ์๊ฒฌ์ด ์์ต๋๋ค. ์ฒซ ๋ฒ์งธ ๋๊ธ์ ๋จ๊ฒจ๋ณด์ธ์!
๋๊ธ ์์
๋๊ธ ์ญ์