Commit Graph

164 Commits

Author SHA1 Message Date
小唯 4c62074a61 fix(consolidate): 按目标分组批量LLM决策,消除O(n²)调用风暴
原实现每对高相似记忆调一次LLM → limit=100产生4950对 → 223s+未完成
→ 每天processed=0(非namespace过滤bug)。改为: 外层目标i,内层收集
全部高相似候选,每目标一次LLM(UpdatePrompt原生支持多候选)。

验证: limit=20 → 4.3s返回 processed=1 updated=1; limit=100 2min(受
llama单slot排队限制)对每日低频可用。
2026-09-06 00:32:27 +08:00
小唯 0881b9c05f fix(softdelete): 单独应用 SoftDelete 持久化修复(506f76b+SoftDelete only, 不含 lancedb_scan 风暴代码)
febc2c9 提取仅 SoftDelete 部分: updateField 提升包级 + SoftDelete 调
lancedb_update 持久化 is_deleted=true。跳过 GetCandidatesForForgetting 全表
扫描改动(有 620% CPU 风暴 bug, 待修复后另部署)。

验证: DELETE scratch2-1788616361067 → [ipc]SoftDelete persisted → 查询0条
→ 重启后仍0条(持久化成功)。
2026-09-06 00:23:23 +08:00
xiaowei 506f76bd00 fix(hermes-plugin): memory_feedback 闭环 — prefetch/memory_search 输出带 memory_id,system prompt 引导标记有用/无用 2026-09-05 21:44:08 +08:00
xiaowei 8356480541 fix(consolidate): eps 1.0->0.4 修复 DBSCAN 聚类失效 (clusters=1->34)
根因: bge-m3 向量已归一化(norm=1.0, 距离 p50=0.42-0.75), 旧 eps=1.0 按未归一化数据(p50=1.029)调试,
在归一化空间过大 -> 全部连成1簇 -> consolidate 空转多日 (clusters=1 error 每15min刷)

实测: eps=0.4 -> clusters=34 noise=1030, 能发现重复状态噪音簇(1045条主profile状态同步/961条CBM状态)
2026-09-05 18:13:53 +08:00
xiaowei 28a3d4f6b8 fix(hermes-plugin): 在正本基础上加 conflicts 解析(保留 prefetch/social 功能,勿用部署副本整体覆盖)
前一版 6fa2d9b 误用旧部署副本覆盖正本(41469B→35801B),丢了 _is_social_close/_prefetch_cache/prefetch()。已恢复正本(checkout HEAD~1)后重新应用:
- ZhiYiClient.__init__ 加 _last_conflicts
- commit() 成功时捕获 conflicts
- _tool_memory_write 检出冲突返回 warning(不静默)
2026-09-04 01:35:31 +08:00
xiaowei 6fa2d9b892 fix(hermes-plugin): commit 解析 conflicts 字段返回 warning(同步部署副本 d520a9091)
zhiyid DetectContradiction 检出矛盾后 conflicts 只放响应,插件 commit() 只取 id 忽略
→ 冲突记忆静默进 episodes→蒸馏→污染长期记忆
现在:_last_conflicts 记录 + _tool_memory_write 返回 conflicts/warning 给 agent 感知
2026-09-04 01:33:41 +08:00
xiaowei 63f123417b fix(distill): commit 检出冲突时不进自动蒸馏(conflict guard)
问题:commit 的 DetectContradiction 检出矛盾后只返回 conflicts 字段,
内容仍进 episodes→自动蒸馏→污染 distilled/memories(TencentDB 误判案例根因链一环)

修复:conflicts>0 时跳过 AutoDistillTrigger,返回 distill_skipped=conflict;
处理路径:①写错→feedback not_useful;②旧记忆错→feedback 降权;
③确认为修正→resolve_conflict=true 重 commit(待客户端支持)

