@chenhw7/dsh-memory 0.7.0 → 0.8.0

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.
Files changed (77) hide show
  1. package/README.i18n.yaml +2 -0
  2. package/README.md +8 -7
  3. package/{README.zh-CN.md → README.zh.md} +7 -6
  4. package/cordis.patch.yml +5 -1
  5. package/lib/benchmark/index.d.ts +24 -7
  6. package/lib/benchmark/index.d.ts.map +1 -1
  7. package/lib/benchmark/index.js +55 -7
  8. package/lib/benchmark/index.js.map +1 -1
  9. package/lib/client/index.js +37 -9
  10. package/lib/context/conflict.d.ts +23 -10
  11. package/lib/context/conflict.d.ts.map +1 -1
  12. package/lib/context/conflict.js +59 -20
  13. package/lib/context/conflict.js.map +1 -1
  14. package/lib/context/index.d.ts.map +1 -1
  15. package/lib/context/index.js +12 -5
  16. package/lib/context/index.js.map +1 -1
  17. package/lib/context/policy.d.ts +12 -0
  18. package/lib/context/policy.d.ts.map +1 -1
  19. package/lib/context/policy.js +22 -4
  20. package/lib/context/policy.js.map +1 -1
  21. package/lib/index.d.ts +23 -1
  22. package/lib/index.d.ts.map +1 -1
  23. package/lib/index.js +20 -0
  24. package/lib/index.js.map +1 -1
  25. package/lib/notes/cleanup.d.ts +7 -1
  26. package/lib/notes/cleanup.d.ts.map +1 -1
  27. package/lib/notes/cleanup.js +17 -12
  28. package/lib/notes/cleanup.js.map +1 -1
  29. package/lib/notes/index.d.ts +3 -1
  30. package/lib/notes/index.d.ts.map +1 -1
  31. package/lib/notes/index.js +8 -3
  32. package/lib/notes/index.js.map +1 -1
  33. package/lib/notes/scope.d.ts +5 -5
  34. package/lib/notes/scope.js +5 -5
  35. package/lib/remote/index.d.ts +67 -6
  36. package/lib/remote/index.d.ts.map +1 -1
  37. package/lib/remote/index.js +94 -9
  38. package/lib/remote/index.js.map +1 -1
  39. package/lib/remote/typert.remote-client.d.ts +8 -1
  40. package/lib/remote/typert.remote-client.js +6 -0
  41. package/lib/remote/types.d.ts +1 -1
  42. package/lib/remote/types.d.ts.map +1 -1
  43. package/lib/review/accumulator.d.ts +1 -1
  44. package/lib/review/accumulator.js +1 -1
  45. package/lib/review/dedup.d.ts +23 -15
  46. package/lib/review/dedup.d.ts.map +1 -1
  47. package/lib/review/dedup.js +34 -83
  48. package/lib/review/dedup.js.map +1 -1
  49. package/lib/review/extract.d.ts.map +1 -1
  50. package/lib/review/extract.js +5 -2
  51. package/lib/review/extract.js.map +1 -1
  52. package/lib/review/index.d.ts.map +1 -1
  53. package/lib/review/index.js +14 -9
  54. package/lib/review/index.js.map +1 -1
  55. package/lib/scanner.d.ts +2 -0
  56. package/lib/scanner.d.ts.map +1 -1
  57. package/lib/scanner.js +22 -0
  58. package/lib/scanner.js.map +1 -1
  59. package/lib/store/bm25.d.ts +75 -1
  60. package/lib/store/bm25.d.ts.map +1 -1
  61. package/lib/store/bm25.js +162 -17
  62. package/lib/store/bm25.js.map +1 -1
  63. package/lib/store/cross-process.d.ts +155 -0
  64. package/lib/store/cross-process.d.ts.map +1 -0
  65. package/lib/store/cross-process.js +254 -0
  66. package/lib/store/cross-process.js.map +1 -0
  67. package/lib/store/index.d.ts +89 -7
  68. package/lib/store/index.d.ts.map +1 -1
  69. package/lib/store/index.js +466 -89
  70. package/lib/store/index.js.map +1 -1
  71. package/lib/tool/index.d.ts +17 -5
  72. package/lib/tool/index.d.ts.map +1 -1
  73. package/lib/tool/index.js +235 -21
  74. package/lib/tool/index.js.map +1 -1
  75. package/lib/types.d.ts +31 -2
  76. package/lib/types.d.ts.map +1 -1
  77. package/package.json +11 -2
