Repository navigation
fix(memory): 切换 Embedding 或重建索引时保留会话记忆 - #96
Merged
Merged
Conversation
stanGSA
marked this pull request as ready for review
November 10, 2026 07:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
动机
用户在设置中更换 Embedding 模型或点击“更新向量索引”后,历史会话记忆会从后续训练的检索上下文中消失。
原因是
invalidateUser删除了当前用户的全部memory_vectors,而重建只恢复薄弱点、个人文档和知识库,没有恢复session_summary/insight。个人文档也会出现向量已删除、列表仍显示ready和旧分块数的状态不一致。行为变化
needs_reindex在同一 SQLite 事务内完成。失效失败时保留原模型配置;清理失败时停止后续重建。rebuilt.session_memories,同步更新契约和生成类型。设置页显示步骤错误,避免随后收到完成事件就显示“已重建”。两个已复盘会话的回归结果(模型服务使用测试替身):
readyneeds_reindex,0 分块ready验证
bun test tests-ts/memory-index-rebuild.test.ts bun run gen:api bun run check新增 17 个回归用例,使用临时画像文件、真实 SQLite 和 Hono
app.request(),无需 API Key。覆盖同维度/不同维度切换、重复重建、持久化失效状态、用户隔离、Embedding 故障、事务回滚、并发失效与删除、取消和鉴权。本地
bun run check全部通过:605 个后端/契约测试、22 个 Node 前端测试、44 个 Bun 前端测试;类型、架构边界、Web/API/桌面构建及 Electron 目录打包通过。环境为 Bun 1.4.2、Node 24.19.0、macOS arm64;lint 0 错误,41 条现有警告。重新生成 OpenAPI 与前端类型后无额外差异。兼容性与边界
rebuilt.session_memories,客户端与服务端需配套更新。weak_point继续从画像重建。last_rebuild_at保持尝试结束时间的原有语义,调用方仍需检查步骤错误和完成标志。