From bc5aa7a33b0c7f0e25e22d7c6ccea69c4e1a9836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=B0=D1=82=20=D0=A4=D0=B0=D0=B7=D1=8B?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2?= Date: Tue, 12 May 2026 20:00:13 +0000 Subject: [PATCH] add qdrant_client --- qdrant_client.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 qdrant_client.py diff --git a/qdrant_client.py b/qdrant_client.py new file mode 100644 index 0000000..b48730c --- /dev/null +++ b/qdrant_client.py @@ -0,0 +1,36 @@ +from qdrant_client import QdrantClient +from qdrant_client.http import models +from langchain_ollama import OllamaEmbeddings + +class QdrantStore: + def __init__(self, url="http://localhost:6333", collection_name="rag_collection"): + self.client = QdrantClient(url=url) + self.collection_name = collection_name + self._ensure_collection() + + def _ensure_collection(self): + if self.collection_name not in self.client.get_collections().collections: + self.client.recreate_collection( + collection_name=self.collection_name, + vectors_config=models.VectorParams(size=384, distance=models.Distance.COSINE), + ) + + def add_documents(self, documents, titles): + embeddings = OllamaEmbeddings(model="nomic-embed-text") + vectors = embeddings.embed_documents(documents) + payload = [{"title": t} for t in titles] + self.client.upsert( + collection_name=self.collection_name, + points=models.Batch(points=[models.PointStruct(id=i, vector=v, payload=p) for i, (v, p) in enumerate(zip(vectors, payload))]) + ) + + def search(self, query, limit=5): + embeddings = OllamaEmbeddings(model="nomic-embed-text") + query_vector = embeddings.embed_query(query) + results = self.client.search( + collection_name=self.collection_name, + query_vector=query_vector, + limit=limit, + with_payload=True, + ) + return [r.payload for r in results]