Qdrant에서 Ollama 사용하기
Qdrant에서 Ollama 사용하기 (ollama)
Ollama는 특화된(닉) 영역의 애플리케이션을 위한 임베딩을 제공해요. 다양한 임베딩 모델을 지원해서, 텍스트 프롬프트에 기존 문서나 특정 영역의 데이터를 결합하는 RAG(Retrieval Augmented Generation) 애플리케이션을 만들 수 있어요.
설치
필요한 패키지는 pip 한 줄로 설치할 수 있어요.
pip install ollama qdrant-client
통합 예제
아래 코드는 Ollama가 포트 11434에, Qdrant가 포트 6333에 떠 있다고 가정해요.
from qdrant_client import QdrantClient, models
import ollama
COLLECTION_NAME = "NicheApplications"
# Initialize Ollama client
oclient = ollama.Client(host="localhost")
# Initialize Qdrant client
qclient = QdrantClient(host="localhost", port=6333)
# Text to embed
text = "Ollama excels in niche applications with specific embeddings"
# Generate embeddings
response = oclient.embeddings(model="qwen3-embedding", prompt=text)
embeddings = response["embedding"]
# Create a collection if it doesn't already exist
if not qclient.collection_exists(COLLECTION_NAME):
qclient.create_collection(
collection_name=COLLECTION_NAME,
vectors_config=models.VectorParams(
size=len(embeddings), distance=models.Distance.COSINE
),
)
# Upload the vectors to the collection along with the original text as payload
qclient.upsert(
collection_name=COLLECTION_NAME,
points=[models.PointStruct(id=1, vector=embeddings, payload={"text": text})],
)
흐름을 짚어 볼게요. ollama.Client로 로컬 Ollama에 접속해서 qwen3-embedding 모델로 텍스트를 벡터로 만들고요. 컬렉션이 없으면 collection_exists로 확인한 뒤 COSINE 거리로 만들어요. 이때 벡터 크기(size)는 만든 임베딩 길이로 정해요. 마지막으로 원본 텍스트를 payload로 붙여서 벡터를 upsert 해요.