@@ -1 +1 @@
1
- {"version":3,"file":"scanner.js","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAwBH,6EAA6E;AAC7E,IAAI,eAAe,GAAkB,EAAE,CAAA;AAEvC;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,SAAwB;IACnD,eAAe,GAAG,SAAS,CAAA;AAC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,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;IAClE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;AACpC,CAAC;AAED,2EAA2E;AAC3E,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAA;AAExC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;IACjC,IAAI,IAAI,CAAC,OAAO;QAAE,OAAO,OAAO,CAAA;IAChC,OAAO,GAAG,cAAc,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAA;AACzD,CAAC"}
@@ -18,10 +18,79 @@
18
18
  * Tokenize text for retrieval scoring. Same script split as the legacy
19
19
  * tokenizer (Latin runs / CJK runs), upgraded so CJK runs emit unigrams plus
20
20
  * adjacent bigrams instead of unigrams alone.
21
+ *
22
+ * Latin word runs additionally receive a CONSERVATIVE suffix stem
23
+ * ({@link stemLatin}): only identity-preserving rule suffixes (plural
24
+ * s/es/ies, ed, ing) collapse, so "testing", "tests" and "test" share the
25
+ * token "test" while CJK paths and words like "session" are untouched. The
26
+ * stem is applied to documents and queries alike — one shared tokenizer —
27
+ * which also means dedup/conflict/suggestion similarity see inflected forms
28
+ * as near-identical (running ≈ runs); that is accepted drift: the similarity
29
+ * users mean by "same memory" is about meaning, not surface forms.
21
30
  * @param text - the raw document or query text.
22
31
  * @returns the token bag (with duplicates; frequency matters to BM25).
23
32
  */
24
33
  export declare function tokenizeForSearch(text: string): string[];
34
+ /**
35
+ * Document frequencies over a fixed corpus, shared by {@link Bm25Index} and
36
+ * the dedup/conflict weighted-overlap similarity. Built from the FULL corpus
37
+ * (e.g. every entry in the store) rather than the handful of documents one
38
+ * call happens to score: when the df base is the per-call candidate set, a
39
+ * candidate pool of 3 entries lets a pure function word that appears in one
40
+ * of them earn the same IDF as a genuinely distinctive term, and the ranking
41
+ * noise dominates real signal at small pool sizes. Pure data — no caching,
42
+ * no cross-call state; callers rebuild it per search at the store's target
43
+ * scale (tens–hundreds of short entries), which is the same order as the
44
+ * tokenization the index build already does.
45
+ */
46
+ export declare class CorpusStats {
47
+ /** Number of documents the frequencies were measured over. */
48
+ readonly documentCount: number;
49
+ private readonly df;
50
+ /**
51
+ * Build the frequency table from one token array per document.
52
+ * @param docsTokens - token bags (with duplicates) per document; a term
53
+ * counts once per document regardless of its frequency inside it.
54
+ */
55
+ constructor(docsTokens: readonly (readonly string[])[]);
56
+ /** Documents (0–{@link documentCount}) containing the term. */
57
+ documentFrequency(term: string): number;
58
+ }
59
+ /** Convenience: build {@link CorpusStats} directly from raw texts. */
60
+ export declare function buildCorpusStats(texts: readonly string[]): CorpusStats;
61
+ /**
62
+ * Build {@link CorpusStats} directly from PRE-TOKENIZED bags — the seam store
63
+ * search uses to keep its merged content+summary document bags and the df
64
+ * table bit-identical (running the merged bags back through
65
+ * {@link tokenizeForSearch} would re-split already-stemmed tokens, which is
66
+ * not just wasted work but type-incorrect: a token array is not a text).
67
+ * @param docsTokens - token bags (with duplicates) per document.
68
+ */
69
+ export declare function buildCorpusStatsFromTokens(docsTokens: readonly (readonly string[])[]): CorpusStats;
70
+ /**
71
+ * The non-negative Robertson/Sparck-Jones IDF over a df table. A term present
72
+ * in every measured document still contributes a small positive weight, never
73
+ * a negative one — the same guarantee the index scorer relies on.
74
+ * @param stats - the df table to measure against.
75
+ * @param term - the term to weight.
76
+ */
77
+ export declare function idfOf(stats: CorpusStats, term: string): number;
78
+ /**
79
+ * Unique-token set for pairwise similarity: the shared {@link tokenizeForSearch}
80
+ * vocabulary (Latin words; CJK unigrams + bigrams) with duplicates collapsed —
81
+ * overlap similarity is a set notion; only BM25 term-frequency scoring wants
82
+ * the bag.
83
+ */
84
+ export declare function uniqueTokens(text: string): Set<string>;
85
+ /**
86
+ * IDF-weighted overlap similarity between two token sets: Σ idf over shared
87
+ * tokens ÷ Σ idf over the union. The IDF weighting (measured on the caller's
88
+ * {@link CorpusStats}) is what keeps unrelated pairs apart WITHOUT a stop-word
89
+ * table: a function word shared by the pair but common across the corpus
90
+ * weighs ~0, while a content bigram shared only by the pair weighs full.
91
+ * Returns 0 when both sets are empty, and approaches 1 as the sets coincide.
92
+ */
93
+ export declare function weightedOverlapSimilarity(stats: CorpusStats, a: ReadonlySet<string>, b: ReadonlySet<string>): number;
25
94
  /**
26
95
  * A prebuilt BM25 index over a fixed document set. Build once per search call;
27
96
  * at the store's target scale (tens–hundreds of short entries) construction is
@@ -30,11 +99,16 @@ export declare function tokenizeForSearch(text: string): string[];
30
99
  export declare class Bm25Index {
31
100
  private readonly docs;
32
101
  private readonly avgLength;
102
+ private readonly stats;
33
103
  /**
34
104
  * Build the index from one token array per document, in document order.
35
105
  * @param docsTokens - token bags (with duplicates) per document.
106
+ * @param corpusStats - optional df table measured over the FULL corpus; when
107
+ * omitted the df is measured over exactly these documents (correct for
108
+ * ad-hoc scoring, but see {@link CorpusStats} for why store search passes
109
+ * a full-corpus table instead).
36
110
  */
