Skip to content

[bug] knowledge-reconciler buildConfidence 取平均导致置信度反常 + stale 检测语义错误 #82

Description

@jeff-r2026

Bug 1:buildConfidence 取平均 → 证据越多置信度越低

// src/wiki-engine/reconciler-v2-types.ts:39-44
export function buildConfidence(factors: ConfidenceFactor[]): NumericConfidence {
  if (factors.length === 0) return { score: 0, label: "AMBIGUOUS", factors: [] };
  const score = factors.reduce((sum, f) => sum + f.weight, 0) / factors.length; // 平均
  ...
}

对各置信因子取算术平均,导致“补充正向证据反而拉低置信度”:

  • direct_match(0.9) 单独 → 0.9 → EXTRACTED
  • direct_match(0.9) + title_proximity(0.1) → (0.9+0.1)/2 = 0.5INFERRED

即“标题也命中”这种加分项把置信度从 0.9 拉到 0.5。API 匹配同理:path_match(0.7) + method_match(0.3)0.5,反而低于只有 path 命中时的 0.7(src/wiki-engine/knowledge-reconciler.ts:235-246, 302-312)。

→ 边权重系统性偏低,进而影响 graph boost 与 health 指标。

建议:改为 Math.min(1, sum)(因子表示累计证据)或乘积(因子表示独立概率),不要用平均。

Bug 2:stale 检测语义错误

// src/wiki-engine/knowledge-reconciler.ts:348
const daysDrift = Math.abs(now - Math.max(fromMs, toMs)) / MS_PER_DAY;

这里算的是“较新一侧页面距今的绝对年龄”,而不是 product 页与 code 页之间的更新时间差(drift)。一个长期无人改动但两侧同时更新的映射会被误报 stale;而两侧更新时间差很大但都较新的映射反而漏报。

建议:改为 Math.abs(fromMs - toMs) / MS_PER_DAY

严重程度:高(Bug 1 影响所有图谱边的置信度)/ 中(Bug 2)。

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions