@hviana/sema 0.5.3 → 0.5.4

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 (143) hide show
  1. package/AGENTS.md +6 -6
  2. package/HOW_IT_WORKS.md +16 -0
  3. package/jsr.json +1 -1
  4. package/package.json +1 -1
  5. package/src/mind/match.ts +81 -0
  6. package/src/mind/mechanisms/recall.ts +29 -3
  7. package/test/76-reference-binding.test.mjs +72 -0
  8. package/dist/example/demo.d.ts +0 -1
  9. package/dist/example/demo.js +0 -39
  10. package/dist/example/train_base.d.ts +0 -93
  11. package/dist/example/train_base.js +0 -2269
  12. package/dist/src/alphabet.d.ts +0 -7
  13. package/dist/src/alphabet.js +0 -33
  14. package/dist/src/alu/src/alu.d.ts +0 -185
  15. package/dist/src/alu/src/alu.js +0 -440
  16. package/dist/src/alu/src/expr.d.ts +0 -61
  17. package/dist/src/alu/src/expr.js +0 -318
  18. package/dist/src/alu/src/index.d.ts +0 -11
  19. package/dist/src/alu/src/index.js +0 -19
  20. package/dist/src/alu/src/kernel-arith.d.ts +0 -16
  21. package/dist/src/alu/src/kernel-arith.js +0 -264
  22. package/dist/src/alu/src/kernel-bits.d.ts +0 -19
  23. package/dist/src/alu/src/kernel-bits.js +0 -152
  24. package/dist/src/alu/src/kernel-logic.d.ts +0 -4
  25. package/dist/src/alu/src/kernel-logic.js +0 -60
  26. package/dist/src/alu/src/kernel-nd.d.ts +0 -3
  27. package/dist/src/alu/src/kernel-nd.js +0 -208
  28. package/dist/src/alu/src/kernel-numeric.d.ts +0 -54
  29. package/dist/src/alu/src/kernel-numeric.js +0 -366
  30. package/dist/src/alu/src/operation.d.ts +0 -168
  31. package/dist/src/alu/src/operation.js +0 -189
  32. package/dist/src/alu/src/parser.d.ts +0 -221
  33. package/dist/src/alu/src/parser.js +0 -577
  34. package/dist/src/alu/src/resonance.d.ts +0 -55
  35. package/dist/src/alu/src/resonance.js +0 -126
  36. package/dist/src/alu/src/text.d.ts +0 -31
  37. package/dist/src/alu/src/text.js +0 -73
  38. package/dist/src/alu/src/value.d.ts +0 -109
  39. package/dist/src/alu/src/value.js +0 -300
  40. package/dist/src/alu/test/alu.test.d.ts +0 -1
  41. package/dist/src/alu/test/alu.test.js +0 -764
  42. package/dist/src/bytes.d.ts +0 -14
  43. package/dist/src/bytes.js +0 -59
  44. package/dist/src/canon.d.ts +0 -45
  45. package/dist/src/canon.js +0 -85
  46. package/dist/src/config.d.ts +0 -111
  47. package/dist/src/config.js +0 -91
  48. package/dist/src/derive/src/deduction.d.ts +0 -136
  49. package/dist/src/derive/src/deduction.js +0 -159
  50. package/dist/src/derive/src/index.d.ts +0 -8
  51. package/dist/src/derive/src/index.js +0 -11
  52. package/dist/src/derive/src/priority-queue.d.ts +0 -20
  53. package/dist/src/derive/src/priority-queue.js +0 -73
  54. package/dist/src/derive/src/rewrite.d.ts +0 -56
  55. package/dist/src/derive/src/rewrite.js +0 -100
  56. package/dist/src/derive/src/trie.d.ts +0 -90
  57. package/dist/src/derive/src/trie.js +0 -217
  58. package/dist/src/derive/test/derive.test.d.ts +0 -1
  59. package/dist/src/derive/test/derive.test.js +0 -122
  60. package/dist/src/extension.d.ts +0 -37
  61. package/dist/src/extension.js +0 -7
  62. package/dist/src/geometry.d.ts +0 -233
  63. package/dist/src/geometry.js +0 -1089
  64. package/dist/src/index.d.ts +0 -17
  65. package/dist/src/index.js +0 -19
  66. package/dist/src/ingest-cache.d.ts +0 -41
  67. package/dist/src/ingest-cache.js +0 -165
  68. package/dist/src/meter.d.ts +0 -176
  69. package/dist/src/meter.js +0 -274
  70. package/dist/src/mind/articulation.d.ts +0 -6
  71. package/dist/src/mind/articulation.js +0 -99
  72. package/dist/src/mind/attention.d.ts +0 -430
  73. package/dist/src/mind/attention.js +0 -2418
  74. package/dist/src/mind/bridge.d.ts +0 -37
  75. package/dist/src/mind/bridge.js +0 -907
  76. package/dist/src/mind/canonical.d.ts +0 -34
  77. package/dist/src/mind/canonical.js +0 -93
  78. package/dist/src/mind/graph-search.d.ts +0 -294
  79. package/dist/src/mind/graph-search.js +0 -996
  80. package/dist/src/mind/index.d.ts +0 -9
  81. package/dist/src/mind/index.js +0 -5
  82. package/dist/src/mind/junction.d.ts +0 -137
  83. package/dist/src/mind/junction.js +0 -358
  84. package/dist/src/mind/learning.d.ts +0 -75
  85. package/dist/src/mind/learning.js +0 -265
  86. package/dist/src/mind/match.d.ts +0 -351
  87. package/dist/src/mind/match.js +0 -959
  88. package/dist/src/mind/mechanisms/alu.d.ts +0 -4
  89. package/dist/src/mind/mechanisms/alu.js +0 -36
  90. package/dist/src/mind/mechanisms/cast.d.ts +0 -89
  91. package/dist/src/mind/mechanisms/cast.js +0 -1186
  92. package/dist/src/mind/mechanisms/confluence.d.ts +0 -24
  93. package/dist/src/mind/mechanisms/confluence.js +0 -271
  94. package/dist/src/mind/mechanisms/cover.d.ts +0 -6
  95. package/dist/src/mind/mechanisms/cover.js +0 -232
  96. package/dist/src/mind/mechanisms/extraction.d.ts +0 -33
  97. package/dist/src/mind/mechanisms/extraction.js +0 -327
  98. package/dist/src/mind/mechanisms/prefix-completion.d.ts +0 -22
  99. package/dist/src/mind/mechanisms/prefix-completion.js +0 -243
  100. package/dist/src/mind/mechanisms/recall.d.ts +0 -16
  101. package/dist/src/mind/mechanisms/recall.js +0 -460
  102. package/dist/src/mind/mechanisms/reference.d.ts +0 -6
  103. package/dist/src/mind/mechanisms/reference.js +0 -296
  104. package/dist/src/mind/mind.d.ts +0 -386
  105. package/dist/src/mind/mind.js +0 -754
  106. package/dist/src/mind/pipeline-mechanism.d.ts +0 -238
  107. package/dist/src/mind/pipeline-mechanism.js +0 -622
  108. package/dist/src/mind/pipeline.d.ts +0 -49
  109. package/dist/src/mind/pipeline.js +0 -343
  110. package/dist/src/mind/primitives.d.ts +0 -85
  111. package/dist/src/mind/primitives.js +0 -333
  112. package/dist/src/mind/rationale.d.ts +0 -139
  113. package/dist/src/mind/rationale.js +0 -163
  114. package/dist/src/mind/reasoning.d.ts +0 -42
  115. package/dist/src/mind/reasoning.js +0 -305
  116. package/dist/src/mind/recognition.d.ts +0 -20
  117. package/dist/src/mind/recognition.js +0 -696
  118. package/dist/src/mind/resonance.d.ts +0 -35
  119. package/dist/src/mind/resonance.js +0 -365
  120. package/dist/src/mind/trace.d.ts +0 -15
  121. package/dist/src/mind/trace.js +0 -73
  122. package/dist/src/mind/traverse.d.ts +0 -196
  123. package/dist/src/mind/traverse.js +0 -806
  124. package/dist/src/mind/types.d.ts +0 -418
  125. package/dist/src/mind/types.js +0 -179
  126. package/dist/src/rabitq-ivf/src/database.d.ts +0 -113
  127. package/dist/src/rabitq-ivf/src/database.js +0 -201
  128. package/dist/src/rabitq-ivf/src/index.d.ts +0 -7
  129. package/dist/src/rabitq-ivf/src/index.js +0 -4
  130. package/dist/src/rabitq-ivf/src/ivf.d.ts +0 -200
  131. package/dist/src/rabitq-ivf/src/ivf.js +0 -1165
  132. package/dist/src/rabitq-ivf/src/prng.d.ts +0 -19
  133. package/dist/src/rabitq-ivf/src/prng.js +0 -36
  134. package/dist/src/rabitq-ivf/src/rabitq.d.ts +0 -95
  135. package/dist/src/rabitq-ivf/src/rabitq.js +0 -313
  136. package/dist/src/sema.d.ts +0 -41
  137. package/dist/src/sema.js +0 -77
  138. package/dist/src/store-sqlite.d.ts +0 -184
  139. package/dist/src/store-sqlite.js +0 -942
  140. package/dist/src/store.d.ts +0 -762
  141. package/dist/src/store.js +0 -1823
  142. package/dist/src/vec.d.ts +0 -31
  143. package/dist/src/vec.js +0 -109
