@restregular/dsh-memory 0.13.0 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,32 @@
2
2
 
3
3
  本项目的版本记录。安装 id 与 npm 版本一一对应。
4
4
 
5
+ ## 0.13.2 — 修复检索分数全部相同
6
+
7
+ - **根因**:`search()` 组装最终分数时写成了 `c.id`,而候选对象只有 `c.record`,于是所有候选都落到
8
+ `finalScores` 的同一个 `undefined` 键上 —— 每条命中拿到的都是**最后一个候选**的分数。召回顺序
9
+ 一直是对的(排序用的是 `shape`),所以只有分数是错的:工具返回的 `score`、记录页语义检索的
10
+ 「得分」全都一样。
11
+ - 同一处 `c.id` 还让传给 LLM 重排的候选 id 全变成 `undefined`,重排永远匹配不上;另外重排成功后
12
+ 只改了分数、没有重排数组,即使匹配上也不会改变结果顺序。现在两处都修好:候选用
13
+ `c.record.id`,重排成功后按混合分数重新排序(无重排时该排序与原顺序完全一致)。
14
+ - 记录页结果卡的「相关度」改名为「得分」:这是排序分(向量/词法命中 × 重要度 × 时效 × 访问次数),
15
+ 不是 0~1 的概率,访问次数多时可能大于 1;结果顺序与它一致。
16
+ - 回归测试(`search-scores.test.ts`):只有重要度不同的两条记录必须拿到不同分数(≈0.95 / ≈0.60);
17
+ 重排 prompt 必须包含真实 record id,且重排能把结果顺序翻转(混合分 ≈0.84)。
18
+
19
+ ## 0.13.1 — 语义检索改成 toggle 开关
20
+
21
+ - 记录页的「语义检索」从普通文字按钮改成真正的 **toggle 开关**:轨道 + 圆点 + 可见的
22
+ 「已开启 / 已关闭」,`role="switch"` + `aria-checked`,不再只靠按钮高亮表示状态。
23
+ - 造型与「向量服务」开关完全一致,配色全部走宿主主题 token:关闭态轨道 `--dsw-alias-border-l3`
24
+ (不是几乎透明的 border-l1)、圆点 `--dsw-alias-switch-thumb`;开启态轨道
25
+ `--dsw-alias-brand-primary`、圆点 `--dsw-alias-label-primary-foreground`。深色主题下
26
+ 轨道与圆点都有足够对比度,没有写死任何色值。
27
+ - 向量未配置时开关保持可见但禁用(半透明、轨道仍可辨认),`aria-checked` 仍如实报告 `false`。
28
+ - 测试补充:语义控件必须是 `role="switch"`、含 `toggle-track` / `toggle-knob`、开启态带 `.on`,
29
+ 状态文案随开关变化;并断言开关文字颜色来自主题 token、不含硬编码色值。
30
+
5
31
  ## 0.13.0 — 记录页语义检索与测试内存修复
6
32
 
7
33
  - **记录页可以主动做语义检索**:搜索框旁边新增「语义检索」开关。开启后搜索不再做关键词过滤,
package/README.md CHANGED
@@ -56,6 +56,8 @@ JSONL 落盘 · 本机向量检索 · 五个模型工具 · 自动召回 · 硬
56
56
 
57
57
  - 开关只在向量后端已配置时可用;没装后端时保持禁用并说明原因。
58
58
  - 语义检索是**只读浏览**:不增加访问计数,不会把 `memory_search` 后续的排序带偏。
59
+ - 结果卡上的「得分」是**排序分**(向量/词法命中 × 重要度 × 时效 × 访问次数),不是概率,
60
+ 访问次数多时可能大于 1;结果顺序与这个分数一致。
59
61
  - 结果说明会如实写出这次是「语义排序」还是「关键词回退」:例如记录还没嵌入向量、或向量服务
60
62
  没有响应时,不会把词法结果冒充成语义结果。嵌入完成后列表会自动刷新成语义结果。
