From c498d22e737c8e25df6cd90b1894ccaf8f4fb8c7 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: Tue, 2 Jun 2026 07:07:09 +0000 Subject: [PATCH] Add rag_tools.py --- rag_tools.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 rag_tools.py diff --git a/rag_tools.py b/rag_tools.py new file mode 100644 index 0000000..7ec0017 --- /dev/null +++ b/rag_tools.py @@ -0,0 +1,48 @@ +""" +Tools for the RAG agent. +""" + +from typing import List + +from langchain.tools import tool +from qdrant_store import search, add_document + +@tool("search_knowledge_base") +async def search_knowledge_base(query: str, max_results: int = 5) -> List[str]: + """Perform semantic search in the knowledge base. + + Parameters + ---------- + query: str + Search query. + max_results: int + Number of results to return. + + Returns + ------- + List[str] + List of retrieved document snippets. + """ + docs = search(query, max_results) + return [doc.page_content for doc in docs] + +@tool("add_to_knowledge_base") +async def add_to_knowledge_base(content: str, title: str) -> str: + """Add a new document to the knowledge base. + + Parameters + ---------- + content: str + Full text of the document. + title: str + Title or identifier for the document. + + Returns + ------- + str + Confirmation message. + """ + add_document(content, title) + return f"Document '{title}' added successfully." + +__all__ = ["search_knowledge_base", "add_to_knowledge_base"]