diff --git a/go/internal/storage/recall.go b/go/internal/storage/recall.go index 09cede9..4408c4f 100644 --- a/go/internal/storage/recall.go +++ b/go/internal/storage/recall.go @@ -263,6 +263,25 @@ func (p *RecallPipeline) recallUncached(query, namespace string, topK int, diver } } + // Step 3.7: 来源加权偏置(2026-10-09 P0 修正) + // + // 修前的错位:λ 只加在 Step 4 之后的**展示分**上,而候选的取舍早已由 rerank+MMR 定死 + // ⇒ λ 无论取多大都只改返回的数字、不改结果集合。实测(λ=0.1 vs 0,同一批 14 条 query, + // 全部 cache-miss):逐条分数位移与理论吻合(legacy -0.0277 / conf1.0 +0.0294), + // 但 top-10 集合与 legacy 占比 33.57% 两轮完全相同 —— 典型的"接上了但接在阀门下游"。 + // + // 现在把偏置移到 MMR 之前:选择与展示共用同一套分数(rel = r.Score,见 MMRSelect)。 + // λ=0 时本循环不执行 ⇒ 与旧实现逐字节等价,回滚只需把环境变量置 0。 + if confidenceLambda > 0 { + for i := range reranked { + idx := reranked[i].Index + if idx >= 0 && idx < len(candidates) { + conf := coalesceConfidence(candidates[idx].Confidence) + reranked[i].Score += confidenceLambda * (conf - confidenceMean) + } + } + } + // Step 4: MMR diversity finalIndices := MMRSelect(reranked, candidates, topK*2, diversity) @@ -291,10 +310,9 @@ func (p *RecallPipeline) recallUncached(query, namespace string, topK int, diver // 见 server.go 唯一 InsertMemory 调用点),并与 QualityScore 在同一根轴上二次惩罚; // 加性 base+λ(conf-mean) 只平移均值、不缩方差,对尾部排序影响可控。 conf := coalesceConfidence(c.Confidence) + // 2026-10-09 (P0 修正):λ 已在 Step 3.7 偏置进 reranked[i].Score,选择与展示 + // 共用同一套分数;此处不再重复施加(否则 legacy 被双重扣分)。 base := score*0.7 + c.QualityScore*0.3 - if confidenceLambda > 0 { - base += confidenceLambda * (conf - confidenceMean) - } results = append(results, models.RecallResult{ ID: c.ID, Content: c.Content,