This commit is contained in:
23
backend/app/agent/rag_initializer.py
Normal file
23
backend/app/agent/rag_initializer.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# app/rag_initializer.py
|
||||
from ..rag.tools import create_rag_tool_sync
|
||||
from rag_core import create_parent_retriever
|
||||
from ..logger import info, warning
|
||||
|
||||
async def init_rag_tool(local_llm_creator):
|
||||
"""初始化 RAG 工具,失败返回 None"""
|
||||
try:
|
||||
info("🔄 正在初始化 RAG 检索系统...")
|
||||
retriever = create_parent_retriever(
|
||||
collection_name="rag_documents",
|
||||
search_k=5,
|
||||
)
|
||||
rewrite_llm = local_llm_creator()
|
||||
rag_tool = create_rag_tool_sync(
|
||||
retriever, rewrite_llm,
|
||||
num_queries=3, rerank_top_n=5
|
||||
)
|
||||
info("✅ RAG 检索工具初始化成功")
|
||||
return rag_tool
|
||||
except Exception as e:
|
||||
warning(f"⚠️ RAG 检索工具初始化失败: {e}")
|
||||
return None
|
||||
Reference in New Issue
Block a user