Files
task-6a02e23da6fe2e4ac16acf65/rag_tools.py
T
2026-05-14 16:53:23 +00:00

19 lines
663 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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']['title']} {r['metadata']['content'][:200]}..." 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}'."