61
63
  - 作用域下拉与新建 / 编辑 / 删除仍然照常工作;从审计页点记忆 ID 跳过来时会自动回到普通列表并展开该条。
package/lib/client.js CHANGED
@@ -104,9 +104,13 @@ window.__ModuleLoader__.load({
104
104
  '.memp .editrow input[type=number]{width:64px;padding:4px 8px}',
105
105
  '.memp .err{color:var(--dsw-alias-label-danger, #e05555);font-size:12px}',
106
106
  '.memp .empty{color:var(--dsw-alias-label-secondary);font-size:12.5px;padding:16px 2px;text-align:center}',
107
- // 语义检索:搜索框旁的开关 + 结果说明行 + 结果卡上的相关度
108
- '.memp .toolbar .semantic{flex:none}',
109
- '.memp .toolbar .semantic.on{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary);background:color-mix(in srgb,var(--dsw-alias-brand-primary) 10%,transparent)}',
107
+ // 语义检索:搜索框旁的 toggle(轨道 + 圆点,沿用 .toggle 的宿主 token 配色,
108
+ // 深浅色都由 --dsw-alias-switch-thumb / brand-primary / label-primary-foreground
109
+ // 决定,不再写死颜色)+ 结果说明行 + 结果卡上的排序得分
110
+ '.memp .toolbar .semantic{flex:none;padding:4px 10px 4px 5px}',
111
+ '.memp .toolbar .semantic-label{font-size:12px;line-height:1.6}',
112
+ '.memp .toolbar .semantic-state{font-size:11px;color:var(--dsw-alias-label-secondary)}',
113
+ '.memp .toolbar .semantic.on .semantic-state{color:var(--dsw-alias-brand-primary)}',
110
114
  '.memp .search-note{display:flex;flex-wrap:wrap;align-items:center;gap:4px 10px;font-size:11.5px;line-height:1.55;color:var(--dsw-alias-label-secondary)}',
111
115
  '.memp .search-note b{font-weight:600;color:var(--dsw-alias-label-primary)}',
112
116
  '.memp .search-note .muted{font-size:11.5px}',
@@ -804,8 +808,10 @@ window.__ModuleLoader__.load({
804
808
  score !== null && score !== undefined && Number.isFinite(Number(score))
805
809
  ? h('span', {
806
810
  className: 'badge score',
807
- title: '检索得分:向量相似度 / 词法命中,再按时效与重要度加权后的排序分',
808
- }, `相关度 ${Number(score).toFixed(2)}`)
811
+ // 这是**排序分**,不是概率:向量/词法命中 × 重要度 × 时效 × 访问次数加权,
812
+ // 访问次数多时可能大于 1。叫「相关度」会让人误以为一定在 0~1 之间。
813
+ title: '检索得分 = 向量/词法命中 × 重要度 × 时效 × 访问次数;只用于结果排序,可能大于 1',
814
+ }, `得分 ${Number(score).toFixed(2)}`)
809
815
  : null,
810
816
  rec.supersedes
811
817
  ? h('span', {
@@ -3078,10 +3084,14 @@ window.__ModuleLoader__.load({
3078
3084
  onChange: (e) => setQ(e.target.value),
3079
3085
  onKeyDown: (e) => { if (e.key === 'Enter') load(q, scopeFilter) },
3080
3086
  }),
3081
- // 语义检索开关:向量没启用时保持可读但不许点(点开只会给出词法结果,容易误解)。
3087
+ // 语义检索开关:与「向量服务」同一套 toggle(轨道 + 圆点)。轨道/圆点/文字颜色
3088
+ // 全部走宿主 token,深色主题下关闭态轨道用 border-l3、圆点用 switch-thumb,
3089
+ // 开启态轨道用 brand-primary、圆点用 label-primary-foreground。
3082
3090
  h('button', {
3083
- className: 'semantic' + (semantic ? ' on' : ''),
3084
- 'aria-pressed': semantic,
3091
+ type: 'button',
3092
+ className: 'toggle semantic' + (semantic ? ' on' : ''),
3093
+ role: 'switch',
3094
+ 'aria-checked': semantic,
3085
3095
  disabled: !(configured && vectorEnabled),
3086
3096
  title: configured && vectorEnabled
3087
3097
  ? (semantic ? '语义检索已开启:按语义相似度排序,点击切回关键词过滤' : '按语义相似度检索(向量 + 词法;未命中时结果会标注已回退)')
@@ -3092,7 +3102,11 @@ window.__ModuleLoader__.load({
3092
3102
  // 已经有查询词时立刻按新模式重跑一次,不用再敲回车。
3093
3103
  if (q.trim() !== '') load(q, scopeFilter, next)
3094
3104
  },
3095
- }, '语义检索'),
3105
+ },
3106
+ h('span', { className: 'toggle-track' }, h('span', { className: 'toggle-knob' })),
3107
+ h('span', { className: 'semantic-label' }, '语义检索'),
3108
+ h('span', { className: 'semantic-state' }, semantic ? '已开启' : '已关闭'),
3109
+ ),
3096
3110
  // 作用域也用同一个自绘下拉(与模型/运行时统一);标签优先用服务端给的 label
3097
3111
  h(Dropdown, {
3098
3112
  items: [
@@ -1574,10 +1574,13 @@ export class LocalMemoryService {
1574
1574
  .slice(0, recallN)
1575
1575
 
1576
1576
  // --- channel 3: LLM rerank (optional; any skip/failure keeps recall order) ---
1577
- const finalScores = new Map (ranked.map((c) => [c.id, shape(c)]))
1577
+ // 键必须是 **record.id**。这里曾经写成 `c.id`(Cand 上没有 id 字段),所有候选都落到
1578
+ // 同一个 `undefined` 键上:排序数组本身是对的,但每条命中拿到的都是最后一个候选的
1579
+ // 分数(面板上表现为「每条相关度都一样」),重排的候选 id 也全成了 undefined。
1580
+ const finalScores = new Map (ranked.map((c) => [c.record.id, shape(c)]))
1578
1581
  if (this.cfg.llm.enabled && this.llmInvoke && ranked.length >= 2) {
1579
- const asCands = ranked.map((c) => ({ id: c.id, content: c.record.content, recallScore: finalScores.get(c.id) }))
1580
- const cacheKey = RerankCache.key(query.text, ranked.map((c) => c.id), this.cfg.llm.model)
1582
+ const asCands = ranked.map((c) => ({ id: c.record.id, content: c.record.content, recallScore: finalScores.get(c.record.id) }))
1583
+ const cacheKey = RerankCache.key(query.text, ranked.map((c) => c.record.id), this.cfg.llm.model)
1581
1584
  let outcome = this.rerankCache.get(cacheKey)
1582
1585
  if (!outcome) {
1583
1586
  outcome = await rerank({
@@ -1595,11 +1598,16 @@ export class LocalMemoryService {
1595
1598
  finalScores.set(id, score)
1596
1599
  }
1597
1600
  }
1601
+ // 重排必须能改变顺序,否则它只改了显示分数、召回序列原样输出。没有重排时
1602
+ // finalScores 就等于 shape(),这个二次排序与原顺序完全一致(同一套 tie-break)。
1603
+ ranked.sort((a, b) => finalScores.get(b.record.id) - finalScores.get(a.record.id)
1604
+ || scopeTier(a.record.scope) - scopeTier(b.record.scope)
1605
+ || a.record.id.localeCompare(b.record.id))
1598
1606
  }
1599
1607
 
1600
1608
  const hits = ranked.map((c) => ({
1601
1609
  record: internal.touch === false ? c.record : touch(c.record),
1602
- score: round4(finalScores.get(c.id) ),
1610
+ score: round4(finalScores.get(c.record.id) ),
1603
1611
  }))
1604
1612
 
1605
1613
  this.store.scheduleFlush()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-memory",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "description": "DeepSeek Harness 记忆系统(单包单入口):JSONL 存储 + 本地向量检索(BGE-M3)+ 五个模型工具 + 自动召回注入 + 管理面板。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",