본문 바로가기
IT & 개발

벡터 데이터베이스 완전 정복 - RAG 구현을 위한 Pinecone vs Qdrant vs Milvus 실전 비교

by 냉국이 2026. 3. 16.
728x90

RAG(Retrieval-Augmented Generation) 시스템을 처음 구축하던 날, 나는 PostgreSQL에 텍스트를 그낥 저장하고 LIKE 검색으로 관련 문서를 찾으려 했다. 결과는 처참했다.

벡터 데이터베이스가 해결하는 문제

전통적인 DB는 정확한 값을 찾는다. 하지만 AI 시대의 검색은 "의미적으로 유사한 것 찾기"가 필요하다. 벡터 DB는 텍스트를 고차원 벡터로 변환하고, 벡터 간 거리를 측정해서 유사한 것들을 찾는다.


from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity

model = SentenceTransformer('paraphrase-multilingual-MiniLM-L12-v2')

sentences = [
    "강아지가 공원에서 뛰고 있다",
    "개가 잔디밖을 달린다",       # 의미적으로 위와 유사
    "주식 시장이 하락했다",        # 전혀 다른 의미
]
embeddings = model.encode(sentences)
similarities = cosine_similarity([embeddings[0]], embeddings[1:])
print(similarities)  # [[0.87, 0.12]]

주요 벡터 DB 비교

항목PineconeQdrantMilvus
타입클라우드 SaaS오픈소스오픈소스
설치매우 쉬움중간 (Docker)복잡 (K8s 권장)
비용유료 (무료 티어)무료무료
추천 사용처빠른 프로토타입프로덕션대규모 엔터프라이즈

from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams, PointStruct

client = QdrantClient("localhost", port=6333)
client.create_collection(collection_name="docs",
    vectors_config=VectorParams(size=384, distance=Distance.COSINE))

docs = [
    {"id": 1, "text": "Python 비동기 프로그래밍 가이드", "category": "tech"},
    {"id": 2, "text": "asyncio와 aiohttp 실전 활용", "category": "tech"},
]
points = [PointStruct(id=d["id"], vector=model.encode(d["text"]).tolist(),
    payload={"text": d["text"], "category": d["category"]}) for d in docs]
client.upsert(collection_name="docs", points=points)

results = client.search(collection_name="docs",
    query_vector=model.encode("Python async 사용법").tolist(),
    query_filter={"must": [{"key": "category", "match": {"value": "tech"}}]},
    limit=2)
for r in results:
    print(f"Score: {r.score:.3f} | {r.payload['text']}")

데이터를 수치로 이해하는 것이 AI 시대 DB 엔지니어의 출발점이다

전통적인 "행과 열" 사고에서 "방향과 거리"의 사고로 전환하는 것, 그게 AI 시대 데이터 엔지니어가 갖춰야 할 새로운 직관이다.


함께 읽으면 좋은 글

300x250

댓글