好,那我直接进入「② Production-ready 架构图 + 配置清单」。

下面这份不是概念示意,而是可以直接照着落地部署、长期维护的版本。

属灵书籍 AI 知识库(RAG)

Production-ready 架构图 + 关键配置清单(生命读经专用)
一、整体系统架构(生产级)
┌───────────────────────────────┐
│ Web UI │
│ (Query / Filters / Citations)│
└───────────────▲───────────────┘

│ HTTPS

┌───────────────┴───────────────┐
│ API Gateway (FastAPI) │
│ – Query Preprocessing │
│ – Query Type Classifier │
│ – Threshold Controller │
└───────▲──────────▲────────────┘
│ │
│ │
│ │
┌───────┴──────┐ │
│ Elasticsearch │ │
│ 8.x Cluster │ │
│ │ │
│ • BM25 │ │
│ • IK + Dict │ │
│ • ELSER │ │
│ • Dense Vec │◄──┘
└───────▲──────┘

│ Top-K (BM25 / ELSER / Dense)

┌───────┴────────────────────────┐
│ Fusion & Reranking Layer │
│ │
│ 1. RRF (Dynamic Weights) │
│ 2. Cross-Encoder Reranker │
│ 3. Dual Threshold Filter │
└───────▲────────────────────────┘
│ (Context or Reject)

┌───────┴────────────────────────┐
│ Generation Guard Layer │
│ │
│ • Empty-context Blocker │
│ • Prompt Hard Constraint │
│ • Answer–Context Validator │
└───────▲────────────────────────┘

┌───────┴────────────────────────┐
│ LLM (Claude) │
│ (Summarize / Cite / Refuse) │
└────────────────────────────────┘
二、模块级 Production 设计要点

1️⃣ API Gateway(FastAPI)

职责

Query 正则预处理(经节 / 对比 / 定义)

问题类型轻分类(无 LLM)

动态 RRF 参数控制

统一拒答出口(Refusal Controller)

关键中间件

QueryNormalizer

QueryTypeRouter

ConfidenceGate

2️⃣ Elasticsearch Index 设计(核心)

Index:
life_study_chunks_v1
{
“settings”: {
“analysis”: {
“analyzer”: {
“ik_spiritual”: {
“type”: “custom”,
“tokenizer”: “ik_max_word”,
“filter”: [“lowercase”]
}
}
}
},
“mappings”: {
“properties”: {
“content_zh”: { “type”: “text”, “analyzer”: “ik_spiritual” },
“content_en”: { “type”: “text” },

“dense_vector”: {
“type”: “dense_vector”,
“dims”: 1024,
“index”: true,
“similarity”: “cosine”
},

“elser_vector”: {
“type”: “sparse_vector”
},

“book_name”: { “type”: “keyword” },
“message_num”: { “type”: “integer” },
“small_heading”: {
“type”: “text”,
“boost”: 2.0
},

“related_verses”: {
“type”: “nested”,
“properties”: {
“book”: { “type”: “keyword” },
“chapter”: { “type”: “integer” },
“verse”: { “type”: “keyword” }
}
},

“theology_tag”: {
“type”: “keyword”
}
}
}
}
📌 注意

Dense / Sparse / BM25 全部在一个 index → 减少 IO

small_heading 明确 boost

theology_tag 为后续教义一致性预留

3️⃣ 专业字典(IK Analyzer)

spiritual_dict.dic(示例)

三一神
神人
生机拯救
法理救赎
终极完成
职事
神新约经纶
神圣分赐
构成
调和
Synonym Graph(示例)

生机拯救 => 生命的救恩
职事 => ministry
三、三路检索 + 融合(Production 参数)

4️⃣ Query → 三路检索
通道

Top-K

BM25

30

Dense Vector

30

ELSER

30

5️⃣ RRF(动态权重)
if query_type == “verse”:
weights = {BM25:1.2, ELSER:1.1, DENSE:0.8}
elif query_type == “definition”:
weights = {ELSER:1.3, DENSE:1.1, BM25:0.7}
else:
weights = {DENSE:1.3, ELSER:1.0, BM25:1.0}
四、Reranking & 拦截机制(系统灵魂)

6️⃣ Reranker 参数
输入:Top-15(RRF 后)

输出:0–1 概率分数

Cross-Encoder(中英混合友好)

7️⃣ 双阈值规则(Production 推荐)
Rule A: Top-1 ≥ 0.55
Rule B: (Top-1 − Top-2) ≥ 0.08

Fail any → 拒答
📌 所有拒答都发生在 LLM 之前

五、生成层(不可妥协约束)

8️⃣ Prompt 硬约束(简化示意)
你只能基于【上下文】回答。
禁止补充任何外部神学知识。
禁止推断未出现的经文或结论。
必须标注篇目与小标题。
若信息不足,必须明确拒答。
9️⃣ Answer–Context Alignment(可选但强烈推荐)

自动校验

回答中的经节是否在 context

关键判断句是否有原文支持

失败 → 丢弃回答 → 返回拒答模板

六、部署建议(长期稳定)

10️⃣ 服务器角色划分
组件

推荐

ES + ELSER

Oracle A1(大内存)

API

同机或 Cloudflare Workers

LLM

API(不自建)

前端

Nginx 静态

📌 若 corpus < 200k chunks → 无需 Pinecone 七、你现在已经站在什么位置? ✔ 学术级 RAG ✔ 可防幻觉 ✔ 可拒答 ✔ 可维护 ✔ 可扩展到多卷、多作者 这套架构,已经不是“实验系统”,而是: 「神学研究基础设施 v1」 下一步你可以选(我可直接继续): ③ 给你一份「完整配置文件模板(YAML + JSON)」 ④ 设计一套「Precision / Refusal Correctness 评测体系」 ⑤ 扩展到「多作者神学 corpus(仍保持一致性)」 只要回一句:3 / 4 / 5