dsh-memory-huixiang 0.1.4 → 0.1.5
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/README.md +2 -2
- package/index.js +11 -2
- package/lib/recall.js +5 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -155,7 +155,7 @@ dsh plugin --profile web add link:~/.dsh/plugin-src/dsh-memory-huixiang
|
|
|
155
155
|
以下命令**只在源码树里跑**——npm 包不带 `test/`、`demo/`、`eval/`(包只含 `index.js`、`lib/`、`cordis.patch.yml`、`README.md`、`NOTICE`、`LICENSE`)。
|
|
156
156
|
|
|
157
157
|
```bash
|
|
158
|
-
node --test #
|
|
158
|
+
node --test # 246 个测试全过
|
|
159
159
|
node demo/simulate.mjs # 10 项演示,用临时库,不碰真库
|
|
160
160
|
node eval/run.mjs --golden <你的题库.jsonl> --dir <你的库目录>
|
|
161
161
|
```
|
|
@@ -173,7 +173,7 @@ node eval/run.mjs --golden <你的题库.jsonl> --dir <你的库目录>
|
|
|
173
173
|
- 召回是词面驱动的:换个说法(「家在何方」对「住哪」)可能翻不到。
|
|
174
174
|
- 单机单进程假设:多进程靠 `O_EXCL` 文件锁,不是分布式锁。
|
|
175
175
|
- `stream.jsonl` 会存每一轮原话(单条截断 4000 字)。这是特性也是风险,见「隐私」。
|
|
176
|
-
-
|
|
176
|
+
- 246 个测试覆盖的是核心路径,不是全覆盖。
|
|
177
177
|
|
|
178
178
|
## 隐私
|
|
179
179
|
|
package/index.js
CHANGED
|
@@ -570,7 +570,7 @@ const catalogLimit = countOr(config.catalogLimit, 130)
|
|
|
570
570
|
ids: { type: 'array', items: { type: 'string' }, maxItems: 10, description: '按短 id 直接取全文(便签行里 [xxxx] 那个;也认完整 id 或尾 4 位)。给 ids 时 cue 可以不传,比猜自然语言准。' },
|
|
571
571
|
cues: { type: 'array', items: { type: 'string' }, maxItems: 10, description: '换几种说法一次查(可选):命中任一种就算捞到,取最高分。' },
|
|
572
572
|
includeSuperseded: { type: 'boolean', description: '连已被接替/过期的旧卡一起翻(审计用,默认 false)。' },
|
|
573
|
-
limit: { type: 'number', minimum: 1, maximum: 10, description: '最多几条,默认
|
|
573
|
+
limit: { type: 'number', minimum: 1, maximum: 10, description: '最多几条,默认 5。跨事件的问题(谁先/一共/比较/两次)给到 6~8。' },
|
|
574
574
|
},
|
|
575
575
|
},
|
|
576
576
|
output: TEXT({ type: 'object' }),
|
|
@@ -642,7 +642,9 @@ const catalogLimit = countOr(config.catalogLimit, 130)
|
|
|
642
642
|
// 原来单字线索(猫/雨/酒)一律被拦,等于查不了。门控只留给自动检索那条路。
|
|
643
643
|
|
|
644
644
|
// limit 传字符串/NaN 时 Math.trunc 得 NaN → slice(0,NaN)=[] → 命中被吞成 not_found(2026-11-21 B9)。
|
|
645
|
-
|
|
645
|
+
// 默认给 5 条(2026-11-21 全量 500 题实验:top3→top6 让 4~6 段题从 10/33 涨到 21/33,
|
|
646
|
+
// 总分 80.8%→83.0%,逼近「全给原文」上限 83.8%;卡都很短,多两条比答错划算)。
|
|
647
|
+
const limit = Math.min(Math.max(Math.trunc(Number(args.limit) || 5), 1), 10)
|
|
646
648
|
const opts = { limit, includeSuperseded: args.includeSuperseded === true }
|
|
647
649
|
const runs = cues.map((c) => ({ cue: c, r: recallByCue(store, c, opts) }))
|
|
648
650
|
// 合并:同一张卡只留分数最高那次,并记住是哪句说法捞到的(记账要用真的那句)。
|
|
@@ -708,10 +710,17 @@ const catalogLimit = countOr(config.catalogLimit, 130)
|
|
|
708
710
|
gateNote = `实体槽未命中:${g.missing.join('/')}`
|
|
709
711
|
}
|
|
710
712
|
}
|
|
713
|
+
// 被 limit 截断时说一句:让模型知道库里还有更多,值得把 limit 调大再查一次,
|
|
714
|
+
// 而不是以为「库里就这几条」直接作答(2026-11-21 全量 500 题:多段题就吃亏在这)。
|
|
715
|
+
const 候选总数 = Number(topRun?.r.候选总数 || 0)
|
|
716
|
+
if (status === 'matched' && 候选总数 > items.length) {
|
|
717
|
+
reason = (reason ? `${reason};` : '') + `库里还有 ${候选总数 - items.length} 条相关,要看得更全就把 limit 调大再查一次`
|
|
718
|
+
}
|
|
711
719
|
const result = {
|
|
712
720
|
status,
|
|
713
721
|
items,
|
|
714
722
|
reason,
|
|
723
|
+
...(候选总数 ? { 候选总数 } : {}),
|
|
715
724
|
兜底,
|
|
716
725
|
拆解: topRun?.r.拆解 || '',
|
|
717
726
|
...(gateNote ? { 出口闸: gateNote } : {}),
|
package/lib/recall.js
CHANGED
|
@@ -376,7 +376,6 @@ export function recallByCue(store, cue, opts = {}) {
|
|
|
376
376
|
return { status: 'not_found', items: [], reason: '库里没有对得上的记录', 拆解: parseLine }
|
|
377
377
|
}
|
|
378
378
|
const top = scored[0]
|
|
379
|
-
const second = scored[1]
|
|
380
379
|
// 实体槽闸(11-14 复核第二名缺点的补丁):问「公司/学校/小区/型号…」这类具体实体时,
|
|
381
380
|
// 命中的卡里必须真的出现过这个词,否则还是拿「名字」「生日」凑答案。
|
|
382
381
|
// 11-14 二审:地址/角色/专业是多义词(备份包地址、本鲸算什么角色),会误伤正常问句——
|
|
@@ -387,18 +386,8 @@ export function recallByCue(store, cue, opts = {}) {
|
|
|
387
386
|
// 且命中的词里至少一个出现在这张卡的标题/标签里——防「表弟」刚好出现在生日卡正文里那种误命中。
|
|
388
387
|
// 例外:线索里有强证据词(编号 / 长数字串 / 书名号引号点名的串)时,直接放行头名。
|
|
389
388
|
// 短问句不放宽:句长/词数跟负样本几乎一样,按句长放行等于把负样本一起放回来(11-15 二审,别再做)。
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
const cardTitleOrTag = (c) => {
|
|
393
|
-
const s = new Set(tokenize(c.title || ''))
|
|
394
|
-
for (const raw of c.tags || []) {
|
|
395
|
-
const t = String(raw).toLowerCase()
|
|
396
|
-
s.add(t)
|
|
397
|
-
const i = t.indexOf(':')
|
|
398
|
-
if (i >= 0 && i < t.length - 1) s.add(t.slice(i + 1))
|
|
399
|
-
}
|
|
400
|
-
return s
|
|
401
|
-
}
|
|
389
|
+
// 下一版窄路要用的判据函数(hasStrongEvidence / gateWords)留在模块里,别在这里白算一遍——
|
|
390
|
+
// 2026-11-21 外部复核 B17:这三行算完没人读,纯粹每次召回多耗一遍 CPU。
|
|
402
391
|
// 命中门槛(coverage===1)实验版 2026-11-15:全量闸与「单字/别名/改述/时间窗」等产品语义天然冲突
|
|
403
392
|
// (主意识 22:58 判:不过,回退)。只留 gateWords() 函数给下一版窄路用,选卡恢复成直接选头名。
|
|
404
393
|
const chosen = top
|
|
@@ -438,6 +427,9 @@ export function recallByCue(store, cue, opts = {}) {
|
|
|
438
427
|
return {
|
|
439
428
|
status: ambiguous ? 'ambiguous' : 'matched',
|
|
440
429
|
items: picked,
|
|
430
|
+
// 候选总数:调用方据此判断「是不是被 limit 截断了」,好提示模型把 limit 调大再查一次。
|
|
431
|
+
// 2026-11-21 全量 500 题实验:4~6 段题吃亏在只给 3 张卡,多给几张立刻涨 11 题。
|
|
432
|
+
候选总数: scored.length,
|
|
441
433
|
reason: ambiguous ? '命中相近,请补一句是哪件事' : '',
|
|
442
434
|
拆解: parseLine,
|
|
443
435
|
parsed: { when: parsed.when, who: parsed.who, wantLatest: parsed.wantLatest, keywords: parsed.keywords },
|