add rag_tools
This commit is contained in:
@@ -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}'."
|
||||
Reference in New Issue
Block a user