37
- constructor(docsTokens: readonly (readonly string[])[]);
111
+ constructor(docsTokens: readonly (readonly string[])[], corpusStats?: CorpusStats);
38
112
  /**
39
113
  * Score every document against the query tokens.
40
114
  * @param queryTokens - tokenized query (duplicates allowed).
@@ -1 +1 @@
1
- {"version":3,"file":"bm25.d.ts","sourceRoot":"","sources":["../../src/store/bm25.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAQH;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAmBxD;AAUD;;;;GAIG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAoB;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAQ;IAElC;;;OAGG;IACH,YAAY,U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yBAAyB,CACvC,KAAK,EAAE,WAAW,EAClB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,EACtB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GACrB,MAAM,CAaR;AAED;;;;GAIG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAoB;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAQ;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IAEnC;;;;;;;OAOG;IACH,YAAY,UAAU,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EAAE,WAAW,CAAC,EAAE,WAAW,EAShF;IAED;;;;;OAKG;IACH,MAAM,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAiB/C;CACF;AAED,mEAAmE;AACnE,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAG3E"}
package/lib/store/bm25.js CHANGED
@@ -18,10 +18,65 @@
18
18
  const K1 = 1.2;
19
19
  /** BM25 length-normalization parameter (0 = none, 1 = full pivot). */
20
20
  const B = 0.75;
