From c857c9ebda06292793b3d844152de61e24cd65b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A0=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Fri, 5 Jun 2026 13:03:35 +0000 Subject: [PATCH] Delete obsolete vector_store.py --- vector_store.py | 72 ------------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 vector_store.py diff --git a/vector_store.py b/vector_store.py deleted file mode 100644 index da69a63..0000000 --- a/vector_store.py +++ /dev/null @@ -1,72 +0,0 @@ -"""Vector store implementation using Qdrant and Ollama embeddings. - -This module provides a simple wrapper around QdrantVectorStore that handles -- Initialization of the Qdrant client and collection. -- Chunking of documents using RecursiveCharacterTextSplitter. -- Adding documents with embeddings from Ollama. -- Semantic search. -""" - -from pathlib import Path -from typing import List, Dict, Any - -from langchain_ollama import OllamaEmbeddings -from langchain_qdrant import QdrantVectorStore -from langchain_text_splitters import RecursiveCharacterTextSplitter -from langchain.schema import Document - -# Global configuration -QDRANT_HOST = "localhost" -QDRANT_PORT = 6333 -COLLECTION_NAME = "knowledge_base" -EMBEDDING_MODEL = "nomic-embed-text" - -# Initialize embeddings and splitter -embeddings = OllamaEmbeddings(model=EMBEDDING_MODEL) -text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50) - -# Create or connect to Qdrant collection -vector_store = QdrantVectorStore( - client_kwargs={"host": QDRANT_HOST, "port": QDRANT_PORT}, - collection_name=COLLECTION_NAME, - embeddings=embeddings, -) - -# Ensure collection exists -if not vector_store.client.has_collection(COLLECTION_NAME): - vector_store.client.create_collection(COLLECTION_NAME) - -def add_documents(docs: List[Dict[str, str]]) -> None: - """Add a list of documents to the vector store. - - Each document dict must contain ``title`` and ``content`` keys. - The content is split into chunks before being stored. - """ - documents: List[Document] = [] - for doc in docs: - title = doc.get("title", "") - content = doc.get("content", "") - # Split content into chunks - chunks = text_splitter.split_text(content) - for i, chunk in enumerate(chunks): - meta = {"title": title, "chunk_index": i} - documents.append(Document(page_content=chunk, metadata=meta)) - vector_store.add_documents(documents) - -def search(query: str, k: int = 5) -> List[Document]: - """Semantic search in the vector store. - - Returns a list of Documents ordered by relevance. - """ - return vector_store.similarity_search(query, k=k) - -# Convenience: add a single document - -def add_document(title: str, content: str) -> None: - add_documents([{"title": title, "content": content}]) - -# Convenience: search and return plain strings - -def search_text(query: str, k: int = 5) -> List[str]: - docs = search(query, k) - return [f"{doc.metadata.get('title', 'Untitled')} (chunk {doc.metadata.get('chunk_index', 0)}): {doc.page_content[:200]}..." for doc in docs] \ No newline at end of file