๐ป ์์คํ ์ค์น ๋ฐ ์คํ ์๊ตฌ์ฌ์ (System Requirements)
์ต์ Milvus v3.0.5 (์ฅ๊ธฐ ์ง์ ํธ๋ v2.6.26 ๋ณํ) ๋ฐ ๊ณต์ Python SDK pymilvus v3.0.2 ๊ธฐ์ค ์๊ตฌ์ฌ์์
๋๋ค.
| ๊ตฌ๋ถ | ์ต์ ์ฌ์ (Minimum) | ๊ถ์ฅ ์ฌ์ (Recommended) |
|---|---|---|
| ์ด์์ฒด์ (OS) | Linux, macOS, Windows (WSL2 / Docker Desktop) | Ubuntu 24.04 LTS (x86_64 AVX2+ ๋๋ ARM64) |
| CPU | 2 vCPU (Milvus Lite ๋ก์ปฌ ํ ์คํธ) / 4 vCPU (Standalone) | 8 ~ 32+ vCPU (Knowhere SIMD/AVX-512 ๋ฒกํฐ ์ฐ์ฐ ๊ฐ์) |
| ๋ฉ๋ชจ๋ฆฌ (RAM) | 4 GB (Lite) / 8 GB (Docker Standalone) | 16 GB ~ 128 GB+ (HNSW ์ธ๋ฑ์ค ๋ฉ๋ชจ๋ฆฌ ์์ฃผ ๋ฐ QueryNode ์บ์) |
| ๋์คํฌ (Storage) | 10 GB ์ฌ์ ๊ณต๊ฐ | NVMe SSD (DiskANN ๋ฐ MinIO/S3 ์ธ๊ทธ๋จผํธ ์คํ ๋ฆฌ์ง์ฉ) |
| ๋ฐํ์ / ํด๋ผ์ด์ธํธ | Python 3.9+ (pymilvus>=3.0.2) | Python 3.12+ (pymilvus[milvus-lite,model]) + Docker Compose v2 |
์ต์ ๋ฒ์ ์ค์น ๋ฐ ์คํ
# 1. [์
๋ฌธ/๋ก์ปฌ ๊ฐ๋ฐ] Docker ์์ด ํ์ผ ๊ธฐ๋ฐ Milvus Lite ์ฆ์ ์ค์น
python -m venv .venv
source .venv/bin/activate # Windows PowerShell: .venv\Scripts\Activate.ps1
pip install -U "pymilvus[milvus-lite,model]"
# 2. [์ค๋ฌด/๋จ์ผ ๋
ธ๋] Milvus Standalone (etcd + MinIO + Milvus) ์ํด๋ฆญ ์คํ
curl -sfL https://raw.githubusercontent.com/milvus-io/milvus/master/scripts/standalone_embed.sh -o standalone_embed.sh
bash standalone_embed.sh start
# gRPC: localhost:19530 / Attu Web UI ๋๋ Health Check: http://localhost:9091/healthz
๐ง Milvus ๋ฉํ ๋ชจ๋ธ (Proxy ยท QueryNode ยท DataNode ยท Object Storage)
Milvus๋ ์ปดํจํ ๊ณผ ์คํ ๋ฆฌ์ง๊ฐ ์์ ํ ๋ถ๋ฆฌ(Disaggregated Architecture) ๋ ํด๋ผ์ฐ๋ ๋ค์ดํฐ๋ธ ๋ถ์ฐ ๋ฒกํฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋๋ค.
[Client: PyMilvus v3.0 / gRPC :19530]
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Access Layer (Proxy) - ๋ผ์ฐํ
, ์คํค๋ง ๊ฒ์ฆ, ๊ฒฐ๊ณผ ๋ณํฉ โ
โโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโ
โ Write (WAL / Pulsar / Woodpecker) โ Query / Search
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ
โ DataNode & IndexNode โ โ QueryNode (In-Memory)โ
โ - ์ธ๊ทธ๋จผํธ ํ๋ฌ์ โ โ - Growing + Sealed โ
โ - HNSW/IVF/DiskANN โ โ - SIMD ๋ฒกํฐ + ํํฐ โ
โโโโโโโโโโโโฌโโโโโโโโโโโโ โโโโโโโโโโโโฒโโโโโโโโโโโโ
โ โ
โผ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Object Storage (MinIO / S3 / Iceberg External Table) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Milvus Lite:
./milvus_demo.db๋จ์ผ ํ์ผ๋ก ๋์ํ๋ฏ๋ก ๊ฐ๋ฐยทCI ํ ์คํธ์ ์ต์ ์ ๋๋ค. - Standalone / Distributed: ์ฝ๋ ์์ ์์ด
MilvusClient(uri="http://localhost:19530")๋ก URL๋ง ๋ฐ๊พธ๋ฉด ์์ญ์ต ๊ฑด ํด๋ฌ์คํฐ๋ก ์ฆ์ ํ์ฅ๋ฉ๋๋ค.
๐ ๋จ๊ณ๋ณ ์ค์ ์ค์ต (Step-by-Step)
[1๋จ๊ณ] ํฌ๋ก์๋: ์ปฌ๋ ์ ์์ฑ, ์ฝ์ ๋ฐ ๊ธฐ๋ณธ ๋ฒกํฐ ๊ฒ์
MilvusClient ๊ณ ์์ค API๋ฅผ ์ฌ์ฉํ๋ฉด ์คํค๋ง ๋ณด์ผ๋ฌํ๋ ์ดํธ ์์ด ๋ฐ๋ก ๋ฒกํฐ ๊ฒ์์ ์์ํ ์ ์์ต๋๋ค.
from pymilvus import MilvusClient
# ๋ก์ปฌ ํ์ผ(Milvus Lite) ๋๋ ์๋ฒ("http://localhost:19530") ์ฐ๊ฒฐ
client = MilvusClient("./milvus_quickstart.db")
# 1. ์ปฌ๋ ์
์์ฑ (์ด๋ฏธ ์์ผ๋ฉด ์ฌ์์ฑ)
if client.has_collection("docs"):
client.drop_collection("docs")
client.create_collection(
collection_name="docs",
dimension=4, # ์ค๋ฌด์์๋ 768, 1024, 1536 ๋ฑ ์ฌ์ฉ
metric_type="COSINE", # COSINE, L2, IP ์ง์
auto_id=True,
)
# 2. ๋ฐ์ดํฐ ์ฝ์
(๋์ ์คํค๋ง ์ง์: text, category ์๋ ์ ์ฅ)
data = [
{"vector": [0.91, 0.12, 0.05, 0.02], "text": "Milvus 3.0 Lake-Native ๋ฒกํฐ DB", "category": "db"},
{"vector": [0.10, 0.88, 0.14, 0.05], "text": "Kubernetes Ingress ์ค์ ๊ฐ์ด๋", "category": "infra"},
{"vector": [0.85, 0.20, 0.11, 0.01], "text": "HNSW ์ธ๋ฑ์ค์ ์์ํ ํ๋", "category": "db"},
]
insert_res = client.insert(collection_name="docs", data=data)
print("Inserted count:", insert_res["insert_count"])
# 3. ๋ฉํ๋ฐ์ดํฐ ํํฐ๋ง + ์ ์ฌ๋ ๊ฒ์
results = client.search(
collection_name="docs",
data=[[0.90, 0.15, 0.05, 0.02]],
filter='category == "db"',
limit=2,
output_fields=["text", "category"],
)
for hit in results[0]:
print(f"score={hit['distance']:.4f} | {hit['entity']['text']}")
์คํ ์์ ์ถ๋ ฅ:
Inserted count: 3
score=0.9994 | Milvus 3.0 Lake-Native ๋ฒกํฐ DB
score=0.9949 | HNSW ์ธ๋ฑ์ค์ ์์ํ ํ๋
[2๋จ๊ณ] ํต์ฌ ๊ธฐ๋ฅ: ๋ช ์์ ์คํค๋ง, ํํฐ์ ๋ฐ ์ธ๋ฑ์ค ํ๋
์ด์ ํ๊ฒฝ์์๋ ๋ช ์์ ์คํค๋ง(Schema) ์ ์ธ๋ฑ์ค ํ๋ผ๋ฏธํฐ(HNSW / IVF_SQ8 / DiskANN) ๋ฅผ ์ง์ ์ค๊ณํด ๋ฉ๋ชจ๋ฆฌ์ ์ง์ฐ ์๊ฐ์ ์ ์ดํฉ๋๋ค.
from pymilvus import MilvusClient, DataType
client = MilvusClient("http://localhost:19530")
schema = client.create_schema(auto_id=False, enable_dynamic_field=True)
schema.add_field("id", DataType.INT64, is_primary=True)
schema.add_field("tenant_id", DataType.VARCHAR, max_length=64)
schema.add_field("embedding", DataType.FLOAT_VECTOR, dim=1536)
schema.add_field("created_at", DataType.INT64, nullable=True) # v3.0+ nullable ํ๋ ์ง์
# ์ธ๋ฑ์ค ์ค์ (๋ฒกํฐ HNSW + ์ค์นผ๋ผ INVERTED)
index_params = client.prepare_index_params()
index_params.add_index(
field_name="embedding",
index_type="HNSW",
metric_type="COSINE",
params={"M": 16, "efConstruction": 200},
)
index_params.add_index(
field_name="tenant_id",
index_type="INVERTED", # ๋น ๋ฅธ ๋ฉํฐํ
๋ํธ ํํฐ๋ง
)
client.create_collection(
collection_name="enterprise_kb",
schema=schema,
index_params=index_params,
)
# ํ
๋ํธ๋ณ ํํฐ์
๋ถ๋ฆฌ (๋ฐ์ดํฐ ๊ฒฉ๋ฆฌ ๋ฐ ๊ฒ์ ๋ฒ์ ์ถ์)
client.create_partition(collection_name="enterprise_kb", partition_name="tenant_acme")
[3๋จ๊ณ] ์ค๋ฌด ์์ฉ: Dense + Sparse BM25 ํ์ด๋ธ๋ฆฌ๋ RRF ๊ฒ์
RAG ์ ํ๋๋ฅผ ๊ทน๋ํํ๊ธฐ ์ํด ์๋ฏธ ๊ธฐ๋ฐ Dense ๋ฒกํฐ์ ํค์๋ ๊ธฐ๋ฐ Sparse(BM25) ๋ฒกํฐ๋ฅผ ํ๋์ ์ฟผ๋ฆฌ๋ก ๊ฒฐํฉํด RRF(Reciprocal Rank Fusion)๋ก ์ฌ์ ๋ ฌํฉ๋๋ค.
from pymilvus import MilvusClient, DataType, Function, FunctionType, AnnSearchRequest, RRFRanker
client = MilvusClient("http://localhost:19530")
schema = client.create_schema(auto_id=True)
schema.add_field("id", DataType.INT64, is_primary=True)
schema.add_field("content", DataType.VARCHAR, max_length=2048, enable_analyzer=True)
schema.add_field("dense_vec", DataType.FLOAT_VECTOR, dim=768)
schema.add_field("sparse_bm25", DataType.SPARSE_FLOAT_VECTOR)
# ์๋ฒ ๋ด์ฅ BM25 ํจ์: content ์ฝ์
์ ์๋์ผ๋ก sparse_bm25 ์์ฑ
bm25_func = Function(
name="text_bm25",
input_field_names=["content"],
output_field_names=["sparse_bm25"],
function_type=FunctionType.BM25,
)
schema.add_function(bm25_func)
index_params = client.prepare_index_params()
index_params.add_index("dense_vec", index_type="HNSW", metric_type="COSINE", params={"M": 16, "efConstruction": 128})
index_params.add_index("sparse_bm25", index_type="SPARSE_INVERTED_INDEX", metric_type="BM25")
client.create_collection("hybrid_rag", schema=schema, index_params=index_params)
# ํ์ด๋ธ๋ฆฌ๋ ๊ฒ์ (Dense Top-20 + BM25 Top-20 -> RRF ๋ณํฉ Top-5)
dense_req = AnnSearchRequest(
data=[[0.12] * 768],
anns_field="dense_vec",
param={"metric_type": "COSINE", "params": {"ef": 64}},
limit=20,
)
sparse_req = AnnSearchRequest(
data=["Milvus DiskANN ์ธ๋ฑ์ค ํ๋"],
anns_field="sparse_bm25",
param={"metric_type": "BM25"},
limit=20,
)
hybrid_hits = client.hybrid_search(
collection_name="hybrid_rag",
reqs=[dense_req, sparse_req],
ranker=RRFRanker(k=60),
limit=5,
output_fields=["content"],
)
๐ ์ธ๋ฑ์ค ์ ํ ์นํธ์ํธ (Index Selection Matrix)
| ์ธ๋ฑ์ค ํ์ | ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ | ๊ฒ์ ์๋ | ์ฌํ์จ(Recall) | ์ถ์ฒ ๊ท๋ชจ ๋ฐ ์ฉ๋ |
|---|---|---|---|---|
HNSW | ๋์ | ๋งค์ฐ ๋น ๋ฆ | 95~99% | 100๋ง~1์ต ๊ฑด, ์ ์ง์ฐ(<10ms) ์ค์๊ฐ RAG ์๋น์ค ํ์ค |
IVF_SQ8 / IVF_PQ | ๋ฎ์ (์์ํ) | ๋น ๋ฆ | 85~94% | RAM ๋น์ฉ ์ ๊ฐ์ด ์ต์ฐ์ ์ธ ๋๊ท๋ชจ ๋ฐฐ์น/์ค๊ฐ ์ ํ๋ ๊ฒ์ |
DISKANN | ๋งค์ฐ ๋ฎ์ (SSD ๊ธฐ๋ฐ) | ๋ณดํต~๋น ๋ฆ | 95%+ | ์์ต~์์ญ์ต ๊ฑด ์ด์ ์ด๋์ฉ๋ ๋ฒกํฐ (NVMe SSD ํ์) |
GPU_CAGRA | GPU VRAM | ์ด๊ณ ์ | 98%+ | GPU ๊ฐ์ ๊ธฐ๋ฐ ์ด๋น ์๋ง QPS ๊ณ ์ฒ๋ฆฌ๋ ๊ฒ์ |
โ ์ค๋ฌด ์ฃผ์์ฌํญ & ํ๋ก๋์ ์ฒดํฌ๋ฆฌ์คํธ
load_collection()์ํ ํ์ธ: Milvus๋ ๋์คํฌ ์ธ๊ทธ๋จผํธ๋ฅผ QueryNode RAM์ ์ฌ๋ฆฐ(load) ํ์๋ง ๊ฒ์์ด ๊ฐ๋ฅํฉ๋๋ค.MilvusClient.create_collection์ ์๋ ๋ก๋ํ์ง๋ง, ์๋ ์ธ๋ฑ์ค ์ฌ๋น๋ ํ์๋client.load_collection()์ ๋ฐ๋์ ํ์ธํ์ธ์.- ์ผ๊ด์ฑ ์์ค(Consistency Level) ์ ํ: ๊ธฐ๋ณธ๊ฐ
Bounded๋ ์ฝ๊ฐ์ ๋ณต์ ์ง์ฐ(๋ณดํต ์๋ฐฑ ms)์ ํ์ฉํด ์ต๊ณ ์ฑ๋ฅ์ ๋ ๋๋ค. ๋ฐฉ๊ธinsert/upsertํ ๋ฐ์ดํฐ๋ฅผ ์ฆ์ ์กฐํํด์ผ ํ๋ค๋ฉดconsistency_level="Strong"๋๋Session์ ์ง์ ํ์ธ์. - Partition Key ํ์ฉ: ์์ฒ ๊ฐ ์ด์์ ๋ฉํฐํ
๋ํธ ํ๊ฒฝ์์ ํํฐ์
์ ์์ฒ ๊ฐ ์ง์ ๋ง๋ค์ง ๋ง๊ณ
is_partition_key=True๋ฅผ ์ค์นผ๋ผ ํ๋์ ์ง์ ํ๋ฉด Milvus๊ฐ ๋ด๋ถ์ ์ผ๋ก 64๊ฐ ๋ฒํท์ ์๋ ํด์ ๋ถ์ฐํด ์ฑ๋ฅ์ ์ ์งํฉ๋๋ค. - ๋๋ ์ ์ฌ ์ BulkWriter ์ฌ์ฉ: ์์ฒ๋ง ๊ฑด ์ด๊ธฐ ์ ์ฌ๋
insert()๋ฃจํ ๋์LocalBulkWriter/RemoteBulkWriter๋ก Parquet ํ์ผ์ ์์ฑํดbulk_insertํ๋ ๊ฒ์ด 10๋ฐฐ ์ด์ ๋น ๋ฆ ๋๋ค.
์๊ฒฌ ๋ฐ ์ง๋ฌธ
0์์ง ๋ฑ๋ก๋ ์๊ฒฌ์ด ์์ต๋๋ค. ์ฒซ ๋ฒ์งธ ๋๊ธ์ ๋จ๊ฒจ๋ณด์ธ์!
๋๊ธ ์์
๋๊ธ ์ญ์