@restregular/dsh-memory 0.13.1 → 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 +14 -0
- package/README.md +2 -0
- package/lib/client.js +5 -3
- package/lib/provider/index.js +12 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
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
|
+
|
|
5
19
|
## 0.13.1 — 语义检索改成 toggle 开关
|
|
6
20
|
|
|
7
21
|
- 记录页的「语义检索」从普通文字按钮改成真正的 **toggle 开关**:轨道 + 圆点 + 可见的
|
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
|
@@ -106,7 +106,7 @@ window.__ModuleLoader__.load({
|
|
|
106
106
|
'.memp .empty{color:var(--dsw-alias-label-secondary);font-size:12.5px;padding:16px 2px;text-align:center}',
|
|
107
107
|
// 语义检索:搜索框旁的 toggle(轨道 + 圆点,沿用 .toggle 的宿主 token 配色,
|
|
108
108
|
// 深浅色都由 --dsw-alias-switch-thumb / brand-primary / label-primary-foreground
|
|
109
|
-
// 决定,不再写死颜色)+ 结果说明行 +
|
|
109
|
+
// 决定,不再写死颜色)+ 结果说明行 + 结果卡上的排序得分
|
|
110
110
|
'.memp .toolbar .semantic{flex:none;padding:4px 10px 4px 5px}',
|
|
111
111
|
'.memp .toolbar .semantic-label{font-size:12px;line-height:1.6}',
|
|
112
112
|
'.memp .toolbar .semantic-state{font-size:11px;color:var(--dsw-alias-label-secondary)}',
|
|
@@ -808,8 +808,10 @@ window.__ModuleLoader__.load({
|
|
|
808
808
|
score !== null && score !== undefined && Number.isFinite(Number(score))
|
|
809
809
|
? h('span', {
|
|
810
810
|
className: 'badge score',
|
|
811
|
-
|
|
812
|
-
|
|
811
|
+
// 这是**排序分**,不是概率:向量/词法命中 × 重要度 × 时效 × 访问次数加权,
|
|
812
|
+
// 访问次数多时可能大于 1。叫「相关度」会让人误以为一定在 0~1 之间。
|
|
813
|
+
title: '检索得分 = 向量/词法命中 × 重要度 × 时效 × 访问次数;只用于结果排序,可能大于 1',
|
|
814
|
+
}, `得分 ${Number(score).toFixed(2)}`)
|
|
813
815
|
: null,
|
|
814
816
|
rec.supersedes
|
|
815
817
|
? h('span', {
|
package/lib/provider/index.js
CHANGED
|
@@ -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
|
-
|
|
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()
|