验证:commit 矛盾内容 → conflicts 返回 + distill_skipped=conflict 
2026-09-04 01:29:11 +08:00
xiaowei ae73982743 fix(distill): max_tokens 800→1200 — Agnes推理token预算不足
Agnes 2.0-flash是推理模型,推理token占大量预算。
800仍不够→JSON截断(parse error: unexpected end of JSON input)。
1200确保推理+正文都够用。
2026-08-20 01:13:06 +08:00
xiaowei ea4b5a4dfe fix(distill): max_tokens 600→800 — Agnes推理模型JSON不再截断
engine.go: max_tokens 600→800
consolidate.go: max_tokens 300→800
根因: Agnes 2.0-flash是推理模型,max_tokens=600里大量是推理token,
正文只剩~300→JSON截断→parse error→蒸馏退化。
800确保推理+正文都够用。
2026-08-20 00:10:51 +08:00
小唯 38701748d1 feat(distill): P4 AAAK压缩索引 + P5 Markdown导出层
P4: 借鉴 mempalace AAAK dialect — 每条事实生成紧凑索引(实体|关键词|权重|类型)
P5: 借鉴 EverOS md真相层 — /api/v1/memories/export 导出人可读 Markdown
2026-08-12 01:37:27 +08:00
小唯 82c3d25423 feat(distill): P2 离线整合(UPDATE_PROMPT) + P3 双缓冲(token积累) + JSON健壮剥离修复
- P2: consolidate.go 新增 ConsolidateMemory + TextSimilarity,LLM三选一(update/delete/ignore)合并相似记忆
- P2: server.go 新增 POST /api/v1/consolidate/memory 手动触发端点
- P3: engine.go Enqueue 按 token 积累触发 flush(阈值2000),batchTimeout兜底
- fix: LLM JSON 剥离增强(找首个{和最后}截取),修复模型返回markdown/注释导致的parse error
2026-08-11 21:38:10 +08:00
小唯 0734ffaa5a feat(distill): LightMem式逐条事实提取 prompt(P1)— 从整段摘要升级为逐条独立事实,保留全部实体细节+时间区分+推断隐含信息 2026-08-11 17:51:08 +08:00
小唯 11162e2f60 fix: consolidation 风暴 — distill cooldown 60s→15min, cluster_only 跳过 PageRank
- triggers.go: TriggerDistill cooldown time.Minute → 15 * time.Minute
- consolidation_pipe.go: runGraphMaintenance 仅 full 模式执行(cluster_only 高频快速聚类跳过重负载 PageRank)
- 修复 zhiyid CPU 80-90% 风暴、recall API 120s+ 超时

根因:t_distill 每 60s 触发全量 DBSCAN + PageRank(10356 nodes),数据量大时单次 30-60s CPU 堆积
2026-08-10 01:21:57 +08:00
xiaowei 98e541b985 fix: distill LLM 模型切换 gemma-4-31b-it + JSON 解析增强
根因链:
1. gpt-oss-120b 是 reasoning 模型,content=null 答案全在 reasoning 字段,
   代码只读 content/reasoning_content(OpenAI 用 reasoning 字段名)→ parse 失败
   → 永远降级 keyword 提取 (facts=1 entities=0)
2. skill 记载的 m3/m2.7/mistral-large 均已 EOL 或渠道失效 (2026-07-27 后)
3. gemma-4-31b-it 对 '0.X' 占位符输出 0.0 → prompt 改为明确 0-1 浮点说明

修复:
- engine.go: 支持 reasoning 字段 + 剥离 markdown code fence + prompt 评分说明明确化
- zhiyid.service: LLM_MODEL=google/gemma-4-31b-it

验证: LLM entities=2, overall=1.000, facts=3 entities=2, recall 命中 0.765
2026-08-02 23:59:29 +08:00
xiaowei 21bc777430 fix: episodes 持久化到 LanceDB(重启不再清零)
根因: RustLanceDBClient.InsertEpisode 只写进程内存 _local.episodes,
从未持久化;Stats 的 total_episodes 用内存值覆盖 Rust 真实计数。

