fix: enforce per-master RAG queries in /compare-masters with tradition-specific terms

Previously LLM might run ONE combined semantic query, causing the non-dominant
master to get fallback search URLs (fojin.app/search?q=...) instead of precise
text_id links.

Now the skill:
- Explicitly requires N separate queries for N masters (emphasized with ⚠️)
- Provides a query-rewriting table: each master's query uses its tradition's
  terminology (唯识/中观/禅宗/天台/华严/净土 terms)
- Example: user asks '因缘果' → xuanzang queries '因缘果 六因 四缘 五果 种子',
  kumarajiva queries '因缘所生法 空 中道 无自性 四句'

This ensures both masters get precise text_id citations, not degraded search URLs.
This commit is contained in:
xianren
2026-04-05 09:43:31 +08:00
parent 9873d0514d
commit 9dffcf3379
+21 -4
View File
@@ -118,14 +118,31 @@ PROJECT_ROOT="$(dirname "$(dirname "$(dirname "$SKILL_FILE")")")"
2. **加载法师角色内容**`$PROJECT_ROOT/prebuilt/{slug}/teaching.md` 和 `voice.md` 2. **加载法师角色内容**`$PROJECT_ROOT/prebuilt/{slug}/teaching.md` 和 `voice.md`
3. **执行语义检索**(使用 `--brief` 减少输出冗余): 3. **⚠️ 必须:为每位法师执行独立的语义检索**(不可合并为一次查询)
为什么必须独立:不同传承有不同的术语体系。一次合并查询会偏向某一传承的术语,导致另一位法师只能得到**降级的搜索链接**(如 `fojin.app/search?q=...`)而非精准的 text_id 直链。
**为每位法师构造传承专属查询词**(将用户原问题用该法师的术语体系改写):
| 法师 | 查询词改写策略 | 示例(用户问"因缘果" |
|------|-------------|---------------------|
| xuanzang(唯识) | 加入唯识/俱舍术语 | "因缘果 六因 四缘 五果 种子" |
| kumarajiva(中观) | 加入般若/中观术语 | "因缘所生法 空 中道 无自性 四句" |
| huineng(禅宗) | 加入禅宗术语 | "自性 本心 见性 顿悟" |
| zhiyi(天台) | 加入天台术语 | "一念三千 三谛圆融 止观" |
| fazang(华严) | 加入华严术语 | "法界缘起 十玄门 事事无碍" |
| yinguang(净土) | 加入净土术语 | "念佛 信愿行 带业往生" |
| ouyi(跨宗派) | 综合天台+净土术语 | "教宗天台 行归净土 现前一念" |
| xuyun(禅宗五宗) | 加入参禅术语 | "参话头 疑情 桶底脱落" |
**执行命令**(每位法师一次,用传承专属查询词):
```bash ```bash
python3 "$PROJECT_ROOT/tools/rag_query.py" semantic "<问题>" --top_k 3 --brief python3 "$PROJECT_ROOT/tools/rag_query.py" semantic "<该法师的专属查询词>" --top_k 3 --brief
``` ```
`--brief` 模式每条结果只显示 2 行(经名+链接+80字摘要),避免 60+ 行的完整经文内容刷屏 `--brief` 模式每条结果只显示 2 行(经名+链接+80字摘要),N 位法师调用 N 次,总输出 ≈ N × 7 行
4. **过滤结果**:根据该法师 meta.json 的 `search_scope.primary_cbeta_ids` 过滤检索结果 4. **过滤结果**:根据该法师 meta.json 的 `search_scope.primary_cbeta_ids` 过滤检索结果,优先选择该法师传承相关的经典作为引用
5. **降级处理**:若 `rag_query.py` 不可达(路径解析失败或 FoJin API 不可用),改用 teaching.md 中已验证的 FoJin 链接作为出处,并在回答开头提示"本次检索基于预置内容" 5. **降级处理**:若 `rag_query.py` 不可达(路径解析失败或 FoJin API 不可用),改用 teaching.md 中已验证的 FoJin 链接作为出处,并在回答开头提示"本次检索基于预置内容"