From c9f762b17eae37e73c2ed46e63c769339167a80c 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: Fri, 15 May 2026 08:39:35 +0000 Subject: [PATCH] add rag_tools --- rag_tools.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 rag_tools.py diff --git a/rag_tools.py b/rag_tools.py new file mode 100644 index 0000000..dd1e622 --- /dev/null +++ b/rag_tools.py @@ -0,0 +1,18 @@ +from langchain.tools import tool +from vector_store import QdrantStore +from chunker import get_chunks + +store = QdrantStore() + +@tool +def search_knowledge_base(query: str, max_results: int = 5) -> str: + """Semantic search in knowledge base.""" + results = store.search(query, limit=max_results) + return "\n".join([f"{i+1}. {r.metadata.get('title', 'no title')}" for i,r in enumerate(results)]) + +@tool +def add_to_knowledge_base(content: str, title: str) -> str: + """Add document to knowledge base.""" + chunks = get_chunks(content, title) + store.add_documents(chunks) + return f"Added {len(chunks)} chunks for title '{title}'."