21
+ /**
22
+ * Strip ONE conservative Latin inflectional suffix, or return the token
23
+ * unchanged. Deliberately not a Porter stemmer: only rule suffixes that never
24
+ * change a word's identity (plural s/es/ies, participles ed/ing) are removed,
25
+ * the etymology-bound ones (-ion, -al, -ize…) stay, and the rule list ends
26
+ * where the special cases would begin:
27
+ * - minimum stem length 3 guards tiny words ("is"→"i", "be"→"b");
28
+ * - "-ies" → "y" restores the true stem (studies→study, not studi-);
29
+ * - stem-final "-ss"/"-us"/"-is" never lose their s (class, census, basis),
30
+ * while "-ses"-after-vowel (uses→use) and sibilant+es (churches→church,
31
+ * boxes→box) drop the whole plural suffix;
32
+ * - doubling the final consonant after "-ed"/"-ing" (stopped→stop) is NOT
33
+ * attempted — the doubled stem is the accepted canonical form.
34
+ * CJK tokens never enter this function (guarded by the caller's script check).
35
+ */
36
+ function stemLatin(token) {
37
+ // Pure-digit runs are identifiers, not words: a trailing 's' is a label
38
+ // (v2s, 2024s), not a plural — never strip from digits.
39
+ if (/^\d+$/.test(token))
40
+ return token;
41
+ // Only stem when a substantial stem survives: the result must keep a
42
+ // consonant + at least 3 more characters, so whole words wearing suffix
43
+ // letters keep their identity (bring, news, lens, does, aged, speed,
44
+ // tests, builds, boxes) while long inflections still collapse
45
+ // (testing→test, configuring→configur, computers→computer).
46
+ if (token.length < 6 || token.length - 1 < 5)
47
+ return token;
48
+ if (token.length >= 5 && token.endsWith('ies'))
49
+ return token.slice(0, -3) + 'y';
50
+ if (token.length >= 4 && token.endsWith('sses'))
51
+ return token.slice(0, -2);
52
+ if (token.length >= 4 && token.endsWith('ches') || token.length >= 4 && token.endsWith('shes') || token.length >= 4 && token.endsWith('xes') || token.length >= 4 && token.endsWith('zes')) {
53
+ return token.slice(0, -2);
54
+ }
55
+ if (token.length >= 5 && token.endsWith('ses') && /[aeiou]/.test(token.charAt(token.length - 4))) {
56
+ return token.slice(0, -2); // uses→use, bases→base (needs a 3-char stem)
57
+ }
58
+ if (token.length >= 6 && token.endsWith('ed') && !/[aeiou]{2}$/.test(token))
59
+ return token.slice(0, -2);
60
+ if (token.length >= 7 && token.endsWith('ing') && !/[aeiou]{2}$/.test(token))
61
+ return token.slice(0, -3);
62
+ if (token.length >= 6 && token.endsWith('s') && !/ss$|us$|is$/.test(token)) {
63
+ return token.slice(0, -1); // computers→computer, managers→manager
64
+ }
65
+ return token;
66
+ }
21
67
  /**
22
68
  * Tokenize text for retrieval scoring. Same script split as the legacy
23
69
  * tokenizer (Latin runs / CJK runs), upgraded so CJK runs emit unigrams plus
24
70
  * adjacent bigrams instead of unigrams alone.
71
+ *
72
+ * Latin word runs additionally receive a CONSERVATIVE suffix stem
73
+ * ({@link stemLatin}): only identity-preserving rule suffixes (plural
74
+ * s/es/ies, ed, ing) collapse, so "testing", "tests" and "test" share the
75
+ * token "test" while CJK paths and words like "session" are untouched. The
76
+ * stem is applied to documents and queries alike — one shared tokenizer —
77
+ * which also means dedup/conflict/suggestion similarity see inflected forms
78
+ * as near-identical (running ≈ runs); that is accepted drift: the similarity
79
+ * users mean by "same memory" is about meaning, not surface forms.
25
80
  * @param text - the raw document or query text.
26
81
  * @returns the token bag (with duplicates; frequency matters to BM25).
27
82
  */