修复:
- InsertEpisode 增加 IPC 写入 LanceDB episodes 表(24 字段完整 schema)
- Stats 优先用 Rust sidecar 返回的 episodes 计数,缺失才回退内存
- 持久化失败只记日志不阻断请求(保持'总是写入'语义)

验证: 提交测试 episode → stats episodes=1 → 重启 zhiyid → 仍为 1
历史 45 条内存 episodes 已随重启丢失(原始日志,蒸馏结果在 memories 5063 条保留)
2026-08-02 23:41:37 +08:00
小唯 6f9361f4e9 docs: 更新 README — 4个项目关系图 + TencentDB + Soulful 2026-07-20 15:58:54 +08:00
小唯 4e17b8cb98 docs: 说明与 xiaowei-system 的关系和安装顺序
- 明确织忆是底层基础设施,xiaowei-system 是上层应用
- 安装顺序:先织忆,再小唯系统
- 加 API 调用示例
2026-07-20 15:50:07 +08:00
小唯 c4d17df71c fix: Phase D/G/H 编译修复
- governance.go: 加 PendingCount() 方法给 ConflictsPending metrics
- distill/: 删 consolidation.go(死代码,231行无引用)
- scripts/: backup.sh 加7天保留策略 + restore.sh 恢复脚本
2026-07-10 05:10:12 +08:00
小唯 d524fd741b docs: 分身速通卡(rag-skill集成+100%自动化管道说明) 2026-07-08 15:20:47 +08:00
小唯 707903dee7 docs: 织忆v3.9+rag-skill 项目复盘报告(全自动化管道产出) 2026-07-08 12:58:14 +08:00
小唯 1970fb4f06 feat: 织忆+rag-skill深度检索模式 + 07-Wiki全目录索引
Phase 3: Hermes 插件深度检索
- prefetch() 新增 depth='deep' 参数
- depth=deep: 织忆语义搜索后,异步触发本地文件渐进检索
- 结果标记 [rag-skill File — local Wiki evidence]
- 缓存 TTL 60s,支持双轮(第一轮触发,第二轮拿缓存)
- depth='fast' 默认行为完全不变

Phase 4: 07-Wiki 目录索引补全
- docs/07-Wiki-index/: 织忆同步(1039files)、织忆图谱(299files)、经证同步(29files)
- docs/memory-index/: 记忆顶层 + 织忆进度快照
2026-07-08 12:42:17 +08:00
小唯 25a1bb52dc docs: 织忆系统功能用法说明(v3.9全功能速查) 2026-07-08 12:26:49 +08:00
小唯 25151bfda2 fix: three-way-check.sh — add X-API-Key to zhiyid endpoint check, replace *** placeholder 2026-07-08 12:26:28 +08:00
小唯 8ca3ca0497 feat: 织忆系统全面推 Gitea v3.9
新增:
- cli-anything/ — 命令行伴侣
- docs/ — v3.8设计文档、v3.9 rag-skill补充设计、实施计划、进度快照、data_structure.md索引
- skills/ — zhiyi技能(SKILL.md+scripts+references)、rag-progressive-search渐进检索技能
- scripts/ — 更新wiki_curator.py(中文版)、新增three-way-check.sh、verify-gitea-deploy.sh

变更:
- scripts/wiki_curator.py — 更新为中文说明版
- README.md — 已完成(ca37de9)

