From e98565f0c98174dfa80d5b77d0477ff4868afe9b Mon Sep 17 00:00:00 2001 From: xiaoyi Date: Fri, 9 Oct 2026 08:46:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(recall):=20=E6=9D=A5=E6=BA=90=E5=8A=A0?= =?UTF-8?q?=E6=9D=83=20=CE=BB=20=E7=A7=BB=E5=88=B0=20MMR=20=E4=B9=8B?= =?UTF-8?q?=E5=89=8D=20=E2=80=94=E2=80=94=20=E5=8E=9F=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E5=8F=AA=E6=94=B9=E5=B1=95=E7=A4=BA=E5=88=86=E4=B8=8D=E6=94=B9?= =?UTF-8?q?=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit λ 原加在 Step 4 之后的展示分上,候选取舍已由 rerank+MMR 定死, 故 λ 无论多大都不改变结果集合(实测 λ=0.1 vs 0:14 条 query 全部 cache-miss 下 top-10 集合与 legacy 占比 33.57% 完全一致,而逐条分数 位移与理论吻合 legacy -0.0277 / conf1.0 +0.0294)。 现移到 MMR 之前,使选择与展示共用同一套分数;λ=0 时循环不执行, 与旧行为逐字节等价。 --- go/internal/storage/recall.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) 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,