Spaces:
Sleeping
Sleeping
| """ | |
| RAG search tool — tìm kiếm hybrid (dense + BM25) trên knowledge base PDF của conversation. | |
| """ | |
| import logging | |
| from .base import register_tool | |
| logger = logging.getLogger(__name__) | |
| def tool_rag_search(query: str, conversation_id: str) -> str: | |
| try: | |
| from src.pdf_rag import hybrid_search | |
| chunks = hybrid_search(query, conversation_id, top_k=5) | |
| except RuntimeError as e: | |
| return f"(Lỗi kết nối knowledge base: {e})" | |
| except Exception: | |
| logger.exception("rag_search thất bại cho conversation '%s'", conversation_id) | |
| return "(Lỗi tìm kiếm tài liệu. Vui lòng thử lại.)" | |
| if not chunks: | |
| return "(Không tìm thấy nội dung liên quan trong knowledge base của conversation này.)" | |
| return "\n\n---\n\n".join(chunks) | |