@hviana/sema 0.1.5 → 0.1.7
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 +6 -5
- package/CITATION.cff +49 -0
- package/HOW_IT_WORKS.md +11 -12
- package/README.md +7 -5
- package/dist/example/demo.js +25 -25
- package/dist/example/train_base.d.ts +19 -21
- package/dist/example/train_base.js +1700 -1952
- package/dist/src/alphabet.d.ts +3 -3
- package/dist/src/alphabet.js +24 -27
- package/dist/src/alu/src/alu.d.ts +169 -194
- package/dist/src/alu/src/alu.js +374 -414
- package/dist/src/alu/src/expr.d.ts +36 -43
- package/dist/src/alu/src/expr.js +252 -278
- package/dist/src/alu/src/index.d.ts +9 -98
- package/dist/src/alu/src/index.js +10 -64
- package/dist/src/alu/src/kernel-arith.d.ts +1 -5
- package/dist/src/alu/src/kernel-arith.js +195 -285
- package/dist/src/alu/src/kernel-bits.d.ts +1 -5
- package/dist/src/alu/src/kernel-bits.js +81 -115
- package/dist/src/alu/src/kernel-logic.js +33 -63
- package/dist/src/alu/src/kernel-nd.js +155 -195
- package/dist/src/alu/src/kernel-numeric.d.ts +16 -80
- package/dist/src/alu/src/kernel-numeric.js +259 -331
- package/dist/src/alu/src/operation.d.ts +112 -132
- package/dist/src/alu/src/operation.js +149 -163
- package/dist/src/alu/src/parser.d.ts +168 -175
- package/dist/src/alu/src/parser.js +382 -421
- package/dist/src/alu/src/resonance.d.ts +16 -25
- package/dist/src/alu/src/resonance.js +49 -56
- package/dist/src/alu/src/text.d.ts +3 -7
- package/dist/src/alu/src/text.js +31 -37
- package/dist/src/alu/src/value.d.ts +14 -14
- package/dist/src/alu/src/value.js +150 -160
- package/dist/src/alu/test/alu.test.js +543 -656
- package/dist/src/bytes.d.ts +1 -5
- package/dist/src/bytes.js +33 -40
- package/dist/src/config.d.ts +99 -102
- package/dist/src/config.js +78 -83
- package/dist/src/derive/src/deduction.d.ts +60 -62
- package/dist/src/derive/src/deduction.js +103 -109
- package/dist/src/derive/src/index.d.ts +1 -7
- package/dist/src/derive/src/priority-queue.d.ts +8 -8
- package/dist/src/derive/src/priority-queue.js +57 -61
- package/dist/src/derive/src/rewrite.d.ts +15 -18
- package/dist/src/derive/src/rewrite.js +59 -67
- package/dist/src/derive/src/trie.d.ts +56 -56
- package/dist/src/derive/src/trie.js +175 -179
- package/dist/src/derive/test/derive.test.js +96 -100
- package/dist/src/extension.d.ts +13 -16
- package/dist/src/geometry.d.ts +29 -43
- package/dist/src/geometry.js +324 -268
- package/dist/src/index.d.ts +2 -17
- package/dist/src/index.js +2 -12
- package/dist/src/ingest-cache.d.ts +25 -30
- package/dist/src/ingest-cache.js +108 -127
- package/dist/src/mind/articulation.d.ts +1 -5
- package/dist/src/mind/articulation.js +77 -112
- package/dist/src/mind/attention.d.ts +40 -108
- package/dist/src/mind/attention.js +754 -872
- package/dist/src/mind/canonical.d.ts +4 -19
- package/dist/src/mind/canonical.js +27 -31
- package/dist/src/mind/graph-search.d.ts +201 -225
- package/dist/src/mind/graph-search.js +742 -821
- package/dist/src/mind/index.d.ts +2 -10
- package/dist/src/mind/junction.d.ts +31 -58
- package/dist/src/mind/junction.js +172 -237
- package/dist/src/mind/learning.d.ts +16 -52
- package/dist/src/mind/learning.js +143 -165
- package/dist/src/mind/match.d.ts +20 -69
- package/dist/src/mind/match.js +259 -318
- package/dist/src/mind/mechanisms/alu.js +16 -16
- package/dist/src/mind/mechanisms/cast.d.ts +9 -13
- package/dist/src/mind/mechanisms/cast.js +363 -456
- package/dist/src/mind/mechanisms/confluence.d.ts +8 -12
- package/dist/src/mind/mechanisms/confluence.js +152 -183
- package/dist/src/mind/mechanisms/cover.d.ts +2 -8
- package/dist/src/mind/mechanisms/cover.js +148 -210
- package/dist/src/mind/mechanisms/extraction.d.ts +8 -34
- package/dist/src/mind/mechanisms/extraction.js +234 -288
- package/dist/src/mind/mechanisms/recall.d.ts +6 -10
- package/dist/src/mind/mechanisms/recall.js +141 -185
- package/dist/src/mind/mind.d.ts +194 -155
- package/dist/src/mind/mind.js +392 -289
- package/dist/src/mind/pipeline-mechanism.d.ts +112 -124
- package/dist/src/mind/pipeline-mechanism.js +161 -172
- package/dist/src/mind/pipeline.d.ts +4 -14
- package/dist/src/mind/pipeline.js +125 -189
- package/dist/src/mind/primitives.d.ts +20 -33
- package/dist/src/mind/primitives.js +124 -120
- package/dist/src/mind/rationale.d.ts +86 -98
- package/dist/src/mind/rationale.js +113 -121
- package/dist/src/mind/reasoning.d.ts +2 -13
- package/dist/src/mind/reasoning.js +129 -166
- package/dist/src/mind/recognition.d.ts +1 -4
- package/dist/src/mind/recognition.js +198 -210
- package/dist/src/mind/resonance.d.ts +5 -22
- package/dist/src/mind/resonance.js +0 -0
- package/dist/src/mind/trace.d.ts +6 -25
- package/dist/src/mind/trace.js +50 -58
- package/dist/src/mind/traverse.d.ts +29 -58
- package/dist/src/mind/traverse.js +344 -356
- package/dist/src/mind/types.d.ts +122 -127
- package/dist/src/mind/types.js +60 -69
- package/dist/src/rabitq-ivf/src/database.d.ts +113 -0
- package/dist/src/rabitq-ivf/src/database.js +201 -0
- package/dist/src/rabitq-ivf/src/index.d.ts +7 -0
- package/dist/src/{rabitq-hnsw → rabitq-ivf}/src/index.js +1 -3
- package/dist/src/rabitq-ivf/src/ivf.d.ts +200 -0
- package/dist/src/rabitq-ivf/src/ivf.js +1165 -0
- package/dist/src/rabitq-ivf/src/prng.d.ts +19 -0
- package/dist/src/rabitq-ivf/src/prng.js +36 -0
- package/dist/src/rabitq-ivf/src/rabitq.d.ts +95 -0
- package/dist/src/rabitq-ivf/src/rabitq.js +283 -0
- package/dist/src/sema.d.ts +9 -13
- package/dist/src/sema.js +26 -40
- package/dist/src/store-sqlite.d.ts +171 -166
- package/dist/src/store-sqlite.js +768 -662
- package/dist/src/store.d.ts +597 -630
- package/dist/src/store.js +1434 -1581
- package/dist/src/vec.d.ts +5 -9
- package/dist/src/vec.js +61 -73
- package/example/train_base.ts +33 -15
- package/index.html +65 -0
- package/package.json +1 -1
- package/src/alu/README.md +1 -1
- package/src/alu/src/index.ts +1 -1
- package/src/config.ts +19 -27
- package/src/geometry.ts +93 -1
- package/src/index.ts +6 -11
- package/src/mind/attention.ts +11 -6
- package/src/mind/mechanisms/recall.ts +29 -13
- package/src/mind/mind.ts +250 -19
- package/src/mind/primitives.ts +43 -6
- package/src/mind/recognition.ts +26 -8
- package/src/mind/traverse.ts +47 -0
- package/src/mind/types.ts +20 -21
- package/src/rabitq-ivf/README.md +56 -0
- package/src/rabitq-ivf/src/database.ts +276 -0
- package/src/{rabitq-hnsw → rabitq-ivf}/src/index.ts +2 -5
- package/src/rabitq-ivf/src/ivf.ts +1330 -0
- package/src/{rabitq-hnsw → rabitq-ivf}/src/prng.ts +1 -1
- package/src/store-sqlite.ts +204 -9
- package/src/store.ts +27 -34
- package/test/08-storage.test.mjs +3 -3
- package/test/13-conversation.test.mjs +190 -20
- package/test/14-scaling.test.mjs +2 -2
- package/test/35-ivf.test.mjs +263 -0
- package/test/36-bloom.test.mjs +123 -0
- package/dist/src/rabitq-hnsw/src/database.d.ts +0 -202
- package/dist/src/rabitq-hnsw/src/database.js +0 -405
- package/dist/src/rabitq-hnsw/src/heap.d.ts +0 -22
- package/dist/src/rabitq-hnsw/src/heap.js +0 -94
- package/dist/src/rabitq-hnsw/src/hnsw.d.ts +0 -125
- package/dist/src/rabitq-hnsw/src/hnsw.js +0 -500
- package/dist/src/rabitq-hnsw/src/index.d.ts +0 -15
- package/dist/src/rabitq-hnsw/src/prng.d.ts +0 -19
- package/dist/src/rabitq-hnsw/src/prng.js +0 -38
- package/dist/src/rabitq-hnsw/src/rabitq.d.ts +0 -95
- package/dist/src/rabitq-hnsw/src/rabitq.js +0 -299
- package/dist/src/rabitq-hnsw/src/store.d.ts +0 -162
- package/dist/src/rabitq-hnsw/src/store.js +0 -916
- package/dist/src/rabitq-hnsw/test/hnsw.test.d.ts +0 -1
- package/dist/src/rabitq-hnsw/test/hnsw.test.js +0 -1197
- package/src/rabitq-hnsw/README.md +0 -303
- package/src/rabitq-hnsw/src/database.ts +0 -492
- package/src/rabitq-hnsw/src/heap.ts +0 -90
- package/src/rabitq-hnsw/src/hnsw.ts +0 -514
- package/src/rabitq-hnsw/src/store.ts +0 -994
- package/src/rabitq-hnsw/test/hnsw.test.ts +0 -1213
- /package/src/{rabitq-hnsw → rabitq-ivf}/src/rabitq.ts +0 -0
|
@@ -4,12 +4,7 @@
|
|
|
4
4
|
// index and grounds the nearest learned form. Four tiers, orderly degrading
|
|
5
5
|
// from exact self-match to honest echo.
|
|
6
6
|
import { cosine } from "../../vec.js";
|
|
7
|
-
import {
|
|
8
|
-
consensusFloor,
|
|
9
|
-
identityBar,
|
|
10
|
-
reachThreshold,
|
|
11
|
-
significanceBar,
|
|
12
|
-
} from "../../geometry.js";
|
|
7
|
+
import { consensusFloor, identityBar, reachThreshold, significanceBar, } from "../../geometry.js";
|
|
13
8
|
import { gistOf, read, resolve } from "../primitives.js";
|
|
14
9
|
import { corpusN, hubBound } from "../traverse.js";
|
|
15
10
|
import { project, reverseContext } from "../match.js";
|
|
@@ -18,193 +13,154 @@ import { unexplainedLabel } from "../rationale.js";
|
|
|
18
13
|
import { rItem, rNode } from "../trace.js";
|
|
19
14
|
/** Recall the answer by resonating the whole query against the content index. */
|
|
20
15
|
export async function recallByResonance(ctx, query, pre) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
moves,
|
|
38
|
-
unexplained: unexplainedLabel(query, accounted),
|
|
16
|
+
const t = ctx.trace?.enter("recallByResonance", [
|
|
17
|
+
rItem(query, "query"),
|
|
18
|
+
]);
|
|
19
|
+
const whole_ = [[0, query.length]];
|
|
20
|
+
const nothing = [];
|
|
21
|
+
const ground = (bytes, note, accounted, moves, echoed = false) => {
|
|
22
|
+
t?.done(bytes === null
|
|
23
|
+
? []
|
|
24
|
+
: [rItem(bytes, "answer", resolve(ctx, bytes) ?? undefined)], note);
|
|
25
|
+
return bytes === null ? null : {
|
|
26
|
+
bytes,
|
|
27
|
+
echoed,
|
|
28
|
+
accounted,
|
|
29
|
+
moves,
|
|
30
|
+
unexplained: unexplainedLabel(query, accounted),
|
|
31
|
+
};
|
|
39
32
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const g = reverseContext(ctx, qId, queryGist, rev);
|
|
48
|
-
if (g !== null) {
|
|
49
|
-
return ground(
|
|
50
|
-
g,
|
|
51
|
-
rev.length === 1
|
|
52
|
-
? "exact self-match — reverse recall to the sole predecessor"
|
|
53
|
-
: "exact self-match — reverse recall to the best-resonating predecessor",
|
|
54
|
-
nothing,
|
|
55
|
-
STEP,
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const whole = await ctx.store.resonate(queryGist, k);
|
|
60
|
-
if (whole.length === 0) {
|
|
61
|
-
return ground(null, "empty store — nothing to resonate with", [], 0);
|
|
62
|
-
}
|
|
63
|
-
const top = whole[0];
|
|
64
|
-
ctx.trace?.step(
|
|
65
|
-
"resonate",
|
|
66
|
-
[rItem(query, "query-gist")],
|
|
67
|
-
whole.map((h) => rNode(ctx, h.id, "hit", h.score)),
|
|
68
|
-
`resonate the whole-query gist → ${whole.length} nearest learnt form(s)`,
|
|
69
|
-
);
|
|
70
|
-
// 1. Clean resonance — the scale-aware identity claim. The ANGLE
|
|
71
|
-
// (top.score) carries the shared fraction; the query's MAGNITUDE (√len,
|
|
72
|
-
// the linear fold's own norm) converts the tolerated foreign fraction
|
|
73
|
-
// into bytes — at most one river window (see {@link identityBar}). A
|
|
74
|
-
// fixed cosine bar let long queries claim "near-identical" while whole
|
|
75
|
-
// windows — an answer word — differed.
|
|
76
|
-
if (top.score >= identityBar(ctx.store.D, ctx.space.maxGroup, query.length)) {
|
|
77
|
-
for (const h of whole) {
|
|
78
|
-
if (h.id === qId || h.score >= 1.0) {
|
|
79
|
-
const rev = ctx.store.prevFirst(h.id, hubBound(ctx));
|
|
80
|
-
const g = reverseContext(ctx, h.id, queryGist, rev);
|
|
33
|
+
const k = pre.k;
|
|
34
|
+
const queryGist = pre.guide;
|
|
35
|
+
// 0. Exact self-match — content-addressed, deterministic.
|
|
36
|
+
const qId = pre.queryResolved;
|
|
37
|
+
if (qId !== null) {
|
|
38
|
+
const rev = ctx.store.prevFirst(qId, hubBound(ctx));
|
|
39
|
+
const g = reverseContext(ctx, qId, queryGist, rev);
|
|
81
40
|
if (g !== null) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
? "perfect self-match — reverse recall to the sole predecessor"
|
|
86
|
-
: "perfect self-match — reverse recall to the best-resonating predecessor",
|
|
87
|
-
nothing,
|
|
88
|
-
STEP,
|
|
89
|
-
);
|
|
41
|
+
return ground(g, rev.length === 1
|
|
42
|
+
? "exact self-match — reverse recall to the sole predecessor"
|
|
43
|
+
: "exact self-match — reverse recall to the best-resonating predecessor", nothing, STEP);
|
|
90
44
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
45
|
+
}
|
|
46
|
+
const whole = await ctx.store.resonate(queryGist, k);
|
|
47
|
+
if (whole.length === 0) {
|
|
48
|
+
return ground(null, "empty store — nothing to resonate with", [], 0);
|
|
49
|
+
}
|
|
50
|
+
const top = whole[0];
|
|
51
|
+
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)`);
|
|
52
|
+
// 1. Clean resonance — the scale-aware identity claim. The ANGLE
|
|
53
|
+
// (top.score) carries the shared fraction; the query's MAGNITUDE (√len,
|
|
54
|
+
// the linear fold's own norm) converts the tolerated foreign fraction
|
|
55
|
+
// into bytes — at most one river window (see {@link identityBar}). A
|
|
56
|
+
// fixed cosine bar let long queries claim "near-identical" while whole
|
|
57
|
+
// windows — an answer word — differed.
|
|
58
|
+
if (top.score >= identityBar(ctx.store.D, ctx.space.maxGroup, query.length)) {
|
|
59
|
+
for (const h of whole) {
|
|
60
|
+
if (h.id === qId || h.score >= 1.0) {
|
|
61
|
+
const rev = ctx.store.prevFirst(h.id, hubBound(ctx));
|
|
62
|
+
const g = reverseContext(ctx, h.id, queryGist, rev);
|
|
63
|
+
if (g !== null) {
|
|
64
|
+
return ground(g, rev.length === 1
|
|
65
|
+
? "perfect self-match — reverse recall to the sole predecessor"
|
|
66
|
+
: "perfect self-match — reverse recall to the best-resonating predecessor", nothing, STEP);
|
|
67
|
+
}
|
|
68
|
+
const own = read(ctx, h.id);
|
|
69
|
+
if (own.length > 0) {
|
|
70
|
+
return ground(own, "perfect self-match — the query IS this node", nothing, STEP);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const g = await project(ctx, h.id, queryGist);
|
|
74
|
+
if (g) {
|
|
75
|
+
return ground(g, "clean whole-query resonance — ground the nearest hit", whole_, STEP);
|
|
76
|
+
}
|
|
99
77
|
}
|
|
100
|
-
}
|
|
101
|
-
const g = await project(ctx, h.id, queryGist);
|
|
102
|
-
if (g) {
|
|
103
|
-
return ground(
|
|
104
|
-
g,
|
|
105
|
-
"clean whole-query resonance — ground the nearest hit",
|
|
106
|
-
whole_,
|
|
107
|
-
STEP,
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
78
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
"scaffolding-dominated query — ground the consensus-climb anchor",
|
|
126
|
-
[[forest[0].start, forest[0].end]],
|
|
127
|
-
CONCEPT,
|
|
128
|
-
);
|
|
129
|
-
}
|
|
79
|
+
// 2. Scaffolding-dominated.
|
|
80
|
+
if (top.score >= significanceBar(ctx.store.D)) {
|
|
81
|
+
const N = corpusN(ctx);
|
|
82
|
+
const minVote = consensusFloor(N);
|
|
83
|
+
// The committed points of attention ARE the shared climb's roots (same
|
|
84
|
+
// query, same k, same DF mode) — read them from Precomputed instead of
|
|
85
|
+
// re-climbing, so even a traced response pays for the climb once.
|
|
86
|
+
const forest = (await pre.attention()).roots;
|
|
87
|
+
if (forest.length > 0 && forest[0].vote >= minVote) {
|
|
88
|
+
const g = await project(ctx, forest[0].anchor, queryGist);
|
|
89
|
+
if (g) {
|
|
90
|
+
return ground(g, "scaffolding-dominated query — ground the consensus-climb anchor", [[forest[0].start, forest[0].end]], CONCEPT);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
130
93
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
94
|
+
// 3. Last resort — gated on the FRACTION OF THE QUERY the grounding
|
|
95
|
+
// explains, not the raw cosine. Root gists are unit vectors, but their
|
|
96
|
+
// magnitudes are recoverable from the byte lengths (‖·‖ = √len under the
|
|
97
|
+
// linear fold): cos = shared/√(lenQ·lenG), so shared/lenQ = cos·√(lenG/lenQ).
|
|
98
|
+
// The raw cosine punished honest containment — a query fully inside a
|
|
99
|
+
// longer grounded answer scored √(lenQ/lenG) and was refused — and let a
|
|
100
|
+
// long answer sharing only scaffolding pass; the query-relative fraction
|
|
101
|
+
// measures exactly what the reach bar means: how much of THE QUERY the
|
|
102
|
+
// store accounts for.
|
|
103
|
+
// Chance similarity survives the length conversion AMPLIFIED: the same
|
|
104
|
+
// √(lenG/lenQ) factor that converts an honest shared fraction into a
|
|
105
|
+
// query-relative one multiplies the estimator/chance floor too, so a long
|
|
106
|
+
// stored form (√(lenG/lenQ) ≈ 10 at 100×) lifted a noise-level cosine past
|
|
107
|
+
// the reach bar and grounded pure gibberish (observed). Only the
|
|
108
|
+
// ABOVE-CHANCE part of the similarity is evidence of shared content —
|
|
109
|
+
// subtract the significance bar (3/√D, §8.3) before converting. Derived
|
|
110
|
+
// from the existing bars; never tuned.
|
|
111
|
+
const sig = significanceBar(ctx.store.D);
|
|
112
|
+
const fracOfQuery = (cos, otherLen) => Math.min(1, Math.max(0, cos - sig) *
|
|
113
|
+
Math.sqrt(otherLen / Math.max(1, query.length)));
|
|
114
|
+
for (const h of whole) {
|
|
115
|
+
const g = await project(ctx, h.id, queryGist);
|
|
116
|
+
if (g) {
|
|
117
|
+
if (fracOfQuery(cosine(queryGist, gistOf(ctx, g)), g.length) >=
|
|
118
|
+
reachThreshold(ctx.space.maxGroup)) {
|
|
119
|
+
return ground(g, "last resort: the nearest grounded whole-query hit", [], STEP);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
157
122
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
// Honest echo.
|
|
178
|
-
return ground(
|
|
179
|
-
read(ctx, top.id),
|
|
180
|
-
"last resort: the nearest resonant form's own bytes (echo, not grounded)",
|
|
181
|
-
[],
|
|
182
|
-
0,
|
|
183
|
-
true,
|
|
184
|
-
);
|
|
123
|
+
// The refusal/echo decision. The echo returns a stored form's bytes AS
|
|
124
|
+
// the answer — a near-identity claim about the query — and identity-grade
|
|
125
|
+
// decisions are never made on an estimated score ("approximate scores may
|
|
126
|
+
// rank and propose; they may never decide", §6.2): the RaBitQ estimate
|
|
127
|
+
// overshooting the reach bar echoed a WRONG-entity neighbour ("capital of
|
|
128
|
+
// Zamunda?" echoed the Armenia fact, observed). The bytes are read
|
|
129
|
+
// anyway to be echoed, so the decision uses their EXACT fold: one river
|
|
130
|
+
// fold of the top hit, measured in the same query-relative,
|
|
131
|
+
// chance-corrected units as the tier above.
|
|
132
|
+
const reach = reachThreshold(ctx.space.maxGroup);
|
|
133
|
+
const topBytes = read(ctx, top.id);
|
|
134
|
+
const exact = topBytes.length > 0
|
|
135
|
+
? cosine(queryGist, gistOf(ctx, topBytes))
|
|
136
|
+
: 0;
|
|
137
|
+
if (fracOfQuery(exact, topBytes.length) < reach) {
|
|
138
|
+
return ground(null, "below reach threshold — nothing in the store relates to this query", [], 0);
|
|
139
|
+
}
|
|
140
|
+
// Honest echo.
|
|
141
|
+
return ground(topBytes, "last resort: the nearest resonant form's own bytes (echo, not grounded)", [], 0, true);
|
|
185
142
|
}
|
|
186
143
|
// ── Pipeline mechanism ──────────────────────────────────────────────────────
|
|
187
144
|
export const recallMechanism = {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
},
|
|
145
|
+
name: "recall",
|
|
146
|
+
provenance: "recall",
|
|
147
|
+
// Recall's floor is free to state (one STEP-grade projection) and its run
|
|
148
|
+
// gates its own tiers — no expensive investment happens inside floor, so
|
|
149
|
+
// there is nothing to guard with worthRunning here: the pipeline's own
|
|
150
|
+
// check prunes run() against the incumbent.
|
|
151
|
+
async floor(_ctx, _query, _pre, _worthRunning) {
|
|
152
|
+
return STEP;
|
|
153
|
+
},
|
|
154
|
+
async run(ctx, query, pre) {
|
|
155
|
+
const r = await recallByResonance(ctx, query, pre);
|
|
156
|
+
if (!r)
|
|
157
|
+
return [];
|
|
158
|
+
return [{
|
|
159
|
+
bytes: r.bytes,
|
|
160
|
+
accounted: r.accounted,
|
|
161
|
+
moves: r.moves,
|
|
162
|
+
unexplained: r.unexplained,
|
|
163
|
+
provenance: r.echoed ? "recall-echo" : "recall",
|
|
164
|
+
}];
|
|
165
|
+
},
|
|
210
166
|
};
|