fix(metrics): 拆口径 avg_distill_loss 三来源 + Overall 真实分布 + dashboard 标 stub
t_e5cdc25c 织忆指标口径修复: ① 交付 Overall 真实分布复算脚本 ~/.hermes/scripts/tools/overall-dist-recalc.py (本机无 Python lancedb,改用 Rust 只读工具 qs-dist 全表扫描 46023 行; 字段缺失=0,fallback(==0)=15.0%,历史bug(0.755)=7.9%,可信=77.1%) ② 拆 avg_distill_loss 混算:新增 distill_loss_llm / merge_ratio_loss / quality_backtrace_loss 三独立指标(各带 _count/_valid/_sum),avg_distill_loss 保留但标 deprecated=1、不再作为可信尺子;server.go 三调用点迁移到来源专属 Record。 契约测试 metrics_contract_test.go 增 TestContract_DistillLossSplitThreeSources 验证三来源互不串桶 + sum/count 可复算。go test ./internal/selfoptimize/ 全绿。 ③ DashboardSnapshot 6 硬编码值标 dashboard_stub=true(serde default=true 保守), 逐点注释说明:previous_metrics 恒 None ⇒ 退化判定链路死路;Go consolidate::Result 不读 dashboard/degradation 字段 ⇒ 硬编码值不流入 Go 自优化/调参/告警。 不改蒸馏逻辑(engine.go 评分权重不动);不重启 zhiyid、不改生产 env。
This commit is contained in:
@@ -616,7 +616,7 @@ func NewServer() http.Handler {
|
||||
}
|
||||
// 更新仪表盘指标:蒸馏成功次数(2026-10-14 t_c06ad4d0 改,勿再灌 UsefulCount)
|
||||
selfoptimize.Dash.RecordDistillSuccess()
|
||||
// 记录蒸馏质量损失(avg_distill_loss = 1 - Overall)
|
||||
// 记录蒸馏质量损失(来源①:1 - Overall;t_e5cdc25c 拆口径后走独立 LLM 桶)
|
||||
// 仅记录真实蒸馏:Overall > 0 表示 LLM 成功返回,过滤 fallback (Overall=0)
|
||||
if result.Overall > 0 {
|
||||
loss := 1.0 - result.Overall
|
||||
@@ -626,7 +626,7 @@ func NewServer() http.Handler {
|
||||
if loss > 1 {
|
||||
loss = 1
|
||||
}
|
||||
selfoptimize.Dash.RecordDistillLoss(loss)
|
||||
selfoptimize.Dash.RecordDistillLossLLM(loss)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1855,22 +1855,22 @@ func NewServer() http.Handler {
|
||||
if err == nil && report != nil {
|
||||
// 注入 consolidate 报告 → Dashboard
|
||||
if report.Merged > 0 {
|
||||
// 合并启发式: 按合并数比例缩放, 但限定单次贡献 ≤ 0.05, 防止污染 avg_distill_loss
|
||||
// 来源② 合并条数贡献(t_e5cdc25c 拆口径后走独立 merge 桶,不再混入蒸馏质量)
|
||||
loss := float64(report.Merged) * 0.002
|
||||
if loss > 0.05 {
|
||||
loss = 0.05
|
||||
}
|
||||
selfoptimize.Dash.RecordDistillLoss(loss)
|
||||
selfoptimize.Dash.RecordMergeRatioLoss(loss)
|
||||
}
|
||||
if report.ConflictsFound > 0 {
|
||||
selfoptimize.Dash.RecordConflictResolved(true)
|
||||
}
|
||||
for _, p := range report.Patterns {
|
||||
if len(p) > 13 && p[:13] == "quality_score" {
|
||||
// 解析 quality_score=0.50 → 注入 avg_distill_loss
|
||||
// 来源③ 质量回溯(cos(L0,L0'))损失(t_e5cdc25c 拆口径后走独立 backtrace 桶)
|
||||
var qs float64
|
||||
if _, e := fmt.Sscanf(p, "quality_score=%f", &qs); e == nil {
|
||||
selfoptimize.Dash.RecordDistillLoss(1.0 - qs)
|
||||
selfoptimize.Dash.RecordQualityBacktraceLoss(1.0 - qs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,11 @@
|
||||
// gap_closure_rate | 率 | 0..1 | ClosedGaps / TotalGaps(缺口个数口径) | TotalGaps<20 或 比率越界>1 | TotalGaps>=20
|
||||
// cascade_fix_rate | 率 | 0..1 | CascadeFixedTotal / TotalFixes(/feedback/correct)| TotalFixes<20 | TotalFixes>=20
|
||||
// auto_resolve_rate | 率 | 0..1 | AutoResolvedConflicts / TotalConflicts | TotalConflicts<20 | TotalConflicts>=20
|
||||
// avg_distill_loss | 均值 | 0..1 | Σ(1-overall) / DistillLossCount(overall=5D加权分)| DistillLossCount<20 | DistillLossCount>=20
|
||||
// avg_distill_loss | 均值 | 0..1 | [DEPRECATED] 三来源混算(见下三拆分指标),语义不可信 | DistillLossCount<20 | DistillLossCount>=20(保留仅向后兼容)
|
||||
// distill_loss_llm | 均值 | 0..1 | 来源① Σ(1-Overall)/LLMCount(真·蒸馏质量损失) | LLMCount<20 | LLMCount>=20
|
||||
// merge_ratio_loss | 均值 | 0..1 | 来源② Σ(min(Merged×0.002,0.05))/MergeCount(合并规模)| MergeCount<20 | MergeCount>=20
|
||||
// quality_backtrace_loss | 均值 | 0..1 | 来源③ Σ(1-cos(L0,L0'))/QBCount(质量回溯损失) | QBCount<20 | QBCount>=20
|
||||
// avg_distill_loss_deprecated| 标记 | 0/1 | 恒 1:表示 avg_distill_loss 是 deprecated 混算桶(消费方读值前必看)| 无 | n/a
|
||||
// deprecated_per_day | 计数 | 条/天 | 当天 /feedback/deprecate 调用数(跨天归零) | 无(计数不为 null) | n/a(0 是合法值)
|
||||
// deprecated_total | 计数 | 条 | 累计 /feedback/deprecate 调用数(跨重启存活) | 无(计数不为 null) | n/a(0=链路未接线,见下)
|
||||
// distill_success_count | 计数 | 条 | 蒸馏成功条数 | 无 | n/a
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
package selfoptimize
|
||||
|
||||
import (
|
||||
"math"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
@@ -42,17 +43,31 @@ func TestContract_RateKeysHaveValidAndSamples(t *testing.T) {
|
||||
if _, ok := m["avg_distill_loss_valid"]; !ok {
|
||||
t.Fatal("avg_distill_loss 缺 _valid(均值有分母,必须给有效位)")
|
||||
}
|
||||
// t_e5cdc25c 口径拆分三来源:各自带 _valid / _samples,且 avg_distill_loss 标注 deprecated。
|
||||
for _, k := range []string{"distill_loss_llm", "merge_ratio_loss", "quality_backtrace_loss"} {
|
||||
if _, ok := m[k]; !ok {
|
||||
t.Fatalf("拆分指标 %s 缺失(t_e5cdc25c:三来源必须独立可复算)", k)
|
||||
}
|
||||
for _, suffix := range []string{"_valid", "_samples"} {
|
||||
if _, ok := m[k+suffix]; !ok {
|
||||
t.Fatalf("拆分指标 %s 缺姊妹键 %s%s(每个均值必须可自证分母)", k, k, suffix)
|
||||
}
|
||||
}
|
||||
}
|
||||
if m["avg_distill_loss_deprecated"] != 1 {
|
||||
t.Fatal("avg_distill_loss 必须显式标注 deprecated=1(混算值已不可信)")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContract_ZeroSampleIsMinusOneNotZero(t *testing.T) {
|
||||
d := freshDash(t)
|
||||
m := d.Metrics()
|
||||
for _, k := range []string{"recall_usefulness_rate", "gap_closure_rate", "cascade_fix_rate", "auto_resolve_rate", "avg_distill_loss"} {
|
||||
for _, k := range []string{"recall_usefulness_rate", "gap_closure_rate", "cascade_fix_rate", "auto_resolve_rate", "avg_distill_loss", "distill_loss_llm", "merge_ratio_loss", "quality_backtrace_loss"} {
|
||||
if m[k] != metricNA {
|
||||
t.Fatalf("%s 零样本应=%v,实得 %v(契约 B:无数据必须是哨兵 -1,禁止假 0)", k, metricNA, m[k])
|
||||
}
|
||||
}
|
||||
for _, k := range []string{"recall_usefulness_valid", "gap_closure_valid", "cascade_fix_valid", "auto_resolve_valid", "avg_distill_loss_valid"} {
|
||||
for _, k := range []string{"recall_usefulness_valid", "gap_closure_valid", "cascade_fix_valid", "auto_resolve_valid", "avg_distill_loss_valid", "distill_loss_llm_valid", "merge_ratio_loss_valid", "quality_backtrace_loss_valid"} {
|
||||
if m[k] != 0 {
|
||||
t.Fatalf("%s 零样本应=0,实得 %v(契约 B:值与 valid 必须同步)", k, m[k])
|
||||
}
|
||||
@@ -74,3 +89,53 @@ func TestContract_ThresholdsPinned(t *testing.T) {
|
||||
t.Fatalf("面板可解读门应为 20(契约 C),实为 %d —— 改门槛必须同步 metrics_contract.go 语义表", minRateSamples)
|
||||
}
|
||||
}
|
||||
|
||||
// TestContract_DistillLossSplitThreeSources(t_e5cdc25c):
|
||||
// 三个来源各自灌入独立计数器后,每个指标的 sum/count 必须与「该来源单独复算」一致,
|
||||
// 且三者互不串桶(LLM 的 loss 不污染 merge 桶,反之亦然)。
|
||||
func TestContract_DistillLossSplitThreeSources(t *testing.T) {
|
||||
d := freshDash(t)
|
||||
// 来源① LLM:灌 25 个样本(≥ 样本门 20),均值已知。
|
||||
llmVals := []float64{0.2, 0.4, 0.1, 0.3, 0.5, 0.25, 0.45, 0.15, 0.35, 0.55,
|
||||
0.2, 0.4, 0.1, 0.3, 0.5, 0.25, 0.45, 0.15, 0.35, 0.55, 0.2, 0.4, 0.1, 0.3, 0.5}
|
||||
for _, v := range llmVals {
|
||||
d.RecordDistillLossLLM(v)
|
||||
}
|
||||
// 来源② 合并:灌 25 个固定 0.05。
|
||||
for i := 0; i < 25; i++ {
|
||||
d.RecordMergeRatioLoss(0.05)
|
||||
}
|
||||
// 来源③ 回溯:灌 25 个固定 0.1。
|
||||
for i := 0; i < 25; i++ {
|
||||
d.RecordQualityBacktraceLoss(0.1)
|
||||
}
|
||||
|
||||
m := d.Metrics()
|
||||
|
||||
// 复算:LLM 均值 = Σ/25
|
||||
wantLLM := 0.0
|
||||
for _, v := range llmVals {
|
||||
wantLLM += v
|
||||
}
|
||||
wantLLM = math.Round(wantLLM/25*1000) / 1000
|
||||
if m["distill_loss_llm"] != wantLLM {
|
||||
t.Fatalf("distill_loss_llm = %v,期望复算值 %v(Σ/25)", m["distill_loss_llm"], wantLLM)
|
||||
}
|
||||
if m["distill_loss_llm_samples"] != 25 || m["distill_loss_llm_valid"] != 1 {
|
||||
t.Fatalf("distill_loss_llm samples/valid 应为 25/1,实得 %v/%v", m["distill_loss_llm_samples"], m["distill_loss_llm_valid"])
|
||||
}
|
||||
if m["merge_ratio_loss"] != 0.05 || m["merge_ratio_loss_samples"] != 25 || m["merge_ratio_loss_valid"] != 1 {
|
||||
t.Fatalf("merge_ratio_loss 应为 0.05/25/1,实得 %v/%v/%v", m["merge_ratio_loss"], m["merge_ratio_loss_samples"], m["merge_ratio_loss_valid"])
|
||||
}
|
||||
if m["quality_backtrace_loss"] != 0.1 || m["quality_backtrace_loss_samples"] != 25 || m["quality_backtrace_loss_valid"] != 1 {
|
||||
t.Fatalf("quality_backtrace_loss 应为 0.1/25/1,实得 %v/%v/%v", m["quality_backtrace_loss"], m["quality_backtrace_loss_samples"], m["quality_backtrace_loss_valid"])
|
||||
}
|
||||
|
||||
// 互不串桶:avg_distill_loss(deprecated 桶)本测试没调 RecordDistillLoss ⇒ 应零样本 NA。
|
||||
if m["avg_distill_loss"] != metricNA || m["avg_distill_loss_samples"] != 0 {
|
||||
t.Fatalf("deprecated avg_distill_loss 不应被拆分来源污染,实得 val=%v samples=%v", m["avg_distill_loss"], m["avg_distill_loss_samples"])
|
||||
}
|
||||
if m["avg_distill_loss_deprecated"] != 1 {
|
||||
t.Fatalf("avg_distill_loss_deprecated 标记应为 1")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,14 @@ type dashboardState struct {
|
||||
DeprecatedDate string `json:"deprecated_date"` // deprecated_today 的归属日期(跨天归零用)
|
||||
DistillLossSum float64 `json:"distill_loss_sum"`
|
||||
DistillLossCount int `json:"distill_loss_count"`
|
||||
// 口径拆分三来源(t_e5cdc25c):avg_distill_loss 曾把三种互不相关的量混进一个平均,
|
||||
// 拆成独立计数器后 avg_distill_loss 降级为 deprecated 混算值(仅向后兼容,禁再当质量看)。
|
||||
DistillLossLLMSum float64 `json:"distill_loss_llm_sum"`
|
||||
DistillLossLLMCount int `json:"distill_loss_llm_count"`
|
||||
MergeRatioLossSum float64 `json:"merge_ratio_loss_sum"`
|
||||
MergeRatioLossCount int `json:"merge_ratio_loss_count"`
|
||||
QualityBacktraceLossSum float64 `json:"quality_backtrace_loss_sum"`
|
||||
QualityBacktraceLossCount int `json:"quality_backtrace_loss_count"`
|
||||
DistillSuccessCount int `json:"distill_success_count"`
|
||||
AutoResolvedConflicts int `json:"auto_resolved_conflicts"`
|
||||
TotalConflicts int `json:"total_conflicts"`
|
||||
@@ -111,6 +119,12 @@ func loadDashboardLocal() error {
|
||||
}
|
||||
Dash.DistillLossSum = st.DistillLossSum
|
||||
Dash.DistillLossCount = st.DistillLossCount
|
||||
Dash.DistillLossLLMSum = st.DistillLossLLMSum
|
||||
Dash.DistillLossLLMCount = st.DistillLossLLMCount
|
||||
Dash.MergeRatioLossSum = st.MergeRatioLossSum
|
||||
Dash.MergeRatioLossCount = st.MergeRatioLossCount
|
||||
Dash.QualityBacktraceLossSum = st.QualityBacktraceLossSum
|
||||
Dash.QualityBacktraceLossCount = st.QualityBacktraceLossCount
|
||||
Dash.DistillSuccessCount = st.DistillSuccessCount
|
||||
Dash.AutoResolvedConflicts = st.AutoResolvedConflicts
|
||||
Dash.TotalConflicts = st.TotalConflicts
|
||||
@@ -141,6 +155,12 @@ func (d *Dashboard) persistLocalLocked() {
|
||||
DeprecatedDate: todayStr(),
|
||||
DistillLossSum: d.DistillLossSum,
|
||||
DistillLossCount: d.DistillLossCount,
|
||||
DistillLossLLMSum: d.DistillLossLLMSum,
|
||||
DistillLossLLMCount: d.DistillLossLLMCount,
|
||||
MergeRatioLossSum: d.MergeRatioLossSum,
|
||||
MergeRatioLossCount: d.MergeRatioLossCount,
|
||||
QualityBacktraceLossSum: d.QualityBacktraceLossSum,
|
||||
QualityBacktraceLossCount: d.QualityBacktraceLossCount,
|
||||
DistillSuccessCount: d.DistillSuccessCount,
|
||||
AutoResolvedConflicts: d.AutoResolvedConflicts,
|
||||
TotalConflicts: d.TotalConflicts,
|
||||
@@ -180,6 +200,13 @@ func (d *Dashboard) persist() {
|
||||
_ = redisPersistence.HSet(dashboardRedisKey, "deprecated_date", d.DeprecatedDate)
|
||||
_ = redisPersistence.HSet(dashboardRedisKey, "distill_loss_sum", strconv.FormatFloat(d.DistillLossSum, 'f', 4, 64))
|
||||
_ = redisPersistence.HSet(dashboardRedisKey, "distill_loss_count", strconv.Itoa(d.DistillLossCount))
|
||||
// 口径拆分三来源(t_e5cdc25c)
|
||||
_ = redisPersistence.HSet(dashboardRedisKey, "distill_loss_llm_sum", strconv.FormatFloat(d.DistillLossLLMSum, 'f', 6, 64))
|
||||
_ = redisPersistence.HSet(dashboardRedisKey, "distill_loss_llm_count", strconv.Itoa(d.DistillLossLLMCount))
|
||||
_ = redisPersistence.HSet(dashboardRedisKey, "merge_ratio_loss_sum", strconv.FormatFloat(d.MergeRatioLossSum, 'f', 6, 64))
|
||||
_ = redisPersistence.HSet(dashboardRedisKey, "merge_ratio_loss_count", strconv.Itoa(d.MergeRatioLossCount))
|
||||
_ = redisPersistence.HSet(dashboardRedisKey, "quality_backtrace_loss_sum", strconv.FormatFloat(d.QualityBacktraceLossSum, 'f', 6, 64))
|
||||
_ = redisPersistence.HSet(dashboardRedisKey, "quality_backtrace_loss_count", strconv.Itoa(d.QualityBacktraceLossCount))
|
||||
_ = redisPersistence.HSet(dashboardRedisKey, "distill_success_count", strconv.Itoa(d.DistillSuccessCount))
|
||||
_ = redisPersistence.HSet(dashboardRedisKey, "auto_resolved_conflicts", strconv.Itoa(d.AutoResolvedConflicts))
|
||||
_ = redisPersistence.HSet(dashboardRedisKey, "total_conflicts", strconv.Itoa(d.TotalConflicts))
|
||||
@@ -243,6 +270,25 @@ func loadDashboard() error {
|
||||
if v, err := strconv.Atoi(data["distill_loss_count"]); err == nil {
|
||||
Dash.DistillLossCount = v
|
||||
}
|
||||
// 口径拆分三来源(t_e5cdc25c):缺则保持零值,兼容旧 Redis 数据
|
||||
if v, err := strconv.ParseFloat(data["distill_loss_llm_sum"], 64); err == nil {
|
||||
Dash.DistillLossLLMSum = v
|
||||
}
|
||||
if v, err := strconv.Atoi(data["distill_loss_llm_count"]); err == nil {
|
||||
Dash.DistillLossLLMCount = v
|
||||
}
|
||||
if v, err := strconv.ParseFloat(data["merge_ratio_loss_sum"], 64); err == nil {
|
||||
Dash.MergeRatioLossSum = v
|
||||
}
|
||||
if v, err := strconv.Atoi(data["merge_ratio_loss_count"]); err == nil {
|
||||
Dash.MergeRatioLossCount = v
|
||||
}
|
||||
if v, err := strconv.ParseFloat(data["quality_backtrace_loss_sum"], 64); err == nil {
|
||||
Dash.QualityBacktraceLossSum = v
|
||||
}
|
||||
if v, err := strconv.Atoi(data["quality_backtrace_loss_count"]); err == nil {
|
||||
Dash.QualityBacktraceLossCount = v
|
||||
}
|
||||
if v, err := strconv.Atoi(data["distill_success_count"]); err == nil {
|
||||
Dash.DistillSuccessCount = v
|
||||
}
|
||||
@@ -281,6 +327,14 @@ type Dashboard struct {
|
||||
DeprecatedDate string `json:"deprecated_date"` // t_4bbddae6:deprecated_today 的归属日期(跨天归零用)
|
||||
DistillLossSum float64 `json:"distill_loss_sum"`
|
||||
DistillLossCount int `json:"distill_loss_count"`
|
||||
// 口径拆分三来源(t_e5cdc25c)。三者互不相关,拆开各自可复算;avg_distill_loss 保留为
|
||||
// deprecated 混算(= 三来源加权的单一平均),不再作为「记性有多好」的尺子(见分布表)。
|
||||
DistillLossLLMSum float64 `json:"distill_loss_llm_sum"`
|
||||
DistillLossLLMCount int `json:"distill_loss_llm_count"`
|
||||
MergeRatioLossSum float64 `json:"merge_ratio_loss_sum"`
|
||||
MergeRatioLossCount int `json:"merge_ratio_loss_count"`
|
||||
QualityBacktraceLossSum float64 `json:"quality_backtrace_loss_sum"`
|
||||
QualityBacktraceLossCount int `json:"quality_backtrace_loss_count"`
|
||||
DistillSuccessCount int `json:"distill_success_count"`
|
||||
AutoResolvedConflicts int `json:"auto_resolved_conflicts"`
|
||||
TotalConflicts int `json:"total_conflicts"`
|
||||
@@ -377,12 +431,30 @@ func (d *Dashboard) Metrics() map[string]float64 {
|
||||
avgLoss = math.Round(d.DistillLossSum/float64(d.DistillLossCount)*100) / 100
|
||||
}
|
||||
|
||||
// 口径拆分三来源(t_e5cdc25c)。每个均值独立可复算(sum/count),各带 _count/_valid。
|
||||
// avg_distill_loss 降级为 deprecated:它是三来源混算的单一平均,语义已不可信。
|
||||
llmLoss := metricNA
|
||||
if d.DistillLossLLMCount > 0 {
|
||||
llmLoss = math.Round(d.DistillLossLLMSum/float64(d.DistillLossLLMCount)*1000) / 1000
|
||||
}
|
||||
mergeLoss := metricNA
|
||||
if d.MergeRatioLossCount > 0 {
|
||||
mergeLoss = math.Round(d.MergeRatioLossSum/float64(d.MergeRatioLossCount)*1000) / 1000
|
||||
}
|
||||
qbLoss := metricNA
|
||||
if d.QualityBacktraceLossCount > 0 {
|
||||
qbLoss = math.Round(d.QualityBacktraceLossSum/float64(d.QualityBacktraceLossCount)*1000) / 1000
|
||||
}
|
||||
|
||||
// 最小样本门:samples < minRateSamples ⇒ 值 = -1 且 valid = 0,不参与面板解读。
|
||||
usefulVal, usefulValid := usefulRate, b2f(usefulSamples >= minRateSamples && d.NotUsefulCount > 0)
|
||||
gapVal, gapValid := gapRate, b2f(d.TotalGaps >= minRateSamples)
|
||||
cascadeVal, cascadeValid := cascadeRate, b2f(d.TotalFixes >= minRateSamples)
|
||||
autoVal, autoValid := autoRate, b2f(d.TotalConflicts >= minRateSamples)
|
||||
lossVal, lossValid := avgLoss, b2f(d.DistillLossCount >= minRateSamples)
|
||||
llmLossVal, llmLossValid := llmLoss, b2f(d.DistillLossLLMCount >= minRateSamples)
|
||||
mergeLossVal, mergeLossValid := mergeLoss, b2f(d.MergeRatioLossCount >= minRateSamples)
|
||||
qbLossVal, qbLossValid := qbLoss, b2f(d.QualityBacktraceLossCount >= minRateSamples)
|
||||
if usefulSamples < minRateSamples || d.NotUsefulCount == 0 {
|
||||
usefulVal = metricNA
|
||||
}
|
||||
@@ -400,6 +472,15 @@ func (d *Dashboard) Metrics() map[string]float64 {
|
||||
if d.DistillLossCount < minRateSamples {
|
||||
lossVal = metricNA
|
||||
}
|
||||
if d.DistillLossLLMCount < minRateSamples {
|
||||
llmLossVal = metricNA
|
||||
}
|
||||
if d.MergeRatioLossCount < minRateSamples {
|
||||
mergeLossVal = metricNA
|
||||
}
|
||||
if d.QualityBacktraceLossCount < minRateSamples {
|
||||
qbLossVal = metricNA
|
||||
}
|
||||
|
||||
return map[string]float64{
|
||||
"recall_usefulness_rate": usefulVal,
|
||||
@@ -428,6 +509,23 @@ func (d *Dashboard) Metrics() map[string]float64 {
|
||||
"avg_distill_loss": lossVal,
|
||||
"avg_distill_loss_samples": float64(d.DistillLossCount),
|
||||
"avg_distill_loss_valid": lossValid,
|
||||
// avg_distill_loss 已 deprecated(t_e5cdc25c):三来源混算,语义不可信。
|
||||
// 显式标记位:valid=1 表示该 deprecated 键仍在输出(向后兼容),值本身禁再当质量看。
|
||||
"avg_distill_loss_deprecated": 1,
|
||||
|
||||
// 口径拆分三来源(t_e5cdc25c)—— 各自独立可复算,取代 avg_distill_loss 作为可信尺子。
|
||||
"distill_loss_llm": llmLossVal,
|
||||
"distill_loss_llm_samples": float64(d.DistillLossLLMCount),
|
||||
"distill_loss_llm_valid": llmLossValid,
|
||||
"distill_loss_llm_sum": d.DistillLossLLMSum,
|
||||
"merge_ratio_loss": mergeLossVal,
|
||||
"merge_ratio_loss_samples": float64(d.MergeRatioLossCount),
|
||||
"merge_ratio_loss_valid": mergeLossValid,
|
||||
"merge_ratio_loss_sum": d.MergeRatioLossSum,
|
||||
"quality_backtrace_loss": qbLossVal,
|
||||
"quality_backtrace_loss_samples": float64(d.QualityBacktraceLossCount),
|
||||
"quality_backtrace_loss_valid": qbLossValid,
|
||||
"quality_backtrace_loss_sum": d.QualityBacktraceLossSum,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1014,7 +1112,13 @@ func (d *Dashboard) RecordConflictResolved(auto bool) {
|
||||
d.persist()
|
||||
}
|
||||
|
||||
// RecordDistillLoss 记录蒸馏质量损失
|
||||
// RecordDistillLoss 记录蒸馏质量损失([DEPRECATED] t_e5cdc25c)。
|
||||
//
|
||||
// 历史上三来源(LLM 蒸馏 1-Overall / 合并条数 / 质量回溯)都灌进这一个计数器,
|
||||
// 导致 avg_distill_loss 无单一语义。现拆为三个独立 Record 方法(见下),本方法仅作
|
||||
// 向后兼容保留:只更新 deprecated 的 avg_distill_loss 混算桶,**不再**作为任何
|
||||
// 可信指标的来源。调用点应迁移到 RecordDistillLossLLM / RecordMergeRatioLoss /
|
||||
// RecordQualityBacktraceLoss。
|
||||
func (d *Dashboard) RecordDistillLoss(loss float64) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
@@ -1023,6 +1127,35 @@ func (d *Dashboard) RecordDistillLoss(loss float64) {
|
||||
d.persist()
|
||||
}
|
||||
|
||||
// RecordDistillLossLLM 记录「真·蒸馏质量损失」来源(来源①:1.0 - distill.Overall)。
|
||||
// Overall 为 distill engine 五维加权分,scoreMinOverall 默认 0.30。
|
||||
func (d *Dashboard) RecordDistillLossLLM(loss float64) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
d.DistillLossLLMSum += loss
|
||||
d.DistillLossLLMCount++
|
||||
d.persist()
|
||||
}
|
||||
|
||||
// RecordMergeRatioLoss 记录「合并条数贡献」来源(来源②:min(Merged×0.002, 0.05))。
|
||||
// 与蒸馏质量无关,仅反映 consolidate 合并规模,不应并入质量损失。
|
||||
func (d *Dashboard) RecordMergeRatioLoss(loss float64) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
d.MergeRatioLossSum += loss
|
||||
d.MergeRatioLossCount++
|
||||
d.persist()
|
||||
}
|
||||
|
||||
// RecordQualityBacktraceLoss 记录「质量回溯损失」来源(来源③:1.0 - cos(L0,L0'))。
|
||||
func (d *Dashboard) RecordQualityBacktraceLoss(loss float64) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
d.QualityBacktraceLossSum += loss
|
||||
d.QualityBacktraceLossCount++
|
||||
d.persist()
|
||||
}
|
||||
|
||||
func (pg *PrefetchGraph) GetPrefetch(query string) []string {
|
||||
pg.mu.RLock()
|
||||
defer pg.mu.RUnlock()
|
||||
|
||||
@@ -1068,6 +1068,9 @@ fn run_consolidation(args: &Args, lancedb: &LanceDBOps) -> ConsolidationReport {
|
||||
// Step 5: 生成报告
|
||||
reclaim("Step 4 后(质量回溯)");
|
||||
let dashboard = DashboardSnapshot {
|
||||
// ⚠️ 全部硬编码占位值(t_e5cdc25c 已标 stub):禁当真值。真实来源在 Go
|
||||
// selfoptimize.Dash.Metrics(),本 Rust 侧不直连该计数器。dashboard_stub=true
|
||||
// 使任何消费 JSON 报告者能看到这是占位数据。
|
||||
recall_useful_rate: 0.85,
|
||||
recall_hit_rate: 0.90,
|
||||
gap_closure_rate: 0.75,
|
||||
@@ -1075,6 +1078,7 @@ fn run_consolidation(args: &Args, lancedb: &LanceDBOps) -> ConsolidationReport {
|
||||
deprecation_rate: 3.0,
|
||||
distill_loss_rate: quality_score.max(0.0),
|
||||
auto_resolve_rate: 0.70,
|
||||
dashboard_stub: true,
|
||||
};
|
||||
|
||||
let gen = ReportGenerator::new();
|
||||
|
||||
+24
-3
@@ -47,13 +47,25 @@ pub struct PruneStats {
|
||||
}
|
||||
|
||||
/// 仪表盘快照
|
||||
///
|
||||
/// ⚠️ [STUB](t_e5cdc25c):6 个比率/计数指标当前**全部硬编码占位值**
|
||||
/// (main.rs:1070),不是真实来源。消费方读任何字段前必须先看 dashboard_stub:
|
||||
/// - 5 个率值 (0.85/0.90/0.75/0.60/0.70) 与 deprecation_rate(3.0) 是**假常量**,
|
||||
/// 真实值应从 Go selfoptimize.Dash.Metrics() 取(本 Rust 侧不直连该计数器)。
|
||||
/// - distill_loss_rate 直接复用 quality_score(回溯 cos 分)当「损失率」,语义反
|
||||
/// (质量分越高损失越大?),且 quality_score 失败时=0 ⇒ 损失恒 0,退化判定失真。
|
||||
/// - previous_metrics 恒 None(new() 不设值)⇒ detect_degradation 永远返回空,
|
||||
/// 该退化判定链路目前是**死路**(不会因硬编码值误告警,但也不会真触发)。
|
||||
/// 影响面:本结构仅流入 Rust CLI 的 stdout JSON 报告(人读)与 IPC 发给 Go 的
|
||||
/// ConsolidationReport;Go 侧 consolidate::Result **不读** dashboard/degradation 字段,
|
||||
/// 故 6 个硬编码值**不流入** Go 自优化/调参/告警。详见 t_e5cdc25c 交付报告。
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DashboardSnapshot {
|
||||
/// 召回有用率
|
||||
/// 召回有用率 [STUB 硬编码 0.85]
|
||||
pub recall_useful_rate: f64,
|
||||
/// 召回命中率
|
||||
/// 召回命中率 [STUB 硬编码 0.90]
|
||||
pub recall_hit_rate: f64,
|
||||
/// 缺口闭环率
|
||||
/// 缺口闭环率 [STUB 硬编码 0.75]
|
||||
pub gap_closure_rate: f64,
|
||||
/// 修正传播率
|
||||
pub cascade_propagation_rate: f64,
|
||||
@@ -63,6 +75,15 @@ pub struct DashboardSnapshot {
|
||||
pub distill_loss_rate: f64,
|
||||
/// 冲突自动裁决率
|
||||
pub auto_resolve_rate: f64,
|
||||
/// [STUB 标记位](t_e5cdc25c):true = 本快照全部指标为硬编码占位值,禁当真值用。
|
||||
/// 消费方(报告/告警/调参)读前必看此位;false 才代表已接真实来源。
|
||||
#[serde(default = "default_dashboard_stub_true")]
|
||||
pub dashboard_stub: bool,
|
||||
}
|
||||
|
||||
// 默认 true:旧数据/缺省反序列化时保守标为 stub,避免把未知来源的快照当真实指标用。
|
||||
fn default_dashboard_stub_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// 退化告警
|
||||
|
||||
Reference in New Issue
Block a user