fix(rag): 检索三路不再静默吞错 —— 逐路诊断 + 一路挂不拖垮全部
排查"向量路为什么是空的"花了半小时,因为空就是空,没有任何线索。这次把
整条检索链上的静默降级一次清掉。
真 bug(不只是可观测性):
- kb_search 与 Search() 都拿 rag.Ready() 当总闸,而 Ready() 只代表"向量路
可用"(embedding + Milvus)。全文(bleve)与图谱(Neo4j)根本不依赖它们,却
被一并毙掉 → "模型配置没下发"表现为"整个知识库什么都搜不到",还不报错。
改为逐路判定,任一路可用就仍有召回。
不再吞错:
- milvus.search 原先把 error 转成 nil,nil —— 检索失败与无召回彻底无法区分;
- bleve.search / graph.search 出错直接回 nil,连日志都没有;
- searchPaths 丢掉 embedding 的 error。
三处改为如实返回,错误统一打日志。
逐路诊断(RouteDiag):每路上报 ok/empty/disabled/error + 耗时 + 原因,经
kb_search 的 diag 参数(仅试验台传,生产调用返回值不变)→ gateway → 检索
试验台。界面上现在能直接看出"这一路没配置/报错了/确实没匹配",不必翻日志。
内存兜底索引也会在 note 里点明"重启即清零"。
测试:3 组,覆盖"无 embedding 时全文仍可召回"、三种空的区分、内存索引提示。
把总闸加回去验证过第一条确实会红——测试能抓到这个回归,不是摆设。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -126,9 +126,10 @@ func (b *bleveStore) deleteDoc(kb, doc string) error {
|
||||
}
|
||||
|
||||
// search 全文检索(可按 kb 过滤),返回 BM25 排序的命中。
|
||||
func (b *bleveStore) search(kb, q string, topK int) []Hit {
|
||||
// 错误如实返回:以前吞掉错误只回 nil,全文路挂了看起来就只是"没召回"。
|
||||
func (b *bleveStore) search(kb, q string, topK int) ([]Hit, error) {
|
||||
if !b.ready() || q == "" {
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
mq := bleve.NewMatchQuery(q)
|
||||
mq.SetField("text")
|
||||
@@ -143,7 +144,7 @@ func (b *bleveStore) search(kb, q string, topK int) []Hit {
|
||||
req.Fields = []string{"text"}
|
||||
res, err := b.idx.Search(req)
|
||||
if err != nil {
|
||||
return nil
|
||||
return nil, err
|
||||
}
|
||||
var hits []Hit
|
||||
for _, h := range res.Hits {
|
||||
@@ -152,7 +153,7 @@ func (b *bleveStore) search(kb, q string, topK int) []Hit {
|
||||
hits = append(hits, Hit{Text: text, Score: float32(h.Score)})
|
||||
}
|
||||
}
|
||||
return hits
|
||||
return hits, nil
|
||||
}
|
||||
|
||||
func fnvHash(s string) uint64 {
|
||||
|
||||
Reference in New Issue
Block a user