@ssamurias/dsh-fish 1.1.7 → 1.1.8
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/AGENTS.md +5 -4
- package/CHANGELOG.md +76 -5000
- package/README.md +23 -22
- package/docs/README.md +16 -0
- package/docs/releases/CHANGELOG.md +5055 -0
- package/docs/releases/README.md +54 -0
- package/docs/releases/RELEASE-NOTES-1.1.8.md +94 -0
- package/lib/at.js +5 -3
- package/lib/backup.js +5 -3
- package/lib/capture.js +45 -0
- package/lib/client.js +14 -4
- package/lib/compact.js +122 -18
- package/lib/decisions.js +1 -0
- package/lib/derive.js +85 -2
- package/lib/didclaim.js +65 -9
- package/lib/foreignline.js +96 -0
- package/lib/hear.js +3 -0
- package/lib/herpeople.js +3 -2
- package/lib/herperson.js +9 -8
- package/lib/index.js +1 -1
- package/lib/mapserve.js +45 -6
- package/lib/markup.js +349 -6
- package/lib/memorymap.js +75 -16
- package/lib/observe-bili.js +89 -16
- package/lib/observe-home.js +2 -0
- package/lib/observe.js +3 -2
- package/lib/peopledoc.js +2 -2
- package/lib/persona.js +19 -4
- package/lib/photoanchor.js +172 -0
- package/lib/pronoun.js +62 -3
- package/lib/pronounask.js +8 -4
- package/lib/recall-query.js +282 -0
- package/lib/recall.js +121 -15
- package/lib/report.js +8 -1
- package/lib/say.js +10 -2
- package/lib/scheduler.js +67 -17
- package/lib/schema.js +50 -1
- package/lib/scrub.js +146 -15
- package/lib/selfdoc.js +5 -3
- package/lib/settings.js +3 -1
- package/lib/turnexport.js +53 -3
- package/lib/turns.js +17 -1
- package/lib/types.d.ts +1 -1
- package/lib/wiki.js +25 -5
- package/package.json +1 -2
- package/tools/README.md +71 -2
- package/tools/claim-report.mjs +97 -0
- package/tools/recall-bench.mjs +31 -3
- package/tools/recall-cases-100.freeze.json +15 -0
- package/tools/recall-cases-100.json +196 -0
- package/tools/recall-cases-user.json +313 -0
- package/tools/recall-cases.json +1 -1
- package/tools/recall-compare.mjs +169 -0
- package/tools/recall-eval.mjs +142 -0
- /package/{RELEASE-NOTES-0.8.0.md → docs/releases/RELEASE-NOTES-0.8.0.md} +0 -0
- /package/{RELEASE-NOTES-0.8.1.md → docs/releases/RELEASE-NOTES-0.8.1.md} +0 -0
- /package/{RELEASE-NOTES-0.8.2.md → docs/releases/RELEASE-NOTES-0.8.2.md} +0 -0
- /package/{RELEASE-NOTES-0.8.3.md → docs/releases/RELEASE-NOTES-0.8.3.md} +0 -0
- /package/{RELEASE-NOTES-0.8.4.md → docs/releases/RELEASE-NOTES-0.8.4.md} +0 -0
- /package/{RELEASE-NOTES-0.8.5.md → docs/releases/RELEASE-NOTES-0.8.5.md} +0 -0
- /package/{RELEASE-NOTES-0.8.6.md → docs/releases/RELEASE-NOTES-0.8.6.md} +0 -0
- /package/{RELEASE-NOTES-0.8.7.md → docs/releases/RELEASE-NOTES-0.8.7.md} +0 -0
- /package/{RELEASE-NOTES-0.8.8.md → docs/releases/RELEASE-NOTES-0.8.8.md} +0 -0
- /package/{RELEASE-NOTES-0.9.0.md → docs/releases/RELEASE-NOTES-0.9.0.md} +0 -0
- /package/{RELEASE-NOTES-0.9.1.md → docs/releases/RELEASE-NOTES-0.9.1.md} +0 -0
- /package/{RELEASE-NOTES-0.9.2.md → docs/releases/RELEASE-NOTES-0.9.2.md} +0 -0
- /package/{RELEASE-NOTES-0.9.3.md → docs/releases/RELEASE-NOTES-0.9.3.md} +0 -0
- /package/{RELEASE-NOTES-0.9.5.md → docs/releases/RELEASE-NOTES-0.9.5.md} +0 -0
- /package/{RELEASE-NOTES-0.9.6.md → docs/releases/RELEASE-NOTES-0.9.6.md} +0 -0
- /package/{RELEASE-NOTES-0.9.7.md → docs/releases/RELEASE-NOTES-0.9.7.md} +0 -0
- /package/{RELEASE-NOTES-0.9.8.md → docs/releases/RELEASE-NOTES-0.9.8.md} +0 -0
- /package/{RELEASE-NOTES-0.9.9.md → docs/releases/RELEASE-NOTES-0.9.9.md} +0 -0
- /package/{RELEASE-NOTES-1.0.0.md → docs/releases/RELEASE-NOTES-1.0.0.md} +0 -0
- /package/{RELEASE-NOTES-1.0.1.md → docs/releases/RELEASE-NOTES-1.0.1.md} +0 -0
- /package/{RELEASE-NOTES-1.0.2.md → docs/releases/RELEASE-NOTES-1.0.2.md} +0 -0
- /package/{RELEASE-NOTES-1.0.3.md → docs/releases/RELEASE-NOTES-1.0.3.md} +0 -0
- /package/{RELEASE-NOTES-1.0.4.md → docs/releases/RELEASE-NOTES-1.0.4.md} +0 -0
- /package/{RELEASE-NOTES-1.0.5.md → docs/releases/RELEASE-NOTES-1.0.5.md} +0 -0
- /package/{RELEASE-NOTES-1.0.6.md → docs/releases/RELEASE-NOTES-1.0.6.md} +0 -0
- /package/{RELEASE-NOTES-1.0.7.md → docs/releases/RELEASE-NOTES-1.0.7.md} +0 -0
- /package/{RELEASE-NOTES-1.0.8.md → docs/releases/RELEASE-NOTES-1.0.8.md} +0 -0
- /package/{RELEASE-NOTES-1.0.9.md → docs/releases/RELEASE-NOTES-1.0.9.md} +0 -0
- /package/{RELEASE-NOTES-1.1.0.md → docs/releases/RELEASE-NOTES-1.1.0.md} +0 -0
- /package/{RELEASE-NOTES-1.1.1.md → docs/releases/RELEASE-NOTES-1.1.1.md} +0 -0
- /package/{RELEASE-NOTES-1.1.2.md → docs/releases/RELEASE-NOTES-1.1.2.md} +0 -0
- /package/{RELEASE-NOTES-1.1.3.md → docs/releases/RELEASE-NOTES-1.1.3.md} +0 -0
- /package/{RELEASE-NOTES-1.1.4.md → docs/releases/RELEASE-NOTES-1.1.4.md} +0 -0
- /package/{RELEASE-NOTES-1.1.5.md → docs/releases/RELEASE-NOTES-1.1.5.md} +0 -0
- /package/{RELEASE-NOTES-1.1.6.md → docs/releases/RELEASE-NOTES-1.1.6.md} +0 -0
- /package/{RELEASE-NOTES-1.1.7.md → docs/releases/RELEASE-NOTES-1.1.7.md} +0 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 成对对照:把同一份考卷同时喂给两个检出,只比排名,不比耗时结论。
|
|
4
|
+
*
|
|
5
|
+
* 这是诊断工具,不是门槛:默认退出码 0,失败题打印出来给人看,别接成 CI 必过门。
|
|
6
|
+
*
|
|
7
|
+
* baseline 必须是官方检出(按 tools/recall-cases-100.freeze.json 里钉死的 commit 逐字节校验),
|
|
8
|
+
* 防止「拿着改过的自己当基线」。candidate 默认就是本仓库。
|
|
9
|
+
*
|
|
10
|
+
* 本仓库没有 lib/recall-query.js(那是上游 #195 新增的独立模块),所以候选侧的可选源文件
|
|
11
|
+
* 缺失时按「没有」处理,不当成错误——对照的是 lib/recall.js 的行为本身。
|
|
12
|
+
*/
|
|
13
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'
|
|
14
|
+
import { dirname, resolve, join } from 'node:path'
|
|
15
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
16
|
+
import { performance } from 'node:perf_hooks'
|
|
17
|
+
import { execFileSync } from 'node:child_process'
|
|
18
|
+
import { sha256, readJson, loadSuite, runSuite, summarize, compareRows } from './recall-eval.mjs'
|
|
19
|
+
|
|
20
|
+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
21
|
+
const argv = process.argv.slice(2)
|
|
22
|
+
const arg = (name, fallback = '') => {
|
|
23
|
+
const i = argv.indexOf(name)
|
|
24
|
+
return i >= 0 ? argv[i + 1] : fallback
|
|
25
|
+
}
|
|
26
|
+
const suiteFile = resolve(arg('--cases', join(ROOT, 'tools/recall-cases-100.json')))
|
|
27
|
+
const freezeFile = suiteFile.replace(/\.json$/, '.freeze.json')
|
|
28
|
+
const suite = loadSuite(suiteFile)
|
|
29
|
+
if (argv.includes('--freeze')) {
|
|
30
|
+
writeFileSync(freezeFile, JSON.stringify({
|
|
31
|
+
version: 1, frozenOn: '2026-12-03', hashes: suite.hashes,
|
|
32
|
+
originalCases: 32, expandedCases: 68, development: 70, holdout: 30,
|
|
33
|
+
officialCommit: suite.provenance.officialCommit,
|
|
34
|
+
protocol: 'Freeze before implementation. No tuning on holdout results. Author-created diagnostic suite, not independent validation.',
|
|
35
|
+
}, null, 2) + '\n')
|
|
36
|
+
console.log(`Frozen ${suite.cases.length} cases: ${freezeFile}`)
|
|
37
|
+
process.exit(0)
|
|
38
|
+
}
|
|
39
|
+
const freeze = readJson(freezeFile)
|
|
40
|
+
if (JSON.stringify(freeze.hashes) !== JSON.stringify(suite.hashes)) throw new Error('Frozen suite hash mismatch')
|
|
41
|
+
const baselineRoot = resolve(arg('--baseline') || (() => { throw new Error('--baseline <official checkout> is required') })())
|
|
42
|
+
const officialFile = join(baselineRoot, 'lib/recall.js')
|
|
43
|
+
// A same-named source file is not enough: verify byte-for-byte against the pinned Git commit.
|
|
44
|
+
const officialBytes = execFileSync('git', ['show', `${freeze.officialCommit}:lib/recall.js`], { cwd: ROOT, maxBuffer: 4 * 1024 * 1024 })
|
|
45
|
+
if (sha256(readFileSync(officialFile)) !== sha256(officialBytes)) throw new Error('Baseline is not the pinned official recall.js')
|
|
46
|
+
process.env.TZ = suite.timezone
|
|
47
|
+
suite.asOf = argv.includes('--as-of') ? suite.now : undefined
|
|
48
|
+
const baseline = await import(pathToFileURL(officialFile).href)
|
|
49
|
+
// C1 remains reproducible after new experiments change the working branch.
|
|
50
|
+
const candidateRoot = resolve(arg('--candidate', ROOT))
|
|
51
|
+
const candidateFile = join(candidateRoot, 'lib/recall.js')
|
|
52
|
+
const candidate = await import(pathToFileURL(candidateFile).href)
|
|
53
|
+
// 可选源:上游把它拆成独立模块,我们这边没有就是没有,不写进哈希、也不拦。
|
|
54
|
+
const optionalSource = (file) => (existsSync(file) ? sha256(readFileSync(file)) : null)
|
|
55
|
+
const candidateQueryFile = join(candidateRoot, 'lib/recall-query.js')
|
|
56
|
+
const candidateHashes = {
|
|
57
|
+
recall: sha256(readFileSync(candidateFile)),
|
|
58
|
+
query: optionalSource(candidateQueryFile),
|
|
59
|
+
}
|
|
60
|
+
const candidateFreezeFile = join(ROOT, 'tools/recall-candidate.freeze.json')
|
|
61
|
+
if (argv.includes('--seal')) {
|
|
62
|
+
writeFileSync(candidateFreezeFile, JSON.stringify({
|
|
63
|
+
sealedOn: '2026-12-03', beforeHoldout: true,
|
|
64
|
+
sources: candidateHashes, dataset: suite.hashes,
|
|
65
|
+
note: 'Sealed after development and regression checks, before inspecting holdout retrieval results. Same author wrote the synthetic holdout; not an external blind test.',
|
|
66
|
+
}, null, 2) + '\n')
|
|
67
|
+
console.log(`Sealed candidate sources: ${candidateFreezeFile}`)
|
|
68
|
+
process.exit(0)
|
|
69
|
+
}
|
|
70
|
+
if (splitNeedsSeal()) {
|
|
71
|
+
const sealed = readJson(candidateFreezeFile)
|
|
72
|
+
if (JSON.stringify(sealed.sources) !== JSON.stringify(candidateHashes)) throw new Error('Candidate changed after sealing')
|
|
73
|
+
}
|
|
74
|
+
// 封存是「我先承诺不改了」的可选动作,不是跑对照的前提:只要 seam 文件在,看 holdout 就必须对得上;
|
|
75
|
+
// 文件不在就照跑,只在输出里记一句「这次没有封存」。诊断卷不该因为有门槛而让人放弃跑它。
|
|
76
|
+
function splitNeedsSeal() {
|
|
77
|
+
return existsSync(candidateFreezeFile) && ['all', 'holdout'].includes(arg('--split', 'all'))
|
|
78
|
+
}
|
|
79
|
+
// Match the original examiner's default, and share the same derived IDs between engines.
|
|
80
|
+
suite.solidByCorpus = Object.fromEntries(Object.entries(suite.corpora)
|
|
81
|
+
.map(([name, events]) => [name, [...baseline.solidIdsOf(events, 30)]]))
|
|
82
|
+
const split = arg('--split', 'all')
|
|
83
|
+
if (!['all', 'development', 'holdout', 'original'].includes(split)) throw new Error('Invalid --split')
|
|
84
|
+
const cases = suite.cases.filter((c) => split === 'all' || (split === 'original' ? c.original : c.split === split))
|
|
85
|
+
const before = runSuite(suite, baseline.searchEvents, cases)
|
|
86
|
+
const after = runSuite(suite, candidate.searchEvents, cases)
|
|
87
|
+
const grouped = (predicate) => {
|
|
88
|
+
const b = before.filter(predicate)
|
|
89
|
+
const a = after.filter(predicate)
|
|
90
|
+
return { baseline: summarize(b), candidate: summarize(a), comparison: compareRows(b, a) }
|
|
91
|
+
}
|
|
92
|
+
const familyNames = [...new Set(cases.map((c) => c.family))]
|
|
93
|
+
|
|
94
|
+
function percentile(values, p) {
|
|
95
|
+
const sorted = values.slice().sort((a, b) => a - b)
|
|
96
|
+
return sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * p))]
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function latency(search, events, query) {
|
|
100
|
+
const options = { now: suite.now, ...(suite.asOf === undefined ? {} : { asOf: suite.asOf }), limit: 5, solidIds: new Set() }
|
|
101
|
+
const firstStart = performance.now()
|
|
102
|
+
search(events, query, options)
|
|
103
|
+
const firstMs = performance.now() - firstStart
|
|
104
|
+
for (let i = 0; i < 12; i++) search(events, query, options)
|
|
105
|
+
const times = []
|
|
106
|
+
for (let i = 0; i < 45; i++) {
|
|
107
|
+
const start = performance.now()
|
|
108
|
+
search(events, query, options)
|
|
109
|
+
times.push(performance.now() - start)
|
|
110
|
+
}
|
|
111
|
+
return { firstMs, p50Ms: percentile(times, 0.5), p95Ms: percentile(times, 0.95), samples: times.length }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let timing
|
|
115
|
+
if (argv.includes('--perf')) {
|
|
116
|
+
timing = []
|
|
117
|
+
for (const count of [1000, 5000, 10000, 20000]) {
|
|
118
|
+
const events = Array.from({ length: count }, (_, i) => ({
|
|
119
|
+
id: `perf-${i}`, ts: new Date(suite.now - (count - i) * 60000).toISOString(),
|
|
120
|
+
type: i % 7 === 0 ? 'voice' : 'utterance',
|
|
121
|
+
...(i % 7 === 0 ? { who: { id: `qq:${i % 101}`, name: `群友${i % 101}` } } : {}),
|
|
122
|
+
text: i % 3 === 0 ? '画布导出 api/note 记下计划' : '散步回来,把书放到桌上。',
|
|
123
|
+
}))
|
|
124
|
+
for (const query of ['画布', 'api/note', '群友7说画布', '']) {
|
|
125
|
+
// Alternate order to reduce one-sided warmup bias. These are in-process function timings.
|
|
126
|
+
const order = count % 2000 === 0 ? ['candidate', 'baseline'] : ['baseline', 'candidate']
|
|
127
|
+
const result = { events: count, query }
|
|
128
|
+
for (const key of order) result[key] = latency(key === 'baseline' ? baseline.searchEvents : candidate.searchEvents, events, query)
|
|
129
|
+
timing.push(result)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const payload = {
|
|
134
|
+
protocol: 'C1-100-v1', runDate: '2026-12-03', node: process.version, platform: process.platform,
|
|
135
|
+
clock: new Date(suite.now).toISOString(), timezone: process.env.TZ, split,
|
|
136
|
+
cutoffMode: suite.asOf === undefined ? 'existing API (no asOf)' : 'new optional asOf=now',
|
|
137
|
+
hashes: { ...suite.hashes, baselineSource: sha256(officialBytes), candidateSource: sha256(readFileSync(candidateFile)),
|
|
138
|
+
candidateQuerySource: optionalSource(candidateQueryFile),
|
|
139
|
+
harnessSource: sha256(readFileSync(fileURLToPath(import.meta.url))),
|
|
140
|
+
scoringSource: sha256(readFileSync(join(ROOT, 'tools/recall-eval.mjs'))) },
|
|
141
|
+
officialCommit: freeze.officialCommit,
|
|
142
|
+
solidByCorpus: suite.solidByCorpus,
|
|
143
|
+
cases: cases.length, corpusSizes: Object.fromEntries(Object.entries(suite.corpora).map(([k, v]) => [k, v.length])),
|
|
144
|
+
note: 'Both engines receive identical raw events, query, now, kind, days, solidIds and limit=5. Only --as-of adds the identical asOf=now argument to both; the official implementation ignores that new option. Default results measure the existing API contract. No prefiltering future events, LLM, disk index, live private ledger or answer generation.',
|
|
145
|
+
overall: grouped(() => true), original: grouped((r) => r.original),
|
|
146
|
+
expanded: grouped((r) => !r.original), development: grouped((r) => r.split === 'development'),
|
|
147
|
+
holdout: grouped((r) => r.split === 'holdout'),
|
|
148
|
+
byFamily: Object.fromEntries(familyNames.map((f) => [f, grouped((r) => r.family === f)])),
|
|
149
|
+
results: before.map((b, i) => ({ id: b.id, baseline: b, candidate: after[i] })),
|
|
150
|
+
...(timing ? { timing, timingNote: '45 warm samples after 12 warmups, first-call latency excludes process/module loading; synthetic performance corpus, not retrieval-accuracy evidence.' } : {}),
|
|
151
|
+
}
|
|
152
|
+
const output = arg('--output')
|
|
153
|
+
if (output) {
|
|
154
|
+
const path = resolve(output)
|
|
155
|
+
mkdirSync(dirname(path), { recursive: true })
|
|
156
|
+
writeFileSync(path, JSON.stringify(payload, null, 2) + '\n')
|
|
157
|
+
}
|
|
158
|
+
if (argv.includes('--json')) console.log(JSON.stringify(payload, null, 2))
|
|
159
|
+
else {
|
|
160
|
+
for (const key of ['overall', 'original', 'expanded', 'development', 'holdout']) {
|
|
161
|
+
const { baseline: b, candidate: c, comparison: d } = payload[key]
|
|
162
|
+
if (!b.total) continue
|
|
163
|
+
console.log(`${key}: pass ${b.passed}/${b.total} -> ${c.passed}/${c.total}; hit@5 ${b.hit}/${b.positive} -> ${c.hit}/${c.positive}; MRR ${b.mrrAt5?.toFixed(4)} -> ${c.mrrAt5?.toFixed(4)}; wins/losses ${d.wins}/${d.losses}`)
|
|
164
|
+
}
|
|
165
|
+
for (const r of payload.results.filter((r) => !r.candidate.passed)) {
|
|
166
|
+
console.log(`FAIL ${r.id}: ${r.candidate.query} -> ${r.candidate.got.join(', ') || '(empty)'}`)
|
|
167
|
+
}
|
|
168
|
+
if (output) console.log(`Saved: ${resolve(output)}`)
|
|
169
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/** Shared, read-only scoring for both retrieval implementations. No model calls. */
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { createHash } from 'node:crypto'
|
|
4
|
+
import { readFileSync } from 'node:fs'
|
|
5
|
+
import { dirname, resolve } from 'node:path'
|
|
6
|
+
|
|
7
|
+
export const sha256 = (bytes) => createHash('sha256').update(bytes).digest('hex')
|
|
8
|
+
export const readJson = (file) => JSON.parse(readFileSync(file, 'utf8'))
|
|
9
|
+
|
|
10
|
+
export function loadSuite(file) {
|
|
11
|
+
const expanded = readJson(file)
|
|
12
|
+
const originalFile = resolve(dirname(file), expanded.extends)
|
|
13
|
+
const original = readJson(originalFile)
|
|
14
|
+
const cases = [
|
|
15
|
+
...original.cases.map((c) => ({ ...c, split: 'development', corpus: 'original', cluster: 'original-32', original: true })),
|
|
16
|
+
...expanded.cases.map((c) => ({ ...c, corpus: 'expanded', original: false })),
|
|
17
|
+
]
|
|
18
|
+
const corpora = { original: original.events, expanded: expanded.events }
|
|
19
|
+
assert.equal(cases.length, 100)
|
|
20
|
+
assert.equal(new Set(cases.map((c) => c.id)).size, 100, 'Duplicate case IDs')
|
|
21
|
+
assert.equal(cases.filter((c) => c.split === 'holdout').length, 30)
|
|
22
|
+
assert.equal(cases.filter((c) => c.original).length, 32)
|
|
23
|
+
const clusters = new Map()
|
|
24
|
+
for (const [name, events] of Object.entries(corpora)) {
|
|
25
|
+
assert.equal(new Set(events.map((e) => e.id)).size, events.length, `${name}: duplicate events`)
|
|
26
|
+
}
|
|
27
|
+
for (const c of cases) {
|
|
28
|
+
assert.ok(['development', 'holdout'].includes(c.split), `${c.id}: invalid split`)
|
|
29
|
+
const previous = clusters.get(c.cluster)
|
|
30
|
+
assert.ok(!previous || previous === c.split, `${c.cluster}: cluster crosses splits`)
|
|
31
|
+
clusters.set(c.cluster, c.split)
|
|
32
|
+
const eventIds = new Set(corpora[c.corpus].map((e) => e.id))
|
|
33
|
+
for (const key of ['expect', 'expectAll', 'forbid', 'expectLinks', 'forbidLinks']) {
|
|
34
|
+
for (const id of c[key] ?? []) assert.ok(eventIds.has(id), `${c.id}: missing ${key} ${id}`)
|
|
35
|
+
}
|
|
36
|
+
if (c.expectFirst) assert.ok(eventIds.has(c.expectFirst), `${c.id}: missing expectFirst`)
|
|
37
|
+
const wanted = [...(c.expect ?? []), ...(c.expectAll ?? []), ...(c.expectFirst ? [c.expectFirst] : [])]
|
|
38
|
+
if (!['negative', 'noise'].includes(c.family)) assert.ok(wanted.length, `${c.id}: no positive gold`)
|
|
39
|
+
assert.ok(!wanted.some((id) => (c.forbid ?? []).includes(id)), `${c.id}: contradictory gold`)
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
name: expanded.name,
|
|
43
|
+
now: Date.parse(expanded.now),
|
|
44
|
+
timezone: expanded.timezone,
|
|
45
|
+
cases,
|
|
46
|
+
corpora,
|
|
47
|
+
hashes: { original: sha256(readFileSync(originalFile)), expanded: sha256(readFileSync(file)) },
|
|
48
|
+
provenance: expanded.provenance,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function scoreCase(c, out) {
|
|
53
|
+
const got = out.rows.map((r) => String(r.id))
|
|
54
|
+
const links = [...new Set(out.rows.flatMap((r) => [r.later?.id, r.earlier?.id].filter(Boolean).map(String)))]
|
|
55
|
+
const relevant = [...new Set([...(c.expect ?? []), ...(c.expectAll ?? []), ...(c.expectFirst ? [c.expectFirst] : [])])]
|
|
56
|
+
const negative = c.family === 'negative' || c.family === 'noise'
|
|
57
|
+
const rank = got.findIndex((id) => relevant.includes(id)) + 1
|
|
58
|
+
const hit = rank > 0
|
|
59
|
+
const hitAll = (c.expectAll ?? []).every((id) => got.includes(id))
|
|
60
|
+
const firstOk = c.expectFirst ? got[0] === c.expectFirst : null
|
|
61
|
+
const forbidden = got.filter((id) => (c.forbid ?? []).includes(id))
|
|
62
|
+
const missingLinks = (c.expectLinks ?? []).filter((id) => !links.includes(id))
|
|
63
|
+
const forbiddenLinks = links.filter((id) => (c.forbidLinks ?? []).includes(id))
|
|
64
|
+
const falseHit = forbidden.length > 0 || forbiddenLinks.length > 0 || (c.family === 'negative' && got.length > 0)
|
|
65
|
+
const passed = negative
|
|
66
|
+
? !falseHit
|
|
67
|
+
: hit && hitAll && firstOk !== false && !falseHit && !missingLinks.length
|
|
68
|
+
return {
|
|
69
|
+
id: c.id, family: c.family, split: c.split, cluster: c.cluster, original: c.original,
|
|
70
|
+
query: c.query ?? '', negative, relevant, expectFirst: c.expectFirst ?? null,
|
|
71
|
+
got, links, total: out.total, timeline: out.timeline, hit, hitAll, firstOk,
|
|
72
|
+
rr: rank ? 1 / rank : 0, falseHit, forbidden, missingLinks, forbiddenLinks, passed,
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function runSuite(suite, searchEvents, cases = suite.cases) {
|
|
77
|
+
return cases.map((c) => scoreCase(c, searchEvents(suite.corpora[c.corpus], c.query ?? '', {
|
|
78
|
+
now: suite.now, ...(suite.asOf === undefined ? {} : { asOf: suite.asOf }), days: c.days, kind: c.typeFilter, limit: 5,
|
|
79
|
+
solidIds: new Set(c.solidIds?.length ? c.solidIds : (suite.solidByCorpus?.[c.corpus] ?? [])), weigh: c.weigh !== false,
|
|
80
|
+
})))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function summarize(rows) {
|
|
84
|
+
const positive = rows.filter((r) => !r.negative)
|
|
85
|
+
const negative = rows.filter((r) => r.negative)
|
|
86
|
+
const first = positive.filter((r) => r.expectFirst)
|
|
87
|
+
return {
|
|
88
|
+
total: rows.length, passed: rows.filter((r) => r.passed).length,
|
|
89
|
+
positive: positive.length, hit: positive.filter((r) => r.hit).length,
|
|
90
|
+
hitAt5: positive.length ? positive.filter((r) => r.hit).length / positive.length : null,
|
|
91
|
+
mrrAt5: positive.length ? positive.reduce((n, r) => n + r.rr, 0) / positive.length : null,
|
|
92
|
+
firstAsked: first.length, firstOk: first.filter((r) => r.firstOk).length,
|
|
93
|
+
negatives: negative.length, negativeFalseHits: negative.filter((r) => r.falseHit).length,
|
|
94
|
+
allCasesWithForbidden: rows.filter((r) => r.falseHit).length,
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function rng(seed) {
|
|
99
|
+
let state = seed >>> 0
|
|
100
|
+
return () => {
|
|
101
|
+
state = (Math.imul(1664525, state) + 1013904223) >>> 0
|
|
102
|
+
return state / 4294967296
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function compareRows(baseline, candidate) {
|
|
107
|
+
assert.deepEqual(baseline.map((r) => r.id), candidate.map((r) => r.id))
|
|
108
|
+
const changes = baseline.map((b, i) => {
|
|
109
|
+
const c = candidate[i]
|
|
110
|
+
return { id: b.id, cluster: b.cluster, split: b.split, family: b.family,
|
|
111
|
+
baselinePassed: b.passed, candidatePassed: c.passed,
|
|
112
|
+
rrDelta: c.rr - b.rr, firstDelta: Number(c.firstOk) - Number(b.firstOk),
|
|
113
|
+
changed: JSON.stringify([b.got, b.links]) !== JSON.stringify([c.got, c.links]) }
|
|
114
|
+
})
|
|
115
|
+
const wins = changes.filter((c) => !c.baselinePassed && c.candidatePassed).length
|
|
116
|
+
const losses = changes.filter((c) => c.baselinePassed && !c.candidatePassed).length
|
|
117
|
+
const clusters = [...new Set(changes.map((c) => c.cluster))]
|
|
118
|
+
.map((name) => changes.filter((c) => c.cluster === name))
|
|
119
|
+
const random = rng(194100)
|
|
120
|
+
const deltas = []
|
|
121
|
+
// Resample scenario clusters, not individual paraphrases of one event.
|
|
122
|
+
for (let n = 0; n < 10000 && clusters.length; n++) {
|
|
123
|
+
let sum = 0
|
|
124
|
+
let count = 0
|
|
125
|
+
for (let j = 0; j < clusters.length; j++) {
|
|
126
|
+
const group = clusters[Math.floor(random() * clusters.length)]
|
|
127
|
+
count += group.length
|
|
128
|
+
for (const c of group) sum += Number(c.candidatePassed) - Number(c.baselinePassed)
|
|
129
|
+
}
|
|
130
|
+
deltas.push(sum / count)
|
|
131
|
+
}
|
|
132
|
+
deltas.sort((a, b) => a - b)
|
|
133
|
+
return {
|
|
134
|
+
wins, losses, ties: changes.length - wins - losses,
|
|
135
|
+
changedRankings: changes.filter((c) => c.changed).length,
|
|
136
|
+
scenarioClusters: clusters.length,
|
|
137
|
+
pairedPassDelta: changes.length ? (wins - losses) / changes.length : null,
|
|
138
|
+
clusterBootstrap95: deltas.length ? [deltas[250], deltas[9749]] : null,
|
|
139
|
+
bootstrap: { seed: 194100, samples: 10000, unit: 'scenario cluster; original 32 share one cluster' },
|
|
140
|
+
changes,
|
|
141
|
+
}
|
|
142
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|