功能覆盖:
- P0 Recall降级策略 / P1 自动注入 / P2 信任评分
- P3 CREATIVE.md / P4 Ground Truth / P5 Wiki策展
- H1 BM25融合 / H2 LLM策展 / H3自动信任 / H4 diversity / H5三模式 / H6多级存储
- rag-skill渐进式检索集成(分层索引+渐进检索+先学再做)
2026-07-08 12:24:39 +08:00
小唯 ca37de93b6 docs: 重写 README.md — 完整项目说明(架构图/特性清单/API速查表/目录结构) 2026-07-08 12:23:56 +08:00
小唯 51aa9de939 fix: robust auto-start after reboot
- Moved bge_embed_server.py to ~/.hermes/scripts/ (persistent)
- Moved Rust sidecar binary to ~/bin/zhiyi-consolidate (persistent)
- zhiyid.service: After=zhiyi-consolidate bge-embed (start ordering)
- All services: enabled + Linger=yes → auto-start on boot
- ExecStartPre fallback: re-copy from Gitea clone if file missing
2026-07-02 01:05:24 +08:00
小唯 c86f5bc304 fix: NewAPI key strip sk- prefix + LLM wiki graceful fallback 2026-07-02 01:00:23 +08:00
小唯 57ac628b3f fix: H1-H6 gaps all resolved
H1: BM25 keyword scoring in recall pipeline (0.7 vector + 0.3 keyword)
H2: LLM wiki curation mode (--llm flag, graceful heuristic fallback)
H3: Auto trust score update after each recall call
H4: Default diversity=0.3 (was 0 = no diversity)
H5: Three search modes: hybrid(semantic+BM25) / keyword / semantic
H6: Multi-tier fallback already covered by P0 + SQLiteClient

All verified: hybrid(0.962), keyword(1.000), semantic(0.962)
2026-07-02 00:43:46 +08:00
小唯 db3d3d8e85 docs: P3-P5 implementation plans + skill update 2026-07-02 00:30:43 +08:00
小唯 7fabc58bf3 feat: P3 CREATIVE.md isolation + P4 Ground Truth prompt + P5 Wiki curator
P3: Created ~/.hermes/CREATIVE.md for 织忆 working memory.
Updated plugin system_prompt_block() to load CREATIVE.md as [织忆 工作记忆].

P4: Added Ground Truth hierarchy (4 levels), Context injection convention,
and Memory feedback rule to SOUL.md. Injected [织忆] memory now
explicitly takes priority level 2.

P5: Created wiki_curator.py — scans .md files, extracts concepts/entities/
relations via heuristic, writes to 织忆 via /commit + /graph/edge APIs.
Includes dry-run, force, state tracking, skip rules.
2026-07-02 00:29:47 +08:00
小唯 f4313a40ef docs: add implementation plans for P0/P1/P2 features 2026-07-02 00:23:04 +08:00
小唯 5e24646600 feat: P1 auto-injection hook with social close detection
- queue_prefetch now caches next-turn recall results asynchronously
- Social closer detection skips trivial messages (ok, thanks, emoji)
- prefetch uses cached queue results when available (TTL 30s)
- Output header changed to [织忆 Memory] for source clarity
2026-07-02 00:22:43 +08:00
小唯 72cbf73583 feat: P0 recall fallback + P2 trust scoring for graph edges
P0: When bge-embed/IPC recall fails, fall back to graph.db keyword search (FallbackTextSearch) instead of 500 error. Response includes X-Fallback: graph header.