@@ -34,11 +89,12 @@ export function tokenizeForSearch(text) {
34
89
  while ((match = re.exec(lowered)) !== null) {
35
90
  const run = match[0];
36
91
  if (!/[\u3040-\u30ff\u4e00-\u9fff\u3400-\u4dbf\uac00-\ud7af]/.test(run)) {
37
- // Pure Latin/alphanumeric run → one word token.
38
- tokens.push(run);
92
+ // Pure Latin/alphanumeric run → one stemmed word token. Pure-digit runs
93
+ // are identifiers and pass through stemLatin unchanged.
94
+ tokens.push(stemLatin(run));
39
95
  continue;
40
96
  }
41
- // CJK run → unigrams + adjacent bigrams.
97
+ // CJK run → unigrams + adjacent bigrams (no stemming on this path).
42
98
  const chars = Array.from(run);
43
99
  for (const ch of chars)
44
100
  tokens.push(ch);
@@ -47,6 +103,101 @@ export function tokenizeForSearch(text) {
47
103
  }
48
104
  return tokens;
49
105
  }
106
+ /**
107
+ * Document frequencies over a fixed corpus, shared by {@link Bm25Index} and
108
+ * the dedup/conflict weighted-overlap similarity. Built from the FULL corpus
109
+ * (e.g. every entry in the store) rather than the handful of documents one
110
+ * call happens to score: when the df base is the per-call candidate set, a
111
+ * candidate pool of 3 entries lets a pure function word that appears in one
112
+ * of them earn the same IDF as a genuinely distinctive term, and the ranking
113
+ * noise dominates real signal at small pool sizes. Pure data — no caching,
114
+ * no cross-call state; callers rebuild it per search at the store's target
115
+ * scale (tens–hundreds of short entries), which is the same order as the
116
+ * tokenization the index build already does.
117
+ */
118
+ export class CorpusStats {
119
+ /** Number of documents the frequencies were measured over. */
120
+ documentCount;
121
+ df;
122
+ /**
123
+ * Build the frequency table from one token array per document.
124
+ * @param docsTokens - token bags (with duplicates) per document; a term
125
+ * counts once per document regardless of its frequency inside it.
126
+ */
127
+ constructor(docsTokens) {
128
+ this.documentCount = docsTokens.length;
129
+ this.df = new Map();
130
+ for (const tokens of docsTokens) {
131
+ for (const term of new Set(tokens)) {
132
+ this.df.set(term, (this.df.get(term) ?? 0) + 1);
133
+ }
134
+ }
135
+ }
136
+ /** Documents (0–{@link documentCount}) containing the term. */
137
+ documentFrequency(term) {
138
+ return this.df.get(term) ?? 0;
139
+ }
140
+ }
141
+ /** Convenience: build {@link CorpusStats} directly from raw texts. */
142
+ export function buildCorpusStats(texts) {
143
+ return new CorpusStats(texts.map(text => tokenizeForSearch(text)));
144
+ }
145
+ /**
146
+ * Build {@link CorpusStats} directly from PRE-TOKENIZED bags — the seam store
147
+ * search uses to keep its merged content+summary document bags and the df
148
+ * table bit-identical (running the merged bags back through
149
+ * {@link tokenizeForSearch} would re-split already-stemmed tokens, which is
150
+ * not just wasted work but type-incorrect: a token array is not a text).
151
+ * @param docsTokens - token bags (with duplicates) per document.
152
+ */
153
+ export function buildCorpusStatsFromTokens(docsTokens) {
154
+ return new CorpusStats(docsTokens);
155
+ }
156
+ /**
157
+ * The non-negative Robertson/Sparck-Jones IDF over a df table. A term present
158
+ * in every measured document still contributes a small positive weight, never
159
+ * a negative one — the same guarantee the index scorer relies on.
160
+ * @param stats - the df table to measure against.
161
+ * @param term - the term to weight.
162
+ */
163
+ export function idfOf(stats, term) {
164
+ const df = stats.documentFrequency(term);
165
+ return Math.log(1 + (stats.documentCount - df + 0.5) / (df + 0.5));
166
+ }
167
+ /**
168
+ * Unique-token set for pairwise similarity: the shared {@link tokenizeForSearch}
169
+ * vocabulary (Latin words; CJK unigrams + bigrams) with duplicates collapsed —
170
+ * overlap similarity is a set notion; only BM25 term-frequency scoring wants
171
+ * the bag.
172
+ */
173
+ export function uniqueTokens(text) {
174
+ return new Set(tokenizeForSearch(text));
175
+ }
176
+ /**
177
+ * IDF-weighted overlap similarity between two token sets: Σ idf over shared
178
+ * tokens ÷ Σ idf over the union. The IDF weighting (measured on the caller's
179
+ * {@link CorpusStats}) is what keeps unrelated pairs apart WITHOUT a stop-word
180
+ * table: a function word shared by the pair but common across the corpus
181
+ * weighs ~0, while a content bigram shared only by the pair weighs full.
182
+ * Returns 0 when both sets are empty, and approaches 1 as the sets coincide.
183
+ */
184
+ export function weightedOverlapSimilarity(stats, a, b) {
185
+ if (a.size === 0 && b.size === 0)
186
+ return 0;
187
+ let intersection = 0;
188
+ let union = 0;
189
+ for (const token of a) {
190
+ const w = idfOf(stats, token);
191
+ union += w;
192
+ if (b.has(token))
193
+ intersection += w;
194
+ }
195
+ for (const token of b) {
196
+ if (!a.has(token))
197
+ union += idfOf(stats, token);
198
+ }
199
+ return union === 0 ? 0 : intersection / union;
200
+ }
50
201
  /**
51
202
  * A prebuilt BM25 index over a fixed document set. Build once per search call;
52
203
  * at the store's target scale (tens–hundreds of short entries) construction is
@@ -55,11 +206,16 @@ export function tokenizeForSearch(text) {
55
206
  export class Bm25Index {
56
207
  docs;
57
208
  avgLength;
209
+ stats;
58
210
  /**
59
211
  * Build the index from one token array per document, in document order.
60
212
  * @param docsTokens - token bags (with duplicates) per document.
213
+ * @param corpusStats - optional df table measured over the FULL corpus; when
214
+ * omitted the df is measured over exactly these documents (correct for
215
+ * ad-hoc scoring, but see {@link CorpusStats} for why store search passes
216
+ * a full-corpus table instead).
61
217
  */
62
- constructor(docsTokens) {
218
+ constructor(docsTokens, corpusStats) {
63
219
  this.docs = docsTokens.map(tokens => {
64
220
  const tf = new Map();
65
221
  for (const token of tokens)
@@ -68,6 +224,7 @@ export class Bm25Index {
68
224
  });
69
225
  const total = this.docs.reduce((sum, d) => sum + d.length, 0);
70
226
  this.avgLength = this.docs.length === 0 ? 0 : total / this.docs.length;
227
+ this.stats = corpusStats ?? new CorpusStats(docsTokens);
71
228
  }
72
229
  /**
73
230
  * Score every document against the query tokens.
@@ -79,16 +236,6 @@ export class Bm25Index {
79
236
  if (queryTokens.length === 0 || this.docs.length === 0) {
80
237
  return this.docs.map(() => 0);
81
238
  }
82
- // Document frequency per distinct query term.
83
- const df = new Map();
84
- for (const term of new Set(queryTokens)) {
85
- let count = 0;
86
- for (const doc of this.docs) {
87
- if (doc.tf.has(term))
88
- count++;
89
- }
90
- df.set(term, count);
91
- }
92
239
  const n = this.docs.length;
93
240
  const avg = this.avgLength;
94
241
  return this.docs.map(doc => {
@@ -97,9 +244,7 @@ export class Bm25Index {
97
244
  const freq = doc.tf.get(term);
98
245
  if (freq === undefined)
99
246
  continue;
100
- const occurrences = df.get(term) ?? 0;
101
- // Non-negative IDF: a term in every document contributes ~0, never < 0.
102
- const idf = Math.log(1 + (n - occurrences + 0.5) / (occurrences + 0.5));
247
+ const idf = idfOf(this.stats, term);
103
248
  const norm = freq * (K1 + 1) / (freq + K1 * (1 - B + B * (avg === 0 ? 0 : doc.length / avg)));
104
249
  score += idf * norm;
105
250
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bm25.js","sourceRoot":"","sources":["../../src/store/bm25.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,gDAAgD;AAChD,MAAM,EAAE,GAAG,GAAG,CAAA;AAEd,sEAAsE;AACtE,MAAM,CAAC,GAAG,IAAI,CAAA;AAEd;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;IAClC,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,8DAA8D;IAC9D,MAAM,EAAE,GAAG,iFAAiF,CAAA;IAC5F,IAAI,KAA6B,CAAA;IACjC,OAAO,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC3C,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QACpB,IAAI,CAAC,wDAAwD,CAAC,IAAI,CAAC,GA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AC,KAAK,CAAC,CAAC,CAAA;AAC/C,CAAC"}
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Cross-process single-writer detection for the memory medium.
3
+ *
4
+ * The host storage-json backend declares a single-writer assumption per
5
+ * process: two DSH processes sharing one storage root each hold their own
6
+ * in-memory authoritative state and republish the whole unit file on every
7
+ * write, silently clobbering each other (last publisher wins). The backend's
8
+ * double-open guard is a per-process map, so the second process opens the
9
+ * same unit without any error — nothing in the host detects the overlap.
10
+ *
11
+ * This module adds detection, not locking: each boot stamps an owner record
12
+ * into the domain's global slot and re-reads the medium periodically. A stamp
13
+ * this boot just wrote that reads back as someone else's proves a concurrent
14
+ * publisher; a foreign stamp seen at startup proves an earlier writer the
15
+ * medium still remembers. Detection needs both sides to stamp — a writer
16
+ * running a version without this guard overwrites the slot with `null` and
17
+ * is invisible here. A foreign stamp is only a live threat when its pid is
18
+ * still alive: `closedAt` marks a clean exit, and a dead pid marks a crashed
19
+ * predecessor — both restart cases stay silent.
20
+ *
21
+ * @module @chenhw7/dsh-memory/store/cross-process
22
+ */
23
+ import zod from 'zod';
24
+ /** The owner stamp one process boot writes into the memory domain's global slot. */
25
+ export interface OwnerStamp {
26
+ pid: number;
27
+ startedAt: number;
28
+ bootId: string;
29
+ closedAt?: number;
30
+ }
31
+ /** Zod schema validating a stamp at the durable boundary (rejects `null`, the "never written" sentinel). */
32
+ export declare const ownerStampSchema: zod.ZodType<OwnerStamp>;
33
+ /**
34
+ * Spec-level `initial` for the global slot: what {@link CrossProcessGuard.startup}
35
+ * sees when the medium has never been claimed (empty `bootId`). Never written
36
+ * as-is — the guard's first act replaces it with a real stamp.
37
+ */
38
+ export declare const EMPTY_OWNER: OwnerStamp;
39
+ /**
40
+ * Default cadence for the medium read-back probe. Lightweight by design —
41
+ * one file read per interval, off the write path; `0` disables probing.
42
+ */
43
+ export declare const DEFAULT_CROSS_PROCESS_PROBE_MS = 60000;
44
+ /** Identity of the current process boot: fresh per construction, so a restart never reads as itself. */
45
+ export declare function currentBootOwner(): OwnerStamp;
46
+ /**
47
+ * Production read seam: the unit file's global slot, read straight from the
48
+ * medium. The domain serves reads from in-memory state, which never observes
49
+ * another process's publish — the file is the only cross-process witness.
50
+ * @param path - Absolute path of the unit file.
51
+ * @returns an async reader yielding the stored global, `undefined` when the
52
+ * file is not materialized yet.
53
+ */
54
+ export declare function mediumOwnerReader(path: string): () => Promise<unknown>;
55
+ /**
56
+ * Production goodbye seam: stamp `closedAt` onto the unit file's global slot
57
+ * directly on the medium. The domain write seam (`global.set`) rejects with
58
+ * `closed` once the storage facility's unmount races our disposer — the
59
+ * medium file is the only write path that stays valid through teardown.
60
+ * The whole-file replacement mirrors the backend's own publish protocol
61
+ * (temp file + rename is unnecessary here: a partial goodbye is a torn
62
+ * stamp at worst, and the pid-dead rule already forgives a lost goodbye;
63
+ * the atomic rename without a directory fsync keeps this free of host
64
+ * internals).
65
+ * @param path - Absolute path of the unit file.
66
+ * @param bootId - This boot's stamp; the write is skipped when the medium's
67
+ * current owner is someone else (we were already overwritten — nothing to
68
+ * say goodbye to).
69
+ * @returns an async writer, or `undefined` when the file is not materialized.
70
+ */
71
+ export declare function mediumGoodbyeWriter(path: string, bootId: string): (() => Promise<void>) | undefined;
72
+ /**
73
+ * Default pid-liveness seam: a live process with that pid means a genuine
74
+ * concurrent writer; only `ESRCH` proves absence. `EPERM` (exists, not
75
+ * signallable) and any other probe error alert — fail toward warning, since
76
+ * an undetected concurrent publisher is the expensive side.
77
+ * @param pid - The foreign stamp's pid.
78
+ * @returns whether a process with that pid is alive.
79
+ */
80
+ export declare function pidAlive(pid: number): boolean;
81
+ /** Failure-reporting seam: the store's {@link reportFailure} (counter + logger warn). */
82
+ export type FailureReporter = (site: string, error: unknown) => void;
83
+ /**
84
+ * One boot's cross-process detector. Watches the owner stamp on the medium:
85
+ * claims it at startup, re-reads it on probes, and closes it with a goodbye
86
+ * stamp on clean dispose. Reports a foreign live stamp at most once per boot
87
+ * — restarts reset the flag, matching the `backgroundFailures` in-process
88
+ * semantics.
89
+ *
90
+ * Misfire semantics: a foreign stamp carrying `closedAt` is a writer that
91
+ * exited cleanly, and one whose pid is gone is a crashed predecessor —
92
+ * neither is a concurrent publisher, so both stay silent. A live pid is a
93
+ * genuine concurrent writer and alerts; pid reuse by an unrelated process
94
+ * can forge this signal, which the one-warn-per-boot bound contains.
95
+ */
96
+ export declare class CrossProcessGuard {
97
+ /** This boot's identity, written as the claim and compared against read-backs. */
98
+ private readonly own;
99
+ /** Medium read-back seam, or `undefined` when the medium path is unresolvable (probes off). */
100
+ private readonly readOwner;
101
+ /** Durable write seam for the global slot (the domain's `global.set`). */
102
+ private readonly writeOwner;
103
+ /** Swallowed-failure channel (store `reportFailure`). */
104
+ private readonly report;
105
+ /** Liveness seam for foreign pids; defaults to the platform `kill(pid, 0)` check. */
106
+ private readonly isAlive;
107
+ /** Direct medium-file goodbye writer, or `undefined` (see {@link sayGoodbye}). */
108
+ private readonly goodbyeWriter;
109
+ /** Set on the first foreign-live observation; one alert per boot. */
110
+ private alerted;
111
+ constructor(
112
+ /** This boot's identity, written as the claim and compared against read-backs. */
113
+ own: OwnerStamp,
114
+ /** Medium read-back seam, or `undefined` when the medium path is unresolvable (probes off). */
115
+ readOwner: (() => Promise<unknown>) | undefined,
116
+ /** Durable write seam for the global slot (the domain's `global.set`). */
117
+ writeOwner: (owner: OwnerStamp) => Promise<void>,
118
+ /** Swallowed-failure channel (store `reportFailure`). */
119
+ report: FailureReporter,
120
+ /** Liveness seam for foreign pids; defaults to the platform `kill(pid, 0)` check. */
121
+ isAlive?: (pid: number) => boolean,
122
+ /** Direct medium-file goodbye writer, or `undefined` (see {@link sayGoodbye}). */
123
+ goodbyeWriter?: (() => Promise<void>) | undefined);
124
+ /**
125
+ * Startup check + claim: judge the open-time global (the medium snapshot
126
+ * the domain loaded), then stamp this boot as owner so later starters see
127
+ * us. A failed claim propagates — an unwritable medium fails loud at mount.
128
+ * @param storedGlobal - the domain's global value at open (`EMPTY_OWNER` reference when never written).
129
+ */
130
+ startup(storedGlobal: unknown): Promise<void>;
131
+ /**
132
+ * Periodic medium read-back. Never throws; a broken read reports under
133
+ * `owner-probe` and waits for the next tick. No-op without a reader.
134
+ */
135
+ probe(): Promise<void>;
136
+ /**
137
+ * Stamp `closedAt` on clean dispose so the next boot reads this writer as
138
+ * gone instead of live. The goodbye prefers the direct medium-file writer:
139
+ * at dispose time the storage facility's own unmount may have already
140
+ * closed the domain (sibling fibers dispose concurrently), which would
141
+ * reject the global-slot write with `closed`. The direct write is the
142
+ * always-valid path. Best-effort: a failing goodbye is reported and
143
+ * teardown continues (the pid-dead rule already keeps crashed/restarted
144
+ * boots silent, so a lost goodbye costs nothing).
145
+ */
146
+ sayGoodbye(): Promise<void>;
147
+ /**
148
+ * Judge one medium-read value. Only a valid stamp with a foreign `bootId`,
149
+ * no `closedAt`, and a still-alive pid is a live concurrent writer; own
150
+ * stamps, closed writers, dead pids, and unreadable values stay silent.
151
+ * Reports at most once per boot.
152
+ */
153
+ private judge;
154
+ }
155
+ //# sourceMappingURL=cross-process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cross-process.d.ts","sourceRoot":"","sources":["../../src/store/cross-process.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,oFAAoF;AACpF,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,4GAA4G;AAC5G,eAAO,MAAM,gBAAgB,EAIZ,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;AAExC;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,UAAiD,CAAA;AAE3E;;;GAGG;AACH,eAAO,MAAM,8BAA8B,QAAS,CAAA;AAEpD,wGAAwG;AACxG,w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