@@ -1,460 +0,0 @@
1
- // mechanisms/recall.ts — Recall by resonance (Grounding VI).
2
- //
3
- // The recall mechanism resonates the whole query's gist against the content
4
- // index and grounds the nearest learned form. Four tiers, orderly degrading
5
- // from exact self-match to honest echo.
6
- import { cosine } from "../../vec.js";
7
- import { consensusFloor, dominates, identityBar, reachThreshold, significanceBar, } from "../../geometry.js";
8
- import { gistOf, read, resolve } from "../primitives.js";
9
- import { bytesEqual, indexOf } from "../../bytes.js";
10
- import { allWindowsAreScaffolding, corpusN, hubBound } from "../traverse.js";
11
- import { follow, project, reverseContext } from "../match.js";
12
- import { CONCEPT, STEP } from "../graph-search.js";
13
- import { unexplainedLabel } from "../rationale.js";
14
- import { rItem, rNode } from "../trace.js";
15
- import { substitutionBridge } from "../bridge.js";
16
- /** Recall the answer by resonating the whole query against the content index. */
17
- export async function recallByResonance(ctx, query, pre) {
18
- const t = ctx.trace?.enter("recallByResonance", [
19
- rItem(query, "query"),
20
- ]);
21
- const whole_ = [[0, query.length]];
22
- const nothing = [];
23
- const ground = (bytes, note, accounted, moves, echoed = false, complete = false) => {
24
- t?.done(bytes === null
25
- ? []
26
- : [rItem(bytes, "answer", resolve(ctx, bytes) ?? undefined)], note);
27
- return bytes === null ? null : {
28
- bytes,
29
- echoed,
30
- accounted,
31
- moves,
32
- unexplained: unexplainedLabel(query, accounted),
33
- ...(complete ? { complete } : {}),
34
- };
35
- };
36
- const k = pre.k;
37
- const queryGist = pre.guide;
38
- // 0. Exact self-match — content-addressed, deterministic.
39
- const qId = pre.queryResolved;
40
- if (qId !== null) {
41
- const rev = ctx.store.prevFirst(qId, hubBound(ctx));
42
- const g = reverseContext(ctx, qId, queryGist, rev);
43
- if (g !== null) {
44
- return ground(g, rev.length === 1
45
- ? "exact self-match — reverse recall to the sole predecessor"
46
- : "exact self-match — reverse recall to the best-resonating predecessor", nothing, STEP);
47
- }
48
- }
49
- // 0b. ARGUMENT BINDING (RC8): the query is not itself a stored form, but
50
- // it CONTAINS a recognised constituent that is an edge SOURCE — a learnt
51
- // pair's left side carried inside a wrapper ("How do you say 'thank you'
52
- // in French?"). The wrapper is scaffolding; the argument is the span
53
- // that LEADS somewhere, so its continuation — guided by the whole query's
54
- // gist — is the answer. Matching the wrapper while ignoring the argument
55
- // (the observed "good morning" template failure) is worse than silence,
56
- // so anything short of ONE unambiguous binding falls through: the
57
- // constituent bar is the same two-quanta (2W) reading confluence binds
58
- // under, nested recognitions collapse to their MAXIMAL span, and two
59
- // distinct maximal arguments mean the query asks about neither alone.
60
- if (qId === null) {
61
- const W2 = 2 * ctx.space.maxGroup;
62
- const args = pre.rec.sites.filter((s) => s.end - s.start >= W2 &&
63
- s.end - s.start < query.length &&
64
- ctx.store.hasNext(s.payload));
65
- // Maximal spans by one sorted sweep (starts ascending, ties longest
66
- // first): every earlier span starts at or before s, so s is contained
67
- // exactly when the running max end already covers it. O(m log m) — a
68
- // long input recognises O(|input|) sites, and a pairwise scan here was
69
- // quadratic in the input.
70
- args.sort((a, b) => a.start - b.start || b.end - a.end);
71
- const maximal = [];
72
- let maxEnd = -1;
73
- for (const s of args) {
74
- if (s.end <= maxEnd)
75
- continue;
76
- maximal.push(s);
77
- maxEnd = s.end;
78
- }
79
- // The wrapper must actually BE scaffolding: RC8's own premise is "the
80
- // wrapper is scaffolding; the argument is the span that leads
81
- // somewhere" ("How do you say 'thank you' in French?" — everything
82
- // outside the argument is a small fixed template). When the query
83
- // instead has ANOTHER substantial recognised form (≥ W2, the same
84
- // constituent bar the argument itself must clear) sitting OUTSIDE the
85
- // chosen argument, the query is not one argument in a wrapper — it is
86
- // several complete, independently-meaningful pieces (a multi-turn
87
- // conversation's own accumulated turns are exactly this shape), and
88
- // binding to the argument's continuation would answer past content
89
- // the query itself already carries forward. Derived from the same W2
90
- // bar the argument itself is held to, never a separate tuned number.
91
- const hasSubstantialOutside = maximal.length === 1 &&
92
- pre.rec.sites.some((s) => s.end - s.start >= W2 &&
93
- (s.end <= maximal[0].start || s.start >= maximal[0].end));
94
- if (maximal.length === 1 && !hasSubstantialOutside) {
95
- const arg = maximal[0];
96
- const g = await follow(ctx, arg.payload, queryGist);
97
- // The same "no restated fragment" guard tier 2 applies below (§ "the
98
- // anchor cleared the consensus floor..."): a followed continuation
99
- // that is itself a proper byte-subspan of the QUERY restates part of
100
- // the question — never an answer. A multi-turn query's own later
101
- // turns are exact, content-addressed matches for exactly this reason
102
- // (each turn is its own previously-learnt form), so without this
103
- // guard the argument's OWN later restatement in the same
104
- // conversation reads as if it were the next thing to say.
105
- if (g !== null && g.length > 0 &&
106
- !(g.length < query.length && indexOf(query, g, 0) >= 0)) {
107
- return ground(g, "argument binding — the query's sole edge-source constituent, continuation followed", [[arg.start, arg.end]], STEP);
108
- }
109
- }
110
- }
111
- // The response's ONE top-k read (Precomputed.resonance) — the same list the
112
- // frame inventory is assembled from, so a query that reaches both pays for a
113
- // single ANN query rather than two identical ones.
114
- const whole = await pre.resonance();
115
- if (whole.length === 0) {
116
- return ground(null, "empty store — nothing to resonate with", [], 0);
117
- }
118
- const top = whole[0];
119
- ctx.trace?.step("resonate", [rItem(query, "query-gist")], whole.map((h) => rNode(ctx, h.id, "hit", h.score)), `resonate the whole-query gist → ${whole.length} nearest learnt form(s)`);
120
- // 1. Clean resonance — the scale-aware identity claim. The ANGLE
121
- // (top.score) carries the shared fraction; the query's MAGNITUDE (√len,
122
- // the linear fold's own norm) converts the tolerated foreign fraction
123
- // into bytes — at most one river window (see {@link identityBar}). A
124
- // fixed cosine bar let long queries claim "near-identical" while whole
125
- // windows — an answer word — differed.
126
- // A hit RESTATES the query when its bytes are the query's own — exactly,
127
- // or under the response's equivalence (a case/width twin). Restating
128
- // hits may only conclude through disciplined reverse recall: voicing
129
- // their bytes echoes the query back at itself (never an answer — the
130
- // same principle that keeps cast from voicing stored questions), and
131
- // projecting them forward is reverse recall's containment failure in the
132
- // other direction — "whatever followed these bytes in some document".
133
- const qKey = ctx.canon ? ctx.canon(query) : query;
134
- const restates = (b) => bytesEqual(b, query) ||
135
- (ctx.canon !== null && bytesEqual(ctx.canon(b), qKey));
136
- const idBar = identityBar(ctx.store.D, ctx.space.maxGroup, query.length);
137
- if (top.score >= idBar) {
138
- for (const h of whole) {
139
- // The identity claim is PER HIT, not per tier: hits are ranked
140
- // nearest-first, and grounding one below the bar under this tier's
141
- // "near-identical" label would launder byte-overlap noise (observed:
142
- // "merci" projecting through the unrelated near hit "meraih").
143
- if (h.score < idBar)
144
- break;
145
- const own = read(ctx, h.id);
146
- if (h.id === qId || restates(own)) {
147
- const rev = ctx.store.prevFirst(h.id, hubBound(ctx));
148
- const g = reverseContext(ctx, h.id, queryGist, rev);
149
- if (g !== null) {
150
- return ground(g, rev.length === 1
151
- ? "perfect self-match — reverse recall to the sole predecessor"
152
- : "perfect self-match — reverse recall to the best-resonating predecessor", nothing, STEP);
153
- }
154
- continue;
155
- }
156
- const g = await project(ctx, h.id, queryGist);
157
- if (g) {
158
- return ground(g, "clean whole-query resonance — ground the nearest hit", whole_, STEP);
159
- }
160
- }
161
- }
162
- // The query-relative grounding fraction, shared by tiers 2–4 — gated on
163
- // the FRACTION OF THE QUERY the grounding explains, not the raw cosine.
164
- // Root gists are unit vectors, but their magnitudes are recoverable from
165
- // the byte lengths (‖·‖ = √len under the linear fold):
166
- // cos = shared/√(lenQ·lenG), so shared/lenQ = cos·√(lenG/lenQ).
167
- // The raw cosine punished honest containment — a query fully inside a
168
- // longer grounded answer scored √(lenQ/lenG) and was refused — and let a
169
- // long answer sharing only scaffolding pass; the query-relative fraction
170
- // measures exactly what the reach bar means: how much of THE QUERY the
171
- // store accounts for.
172
- // Chance similarity survives the length conversion AMPLIFIED: the same
173
- // √(lenG/lenQ) factor that converts an honest shared fraction into a
174
- // query-relative one multiplies the estimator/chance floor too, so a long
175
- // stored form (√(lenG/lenQ) ≈ 10 at 100×) lifted a noise-level cosine past
176
- // the reach bar and grounded pure gibberish (observed). Only the
177
- // ABOVE-CHANCE part of the similarity is evidence of shared content —
178
- // subtract the significance bar (3/√D, §8.3) before converting. Derived
179
- // from the existing bars; never tuned.
180
- const sig = significanceBar(ctx.store.D);
181
- const reach = reachThreshold(ctx.space.maxGroup);
182
- const fracOfQuery = (cos, otherLen) => Math.min(1, Math.max(0, cos - sig) *
183
- Math.sqrt(otherLen / Math.max(1, query.length)));
184
- // 2. Scaffolding-dominated.
185
- if (top.score >= sig) {
186
- // The committed points of attention ARE the shared climb's roots (same
187
- // query, same k, same DF mode) — read them from Precomputed instead of
188
- // re-climbing, so even a traced response pays for the climb once.
189
- const forest = (await pre.attention()).roots;
190
- // TRUST THE ANCHOR ON ITS BREADTH, NOT ON ITS ABSOLUTE VOTE.
191
- //
192
- // This gate read `forest[0].vote >= consensusFloor(N)`. Attention.breadth's
193
- // own contract (types.ts) says why that is the wrong quantity: the IDF vote
194
- // is "an absolute, ln(N)-scaled quantity that means 'strong' on a small
195
- // store and 'weak' on a large one for the SAME degree of genuine
196
- // consensus", while breadth is the SCALE-INVARIANT reading — "a point whose
197
- // breadth clears `dominates` (> half the query's regions corroborate it) is
198
- // real consensus; one that does not is a coincidental single-region echo".
199
- // Attention.peak's contract makes the same point from the other side:
200
- // comparing a POOLED SUM against a floor that prices ONE region's evidence
201
- // is a dimensional error.
202
- //
203
- // Measured on the 15.7M-node store (N=325,615, so the old floor was 13.19).
204
- // The absolute vote cannot separate right from wrong at this scale, and the
205
- // proof is a probe that must stay SILENT:
206
- //
207
- // anchor picked by the climb vote breadth correct?
208
- // "What is the chemical formula …" 10.60 0.556 RIGHT
209
- // "Qual é a capital de França?" 8.19 0.667 RIGHT
210
- // "Who wrote the play Romeo …?" 8.25 0.833 RIGHT
211
- // "How do you say "good morning" …" 10.77 0.800 RIGHT
212
- // "What is the commercial capital …" 12.69 0.333 Zamunda — MUST be silent
213
- // "Menene sunan ginin mafi tsayi …" 12.79 0.214 wrong (Hausa)
214
- // "Today is the 5th of March …" 10.36 0.000 wrong
215
- //
216
- // Zamunda's junk attractor outvotes every correct anchor, so no vote
217
- // threshold admits the right ones without admitting fabrication — while
218
- // breadth > ½ admits exactly the four correct anchors and nothing else.
219
- // The old floor was simply never cleared on a corpus this large: the tier
220
- // was dead code here, which is why 12 probes fell through to silence.
221
- //
222
- // `dominates(breadth, 1)` is the SAME half-dominance predicate used
223
- // throughout, applied to the fraction — no new constant, and the bar the
224
- // breadth contract names. COST: none; breadth is already computed and
225
- // carried on every Attention the climb returns.
226
- //
227
- // The two readings are ALTERNATIVES, never a substitution. REPLACING the
228
- // vote test with the breadth test was tried and broke 7 tests: on a small
229
- // store ln(N) is low, so the vote bar is the one that legitimately fires
230
- // there, and — as Attention.clusters' own contract warns — "breadth starves
231
- // a genuine, evenly-split multi-topic query, since no root in a real N-way
232
- // split can exceed half the vote" (the two 3.1 two-topic fusion tests are
233
- // exactly that shape). Each reading is sufficient on its own evidence: a
234
- // vote that clears the absolute floor is strong enough wherever the corpus
235
- // is small enough for that to mean something, and a breadth past ½ is real
236
- // consensus at any scale. ORing them keeps every admission the floor
237
- // already made and adds only the scale-invariant ones it could never see.
238
- //
239
- // BREADTH ALSO NEEDS DISCRIMINATIVENESS. Breadth asks how much of the
240
- // query corroborates the anchor, never whether the anchor SAYS anything: on
241
- // a one-context store every region trivially corroborates the only anchor
242
- // there is, so breadth is 1 while the anchor's IDF is 0 — and test/31 A2
243
- // ("explain quantum chromodynamics" against a lone cat fact) answered the
244
- // cat, which is fabrication. A region's IDF contribution for an anchor
245
- // reached through c of N contexts is ln(N/c), so requiring it to exceed
246
- // ln 2 is requiring c·2 < N — the SAME half-dominance reading used
247
- // everywhere, expressed in the IDF's own units rather than as a new bar.
248
- // `peak` is that per-region contribution, and reading it here is what
249
- // Attention.peak's contract asks of a consumer gating on this evidence.
250
- //
251
- // AND THE QUERY MUST SAY SOMETHING. Both readings above price the
252
- // ANCHOR's evidence; neither asks whether the QUERY discriminates
253
- // anything. A query that is entirely corpus-global scaffolding gives the
254
- // corpus nothing to be held to, and this tier — which exists to serve
255
- // scaffolding-DOMINATED queries — is exactly where that runs out.
256
- // Measured on the trained store: "What is the capital " answered "Colombo
257
- // is the commercial capital of Sri Lanka…" on breadth 0.667 / clusters 1,
258
- // and every window it spells is a hub ("What":572). See
259
- // allWindowsAreScaffolding for the full separation, including the probes
260
- // this tier serves CORRECTLY, which all retain a discriminating window
261
- // ("what is the capital of france" → "f fr":248).
262
- //
263
- // DISPERSION WAS TRIED HERE FIRST AND FALSIFIED — do not retry it: the
264
- // fabrication and the no-punctuation robustness probe have the IDENTICAL
265
- // profile (breadth 0.667, clusters 1), so requiring clusters >= 2 silenced
266
- // "what is the capital of france" too and cost the battery a probe.
267
- const minVote = consensusFloor(corpusN(ctx));
268
- if (forest.length > 0 &&
269
- !allWindowsAreScaffolding(ctx, query) &&
270
- (forest[0].vote >= minVote ||
271
- (dominates(forest[0].breadth, 1) && forest[0].peak > Math.LN2))) {
272
- const g = await project(ctx, forest[0].anchor, queryGist);
273
- // The anchor cleared the consensus floor, but the floor prices the
274
- // ANCHOR's evidence, not the projection's: a junk attractor can clear
275
- // it and project a PIECE OF THE QUERY back at it (the observed
276
- // "buenos días in English" → "English" fragment). A projection that
277
- // is a proper byte-subspan of the query restates part of the question
278
- // — never an answer (the same principle as `restates` above, extended
279
- // to fragments). Genuine anchor groundings — longer than the query,
280
- // or disjoint from it — pass untouched.
281
- if (g && !(g.length < query.length && indexOf(query, g, 0) >= 0)) {
282
- return ground(g, "scaffolding-dominated query — ground the consensus-climb anchor", [[forest[0].start, forest[0].end]], CONCEPT);
283
- }
284
- }
285
- }
286
- // 3. Last resort — the nearest grounded whole-query hit, same gate.
287
- for (const h of whole) {
288
- const g = await project(ctx, h.id, queryGist);
289
- if (g) {
290
- if (fracOfQuery(cosine(queryGist, gistOf(ctx, g)), g.length) >=
291
- reach) {
292
- return ground(g, "last resort: the nearest grounded whole-query hit", [], STEP);
293
- }
294
- }
295
- }
296
- // 3b. Corroborated-substitution bridge — refusal-path only (bridge.ts).
297
- // The WIDE candidate list every past-the-top-k mechanism reads lives on
298
- // Precomputed (see wideResonance): shared across the whole response, so the
299
- // exhaustive branch runs at most once whoever first-touches it.
300
- const wideIds = () => pre.wideResonance();
301
- // Every gist-based tier has failed; before refusing, align the query
302
- // byte-for-byte against the trained contexts its own stored windows
303
- // anchor, accepting mismatches only as corpus-attested, concept-bar
304
- // substitutions. A bridged context grounds exactly like any hit —
305
- // projected through its learnt edges — under the same restated-fragment
306
- // guard tiers 0b/2 apply. Costs nothing on any answering path.
307
- {
308
- // The resonance hits already ranked above are handed to the bridge as
309
- // PROPOSED candidates alongside its own anchor climbs: on a corpus this
310
- // size a W-byte window is far too common for the clamped climb to
311
- // single out the right trained context, while the whole-query gist
312
- // already ranked it nearest (observed live: "what is the capital of
313
- // france" resonating straight to "What is the capital of France?" yet
314
- // refusing on the reach bar). Approximate scores propose; the bridge's
315
- // byte-exact alignment and attestation gates decide.
316
- //
317
- // Reuse recall's already-ranked proposals. Never scan every IVF cluster:
318
- // exact co-occurrence and bounded anchor ascent are the bridge's structural
319
- // proposal channels, while an exhaustive ANN call made every honest
320
- // refusal cost hundreds of milliseconds regardless of k.
321
- const bridged = await substitutionBridge(ctx, query, wideIds);
322
- if (bridged !== null) {
323
- const g = await project(ctx, bridged.id, queryGist);
324
- // A projection contained in a substituted candidate-side span is the
325
- // substitution RESTATED as if it were knowledge — the exact failure
326
- // observed live: "Darwin was born in England." bridged to the
327
- // Einstein fact through " England." → " Germany." and would have
328
- // voiced "Germany", an answer the substitution itself manufactured.
329
- // The same principle as the restated-fragment guards above, extended
330
- // to the bridge's own substitutions.
331
- const cBytes = ctx.store.bytes(bridged.id);
332
- const manufactured = g !== null &&
333
- bridged.subs.some((s) => indexOf(cBytes.subarray(s.cs, s.ce), g, 0) >= 0);
334
- // THE PREFIX TRAP IS NOT THIS TIER'S TO SPRING. With no substitutions
335
- // the claim is "a trained context IS this query, up to filler". When
336
- // the query is a STRICT BYTE PREFIX of that context, the claim is false
337
- // in the one way that matters: the candidate's extra tail is precisely
338
- // the DISCRIMINATING part, and dismissing it as filler asserts a
339
- // specification the asker never made. Measured on a 4,300-fact fixture
340
- // of "what is the value of <i>?": the query "what is the value of"
341
- // bridged with subs [] to "what is the value of 0?" and answered "the
342
- // value of 0 is 0" — one arbitrary pick from 4,300 equally-matching
343
- // contexts, every one of which fits the query exactly as well.
344
- //
345
- // The engine ALREADY has the right machinery for this shape:
346
- // prefixCompletion runs a few lines below and carries the three guards
347
- // this tier lacks — unreadable-continuation veto, sub-quantum
348
- // continuation, and UNIQUENESS (distinct continuations ⇒ refuse), which
349
- // is exactly what 4,300 competing values must trip. So this is not a
350
- // new rule and not a new threshold: it is deferring a prefix decision to
351
- // the tier that owns it (§2.5, one factored machinery). Byte-strict on
352
- // purpose — a candidate differing by case or punctuation ("what is the
353
- // capital of france" → "What is the capital of France?") is NOT a byte
354
- // prefix, keeps grounding here, and is unaffected.
355
- const strictPrefix = g !== null &&
356
- cBytes.length > query.length &&
357
- indexOf(cBytes, query, 0) === 0;
358
- if (g !== null && g.length > 0 && !restates(g) && !manufactured &&
359
- !(bridged.subs.length === 0 && strictPrefix) &&
360
- !(g.length < query.length && indexOf(query, g, 0) >= 0)) {
361
- return ground(g, bridged.subs.length === 0
362
- ? `identity bridge — a trained context IS this query, up to ` +
363
- `scaffolding the corpus itself treats as filler`
364
- : `substitution bridge — a trained context accounts for the ` +
365
- `query up to ${bridged.subs.length} corroborated ` +
366
- `substitution(s)`,
367
- // WHAT THIS GROUNDING EXPLAINS — the spans its alignment covers,
368
- // matched AND substituted, for BOTH tiers.
369
- //
370
- // A corroborated substitution is not a gap in the explanation; it is
371
- // an explanation the mechanism PAID for, one CONCEPT each in `moves`
372
- // just below. Leaving its span unaccounted charges the same act
373
- // twice — once as a move, once as PASS-per-unexplained-byte — and the
374
- // second charge is far the larger, so a bridge that matched 28 of 29
375
- // bytes declared the whole query unexplained and lost to any
376
- // mechanism with a smaller honest claim. Measured on test/49's
377
- // paraphrase: it FOUND the trained fact through two corroborated case
378
- // substitutions and was outbid 29011 to 1012 by a CAST comparison
379
- // that voiced the wrong country.
380
- //
381
- // This tier DID once report `[]` for the substituted case, against
382
- // the observation that "pricing the aligned spans outweighed
383
- // extraction's correct answer in the grounding decider". That is no
384
- // longer so and the suite is the witness: with the fold's regions
385
- // content-defined and the junction tiers no longer consuming each
386
- // other's candidates, full accounting here passes every test that
387
- // refutation was recorded for. Reporting only the LITERALLY matched
388
- // spans (accounted minus the substituted ones) was also implemented
389
- // and is a strictly worse reading of the same ladder — it still
390
- // double-charges, just less.
391
- //
392
- // An IDENTITY bridge (zero substitutions) substituted nothing, so
393
- // there is nothing to be humble about: every accounted byte is a
394
- // LITERAL match against a trained form, and the query is that form
395
- // up to scaffolding. Reporting `[]` for it was actively wrong in
396
- // two ways — it priced a full explanation at PASS-per-byte so junk
397
- // outweighed it, and, because the honest-remainder test in think()
398
- // reads the same spans, it left the whole query "unaccounted" and
399
- // forced the multi-topic fusion gate open. Observed live: the
400
- // correct "What is the process of photosynthesis?" grounding was
401
- // fused away into an unrelated "Hello! How can I assist you
402
- // today?" point of attention.
403
- [...bridged.accounted], CONCEPT * bridged.subs.length + STEP, false,
404
- // COMPLETE only for the identity tier: the query IS this trained
405
- // context, so `g` is that context's own continuation — the whole
406
- // read-out. A SUBSTITUTED bridge makes no such claim (it stood a
407
- // different word in the query's place), so it stays extendable.
408
- bridged.subs.length === 0);
409
- }
410
- }
411
- }
412
- // The refusal/echo decision. The echo returns a stored form's bytes AS
413
- // the answer — a near-identity claim about the query — and identity-grade
414
- // decisions are never made on an estimated score ("approximate scores may
415
- // rank and propose; they may never decide", §6.2): the RaBitQ estimate
416
- // overshooting the reach bar echoed a WRONG-entity neighbour ("capital of
417
- // Zamunda?" echoed the Armenia fact, observed). The bytes are read
418
- // anyway to be echoed, so the decision uses their EXACT fold: one river
419
- // fold of the top hit, measured in the same query-relative,
420
- // chance-corrected units as the tier above.
421
- const topBytes = read(ctx, top.id);
422
- const exact = topBytes.length > 0
423
- ? cosine(queryGist, gistOf(ctx, topBytes))
424
- : 0;
425
- if (fracOfQuery(exact, topBytes.length) < reach) {
426
- return ground(null, "below reach threshold — nothing in the store relates to this query", [], 0);
427
- }
428
- // Echoing the query's own bytes back at it is not an echo of a RELATED
429
- // form — it is the query restated, which answers nothing.
430
- if (restates(topBytes)) {
431
- return ground(null, "the nearest form IS the query itself — restating it answers nothing", [], 0);
432
- }
433
- // Honest echo.
434
- return ground(topBytes, "last resort: the nearest resonant form's own bytes (echo, not grounded)", [], 0, true);
435
- }
436
- // ── Pipeline mechanism ──────────────────────────────────────────────────────
437
- export const recallMechanism = {
438
- name: "recall",
439
- provenance: "recall",
440
- // Recall's floor is free to state (one STEP-grade projection) and its run
441
- // gates its own tiers — no expensive investment happens inside floor, so
442
- // there is nothing to guard with worthRunning here: the pipeline's own
443
- // check prunes run() against the incumbent.
444
- async floor(_ctx, _query, _pre, _worthRunning) {
445
- return STEP;
446
- },
447
- async run(ctx, query, pre) {
448
- const r = await recallByResonance(ctx, query, pre);
449
- if (!r)
450
- return [];
451
- return [{
452
- bytes: r.bytes,
453
- accounted: r.accounted,
454
- moves: r.moves,
455
- unexplained: r.unexplained,
456
- provenance: r.echoed ? "recall-echo" : "recall",
457
- ...(r.complete ? { complete: true } : {}),
458
- }];
459
- },
460
- };
@@ -1,6 +0,0 @@
1
- import type { MindContext } from "../types.js";
2
- import type { MechanismResult, PipelineMechanism, Precomputed } from "../pipeline-mechanism.js";
3
- /** Voice the query's referents through their frame's own attested carriage, or
4
- * null when the corpus does not attest one. */
5
- export declare function bindReference(ctx: MindContext, query: Uint8Array, pre: Precomputed): Promise<MechanismResult | null>;
6
- export declare const referenceMechanism: PipelineMechanism;