feat: 检索正确性修复 + 情境化 SupportInfo — 适配 master 架构#161
feat: 检索正确性修复 + 情境化 SupportInfo — 适配 master 架构#161398618101 wants to merge 4 commits intoCortexReach:masterfrom
Conversation
…urce typing
- store.ts: add .distanceType('cosine') to vectorSearch (critical: L2 default drops valid results)
- store.ts: add getFtsStatus(), rebuildFtsIndex() for BM25 health diagnostics
- retriever.ts: extend source typing with 'cli' for CLI trace distinction
- cli.ts: mark CLI retrievals with source='cli', add reindex-fts command
- test: add vector-search-cosine.test.mjs (4 tests)
…ce tracking Extends OpenViking's smart memory architecture with context-aware support: - smart-metadata.ts: add SupportInfoV2/ContextualSupport types, normalizeContext, parseSupportInfo (V1→V2 migration), updateSupportStats; fix LegacyStoreCategory missing 'reflection' - memory-categories.ts: extend DedupDecision with support/contextualize/contradict, add contextLabel to DedupResult, supported count to ExtractionStats - extraction-prompts.ts: extend dedup prompt with 3 new decisions + context_label - smart-extractor.ts: add handleSupport/handleContextualize/handleContradict handlers in processCandidate pipeline, extract contextLabel in llmDedupDecision - test: add smart-metadata-v2.mjs (6 tests, all passing)
- smart-extractor.ts: handleMerge now accepts contextLabel and updates support stats after successful merge (aligns with support/contextualize/ contradict handlers) - smart-metadata.ts: stringifySmartMetadata caps arrays to prevent JSON bloat (sources≤20, history≤50, relations≤16) - test/context-support-e2e.mjs: 3 E2E scenarios testing support, contextualize, and contradict decisions end-to-end
AliceLJY
left a comment
There was a problem hiding this comment.
Review 结论:fix-then-merge
这版比 #160 收敛很多,基线改对了(master),9 文件 +704/-47,不动 index.ts 不动 config schema,零兼容性风险。cosine fix 是真实 bug 修复,contextual support 方向也对。
阻塞项
1. 新增测试没有纳入默认回归链
test/smart-metadata-v2.mjs 和 test/vector-search-cosine.test.mjs 没有挂进 package.json:38 的 npm test。如果这两个测试是这次修复的核心证据,它们应该进入默认测试链,否则 CI 不能持续保护这次改动。
2. smart-metadata-v2.mjs 没有真正测试生产代码
test/smart-metadata-v2.mjs:12 直接在测试文件里 inline 重写了逻辑,而不是 import src/smart-metadata.ts。这类测试更像文档/示意,不是有效回归测试。
3. vector-search-cosine.test.mjs 也没有真正绑定生产实现
test/vector-search-cosine.test.mjs:58 用的是自造 fakeStore.vectorSearch(),没有直接约束 src/store.ts:418 里的真实实现路径。建议至少 import 真实 MemoryStore 或围绕真实对象做更接近生产代码的测试。
建议修复项
4. context taxonomy 里"下午"映射成 evening 不够准确
见 src/smart-metadata.ts:280。词表缺 afternoon,建议补上或明确说明归并理由。
5. parseSupportInfo 对 slice 数值字段缺少校验
见 src/smart-metadata.ts:308。目前只过滤了 context 是否是字符串,没有校验 confirmations、contradictions、strength、last_observed_at 的类型和范围。
6. slice 截断后总证据量可能长期漂移
见 src/smart-metadata.ts:364。现在只把"本次被截掉的 slice"计入汇总,但更早历史上被丢掉的证据没有持久化保存,后续更新时 total_observations/global_strength 可能逐步失真。
7. dropIndex() 静默吞错
见 src/store.ts:975。建议至少记录 warning,把 index 名和错误信息带出来。
补充说明
当前分支 npm test 会红在 test/smart-extractor-branches.mjs,这不是 #161 新增问题,是 master 上已有的 LLM 依赖型 flaky test。
Blocking: 1. Add smart-metadata-v2, vector-search-cosine, context-support-e2e to npm test chain (package.json) 2. Rewrite smart-metadata-v2.mjs to import production code via jiti (normalizeContext, parseSupportInfo, updateSupportStats, etc.) 3. Rewrite vector-search-cosine.test.mjs to use real MemoryStore against temp LanceDB (no more fakeStore) Suggestions: 4. Fix '下午' mapping: evening → afternoon (add to vocabulary) 5. parseSupportInfo: validate slice numeric fields (confirmations, contradictions, strength, last_observed_at) 6. Document slice truncation drift as accepted trade-off 7. dropIndex: log warning instead of silently swallowing errors
|
已调整 |
AliceLJY
left a comment
There was a problem hiding this comment.
验证通过。修复 commit da12b2c 逐条对应了 review 的 7 条反馈:
- 3 个阻塞项全部实质性修复(测试接入 npm test、import 生产代码、真实 MemoryStore 替代 fakeStore)
- 4 个建议项全部落实(下午→afternoon、slice 字段校验、漂移注释、dropIndex warn)
- 新增 14 个用例全部通过
npm test 唯一失败的 smart-extractor-branches.mjs:291 是 master 已有的 LLM flaky test,不是本 PR 问题。
概述
本 PR 整合了原先针对
main分支的两项改进(#80 检索正确性、#160 情境化 SupportInfo),重写适配到master分支的 OpenViking 三层架构(L0/L1/L2 + tier + decay),不修改 OpenViking 的核心结构。一、检索正确性修复
在不改变 memory schema 和 Smart Memory lifecycle 的前提下,修复向量搜索正确性并补充 FTS 诊断能力。
1. 修复向量搜索正确性 (
src/store.ts)vectorSearch()显式设置.distanceType('cosine')minScore阈值错误过滤2. FTS 诊断 (
src/store.ts)lastFtsError、getFtsStatus()、rebuildFtsIndex()3. CLI 诊断 (
cli.ts)source: "cli"reindex-fts命令4. 遥测来源 (
src/retriever.ts)"cli"回归测试
test/vector-search-cosine.test.mjs(4 个用例全部通过)二、情境化 SupportInfo
将
SupportInfo从全局标量升级为按上下文切片(ContextualSupport[])记录偏好证据,实现情境化记忆。LLM 在 dedup 阶段输出context_label,通过写入链路传递到updateSupportStats,使系统能够区分"晚上偏茶"和"总体喜欢拿铁"这类情境化偏好。Schema 升级 (
src/smart-metadata.ts)SupportInfo→{global_strength, total_observations, slices: ContextualSupport[]}SUPPORT_CONTEXT_VOCABULARY(11 个标签)normalizeContext()归一化(中英文映射,如"晚上"→"evening")MAX_SUPPORT_SLICES = 8防膨胀parseSupportInfoV1→V2 向后兼容(自动迁移为general切片)LegacyStoreCategory缺少reflection的类型错误写侧 Runtime 传递
src/extraction-prompts.ts:dedup prompt 输出context_label+ 词表规则src/memory-categories.ts:DedupResult增加contextLabel字段;DedupDecision扩展support/contextualize/contradictsrc/smart-extractor.ts:processCandidate新增 3 个 case 分支;新增handleSupport/handleContextualize/handleContradicthandler6 种 Dedup 决策
createmergeskipsupportsupport_info统计(按上下文分片),不创建新条目contextualizecontext_labelcontradict回归测试
test/smart-metadata-v2.mjs(6 个用例全部通过)三、与 OpenViking 架构的协作关系
当前 master 架构概览
master 分支采用 OpenViking 三层架构,核心模块包括:
本 PR 与各模块的互补关系
具体互补点
MemoryStore.vectorSearch,DecayEngine 和 TierManager 依赖的vectorSearch同时受益,检索准确度提升store.update()更新 metadata,不创建新条目,不触发 TierManager 晋升storeCandidate创建新条目(与 create 相同路径),新条目自动获得 L0/L1/L2 metadata 和 tier 分配,DecayEngine 正常管理store.update()(更新原记忆的矛盾证据)和storeCandidate(创建新条目),两步均走已有路径SmartMemoryMetadata的可选字段,存储在[key: string]: unknown索引签名中,与 L0/L1/L2 字段并列但互不干涉不涉及 / 不修改的模块
decay-engine.ts— 未修改,衰减逻辑不变tier-manager.ts— 未修改,层级晋升/降级不变access-tracker.ts— 未修改,访问追踪不变reflection-store.ts— 未修改,反思记忆生成不变noise-prototypes.ts— 未修改,噪声检测不变index.ts— 未修改,auto-capture/auto-recall 流程不变四、兼容性评估
✅ 完全兼容
support_info字段 →parseSupportInfo返回默认值(strength=0.5),正常读写{confirmations, contradictions}→ 自动转为 V2{slices: [{context:"general",...}]}LegacyStoreCategory缺少reflection的 TS 错误(master 预存类型不一致)store()/update()接口签名不变,新字段通过 metadata JSON 透传vectorSearch()/hybridSearch()返回类型不变,cosine 修复只影响内部距离计算support/contextualize/contradict,这些是 VALID_DECISIONS 扩展create(现有保护机制)❌ 不存在的不兼容
设计决策
Out of Scope
统计