Files
ailine/backend/app/rag/__init__.py
root 048f57a89f
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Has been cancelled
集成三个子图到主Agent架构 + 修复前后端字段不匹配问题
主要变更:
1. 创建 subgraph_tools.py - 将三个子图包装为 LangChain 工具
2. 更新 graph_tools.py - 删除旧工具,添加子图工具
3. 更新系统提示词 - 介绍三个子系统 + RAG 能力
4. 简化 backend.py - 删除独立子图 API 端点
5. 修复 service.py 字段名不匹配问题 - content -> token
6. 前端界面优化 - 移动子图测试到侧边栏、删除测试审核按钮
7. 添加 pyjwt 依赖到 requirements.txt
8. 更新 docker-compose.yml - 添加前端代码挂载
2026-04-27 15:23:50 +08:00

68 lines
1.9 KiB
Python
Raw Permalink 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.

"""
RAG 检索与生成模块
提供在线检索与生成功能,包括:
- 基础向量检索(稠密向量 / 混合检索)
- 重排序Cross-Encoder
- 多路查询改写Multi-Query
- RRF 融合Reciprocal Rank Fusion
- 完整的 RAG 流水线
- Agent 工具封装
固定流水线:
用户查询 → 多路改写 → 并行检索 → RRF 融合 → 重排序 → 返回父文档
示例用法:
>>> from app.rag.rag import RAGPipeline, create_rag_tool
>>> from rag_indexer.builder import IndexBuilder, IndexBuilderConfig
>>> from langchain_openai import ChatOpenAI
>>>
>>> # 获取基础检索器(如父子块检索器)
>>> config = IndexBuilderConfig(collection_name="my_docs")
>>> builder = IndexBuilder(config)
>>> retriever = builder.retriever
>>>
>>> # 创建 LLM 和流水线
>>> llm = ChatOpenAI(model="gpt-3.5-turbo")
>>> pipeline = RAGPipeline(retriever=retriever, llm=llm)
>>>
>>> # 检索
>>> docs = await pipeline.aretrieve("什么是 RAG")
>>> context = pipeline.format_context(docs)
>>>
>>> # 创建 Agent 工具
>>> rag_tool = create_rag_tool(retriever=retriever, llm=llm)
"""
from .retriever import (
create_base_retriever,
create_hybrid_retriever,
)
from .rerank import DocumentReranker, create_document_reranker
from .query_transform import MultiQueryGenerator
from .fusion import reciprocal_rank_fusion
from .pipeline import RAGPipeline
from .tools import create_rag_tool_sync
__all__ = [
# 检索器工厂函数
"create_base_retriever",
"create_hybrid_retriever",
# 重排序器
"DocumentReranker",
"create_document_reranker",
# 查询改写生成器
"MultiQueryGenerator",
# 融合算法
"reciprocal_rank_fusion",
# 主流水线
"RAGPipeline",
# 工具创建(供 Agent 使用)
"create_rag_tool_sync",
]