From e9fce11a1ba53a45c8f5336a1458436ff28443d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=94=AF?= Date: Sun, 11 Oct 2026 23:44:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(zhiyi):=20t=5F268b0353=20=E6=B2=BB=E6=A0=B9?= =?UTF-8?q?=20=E2=80=94=20=E6=96=AD=20auto=5Frecall=20V=20=E4=BC=A0?= =?UTF-8?q?=E6=92=AD=20+=20=E5=8F=AC=E5=9B=9E=E4=B8=8D=E5=86=99=20freshnes?= =?UTF-8?q?s=3Dverified(Rust=20=E4=B8=BB=E8=B7=AF=E5=BE=84+Go=20=E5=85=9C?= =?UTF-8?q?=E5=BA=95)=20+=20volatile=5Fflag=20=E6=A0=87=E6=B3=A8=E9=A2=84?= =?UTF-8?q?=E7=95=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - core.go: auto_recall 的 memory_ids 传 nil(「召回命中」不再冒充「记忆有用」进排序权重) - rust lancedb_ops.rs:489/510(zhiyi-consolidate 主写路径)+ go 兜底: 召回不再盖 freshness=verified (「被召回」≠「被验证」,越常被召回的旧快照不再越「可信」) - lancedb_ipc.go: volatile_flag 恒 false 处标注为预留惩罚分支,当前不生效 - 集成测试同步:版本计数负载不再写 freshness 列 --- go/internal/api/routes/core.go | 19 +++++++------------ .../storage/batch_ipc_integration_test.go | 3 ++- go/internal/storage/lancedb_ipc.go | 4 ++++ go/internal/storage/recall.go | 2 +- go/internal/storage/recall_write_buffer.go | 5 ++++- rust/src/lancedb_ops.rs | 11 ++++++++--- 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/go/internal/api/routes/core.go b/go/internal/api/routes/core.go index cb7f19c..fba4694 100644 --- a/go/internal/api/routes/core.go +++ b/go/internal/api/routes/core.go @@ -522,14 +522,15 @@ func (a *API) Recall(w http.ResponseWriter, r *http.Request) { gd.ClearMisses(req.Query) } } - // VProp 自动记录:命中 → success,空结果 → failure + // VProp 自动记录(t_268b0353 治根):「召回成功 ≠ 记忆有用」。 + // 此前 auto_recall 给 top-5 命中记忆各注入 +0.2 V 值(vValue/len(ids)), + // 累积成全库 99.95% 自我表扬的排序权重(实测 top1 V=51.667,自证:外部≈2092:1)。 + // 现在:outcome 保持 success 用于**统计**(命中/空结果),但 memory_ids 传 nil, + // "召回命中" 不再冒充 "记忆有用" —— 只有 user_feedback / distill 等外部信号 + // 才允许直接进排序权重。 decisionID := "recall_" + req.Query + "_" + req.Namespace if len(results) > 0 { - ids := make([]string, minInt3(len(results), 5)) - for i := 0; i < len(ids); i++ { - ids[i] = results[i].ID - } - selfoptimize.VProp.RecordDecision(decisionID, ids, "auto_recall", "success", "") + selfoptimize.VProp.RecordDecision(decisionID, nil, "auto_recall", "success", "") } else { selfoptimize.VProp.RecordDecision(decisionID, nil, "auto_recall", "failure", "") } @@ -1091,12 +1092,6 @@ func stringContains(s, substr string) bool { return false } -func minInt3(a, b int) int { - if a < b { - return a - } - return b -} // convertFallbackResults 将 FallbackTextSearch 结果(map)转换为 RecallResult 格式 func convertFallbackResults(rows []map[string]interface{}) []models.RecallResult { diff --git a/go/internal/storage/batch_ipc_integration_test.go b/go/internal/storage/batch_ipc_integration_test.go index 627e808..9bc4513 100644 --- a/go/internal/storage/batch_ipc_integration_test.go +++ b/go/internal/storage/batch_ipc_integration_test.go @@ -107,10 +107,11 @@ func TestBatchIPCVersionAccounting(t *testing.T) { batchVersions := v1 - v0 // B) 旧路径:3 次单条 lancedb_update(recall 读路径原行为) + // t_268b0353(治根):与主批量路径一致,不再写 freshness='verified' + // (列数不影响 LanceDB 版本计数——一个 update 事务=一个版本,故测试断言不受影响) fields, _ := json.Marshal([]map[string]string{ {"column": "recall_count", "value": "1"}, {"column": "last_recalled_at", "value": "'" + ts + "'"}, - {"column": "freshness", "value": "'verified'"}, }) for i := 3; i < 6; i++ { ipcCall(t, sock, map[string]any{"type": "lancedb_update", "table": "memories", "id": recs[i].ID, "fields": string(fields)}) diff --git a/go/internal/storage/lancedb_ipc.go b/go/internal/storage/lancedb_ipc.go index c54aacf..3ac5e7d 100644 --- a/go/internal/storage/lancedb_ipc.go +++ b/go/internal/storage/lancedb_ipc.go @@ -124,6 +124,8 @@ func (rc *RustLanceDBClient) InsertEpisode(agentID, namespace, content, category "tier": "episode", "importance": 1.0, "quality_score": 0.0, "recall_count": 0, "useful_count": 0, "not_useful_count": 0, "freshness": "fresh", "version": 1, "version_history": "[]", + // t_268b0353:volatile_flag 插入路径恒 false;下方 *0.5 惩罚分支是预留 + //(将来接「≥3 次修正自动置位」),当前不生效,勿依赖。 "source": "episode", "volatile_flag": false, "is_deleted": false, "depends_on": "[]", "derived_from": "", "last_recalled_at": "", "created_at": now.Format(time.RFC3339), @@ -159,6 +161,8 @@ func (rc *RustLanceDBClient) InsertMemory(m models.MemoryRecord) error { "tier": m.Tier, "importance": 1.0, "quality_score": m.QualityScore, "recall_count": m.RecallCount, "useful_count": 0, "not_useful_count": 0, "freshness": m.Freshness, "version": 1, "version_history": "[]", + // t_268b0353:volatile_flag 插入路径恒 false;下方 *0.5 惩罚分支是预留 + //(将来接「≥3 次修正自动置位」),当前不生效,勿依赖。 "source": m.Source, "volatile_flag": false, "is_deleted": m.IsDeleted, "depends_on": "[]", "derived_from": "", "last_recalled_at": "", "embedding_model": m.EmbeddingModel, "script_version": m.ScriptVersion, // 2026-10-08 (t_7e3577c5) 血缘 diff --git a/go/internal/storage/recall.go b/go/internal/storage/recall.go index 9972dc0..204dffd 100644 --- a/go/internal/storage/recall.go +++ b/go/internal/storage/recall.go @@ -582,10 +582,10 @@ func (p *RecallPipeline) incrementRecallCount(results []models.RecallResult) { now := time.Now().Format(time.RFC3339) for _, r := range results { if r.ID != "" { + // t_268b0353(治根):兜底路径同样不写 freshness=verified("被召回"≠"被验证") _ = p.lancedb.Update("memories", r.ID, map[string]any{ "recall_count": map[string]string{"$inc": "1"}, "last_recalled_at": now, - "freshness": "verified", }) } } diff --git a/go/internal/storage/recall_write_buffer.go b/go/internal/storage/recall_write_buffer.go index 08d71d0..1826599 100644 --- a/go/internal/storage/recall_write_buffer.go +++ b/go/internal/storage/recall_write_buffer.go @@ -208,10 +208,13 @@ func (b *RecallWriteBuffer) Flush() (int, error) { } rows = 0 for _, it := range batch { + // t_268b0353(2026-10-11 治根):召回只更新 recall_count / last_recalled_at, + // 不再写 freshness="verified"。freshness=verified 的语义是「经过校验/用户 + // 反馈」;"被召回" ≠ "被验证"。此前每次召回都盖 verified → 越常被召回的 + // 旧快照越"可信",时效判断全被污染(过期快照被当现状的机制根因之一)。 if uerr := b.ldb.Update("memories", it.ID, map[string]any{ "recall_count": map[string]string{"$inc": "1"}, "last_recalled_at": ts, - "freshness": "verified", }); uerr != nil { log.Printf("[recall-buffer] 逐条 Update 失败 id=%s: %v", it.ID, uerr) continue diff --git a/rust/src/lancedb_ops.rs b/rust/src/lancedb_ops.rs index c91fa63..e756db0 100644 --- a/rust/src/lancedb_ops.rs +++ b/rust/src/lancedb_ops.rs @@ -485,8 +485,12 @@ impl LanceDBOps { .update() .only_if(&predicate) .column("recall_count", &format!("recall_count + {}", delta)) - .column("last_recalled_at", &ts_lit) - .column("freshness", "'verified'"); + .column("last_recalled_at", &ts_lit); + // t_268b0353(治根):召回只更新 recall_count / last_recalled_at, + // 不再写 freshness='verified'。freshness=verified 语义是「经过校验/用户 + // 反馈」;「被召回」≠「被验证」。此前每次召回都盖 verified → 越常被召回 + // 的旧快照越「可信」,时效判断全被污染(过期快照被当现状的机制根因之一)。 + // 这是主写路径(zhiyi-consolidate sidecar)——Go 侧 write_buffer 只是兜底。 match rt().block_on(op.execute()) { Ok(n) => { eprintln!( @@ -506,8 +510,9 @@ impl LanceDBOps { ids.len() ); for id in ids { + // t_268b0353(治根):同主路径 —— 召回不写 freshness='verified' let fields = format!( - r#"[{{"column":"recall_count","value":"recall_count + {}"}},{{"column":"last_recalled_at","value":"{}"}},{{"column":"freshness","value":"'verified'"}}]"#, + r#"[{{"column":"recall_count","value":"recall_count + {}"}},{{"column":"last_recalled_at","value":"{}"}}]"#, delta, ts_lit ); match self.update("memories", id, &fields) {