From 9d36fb2bebf2a580083d15d332107ebd80094525 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=9A=D1=83=D1=82?= =?UTF-8?q?=D0=BB=D0=B0=D1=85=D0=BC=D0=B5=D1=82=D0=BE=D0=B2?= Date: Thu, 28 May 2026 07:30:07 +0000 Subject: [PATCH] add vector_store.py --- vector_store.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 vector_store.py diff --git a/vector_store.py b/vector_store.py new file mode 100644 index 0000000..a3fcd5d --- /dev/null +++ b/vector_store.py @@ -0,0 +1,42 @@ +""" +Vector store initialization using Qdrant in-memory. + +The vector store is used by the search tool to perform semantic similarity search. +""" +import os +from pathlib import Path +from langchain_qdrant import QdrantVectorStore +from qdrant_client import QdrantClient +from qdrant_client.models import Distance, VectorParams +from langchain_openai import OpenAIEmbeddings + +# Embedding model compatible with OpenRouter API (used by BroJS LLM) +embeddings = OpenAIEmbeddings( + model="text-embedding-3-small", + base_url="https://openrouter.ai/api/v1", + api_key=os.getenv("OPENAI_API_KEY"), +) + +# In-memory Qdrant client – no external server required +client = QdrantClient(":memory:") +client.create_collection( + "knowledge", + vectors_config=VectorParams(size=1536, distance=Distance.COSINE), +) +vector_store = QdrantVectorStore(client=client, collection_name="knowledge", embedding=embeddings) + +# Helper to add documents – used in examples +from langchain_core.documents import Document + +def add_documents(docs: list[Document]): + """Add a list of :class:`~langchain_core.documents.Document` objects to the store.""" + vector_store.add_documents(docs) + +# Example documents – can be extended by users +if __name__ == "__main__": + docs = [ + Document(page_content="LangChain is a framework for building applications powered by language models.", metadata={"title": "LangChain Overview"}), + Document(page_content="Qdrant is an open-source vector database that stores embeddings and performs similarity search efficiently.", metadata={"title": "Qdrant Documentation"}), + ] + add_documents(docs) + print("Added example documents to Qdrant in-memory store")