@hviana/sema 0.5.2 → 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.
- package/AGENTS.md +115 -53
- package/HOW_IT_WORKS.md +291 -184
- package/jsr.json +6 -0
- package/package.json +1 -1
- package/src/mind/bridge.ts +10 -104
- package/src/mind/match.ts +497 -7
- package/src/mind/{prefix-completion.ts → mechanisms/prefix-completion.ts} +66 -92
- package/src/mind/mechanisms/recall.ts +38 -129
- package/src/mind/mechanisms/reference.ts +343 -0
- package/src/mind/mind.ts +12 -8
- package/src/mind/pipeline-mechanism.ts +120 -3
- package/src/mind/pipeline.ts +16 -2
- package/src/mind/traverse.ts +92 -1
- package/src/store.ts +13 -4
- package/test/33-multi-candidate.test.mjs +21 -11
- package/test/70-prefix-completion.test.mjs +1 -1
- package/test/72-prefix-candidate-supply.test.mjs +7 -9
- package/test/74-prefix-trap-not-sprung-early.test.mjs +1 -1
- package/test/76-reference-binding.test.mjs +543 -0
- package/dist/example/demo.d.ts +0 -1
- package/dist/example/demo.js +0 -39
- package/dist/example/train_base.d.ts +0 -93
- package/dist/example/train_base.js +0 -2269
- package/dist/src/alphabet.d.ts +0 -7
- package/dist/src/alphabet.js +0 -33
- package/dist/src/alu/src/alu.d.ts +0 -185
- package/dist/src/alu/src/alu.js +0 -440
- package/dist/src/alu/src/expr.d.ts +0 -61
- package/dist/src/alu/src/expr.js +0 -318
- package/dist/src/alu/src/index.d.ts +0 -11
- package/dist/src/alu/src/index.js +0 -19
- package/dist/src/alu/src/kernel-arith.d.ts +0 -16
- package/dist/src/alu/src/kernel-arith.js +0 -264
- package/dist/src/alu/src/kernel-bits.d.ts +0 -19
- package/dist/src/alu/src/kernel-bits.js +0 -152
- package/dist/src/alu/src/kernel-logic.d.ts +0 -4
- package/dist/src/alu/src/kernel-logic.js +0 -60
- package/dist/src/alu/src/kernel-nd.d.ts +0 -3
- package/dist/src/alu/src/kernel-nd.js +0 -208
- package/dist/src/alu/src/kernel-numeric.d.ts +0 -54
- package/dist/src/alu/src/kernel-numeric.js +0 -366
- package/dist/src/alu/src/operation.d.ts +0 -168
- package/dist/src/alu/src/operation.js +0 -189
- package/dist/src/alu/src/parser.d.ts +0 -221
- package/dist/src/alu/src/parser.js +0 -577
- package/dist/src/alu/src/resonance.d.ts +0 -55
- package/dist/src/alu/src/resonance.js +0 -126
- package/dist/src/alu/src/text.d.ts +0 -31
- package/dist/src/alu/src/text.js +0 -73
- package/dist/src/alu/src/value.d.ts +0 -109
- package/dist/src/alu/src/value.js +0 -300
- package/dist/src/alu/test/alu.test.d.ts +0 -1
- package/dist/src/alu/test/alu.test.js +0 -764
- package/dist/src/bytes.d.ts +0 -14
- package/dist/src/bytes.js +0 -59
- package/dist/src/canon.d.ts +0 -45
- package/dist/src/canon.js +0 -85
- package/dist/src/config.d.ts +0 -111
- package/dist/src/config.js +0 -91
- package/dist/src/derive/src/deduction.d.ts +0 -136
- package/dist/src/derive/src/deduction.js +0 -159
- package/dist/src/derive/src/index.d.ts +0 -8
- package/dist/src/derive/src/index.js +0 -11
- package/dist/src/derive/src/priority-queue.d.ts +0 -20
- package/dist/src/derive/src/priority-queue.js +0 -73
- package/dist/src/derive/src/rewrite.d.ts +0 -56
- package/dist/src/derive/src/rewrite.js +0 -100
- package/dist/src/derive/src/trie.d.ts +0 -90
- package/dist/src/derive/src/trie.js +0 -217
- package/dist/src/derive/test/derive.test.d.ts +0 -1
- package/dist/src/derive/test/derive.test.js +0 -122
- package/dist/src/extension.d.ts +0 -37
- package/dist/src/extension.js +0 -7
- package/dist/src/geometry.d.ts +0 -233
- package/dist/src/geometry.js +0 -1089
- package/dist/src/index.d.ts +0 -17
- package/dist/src/index.js +0 -19
- package/dist/src/ingest-cache.d.ts +0 -41
- package/dist/src/ingest-cache.js +0 -165
- package/dist/src/meter.d.ts +0 -176
- package/dist/src/meter.js +0 -274
- package/dist/src/mind/articulation.d.ts +0 -6
- package/dist/src/mind/articulation.js +0 -99
- package/dist/src/mind/attention.d.ts +0 -430
- package/dist/src/mind/attention.js +0 -2418
- package/dist/src/mind/bridge.d.ts +0 -39
- package/dist/src/mind/bridge.js +0 -998
- package/dist/src/mind/canonical.d.ts +0 -34
- package/dist/src/mind/canonical.js +0 -93
- package/dist/src/mind/frame-filler.d.ts +0 -15
- package/dist/src/mind/frame-filler.js +0 -535
- package/dist/src/mind/graph-search.d.ts +0 -294
- package/dist/src/mind/graph-search.js +0 -996
- package/dist/src/mind/index.d.ts +0 -9
- package/dist/src/mind/index.js +0 -5
- package/dist/src/mind/junction.d.ts +0 -137
- package/dist/src/mind/junction.js +0 -358
- package/dist/src/mind/learning.d.ts +0 -75
- package/dist/src/mind/learning.js +0 -265
- package/dist/src/mind/match.d.ts +0 -192
- package/dist/src/mind/match.js +0 -666
- package/dist/src/mind/mechanisms/alu.d.ts +0 -4
- package/dist/src/mind/mechanisms/alu.js +0 -36
- package/dist/src/mind/mechanisms/cast.d.ts +0 -89
- package/dist/src/mind/mechanisms/cast.js +0 -1186
- package/dist/src/mind/mechanisms/confluence.d.ts +0 -24
- package/dist/src/mind/mechanisms/confluence.js +0 -271
- package/dist/src/mind/mechanisms/cover.d.ts +0 -6
- package/dist/src/mind/mechanisms/cover.js +0 -232
- package/dist/src/mind/mechanisms/extraction.d.ts +0 -33
- package/dist/src/mind/mechanisms/extraction.js +0 -327
- package/dist/src/mind/mechanisms/recall.d.ts +0 -16
- package/dist/src/mind/mechanisms/recall.js +0 -558
- package/dist/src/mind/mind.d.ts +0 -386
- package/dist/src/mind/mind.js +0 -754
- package/dist/src/mind/pipeline-mechanism.d.ts +0 -183
- package/dist/src/mind/pipeline-mechanism.js +0 -521
- package/dist/src/mind/pipeline.d.ts +0 -49
- package/dist/src/mind/pipeline.js +0 -331
- package/dist/src/mind/prefix-completion.d.ts +0 -59
- package/dist/src/mind/prefix-completion.js +0 -270
- package/dist/src/mind/primitives.d.ts +0 -85
- package/dist/src/mind/primitives.js +0 -333
- package/dist/src/mind/rationale.d.ts +0 -139
- package/dist/src/mind/rationale.js +0 -163
- package/dist/src/mind/reasoning.d.ts +0 -42
- package/dist/src/mind/reasoning.js +0 -305
- package/dist/src/mind/recognition.d.ts +0 -20
- package/dist/src/mind/recognition.js +0 -696
- package/dist/src/mind/resonance.d.ts +0 -35
- package/dist/src/mind/resonance.js +0 -365
- package/dist/src/mind/trace.d.ts +0 -15
- package/dist/src/mind/trace.js +0 -73
- package/dist/src/mind/traverse.d.ts +0 -158
- package/dist/src/mind/traverse.js +0 -716
- package/dist/src/mind/types.d.ts +0 -418
- package/dist/src/mind/types.js +0 -179
- package/dist/src/rabitq-ivf/src/database.d.ts +0 -113
- package/dist/src/rabitq-ivf/src/database.js +0 -201
- package/dist/src/rabitq-ivf/src/index.d.ts +0 -7
- package/dist/src/rabitq-ivf/src/index.js +0 -4
- package/dist/src/rabitq-ivf/src/ivf.d.ts +0 -200
- package/dist/src/rabitq-ivf/src/ivf.js +0 -1165
- package/dist/src/rabitq-ivf/src/prng.d.ts +0 -19
- package/dist/src/rabitq-ivf/src/prng.js +0 -36
- package/dist/src/rabitq-ivf/src/rabitq.d.ts +0 -95
- package/dist/src/rabitq-ivf/src/rabitq.js +0 -313
- package/dist/src/sema.d.ts +0 -41
- package/dist/src/sema.js +0 -77
- package/dist/src/store-sqlite.d.ts +0 -184
- package/dist/src/store-sqlite.js +0 -942
- package/dist/src/store.d.ts +0 -762
- package/dist/src/store.js +0 -1823
- package/dist/src/vec.d.ts +0 -31
- package/dist/src/vec.js +0 -109
- package/src/mind/frame-filler.ts +0 -604
- package/test/69-frame-filler.test.mjs +0 -115
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
// prefix-completion.ts — Grounding a query that IS the opening of a
|
|
2
|
-
// form.
|
|
1
|
+
// mechanisms/prefix-completion.ts — Grounding a query that IS the opening of a
|
|
2
|
+
// trained form (Grounding V).
|
|
3
|
+
//
|
|
4
|
+
// A MECHANISM, NOT A TIER. This used to run inside recall's refusal path, in
|
|
5
|
+
// a fixed if-chain that first-match-wins — the shape CAST was refactored away
|
|
6
|
+
// from, where placement rather than the cost ladder decided. Its claim is
|
|
7
|
+
// maximal (every query byte literally matched, from offset zero, against a
|
|
8
|
+
// trained form) at one STEP, so as a market candidate it competes honestly and
|
|
9
|
+
// the decider weighs it like everything else. It is registered LAST: recall's
|
|
10
|
+
// exact self-match makes an IDENTITY claim about the query while this makes a
|
|
11
|
+
// CONTAINMENT one, and on an exact grade tie the identity claim is the
|
|
12
|
+
// stronger evidence — the same ordering §2.3's ladders use.
|
|
13
|
+
//
|
|
14
|
+
// Its SUPPLY moved too, and further: `formsOpenedBy` (traverse.ts) answers a
|
|
15
|
+
// question about the STORE — "which trained forms does this byte run open?" —
|
|
16
|
+
// so it is retrieval machinery any mechanism may ask, not this one's private
|
|
17
|
+
// helper.
|
|
3
18
|
//
|
|
4
19
|
// THE SHAPE. `The capital of France is` grounds nothing, while
|
|
5
20
|
// `The capital of France is Paris.` is trained and reads back byte-exact. The
|
|
@@ -75,96 +90,12 @@
|
|
|
75
90
|
// same continuation reached through two trained forms is one answer, not an
|
|
76
91
|
// ambiguity.
|
|
77
92
|
|
|
78
|
-
import type { MindContext } from "
|
|
79
|
-
import { bytesEqual } from "
|
|
80
|
-
import { rItem } from "
|
|
81
|
-
import {
|
|
82
|
-
import {
|
|
83
|
-
|
|
84
|
-
/** Trained forms the query may OPEN, proposed from the write side's own
|
|
85
|
-
* leaf-id window index — the supply of last resort for {@link
|
|
86
|
-
* prefixCompletion}.
|
|
87
|
-
*
|
|
88
|
-
* WHY A SECOND SUPPLY EXISTS. The ranked list this mechanism normally reads
|
|
89
|
-
* is a resonance list, and resonance cannot rank a proper prefix: measured on
|
|
90
|
-
* the trained store, cos(prefix, form) falls from 0.9629 at a one-byte
|
|
91
|
-
* truncation to 0.6206 at three bytes, against a reachThreshold of 0.8750.
|
|
92
|
-
* Three bytes of truncation put the answer out of reach on GEOMETRY, not on a
|
|
93
|
-
* bug, so no k and no re-ranking recovers it.
|
|
94
|
-
*
|
|
95
|
-
* WHY THIS ROUTE WORKS WHERE THE FOLD DOES NOT. A query's own fold is
|
|
96
|
-
* useless here: content addressing is not phrase-position-invariant, so a
|
|
97
|
-
* standalone prefix folds to a DIFFERENT node than the same bytes sitting
|
|
98
|
-
* inside a longer deposit, and neither the prefix's own node nor its
|
|
99
|
-
* ancestors lead to the deposit (measured: the 22-byte prefix of the
|
|
100
|
-
* photosynthesis form resolves, is shared by 6 contexts, and does not have
|
|
101
|
-
* the form among its ancestors). Leaf ids ARE position-invariant — they are
|
|
102
|
-
* content-addressed on single bytes — and `indexSubSpans` already interns a
|
|
103
|
-
* flat branch over every canonical WINDOW of a deposit's leaf-id stream, with
|
|
104
|
-
* containment edges to the chunks that window spans. A query that is a
|
|
105
|
-
* prefix therefore shares those window nodes exactly, and reaches the deposit
|
|
106
|
-
* by climbing containment then parents. Nothing is added to the write side;
|
|
107
|
-
* this reads an index training already built.
|
|
108
|
-
*
|
|
109
|
-
* BOUNDED (§2.8), AND WITH NO NEW THRESHOLD. The window whose containment is
|
|
110
|
-
* SMALLEST carries the most evidence, and one saturated at `hubBound` carries
|
|
111
|
-
* none — that is the same √N reading of "hub" the rest of the mind uses, not
|
|
112
|
-
* a tuned knob. The upward walk spends a budget of `hubBound` nodes and
|
|
113
|
-
* fans out by W, so a hub query enumerates nothing and the caller stays
|
|
114
|
-
* silent rather than guessing (§2.13). Measured on the trained store: the
|
|
115
|
-
* photosynthesis form at a one-byte truncation picks a window with 52
|
|
116
|
-
* containers, visits 446 nodes, and yields exactly ONE candidate that
|
|
117
|
-
* survives the caller's byte compare — the form itself.
|
|
118
|
-
*
|
|
119
|
-
* These are PROPOSALS only. Every candidate still faces the byte-exact
|
|
120
|
-
* prefix compare and all three guards below, so a wrong proposal costs one
|
|
121
|
-
* bounded read and can never be voiced (§2.3). */
|
|
122
|
-
export function prefixCandidates(
|
|
123
|
-
ctx: MindContext,
|
|
124
|
-
query: Uint8Array,
|
|
125
|
-
): number[] {
|
|
126
|
-
const store = ctx.store;
|
|
127
|
-
const W = ctx.space.maxGroup;
|
|
128
|
-
const run = leafIdPrefix(ctx, query);
|
|
129
|
-
// The widest canonical window is the most discriminative one the write side
|
|
130
|
-
// ever interned; a query too short to spell one carries no window evidence.
|
|
131
|
-
const len = canonicalWindows(W)[1];
|
|
132
|
-
if (run.length < len) return [];
|
|
133
|
-
const bound = hubBound(ctx);
|
|
134
|
-
|
|
135
|
-
let best: number | null = null;
|
|
136
|
-
let bestN = 0;
|
|
137
|
-
for (let off = 0; off + len <= run.length; off++) {
|
|
138
|
-
const wid = store.findBranch(run.slice(off, off + len));
|
|
139
|
-
if (wid === null) continue;
|
|
140
|
-
const n = store.containersSlice(wid, 0, bound).length;
|
|
141
|
-
// Empty says the window spans no chunk; saturated says it is a hub, whose
|
|
142
|
-
// containment discriminates nothing. Neither is evidence.
|
|
143
|
-
if (n === 0 || n >= bound) continue;
|
|
144
|
-
if (best === null || n < bestN) {
|
|
145
|
-
best = wid;
|
|
146
|
-
bestN = n;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (best === null) return [];
|
|
150
|
-
|
|
151
|
-
let frontier = store.containersSlice(best, 0, bound);
|
|
152
|
-
const seen = new Set<number>(frontier);
|
|
153
|
-
let budget = bound;
|
|
154
|
-
while (frontier.length > 0 && budget > 0) {
|
|
155
|
-
const next: number[] = [];
|
|
156
|
-
for (const f of frontier) {
|
|
157
|
-
if (budget-- <= 0) break;
|
|
158
|
-
for (const p of store.parentsFirst(f, W)) {
|
|
159
|
-
if (seen.has(p)) continue;
|
|
160
|
-
seen.add(p);
|
|
161
|
-
next.push(p);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
frontier = next;
|
|
165
|
-
}
|
|
166
|
-
return [...seen];
|
|
167
|
-
}
|
|
93
|
+
import type { MindContext } from "../types.js";
|
|
94
|
+
import { bytesEqual } from "../../bytes.js";
|
|
95
|
+
import { rItem } from "../trace.js";
|
|
96
|
+
import { formsOpenedBy } from "../traverse.js";
|
|
97
|
+
import { STEP } from "../graph-search.js";
|
|
98
|
+
import type { PipelineMechanism, Precomputed } from "../pipeline-mechanism.js";
|
|
168
99
|
|
|
169
100
|
/** A trained form the query opens, and the bytes by which it continues. */
|
|
170
101
|
export interface PrefixCompletion {
|
|
@@ -312,3 +243,46 @@ export function prefixCompletion(
|
|
|
312
243
|
data,
|
|
313
244
|
);
|
|
314
245
|
}
|
|
246
|
+
|
|
247
|
+
// ── Pipeline mechanism ──────────────────────────────────────────────────────
|
|
248
|
+
|
|
249
|
+
export const prefixMechanism: PipelineMechanism = {
|
|
250
|
+
name: "prefix",
|
|
251
|
+
provenance: "prefix",
|
|
252
|
+
async floor(ctx, query, _pre, worthRunning) {
|
|
253
|
+
// One projection: the form is voiced whole, nothing is substituted.
|
|
254
|
+
// INVESTMENT DISCIPLINE — the supplies below are the response's wide
|
|
255
|
+
// candidate list and a bounded √N walk, so neither is touched until the
|
|
256
|
+
// bound can still beat the incumbent.
|
|
257
|
+
if (!worthRunning(STEP)) return STEP;
|
|
258
|
+
// A query with no room for a perceivable continuation inside the phrase
|
|
259
|
+
// cap cannot clear guard 2, so it is not worth a single read.
|
|
260
|
+
const cap = query.length * ctx.space.maxGroup;
|
|
261
|
+
if (query.length === 0 || cap < query.length + ctx.space.maxGroup) {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
return STEP;
|
|
265
|
+
},
|
|
266
|
+
async run(ctx, query, pre) {
|
|
267
|
+
// The response's shared wide list first; only when it supplies nothing does
|
|
268
|
+
// the write side's window index propose. That ordering is the whole cost
|
|
269
|
+
// story: a query the ranked list can already explain pays not one extra
|
|
270
|
+
// read, and the bounded walk is spent only where the alternative is an
|
|
271
|
+
// empty answer. A second SUPPLY, not a second mechanism — the same three
|
|
272
|
+
// guards decide either way.
|
|
273
|
+
const completed = prefixCompletion(ctx, query, await pre.wideResonance()) ??
|
|
274
|
+
prefixCompletion(ctx, query, formsOpenedBy(ctx, query));
|
|
275
|
+
if (completed === null) return [];
|
|
276
|
+
return [{
|
|
277
|
+
bytes: completed.form,
|
|
278
|
+
// Every query byte is literally matched against the form, so there is
|
|
279
|
+
// nothing to be humble about in the accounting — the same reading the
|
|
280
|
+
// IDENTITY bridge takes.
|
|
281
|
+
accounted: [[0, query.length]],
|
|
282
|
+
moves: STEP,
|
|
283
|
+
unexplained: "",
|
|
284
|
+
// NOT complete: the query is a proper PREFIX, so the form may carry more
|
|
285
|
+
// past the remainder this voiced.
|
|
286
|
+
}];
|
|
287
|
+
},
|
|
288
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// mechanisms/recall.ts — Recall by resonance (Grounding
|
|
1
|
+
// mechanisms/recall.ts — Recall by resonance (Grounding VI).
|
|
2
2
|
//
|
|
3
3
|
// The recall mechanism resonates the whole query's gist against the content
|
|
4
4
|
// index and grounds the nearest learned form. Four tiers, orderly degrading
|
|
@@ -17,14 +17,17 @@ import type { MindContext } from "../types.js";
|
|
|
17
17
|
import { gistOf, read, resolve } from "../primitives.js";
|
|
18
18
|
import { bytesEqual, indexOf } from "../../bytes.js";
|
|
19
19
|
import { allWindowsAreScaffolding, corpusN, hubBound } from "../traverse.js";
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
follow,
|
|
22
|
+
project,
|
|
23
|
+
reverseContext,
|
|
24
|
+
voicesDisplacedFiller,
|
|
25
|
+
} from "../match.js";
|
|
21
26
|
import { CONCEPT, STEP } from "../graph-search.js";
|
|
22
27
|
import { unexplainedLabel } from "../rationale.js";
|
|
23
28
|
import type { PipelineMechanism, Precomputed } from "../pipeline-mechanism.js";
|
|
24
29
|
import { rItem, rNode } from "../trace.js";
|
|
25
30
|
import { substitutionBridge } from "../bridge.js";
|
|
26
|
-
import { frameFillerSubstitution } from "../frame-filler.js";
|
|
27
|
-
import { prefixCandidates, prefixCompletion } from "../prefix-completion.js";
|
|
28
31
|
|
|
29
32
|
/** A recall result. */
|
|
30
33
|
export interface RecallResult {
|
|
@@ -165,7 +168,10 @@ export async function recallByResonance(
|
|
|
165
168
|
}
|
|
166
169
|
}
|
|
167
170
|
|
|
168
|
-
|
|
171
|
+
// The response's ONE top-k read (Precomputed.resonance) — the same list the
|
|
172
|
+
// frame inventory is assembled from, so a query that reaches both pays for a
|
|
173
|
+
// single ANN query rather than two identical ones.
|
|
174
|
+
const whole = await pre.resonance();
|
|
169
175
|
if (whole.length === 0) {
|
|
170
176
|
return ground(null, "empty store — nothing to resonate with", [], 0);
|
|
171
177
|
}
|
|
@@ -348,7 +354,28 @@ export async function recallByResonance(
|
|
|
348
354
|
(dominates(forest[0].breadth, 1) && forest[0].peak > Math.LN2))
|
|
349
355
|
) {
|
|
350
356
|
const g = await project(ctx, forest[0].anchor, queryGist);
|
|
351
|
-
//
|
|
357
|
+
// THE ANCHOR'S OCCUPANT IS NOT THE ASKER'S. This tier grounds an anchor
|
|
358
|
+
// the climb elected, and voices that anchor's continuation. When the
|
|
359
|
+
// query is the same structure with one position filled differently, the
|
|
360
|
+
// continuation speaks the ANCHOR's occupant of that position — a fluent,
|
|
361
|
+
// specific, wrong answer (see voicesDisplacedFiller). Refusing here is
|
|
362
|
+
// silence, not a redirection: putting the asker's referent in its place
|
|
363
|
+
// is a stronger claim that needs the corpus's own carriage evidence, and
|
|
364
|
+
// that is `reference`'s job.
|
|
365
|
+
const anchorBytes = read(
|
|
366
|
+
ctx,
|
|
367
|
+
forest[0].anchor,
|
|
368
|
+
query.length * ctx.space.maxGroup + 1,
|
|
369
|
+
);
|
|
370
|
+
if (g !== null && voicesDisplacedFiller(ctx, query, anchorBytes, g)) {
|
|
371
|
+
ctx.trace?.step(
|
|
372
|
+
"displacedFiller",
|
|
373
|
+
[rItem(query, "query"), rNode(ctx, forest[0].anchor, "anchor")],
|
|
374
|
+
[rItem(g, "withheld")],
|
|
375
|
+
"refused — the anchor's continuation speaks the anchor's own " +
|
|
376
|
+
"occupant of a position this query fills differently",
|
|
377
|
+
);
|
|
378
|
+
} // The anchor cleared the consensus floor, but the floor prices the
|
|
352
379
|
// ANCHOR's evidence, not the projection's: a junk attractor can clear
|
|
353
380
|
// it and project a PIECE OF THE QUERY back at it (the observed
|
|
354
381
|
// "buenos días in English" → "English" fragment). A projection that
|
|
@@ -356,7 +383,7 @@ export async function recallByResonance(
|
|
|
356
383
|
// — never an answer (the same principle as `restates` above, extended
|
|
357
384
|
// to fragments). Genuine anchor groundings — longer than the query,
|
|
358
385
|
// or disjoint from it — pass untouched.
|
|
359
|
-
if (g && !(g.length < query.length && indexOf(query, g, 0) >= 0)) {
|
|
386
|
+
else if (g && !(g.length < query.length && indexOf(query, g, 0) >= 0)) {
|
|
360
387
|
return ground(
|
|
361
388
|
g,
|
|
362
389
|
"scaffolding-dominated query — ground the consensus-climb anchor",
|
|
@@ -385,48 +412,10 @@ export async function recallByResonance(
|
|
|
385
412
|
}
|
|
386
413
|
}
|
|
387
414
|
// 3b. Corroborated-substitution bridge — refusal-path only (bridge.ts).
|
|
388
|
-
//
|
|
389
|
-
//
|
|
390
|
-
//
|
|
391
|
-
|
|
392
|
-
// 13 ms non-exhaustive (36x).
|
|
393
|
-
const wideIdsOnce = async (): Promise<ReadonlyArray<number>> => {
|
|
394
|
-
// When the top resonance hit is below the concept threshold, the query
|
|
395
|
-
// gist has no concept-level match to any stored form — an exhaustive √N
|
|
396
|
-
// ANN would only score more vectors below the bar (profiled at 38K–40K
|
|
397
|
-
// annVectorReads per refusing query on a 325K-context store). The
|
|
398
|
-
// bridge's structural channels (junction walks, anchor climbs) are the
|
|
399
|
-
// correct proposal source for a query whose gist has no clean match;
|
|
400
|
-
// the ANN cannot propose what the gist cannot rank.
|
|
401
|
-
// The condition above is the SCORE of the top hit, not the size of the
|
|
402
|
-
// corpus. It used to be spelled `corpusN(ctx) <= (k · W)³`, which asks
|
|
403
|
-
// a different question and answers it wrongly at exactly the scale the
|
|
404
|
-
// note was written from: on the trained store N = 325,608 with k = 24
|
|
405
|
-
// and W = 4 puts the cube at 884,736, so that store took the exhaustive
|
|
406
|
-
// branch — the very branch measured here as 38K–40K annVectorReads.
|
|
407
|
-
// Measured cost of the mismatch: substitutionBridge 8,544ms of a
|
|
408
|
-
// 19,548ms think (44%), against 1,248ms and 14,218ms without it, with
|
|
409
|
-
// every answer in the battery byte-identical and the suite unchanged
|
|
410
|
-
// at 445/445. Corpus size was never the discriminator; whether the
|
|
411
|
-
// gist ranks ANYTHING at concept level is.
|
|
412
|
-
//
|
|
413
|
-
// Reading it as the note states also removes a duplicated (k · W)³ —
|
|
414
|
-
// the same cube gates crossRegionVotes' walk budget, where it likewise
|
|
415
|
-
// never engages at real scale (see attention.ts).
|
|
416
|
-
if (whole.length > 0 && whole[0].score >= conceptThreshold(ctx.store.D)) {
|
|
417
|
-
const exhaustive = await ctx.store.resonate(
|
|
418
|
-
queryGist,
|
|
419
|
-
hubBound(ctx),
|
|
420
|
-
true,
|
|
421
|
-
);
|
|
422
|
-
return exhaustive.map((h) => h.id);
|
|
423
|
-
}
|
|
424
|
-
return whole.map((h) => h.id);
|
|
425
|
-
};
|
|
426
|
-
let wide: Promise<ReadonlyArray<number>> | null = null;
|
|
427
|
-
const wideIds = (): Promise<
|
|
428
|
-
ReadonlyArray<number>
|
|
429
|
-
> => (wide ??= wideIdsOnce());
|
|
415
|
+
// The WIDE candidate list every past-the-top-k mechanism reads lives on
|
|
416
|
+
// Precomputed (see wideResonance): shared across the whole response, so the
|
|
417
|
+
// exhaustive branch runs at most once whoever first-touches it.
|
|
418
|
+
const wideIds = () => pre.wideResonance();
|
|
430
419
|
|
|
431
420
|
// Every gist-based tier has failed; before refusing, align the query
|
|
432
421
|
// byte-for-byte against the trained contexts its own stored windows
|
|
@@ -547,86 +536,6 @@ export async function recallByResonance(
|
|
|
547
536
|
);
|
|
548
537
|
}
|
|
549
538
|
}
|
|
550
|
-
|
|
551
|
-
// 3b′. PREFIX COMPLETION — refusal-path only (prefix-completion.ts).
|
|
552
|
-
// Inside the bridge's block, and deliberately: it consumes `wideIds`, the
|
|
553
|
-
// list the bridge has already fetched, so it costs a bounded byte compare
|
|
554
|
-
// per candidate and not one resonance. The claim it makes is the
|
|
555
|
-
// strongest in the ladder — every query byte is a LITERAL match from
|
|
556
|
-
// offset zero of a trained form — so it needs no projection and no reach
|
|
557
|
-
// gate. It runs after the bridge only because the bridge answers the
|
|
558
|
-
// richer relation when it can; a prefix match that the bridge also
|
|
559
|
-
// explains is the same trained form either way.
|
|
560
|
-
{
|
|
561
|
-
// The resonance list first; only when it supplies nothing does the
|
|
562
|
-
// write side's leaf-id window index propose (prefixCandidates). That
|
|
563
|
-
// ordering is the whole cost story: a query the ranked list can already
|
|
564
|
-
// explain pays not one extra read, and the fallback's bounded walk is
|
|
565
|
-
// spent only where the alternative is an empty answer. It is a second
|
|
566
|
-
// SUPPLY, not a second mechanism — the same three guards decide.
|
|
567
|
-
const completed = prefixCompletion(ctx, query, await wideIds()) ??
|
|
568
|
-
prefixCompletion(ctx, query, prefixCandidates(ctx, query));
|
|
569
|
-
if (completed !== null) {
|
|
570
|
-
return ground(
|
|
571
|
-
completed.form,
|
|
572
|
-
"prefix completion — the query IS the opening of exactly one " +
|
|
573
|
-
"trained form, which this grounds whole",
|
|
574
|
-
// Every query byte is literally matched against the form. The
|
|
575
|
-
// completion is the form's own continuation, not a substitution, so
|
|
576
|
-
// there is nothing to be humble about in the accounting — the same
|
|
577
|
-
// reading the IDENTITY bridge above takes.
|
|
578
|
-
whole_,
|
|
579
|
-
STEP,
|
|
580
|
-
false,
|
|
581
|
-
// NOT complete: the query is a proper PREFIX, so the form may carry
|
|
582
|
-
// more past the remainder this tier voiced.
|
|
583
|
-
false,
|
|
584
|
-
);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
// 3c. FRAME-FILLER SUBSTITUTION — refusal-path only (frame-filler.ts).
|
|
590
|
-
// The bridge has failed, and for the shape this tier answers it MUST fail:
|
|
591
|
-
// a definite description standing where a proper noun stands is not a
|
|
592
|
-
// similarity relation the bridge can price (raw balance refuses
|
|
593
|
-
// `dominates(6, 37)`, and correctly — that is the France/Spain trap). This
|
|
594
|
-
// tier makes a different claim: not that the two spans resemble each other,
|
|
595
|
-
// but that the store ALREADY HOLDS this query with the filler in the
|
|
596
|
-
// description's place, byte-exactly. A key the store does not hold is
|
|
597
|
-
// discarded, so the answer is always a trained continuation.
|
|
598
|
-
{
|
|
599
|
-
// THE COHORT NEEDS EVIDENCE, AND THE REFUSAL PATH HAS ALREADY BOUGHT IT.
|
|
600
|
-
// This tier reads constituency from what a cohort of exemplars does NOT
|
|
601
|
-
// share, so its resolution is bounded by how many instances of the frame it
|
|
602
|
-
// can see. The top-k resonance hits are too few — on the two-hop probe the
|
|
603
|
-
// exemplars holding the query's discriminative content number TWO, and two
|
|
604
|
-
// structures agree on so little that a whole clause reads as content. The
|
|
605
|
-
// exhaustive list the bridge fetched is the same evidence at ~570 wide, and
|
|
606
|
-
// it is already paid for (memoised above, so this costs no ANN call).
|
|
607
|
-
const filled = frameFillerSubstitution(ctx, query, await wideIds());
|
|
608
|
-
if (filled !== null) {
|
|
609
|
-
const g = await project(ctx, filled.id, queryGist);
|
|
610
|
-
// The same restated-fragment and manufactured-answer guards every tier
|
|
611
|
-
// above applies: a projection contained in the FILLER is the
|
|
612
|
-
// substitution restated as if it were knowledge, not knowledge.
|
|
613
|
-
if (
|
|
614
|
-
g !== null && g.length > 0 && !restates(g) &&
|
|
615
|
-
indexOf(filled.filler, g, 0) < 0 &&
|
|
616
|
-
!(g.length < query.length && indexOf(query, g, 0) >= 0)
|
|
617
|
-
) {
|
|
618
|
-
return ground(
|
|
619
|
-
g,
|
|
620
|
-
"frame-filler substitution — a trained form IS this query with a " +
|
|
621
|
-
"corroborated filler in the described span's place",
|
|
622
|
-
// The frame is literally matched against the resolved form and the
|
|
623
|
-
// described span is explained by the substitution — the same
|
|
624
|
-
// matched-plus-substituted accounting the bridge reports.
|
|
625
|
-
[[0, query.length]],
|
|
626
|
-
CONCEPT + STEP,
|
|
627
|
-
);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
539
|
}
|
|
631
540
|
|
|
632
541
|
// The refusal/echo decision. The echo returns a stored form's bytes AS
|