refactor(graph): 退役知识形态门,只留读侧埋点 + 加 kgprobe 探针
退役依据(实测,非判断):影子期 5 次 [graph][kg-shadow] 命中的 source 全是 wiki:cron-anomaly 且 blocked_by_source=false —— 门放行的全是「本来就不挡」的来源; 它想放行的 worklog/空 source 属过程流水,本就不该进图 ⇒ 该门零增量。 同期真因查明(推翻 11-18 凌晨那版结论):图谱 11-16→11-18 零新增不是「实体抽取能力差」, 而是 zhiyid 三腿 LLM 端点全指已退役 :11435 → 64/64 次调用 connection refused → 静默降级启发式 → entities=0。端点切 8086 后单日 +34 节点、27/27 次蒸馏均有实体。 故不需要额外门,按「开关型机制只有两种终态」退役。 保留:[graph][read] 读侧埋点(navigate/query),用于回答「图有没有消费者」—— 6h 实测外部 0 次,而 [graph/notes] 兜底拆实体 24h 80 次(走 entity_index,不经 navigate)。 新增 go/cmd/kgprobe:用真实 distill.DensitySatisfyCount 统计阈值分布 (实测 0项 63.9% / 1项 32.4% / 2项 3.7% / 3项 0%),供以后判断任何「信息密度门」可行性。
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/xiaoxue/memoryweave/internal/distill"
|
||||
)
|
||||
|
||||
// 一次性探针:用真实 distill.DensitySatisfyCount 统计「知识形态门」在各阈值下的命中率,
|
||||
// 用于在影子期之前就把「开闸后每天写多少」算出来(避免空跑 24h 才发现门太窄)。
|
||||
func main() {
|
||||
b, err := os.ReadFile(os.Args[1])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var facts []string
|
||||
if err := json.Unmarshal(b, &facts); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
dist := map[int]int{}
|
||||
for _, f := range facts {
|
||||
dist[distill.DensitySatisfyCount(f)]++
|
||||
}
|
||||
n := len(facts)
|
||||
ge := func(k int) int { c := 0; for s, v := range dist { if s >= k { c += v } }; return c }
|
||||
fmt.Printf("samples=%d\n", n)
|
||||
for k := 0; k <= 3; k++ {
|
||||
fmt.Printf(" satisfy=%d : %5d (%.1f%%)\n", k, dist[k], float64(dist[k])*100/float64(n))
|
||||
}
|
||||
fmt.Printf(" >=1 : %5d (%.1f%%)\n", ge(1), float64(ge(1))*100/float64(n))
|
||||
fmt.Printf(" >=2 : %5d (%.1f%%) ← 现行 DensityKeep\n", ge(2), float64(ge(2))*100/float64(n))
|
||||
fmt.Printf(" >=3 : %5d (%.1f%%)\n", ge(3), float64(ge(3))*100/float64(n))
|
||||
}
|
||||
@@ -261,21 +261,11 @@ func NewServer() http.Handler {
|
||||
for i, e := range result.Entities {
|
||||
entityNames[i] = e.Name
|
||||
}
|
||||
// 2026-11-18 图谱复活:知识形态标记(至少一条 fact 过信息密度判据 ⇒ 这是知识不是流水)。
|
||||
// 只做一次遍历,零 LLM;仅供 ZHIYI_GRAPH_KNOWLEDGE_GATE=shadow|on 使用,off 时下游不读 ⇒ 逐位等价。
|
||||
knowledgeShape := false
|
||||
for _, f := range result.Facts {
|
||||
if distill.DensityKeep(f) {
|
||||
knowledgeShape = true
|
||||
break
|
||||
}
|
||||
}
|
||||
graphUpdater.UpdateFromDistill(&governance.DistillInput{
|
||||
Content: input.Content, Facts: result.Facts,
|
||||
Entities: entityNames, Namespace: input.Namespace,
|
||||
EpisodeID: input.EpisodeID,
|
||||
Source: input.Source, // 2026-10-12 t_67d0279a 方案A:来源分档透传(auditSource 前缀归一后比对)
|
||||
KnowledgeShape: knowledgeShape,
|
||||
EpisodeID: input.EpisodeID,
|
||||
Source: input.Source, // 2026-10-12 t_67d0279a 方案A:来源分档透传(auditSource 前缀归一后比对)
|
||||
})
|
||||
|
||||
// 回写蒸馏产物到记忆库(LanceDB)
|
||||
|
||||
@@ -96,31 +96,17 @@ func (agu *AutoGraphUpdater) UpdateFromDistill(distilled *DistillInput) {
|
||||
// 本层改为「按来源类 + 内容形态」:命中来源类(过程/会话/迁移层)或纯分身会话
|
||||
// namespace → 实体/概念不写图;事实仍经同一次蒸馏进 LanceDB 记忆层(facts 照写)。
|
||||
// 判据零改动(echo_guard.go 未动),语义边界:跳过的是「进图」,不是「进记忆」。
|
||||
// 2026-11-18 知识形态门(env ZHIYI_GRAPH_KNOWLEDGE_GATE=shadow|on,默认 off ⇒ 逐位等价)。
|
||||
// 起因(实测):24h 内 §1 实体写图 59 次全被来源分档挡掉(worklog-note 43 / 空 source 15),
|
||||
// graph_nodes 的 MAX(created_at) 停在 11-16 ⇒ 图谱 2 天零新增。
|
||||
// 「只对 tier=core 建」实测不可行:蒸馏直写记忆 Tier 恒为 "normal"(api/server.go),
|
||||
// 全仓无任何写者置 core,现存 1926 条 core 全是历史 recovery 导入 ⇒ 按 tier 门等于零增量。
|
||||
// 故改用蒸馏侧已有的确定性判据 DensityKeep(信息密度三项满足 ≥2,零 LLM)作为「知识形态」:
|
||||
// shadow:行为不变,只记「若开闸会写多少」(用于观察期取数,不改任何库存);
|
||||
// on:知识形态 ⇒ 放行来源分档;§2 合成边仍由 ZHIYI_GRAPH_AUTO_SYNTH 独立控制(默认停写)。
|
||||
kgMode := strings.ToLower(strings.TrimSpace(os.Getenv("ZHIYI_GRAPH_KNOWLEDGE_GATE")))
|
||||
kgPass := kgMode == "on" && distilled.KnowledgeShape
|
||||
if kgMode == "shadow" && distilled.KnowledgeShape && len(distilled.Entities) > 0 {
|
||||
blocked := skipSourceClass(distilled.Source) || inSubAgentNamespace(distilled.Namespace)
|
||||
log.Printf("[graph][kg-shadow] ep=%s source=%q ns=%q ents=%d blocked_by_source=%v",
|
||||
distilled.EpisodeID, distilled.Source, distilled.Namespace, len(distilled.Entities), blocked)
|
||||
}
|
||||
|
||||
if !kgPass && (skipSourceClass(distilled.Source) || inSubAgentNamespace(distilled.Namespace)) {
|
||||
if skipSourceClass(distilled.Source) || inSubAgentNamespace(distilled.Namespace) {
|
||||
log.Printf("[graph] skip-entity for source=%q namespace=%q episode=%s(来源分档:实体/概念不写图,事实仍进记忆层)",
|
||||
distilled.Source, distilled.Namespace, distilled.EpisodeID)
|
||||
return
|
||||
}
|
||||
if kgPass {
|
||||
log.Printf("[graph][kg-on] pass ep=%s source=%q ns=%q ents=%d(知识形态放行来源分档)",
|
||||
distilled.EpisodeID, distilled.Source, distilled.Namespace, len(distilled.Entities))
|
||||
}
|
||||
// 2026-11-18 已退役「知识形态门」(曾试 ZHIYI_GRAPH_KNOWLEDGE_GATE=shadow|on,
|
||||
// 判据 distill.DensityKeep)。退役依据(实测,非判断):影子期 5 次命中的 source 全是
|
||||
// wiki:cron-anomaly,blocked_by_source=false —— 即门放行的全是「本来就不挡」的来源,
|
||||
// 想放行的 worklog/空 source 属过程流水,本就不该进图 ⇒ 该门零增量。
|
||||
// 同期真因查明:图谱零新增是 LLM 端点指到已退役 :11435 导致蒸馏全降级(entities=0),
|
||||
// 端点修好后图谱自然增长(11-18 单日 +34 节点),不需要额外门。
|
||||
|
||||
// 0. 密钥过滤(2026-09-10 P0,见 internal/redact):含凭证形状的实体不进图,
|
||||
// 否则实体名会被 ObsidianSync 当文件名,把密钥落成可读镜像文件
|
||||
@@ -413,11 +399,6 @@ type DistillInput struct {
|
||||
// commit 写入方 metadata.source → distill.DistillInput.Source → 本字段。
|
||||
// UpdateFromDistill 用它做来源分档:审计/工作流类来源跳过实体/概念写图。
|
||||
Source string
|
||||
// KnowledgeShape 知识形态标记(2026-11-18 图谱复活):本次蒸馏产出的 facts 中
|
||||
// 至少一条通过 distill.DensityKeep(信息密度 ≥2 项:可执行命令/路径、判据阈值、因果)。
|
||||
// 由 api 层算出并透传(governance 不 import distill,避免包循环)。
|
||||
// 只在 ZHIYI_GRAPH_KNOWLEDGE_GATE=shadow|on 时有语义;off 时整段不读 ⇒ 逐位等价。
|
||||
KnowledgeShape bool
|
||||
}
|
||||
|
||||
func entityID(name string) string {
|
||||
|
||||
Reference in New Issue
Block a user