P2: Add trust_score, retrieval_count, helpful_count columns to graph_edges table. New POST /api/v1/graph/edge/feedback endpoint. UpdateEdgeTrustScores batch calculation.
2026-07-02 00:22:28 +08:00
小唯 fa0eb004a8 docs: add Memory-OS 7-layer comparison with source code analysis (2026-07-01) 2026-07-01 23:53:34 +08:00
小唯 dc8d074cf5 fix: 6 Go code quality fixes + 4 plugin bug fixes 2026-06-20 16:51:13 +08:00
小唯 12c4c58c1c fix: re-enable /api/v1/memories list endpoint (via AdminAPI) 2026-06-20 16:24:52 +08:00
小唯 23c6547503 perf: add graph navigate cache (TTL 5min, 500 entries) + cache invalidation + cache stats API
- NewCachedGraphStore: governance.GraphStore wrapper, only Navigate() is cached
- GraphCacheRef: expose InvalidateAll() + Stats() for cache management
- Cache invalidation on graph/edge add, graph/cleanup (non-dry-run)
- New /api/v1/cache/stats endpoint for cache monitoring
- /api/v1/health now registered at /api/v1/health path too
- normalizeEntity: preserve Unicode letters (Chinese chars not stripped)
2026-06-16 18:09:51 +08:00
小唯 d6188a2bd7 fix: health endpoint + graph/edge API + normalizeEntity Chinese + nl_query comparison
1. Add /api/v1/health endpoint (maps to HandleHealth)
2. Add POST /api/v1/graph/edge for adding relation edges
3. Fix normalizeEntity to preserve Chinese characters (0x4e00-0x9fa5)
4. Fix nl_query direct_path comparison to use normalizeEntity on both sides
2026-06-16 16:16:35 +08:00
小唯 bd8008b3fd fix: comment out api.ListMemories (removed from routes) 2026-06-15 18:34:12 +08:00
小唯 a76b6d3afa feat(graph): add graph cleanup + nl_query + navigate grouped format
- Add CleanupNoiseNodes() to GraphStore interface + SQLiteGraphStore impl
- Add /api/v1/graph/cleanup endpoint (dry_run + execute)
- Add /api/v1/graph/nl_query endpoint for natural language graph queries
- Improve /api/v1/graph/navigate: add grouped_by_relation, suggestions, normalized_entity
- Add CleanupNoiseNodes stubs to InMemoryGraph and FileGraph

BREAKING: navigate response now includes grouped_by_relation and suggestions
2026-06-15 18:09:27 +08:00
小唯 79b994ce4b feat: add memory_graph_navigate and memory_graph_stats tools (v1.1.0)
- Add graph_navigate() and graph_stats() to ZhiYiClient
- Add memory_graph_navigate tool: N-hop knowledge graph navigation
- Add memory_graph_stats tool: graph statistics (nodes/edges/density)
- Update system prompt to list all available tools
- Bump version 1.0.0 -> 1.1.0
2026-06-15 17:28:16 +08:00
小唯 b9f9f75c31 fix: IsContradiction typo in bench_test.go 2026-06-15 11:08:13 +08:00
小唯 8ad4a7c794 feat: add freshness field to memory lifecycle
- server.go: set freshness='fresh' when distill creates new memory
- recall.go: set freshness='verified' when memory is recalled
- Freshness values: fresh (new), verified (recalled), stale (decayed)
2026-06-15 10:39:15 +08:00
xiaowei 42a8aeb53c api/server: only record distill_loss when Overall>0, exclude fallback pollution 2026-06-12 11:43:05 +08:00
xiaowei cf31ff5e8e api: add /api/v1/metrics endpoint exposing Dashboard metrics (avg_distill_loss, etc.) 2026-06-12 08:54:00 +08:00
xiaowei 90c43c0717 fix(distill): increase HTTP client timeout 30s→120s for LLM calls 2026-06-11 10:39:07 +08:00
xiaowei c3db6ffe30 feat(backup): add standalone backup script, deprecate Go API route 2026-06-10 10:19:55 +08:00
xiaowei b237cc9aeb fix(backup): add 5min timeout to tar, fix comment 2026-06-10 10:16:49 +08:00
xiaowei 2c96f805f4 fix: consolidate trigger uses full mode instead of cluster_only
Problem: server.go 30s ticker loop called consolPipe.Run() which
defaults to cluster_only mode. The 'consolidation' and 'backtrack'
actions never executed prune/decay/quality steps.

Fix:
- Separate 'distill' action (keeps cluster_only for fast frequent runs)
- 'consolidation' and 'backtrack' now call RunWithMode(full)
- selfoptimize.Flow.Register('consolidate') also uses RunWithMode('full')
- Proper case indentation (4 tabs for labels, 5 for bodies)

Result: prune + decay + quality steps now run when t_consolidation
or t_backtrack fires (48h cooldown protects against over-firing)
2026-06-09 12:45:33 +08:00
xiaowei ffee97032e docs: save DESIGN-v2-llm-optimizer.md (parked, not implementing yet) 2026-06-08 11:16:54 +08:00