金融领域 RAG (检索增强生成) 系统,基于混合检索 + 查询增强 + 重排序 + LLM 生成。
CHANGE YOU LLM API
# 安装依赖
uv sync
# 配置文件
cp .env.example .env
# 启动qdrant和Infinity(本地embedding+rerank模型)
cd deploy
docker-compose up -dPut you markdown file to ./data/md/
# 数据提取
python -m core.ingest
# 运行 RAG 查询
python main.py
# 运行评估
python -m eval.gen_testset
python -m eval.run_eval用户查询
│
▼
┌─────────────────────────────────────────┐
│ 查询增强 (MQE / HyDE) │
│ - MQE: 生成多角度查询变体 │
│ - HyDE: 生成假设文档 / 重写查询 │
└─────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ 混合检索 (Hybrid Search) │
│ ┌───────────┐ ┌───────────┐ ┌────────┐│
│ │ 向量检索 │ │ BM25 │ │ 网络 ││
│ │ (Qdrant) │ │ │ │ 搜索 ││
│ └───────────┘ └───────────┘ └────────┘│
└─────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ RRF 融合 (k=60) │
│ 倒数排名融合合并多路检索结果 │
└─────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ 重排序 (Rerank) │
│ - Transformer: BCE Reranker │
│ - LLM: MiniMax 打分 (0-10) │
└─────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ LLM 生成 (MiniMax-M2.5) │
│ 基于检索上下文生成最终答案 │
└─────────────────────────────────────────┘
│
▼
答案
| 模式 | 描述 |
|---|---|
base |
向量 + BM25 + (可选) 网络搜索 |
mqe |
多查询增强 - LLM 生成多个查询变体 |
hyde |
假设文档嵌入 - 生成假设答案文档 |
- 加载
data/md/目录下的 Markdown 文件 - 文档存入 SQLite
- 文本分块 (256 tokens, 32 重叠)
- 生成 Embedding 并存入 Qdrant
| 目录 | 说明 |
|---|---|
data/md/ |
源 Markdown 文档 (金融研报等) |
data/sqlite/ |
SQLite 数据库 |
data/qdrant/ |
Qdrant 持久化存储 |
data/infinity/ |
Infinity 本地模型缓存 |
logs/ |
日志文件 |
2026-03-12 11:56:27,097 - main - INFO - ================================================================================
模式 faithfulness answer_relevancy context_precision context_recall
1. base (without web) 0.8125 0.5353 1.0000 1.0000
2. base (with web) 0.9167 0.4882 0.8750 0.8750
3. base + mqe 0.8125 0.4571 0.7917 0.8750
4. base + hyde (完整) 0.9167 0.4976 0.7917 0.8750
5. base + hyde (仅 hypo_doc) 0.6875 0.5584 0.7917 0.8750
6. base + hyde (仅 hyde_rewrite) 0.8125 0.4455 0.7500 0.7500
7. base + mqe + hyde (完整) 0.8125 0.4881 0.8542 0.8750