@hviana/sema 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/example/demo.d.ts +1 -0
- package/dist/example/demo.js +39 -0
- package/dist/example/train_base.d.ts +87 -0
- package/dist/example/train_base.js +2252 -0
- package/dist/src/alphabet.d.ts +7 -0
- package/dist/src/alphabet.js +33 -0
- package/dist/src/alu/src/alu.d.ts +185 -0
- package/dist/src/alu/src/alu.js +440 -0
- package/dist/src/alu/src/expr.d.ts +61 -0
- package/dist/src/alu/src/expr.js +318 -0
- package/dist/src/alu/src/index.d.ts +11 -0
- package/dist/src/alu/src/index.js +19 -0
- package/dist/src/alu/src/kernel-arith.d.ts +16 -0
- package/dist/src/alu/src/kernel-arith.js +264 -0
- package/dist/src/alu/src/kernel-bits.d.ts +19 -0
- package/dist/src/alu/src/kernel-bits.js +152 -0
- package/dist/src/alu/src/kernel-logic.d.ts +4 -0
- package/dist/src/alu/src/kernel-logic.js +60 -0
- package/dist/src/alu/src/kernel-nd.d.ts +3 -0
- package/dist/src/alu/src/kernel-nd.js +208 -0
- package/dist/src/alu/src/kernel-numeric.d.ts +54 -0
- package/dist/src/alu/src/kernel-numeric.js +366 -0
- package/dist/src/alu/src/operation.d.ts +168 -0
- package/dist/src/alu/src/operation.js +189 -0
- package/dist/src/alu/src/parser.d.ts +221 -0
- package/dist/src/alu/src/parser.js +577 -0
- package/dist/src/alu/src/resonance.d.ts +55 -0
- package/dist/src/alu/src/resonance.js +126 -0
- package/dist/src/alu/src/text.d.ts +31 -0
- package/dist/src/alu/src/text.js +73 -0
- package/dist/src/alu/src/value.d.ts +109 -0
- package/dist/src/alu/src/value.js +300 -0
- package/dist/src/alu/test/alu.test.d.ts +1 -0
- package/dist/src/alu/test/alu.test.js +764 -0
- package/dist/src/bytes.d.ts +14 -0
- package/dist/src/bytes.js +59 -0
- package/dist/src/canon.d.ts +26 -0
- package/dist/src/canon.js +57 -0
- package/dist/src/config.d.ts +111 -0
- package/dist/src/config.js +91 -0
- package/dist/src/derive/src/deduction.d.ts +125 -0
- package/dist/src/derive/src/deduction.js +155 -0
- package/dist/src/derive/src/index.d.ts +7 -0
- package/dist/src/derive/src/index.js +11 -0
- package/dist/src/derive/src/priority-queue.d.ts +20 -0
- package/dist/src/derive/src/priority-queue.js +73 -0
- package/dist/src/derive/src/rewrite.d.ts +56 -0
- package/dist/src/derive/src/rewrite.js +100 -0
- package/dist/src/derive/src/trie.d.ts +90 -0
- package/dist/src/derive/src/trie.js +217 -0
- package/dist/src/derive/test/derive.test.d.ts +1 -0
- package/dist/src/derive/test/derive.test.js +122 -0
- package/dist/src/extension.d.ts +37 -0
- package/dist/src/extension.js +7 -0
- package/dist/src/geometry.d.ts +202 -0
- package/dist/src/geometry.js +575 -0
- package/dist/src/index.d.ts +16 -0
- package/dist/src/index.js +18 -0
- package/dist/src/ingest-cache.d.ts +41 -0
- package/dist/src/ingest-cache.js +161 -0
- package/dist/src/mind/articulation.d.ts +6 -0
- package/dist/src/mind/articulation.js +99 -0
- package/dist/src/mind/attention.d.ts +405 -0
- package/dist/src/mind/attention.js +1829 -0
- package/dist/src/mind/bridge.d.ts +30 -0
- package/dist/src/mind/bridge.js +569 -0
- package/dist/src/mind/canonical.d.ts +29 -0
- package/dist/src/mind/canonical.js +88 -0
- package/dist/src/mind/graph-search.d.ts +285 -0
- package/dist/src/mind/graph-search.js +956 -0
- package/dist/src/mind/index.d.ts +7 -0
- package/dist/src/mind/index.js +5 -0
- package/dist/src/mind/junction.d.ts +124 -0
- package/dist/src/mind/junction.js +317 -0
- package/dist/src/mind/learning.d.ts +47 -0
- package/dist/src/mind/learning.js +248 -0
- package/dist/src/mind/match.d.ts +126 -0
- package/dist/src/mind/match.js +441 -0
- package/dist/src/mind/mechanisms/alu.d.ts +4 -0
- package/dist/src/mind/mechanisms/alu.js +36 -0
- package/dist/src/mind/mechanisms/cast.d.ts +89 -0
- package/dist/src/mind/mechanisms/cast.js +716 -0
- package/dist/src/mind/mechanisms/confluence.d.ts +24 -0
- package/dist/src/mind/mechanisms/confluence.js +225 -0
- package/dist/src/mind/mechanisms/cover.d.ts +6 -0
- package/dist/src/mind/mechanisms/cover.js +203 -0
- package/dist/src/mind/mechanisms/extraction.d.ts +67 -0
- package/dist/src/mind/mechanisms/extraction.js +387 -0
- package/dist/src/mind/mechanisms/recall.d.ts +13 -0
- package/dist/src/mind/mechanisms/recall.js +325 -0
- package/dist/src/mind/mind.d.ts +276 -0
- package/dist/src/mind/mind.js +572 -0
- package/dist/src/mind/pipeline-mechanism.d.ts +142 -0
- package/dist/src/mind/pipeline-mechanism.js +213 -0
- package/dist/src/mind/pipeline.d.ts +20 -0
- package/dist/src/mind/pipeline.js +217 -0
- package/dist/src/mind/primitives.d.ts +70 -0
- package/dist/src/mind/primitives.js +287 -0
- package/dist/src/mind/rationale.d.ts +139 -0
- package/dist/src/mind/rationale.js +163 -0
- package/dist/src/mind/reasoning.d.ts +34 -0
- package/dist/src/mind/reasoning.js +240 -0
- package/dist/src/mind/recognition.d.ts +20 -0
- package/dist/src/mind/recognition.js +390 -0
- package/dist/src/mind/resonance.d.ts +23 -0
- package/dist/src/mind/resonance.js +0 -0
- package/dist/src/mind/trace.d.ts +15 -0
- package/dist/src/mind/trace.js +73 -0
- package/dist/src/mind/traverse.d.ts +113 -0
- package/dist/src/mind/traverse.js +568 -0
- package/dist/src/mind/types.d.ts +289 -0
- package/dist/src/mind/types.js +130 -0
- 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-ivf/src/index.js +4 -0
- 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 +31 -0
- package/dist/src/sema.js +63 -0
- package/dist/src/store-sqlite.d.ts +184 -0
- package/dist/src/store-sqlite.js +942 -0
- package/dist/src/store.d.ts +663 -0
- package/dist/src/store.js +1618 -0
- package/dist/src/vec.d.ts +31 -0
- package/dist/src/vec.js +109 -0
- package/package.json +1 -1
- package/src/mind/attention.ts +178 -63
- package/test/51-structural-resonance-ladder.test.mjs +6 -3
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
// learning.ts — ingest and deposition (Section 7 of the mind).
|
|
2
|
+
//
|
|
3
|
+
// Learning is DEPOSITION: perceive a stream into a tree and intern every
|
|
4
|
+
// node. A fact is an EDGE between node ids; recall traverses edges.
|
|
5
|
+
import { bindSeat, companySignature, isChunk } from "../sema.js";
|
|
6
|
+
import { changedNodes } from "./types.js";
|
|
7
|
+
import { inputBytes, latin1Key, perceiveDeposit, resolve, } from "./primitives.js";
|
|
8
|
+
import { canonicalWindows, leafIdPrefix } from "./canonical.js";
|
|
9
|
+
import { fold as foldVecs } from "../sema.js";
|
|
10
|
+
/** Intern a perceived tree into node ids, bottom-up, sharing equal subtrees.
|
|
11
|
+
* Returns the root node id and a map from tree nodes to their ids.
|
|
12
|
+
*
|
|
13
|
+
* Memoized by NODE IDENTITY (ctx._internIds): the pyramid fold shares a
|
|
14
|
+
* prefix's subtree OBJECTS across an accumulated context's deposits, and a
|
|
15
|
+
* node already interned needs nothing again — its id is permanent
|
|
16
|
+
* (content-addressed) and its intern-time side effects (gist capture, kid
|
|
17
|
+
* rows) fired at first mint; re-interning was pure lookups. A memo hit
|
|
18
|
+
* therefore skips the WHOLE shared subtree, making the intern walk
|
|
19
|
+
* O(new nodes) per deposit instead of O(context). Only the hit node
|
|
20
|
+
* itself enters `ids`; descendants stay reachable via the memo (see
|
|
21
|
+
* idOf in indexSubSpans and the changedNodes prune). */
|
|
22
|
+
export async function internTreeIds(ctx, node, ids) {
|
|
23
|
+
const known = ctx._internIds.get(node);
|
|
24
|
+
if (known !== undefined) {
|
|
25
|
+
ids.set(node, known);
|
|
26
|
+
return known;
|
|
27
|
+
}
|
|
28
|
+
let id;
|
|
29
|
+
if (node.kids === null) {
|
|
30
|
+
id = await ctx.store.putLeaf(node.leaf ?? new Uint8Array(0), node.v);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const kds = [];
|
|
34
|
+
for (const k of node.kids)
|
|
35
|
+
kds.push(await internTreeIds(ctx, k, ids));
|
|
36
|
+
id = await ctx.store.putBranch(kds, node.v);
|
|
37
|
+
}
|
|
38
|
+
ids.set(node, id);
|
|
39
|
+
ctx._internIds.set(node, id);
|
|
40
|
+
return id;
|
|
41
|
+
}
|
|
42
|
+
/** Index flat branches for sub-spans of a deposit's byte stream, linked to
|
|
43
|
+
* their structural chunks via durable CONTAINMENT edges. */
|
|
44
|
+
export async function indexSubSpans(ctx, tree, ids) {
|
|
45
|
+
const chunkOf = [];
|
|
46
|
+
const streamIds = [];
|
|
47
|
+
const streamVecs = [];
|
|
48
|
+
const collect = (n) => {
|
|
49
|
+
if (isChunk(n)) {
|
|
50
|
+
// A chunk inside a memo-skipped shared subtree is absent from `ids`;
|
|
51
|
+
// the intern memo still knows it (same object). A miss on both (the
|
|
52
|
+
// WeakMap entry was collected) only forfeits the seenBefore skip.
|
|
53
|
+
const chunkId = ids.get(n) ?? ctx._internIds.get(n);
|
|
54
|
+
for (const k of n.kids) {
|
|
55
|
+
const lid = k.leaf ? ctx.store.findLeaf(k.leaf) : null;
|
|
56
|
+
if (lid === null)
|
|
57
|
+
return false;
|
|
58
|
+
streamIds.push(lid);
|
|
59
|
+
streamVecs.push(k.v);
|
|
60
|
+
chunkOf.push(chunkId);
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
if (n.kids) {
|
|
65
|
+
for (const k of n.kids)
|
|
66
|
+
if (!collect(k))
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
};
|
|
71
|
+
if (!collect(tree))
|
|
72
|
+
return false;
|
|
73
|
+
const W = ctx.space.maxGroup; // write side of the canonical contract
|
|
74
|
+
const prev = ctx._prevSeen;
|
|
75
|
+
const seenBefore = (off, len) => {
|
|
76
|
+
if (!prev)
|
|
77
|
+
return false;
|
|
78
|
+
for (let i = off; i < off + len; i++) {
|
|
79
|
+
const c = chunkOf[i];
|
|
80
|
+
if (c === undefined || !prev.has(c))
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
};
|
|
85
|
+
const lens = streamIds.length >= W ? canonicalWindows(W) : [streamIds.length];
|
|
86
|
+
for (const len of lens) {
|
|
87
|
+
if (len < 1)
|
|
88
|
+
continue;
|
|
89
|
+
for (let off = 0; off + len <= streamIds.length; off++) {
|
|
90
|
+
if (seenBefore(off, len))
|
|
91
|
+
continue;
|
|
92
|
+
const winIds = streamIds.slice(off, off + len);
|
|
93
|
+
const flatId = ctx.store.findBranch(winIds) ??
|
|
94
|
+
await ctx.store.putBranch(winIds, foldVecs(ctx.space, streamVecs.slice(off, off + len)));
|
|
95
|
+
for (let i = off; i < off + len; i++) {
|
|
96
|
+
const c = chunkOf[i];
|
|
97
|
+
if (c !== undefined)
|
|
98
|
+
ctx.store.addContainer(flatId, c);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
/** Perceive, intern, and index a single input. Returns the perceived tree,
|
|
105
|
+
* root id, id map, and the changed (new) subtrees for halo reinforcement. */
|
|
106
|
+
export async function deposit(ctx, input, track, conversational = false) {
|
|
107
|
+
const bytes = inputBytes(ctx, input);
|
|
108
|
+
// Deposit-shaped perception: stable-prefix tree SEEDING (see
|
|
109
|
+
// perceiveDeposit) — an accumulated context re-folds only its new suffix,
|
|
110
|
+
// O(turn) instead of O(context) per conversation turn. Cache-only here
|
|
111
|
+
// (no store-probe fallback): a knownPrefixLength scan on every novel fact
|
|
112
|
+
// would cost O(n²) hashing, while conversation replays are always warm —
|
|
113
|
+
// re-deposition replays from the first turn, rebuilding the cache as it
|
|
114
|
+
// goes. `conversational` scopes the STABLE-PREFIX variant (turn-boundary
|
|
115
|
+
// folding, matching query-time perception) to ingestPair's own growing
|
|
116
|
+
// context argument — a bare ingestOne deposit whose bytes merely happen
|
|
117
|
+
// to extend an earlier UNRELATED deposit (no conversational relationship)
|
|
118
|
+
// must keep the plain fold, or two coincidentally-prefix-sharing facts
|
|
119
|
+
// would stop sharing structure with each other.
|
|
120
|
+
const tree = perceiveDeposit(ctx, bytes, conversational);
|
|
121
|
+
const ids = new Map();
|
|
122
|
+
const rootId = await internTreeIds(ctx, tree, ids);
|
|
123
|
+
const indexed = await indexSubSpans(ctx, tree, ids);
|
|
124
|
+
const leafIds = leafIdPrefix(ctx, bytes);
|
|
125
|
+
if (leafIds.length === bytes.length && leafIds.length >= 2) {
|
|
126
|
+
await ctx.store.putBranch(leafIds, tree.v);
|
|
127
|
+
}
|
|
128
|
+
const changed = (track && ctx._prevSeen)
|
|
129
|
+
? changedNodes(tree, ids, ctx._prevSeen)
|
|
130
|
+
: [tree];
|
|
131
|
+
if (track)
|
|
132
|
+
ctx._prevSeen = indexed ? new Set(ids.values()) : null;
|
|
133
|
+
return { tree, rootId, ids, changed };
|
|
134
|
+
}
|
|
135
|
+
/** Ingest a single input (a bare experience, no continuation). */
|
|
136
|
+
export async function ingestOne(ctx, input) {
|
|
137
|
+
const { tree, rootId, ids } = await deposit(ctx, input, true);
|
|
138
|
+
ctx.store.indexTarget(rootId);
|
|
139
|
+
const parts = tree.kids
|
|
140
|
+
? tree.kids.map((k) => ids.get(k))
|
|
141
|
+
: [rootId];
|
|
142
|
+
const stride = ctx.space.maxGroup;
|
|
143
|
+
if (parts.length > stride) {
|
|
144
|
+
for (let i = 0; i + stride < parts.length; i += stride) {
|
|
145
|
+
await ctx.store.link(parts[i], parts[i + stride]);
|
|
146
|
+
}
|
|
147
|
+
if ((parts.length - 1) % stride !== 0) {
|
|
148
|
+
const lastStart = Math.floor((parts.length - 1) / stride) * stride;
|
|
149
|
+
if (lastStart < parts.length - 1) {
|
|
150
|
+
await ctx.store.link(parts[lastStart], parts[parts.length - 1]);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
for (const id of parts)
|
|
156
|
+
ctx.store.indexTarget(id);
|
|
157
|
+
}
|
|
158
|
+
return Object.assign(tree, { id: rootId });
|
|
159
|
+
}
|
|
160
|
+
/** For each right-edge suffix of the context bytes, resolve it against the
|
|
161
|
+
* store. A suffix whose resolved node is already a known form inherits the
|
|
162
|
+
* continuation edge. Gate: ≥ 2 structural parents (reused across deposits),
|
|
163
|
+
* or (halo > 0 ∧ already an edge source). Pure answers do not qualify. */
|
|
164
|
+
async function propagateSuffixes(ctx, src, dst) {
|
|
165
|
+
const W = ctx.space.maxGroup;
|
|
166
|
+
const bytes = ctx.store.bytes(src);
|
|
167
|
+
const n = bytes.length;
|
|
168
|
+
if (n < 2 * W)
|
|
169
|
+
return;
|
|
170
|
+
// Existence prefilter — the write side of the canonical contract: every
|
|
171
|
+
// deposit interns its WHOLE byte stream as a flat branch of per-byte leaf
|
|
172
|
+
// ids (deposit(), canonical.ts). A suffix is a stored form exactly when
|
|
173
|
+
// that flat twin exists, so one content-hash probe per offset decides;
|
|
174
|
+
// only a hit pays for resolve()'s deposit-shaped perception. This keeps
|
|
175
|
+
// the scan free of river folds — O(1) probes over cheap byte hashes
|
|
176
|
+
// instead of O(suffix) vector folds per offset.
|
|
177
|
+
const leafIds = leafIdPrefix(ctx, bytes);
|
|
178
|
+
for (let i = 1; i <= n - W; i++) {
|
|
179
|
+
if (ctx.store.findBranch(leafIds.slice(i)) === null)
|
|
180
|
+
continue;
|
|
181
|
+
const id = resolve(ctx, bytes.subarray(i));
|
|
182
|
+
if (id === null || id === src)
|
|
183
|
+
continue;
|
|
184
|
+
const known = ctx.store.parentsFirst(id, 2).length >= 2 ||
|
|
185
|
+
(ctx.store.haloMass(id) > 0 && ctx.store.hasNext(id));
|
|
186
|
+
if (!known)
|
|
187
|
+
continue;
|
|
188
|
+
await ctx.store.link(id, dst);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/** Ingest a pair (context, continuation) — learn an edge and pour halos. */
|
|
192
|
+
export async function ingestPair(ctx, ctxInput, cont) {
|
|
193
|
+
const c = await deposit(ctx, ctxInput, true, true);
|
|
194
|
+
const cont_ = await deposit(ctx, cont, false);
|
|
195
|
+
const ctxId = c.rootId, contId = cont_.rootId;
|
|
196
|
+
// Stamp this turn's continuation onto its own cache entry — the proof a
|
|
197
|
+
// FUTURE, longer ctxInput needs (see perceiveDeposit) to recognise itself
|
|
198
|
+
// as this conversation's genuine next turn rather than an unrelated fact
|
|
199
|
+
// that happens to share this ctxInput's byte prefix.
|
|
200
|
+
{
|
|
201
|
+
const ctxBytes = inputBytes(ctx, ctxInput);
|
|
202
|
+
const entry = ctx._depositTrees.get(latin1Key(ctxBytes));
|
|
203
|
+
if (entry !== undefined)
|
|
204
|
+
entry.nextBytes = inputBytes(ctx, cont);
|
|
205
|
+
}
|
|
206
|
+
await ctx.store.link(ctxId, contId);
|
|
207
|
+
await propagateSuffixes(ctx, ctxId, contId);
|
|
208
|
+
// Halos pour company SIGNATURES (identity), not gists (content) — see
|
|
209
|
+
// companySignature in sema.ts.
|
|
210
|
+
const contSeat = bindSeat(ctx.space, companySignature(ctx.space, contId), 1);
|
|
211
|
+
for (const part of c.changed) {
|
|
212
|
+
const partId = c.ids.get(part);
|
|
213
|
+
await ctx.store.pourHalo(partId, contSeat);
|
|
214
|
+
await ctx.store.pourHalo(contId, bindSeat(ctx.space, companySignature(ctx.space, partId), 0));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/** Dispatch the public ingest input shapes onto one-input / pair handlers —
|
|
218
|
+
* THE one reading of ingest's polymorphic surface (scalar, (context,
|
|
219
|
+
* continuation) pair, or a list mixing bare inputs and pairs). Both ingest
|
|
220
|
+
* paths — the direct one below and {@link CachedIngest} — route through
|
|
221
|
+
* this, so the shape-detection can never drift between them again (the
|
|
222
|
+
* ingest cache once re-implemented it and drifted). */
|
|
223
|
+
export async function dispatchIngest(input, second, onOne, onPair) {
|
|
224
|
+
if (Array.isArray(input) && !(input instanceof Uint8Array) &&
|
|
225
|
+
input.width === undefined) {
|
|
226
|
+
const arr = input;
|
|
227
|
+
if (arr.length === 2 && !Array.isArray(arr[0]) && !Array.isArray(arr[1])) {
|
|
228
|
+
await onPair(arr[0], arr[1]);
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
for (const item of arr) {
|
|
232
|
+
if (Array.isArray(item) && item.length === 2) {
|
|
233
|
+
await onPair(item[0], item[1]);
|
|
234
|
+
}
|
|
235
|
+
else
|
|
236
|
+
await onOne(item);
|
|
237
|
+
}
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
if (second === undefined)
|
|
241
|
+
return onOne(input);
|
|
242
|
+
await onPair(input, second);
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
/** Ingest an input or array of inputs/pairs. The public ingest entry point. */
|
|
246
|
+
export async function ingest(ctx, input, second) {
|
|
247
|
+
return dispatchIngest(input, second, (i) => ingestOne(ctx, i), (a, b) => ingestPair(ctx, a, b));
|
|
248
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Vec } from "../vec.js";
|
|
2
|
+
import type { Hit } from "../store.js";
|
|
3
|
+
import type { MindContext } from "./types.js";
|
|
4
|
+
import type { Site } from "./graph-search.js";
|
|
5
|
+
/** The graded LOCATE ladder: find `needle` in `haystack` starting at
|
|
6
|
+
* `fromPos`, strictest matcher first, relaxing only when the stricter one
|
|
7
|
+
* fails. This is the read-out matcher skill extraction locates exemplar
|
|
8
|
+
* frames with.
|
|
9
|
+
*
|
|
10
|
+
* 1. exact — literal byte match (the fast path).
|
|
11
|
+
* 2. halo — the needle's distributional role matches a recognised query
|
|
12
|
+
* form (gate: conceptThreshold).
|
|
13
|
+
* 3. gist — the needle's perceived gist matches a query segment
|
|
14
|
+
* (gate: identityBar — scale-aware).
|
|
15
|
+
*
|
|
16
|
+
* Returns the absolute byte position, or −1. */
|
|
17
|
+
export declare function locate(ctx: MindContext, haystack: Uint8Array, needle: Uint8Array, fromPos: number, sites?: ReadonlyArray<Site>): number;
|
|
18
|
+
/** The ALIGNED matcher: maximal literal matching runs between `query` and
|
|
19
|
+
* `ct` (a learned context's bytes), by seed-and-extend over
|
|
20
|
+
* `space.maxGroup`-sized n-gram seeds. Where locate() finds ONE position of
|
|
21
|
+
* a short frame, this finds EVERY run two whole structures share — the
|
|
22
|
+
* matcher CAST detects a woven query with. Returns non-overlapping runs
|
|
23
|
+
* sorted by query position. */
|
|
24
|
+
export declare function alignRuns(ctx: MindContext, query: Uint8Array, ct: Uint8Array): Array<{
|
|
25
|
+
qs: number;
|
|
26
|
+
qe: number;
|
|
27
|
+
cs: number;
|
|
28
|
+
}>;
|
|
29
|
+
/** A run from {@link alignGraded} — the ALIGNED matcher extended with the
|
|
30
|
+
* same graded-evidence ladder as {@link locate}. Literal runs carry
|
|
31
|
+
* `weight = 1` (exact match is full evidence); halo-matched site runs carry
|
|
32
|
+
* `weight = cosine` (measured evidence — the halo similarity itself).
|
|
33
|
+
* `cs` is the structural byte position in the context regardless of run
|
|
34
|
+
* kind, so the substitution/redirection schemas work unchanged on conceptual
|
|
35
|
+
* alignment. */
|
|
36
|
+
export interface GradedRun {
|
|
37
|
+
qs: number;
|
|
38
|
+
qe: number;
|
|
39
|
+
cs: number;
|
|
40
|
+
weight: number;
|
|
41
|
+
}
|
|
42
|
+
/** The GRADED alignment matcher: extends literal W-gram alignment
|
|
43
|
+
* ({@link alignRuns}) with halo-matched recognised sites in query regions
|
|
44
|
+
* that have no literal coverage. Same ladder as {@link locate}: literal
|
|
45
|
+
* first, then distributional role (halo-matched sites, gate:
|
|
46
|
+
* conceptThreshold, enforced by {@link bestHaloMate}). Returns weighted
|
|
47
|
+
* runs sorted by query position.
|
|
48
|
+
*
|
|
49
|
+
* `querySites` are the pre-computed recognition sites for the query
|
|
50
|
+
* (optional — when absent, only literal alignment fires and graded degrades
|
|
51
|
+
* to the original behaviour). Context sites are recognised internally. */
|
|
52
|
+
export declare function alignGraded(ctx: MindContext, query: Uint8Array, contextBytes: Uint8Array, querySites?: ReadonlyArray<Site>): GradedRun[];
|
|
53
|
+
/** The IN-LIST halo matcher: the best halo-mate for `halo` among EXPLICIT
|
|
54
|
+
* candidates, above the concept threshold — the list counterpart of
|
|
55
|
+
* {@link haloSiblings}, which asks the halo INDEX for candidates instead.
|
|
56
|
+
* Behind locate()'s halo step and articulation's voice matching; a third
|
|
57
|
+
* "best halo among these" decision must come here, not inline. */
|
|
58
|
+
export declare function bestHaloMate<T>(ctx: MindContext, halo: Vec, items: Iterable<T>, haloOf: (item: T) => Vec | null | undefined): {
|
|
59
|
+
item: T;
|
|
60
|
+
score: number;
|
|
61
|
+
} | null;
|
|
62
|
+
export declare function haloSiblings(ctx: MindContext, id: number, halo?: Vec | null, bar?: number): Promise<Hit[]>;
|
|
63
|
+
/** The DISTRIBUTIONAL matcher between two nodes: mutual-nearest-neighbour
|
|
64
|
+
* strength, not a pick. Returns the direct halo cosine, or failing that the
|
|
65
|
+
* highest mutual-halo-sibling min-score (second-order analogy), or failing
|
|
66
|
+
* that the SHARED-FRAME strength (below) — the gate CAST's comparison
|
|
67
|
+
* schema validates genuine analogs with (bar: significanceBar).
|
|
68
|
+
*
|
|
69
|
+
* The result names its TIER alongside the score: `halo: true` means the
|
|
70
|
+
* score cleared a significanceBar-gated HALO tier (direct company cosine
|
|
71
|
+
* or mutual-sibling) — genuine distributional evidence; `halo: false`
|
|
72
|
+
* means only the structural shared-frame fallback matched, a coverage
|
|
73
|
+
* fraction with no bar of its own. CAST's comparison gate treats the two
|
|
74
|
+
* differently (see cast.ts): halo evidence stands alone, frame evidence
|
|
75
|
+
* needs the query to have named the analog or the climb root to be
|
|
76
|
+
* trusted. */
|
|
77
|
+
export interface AnalogyEvidence {
|
|
78
|
+
score: number;
|
|
79
|
+
halo: boolean;
|
|
80
|
+
}
|
|
81
|
+
export declare function analogyStrength(ctx: MindContext, a: number, b: number): Promise<AnalogyEvidence>;
|
|
82
|
+
/** The STRUCTURAL analogy tier: two nodes are analogs when their byte
|
|
83
|
+
* streams share a LEARNT frame — a content-addressed flat form of at least
|
|
84
|
+
* one full river window (W bytes, the perception quantum) that occurs in
|
|
85
|
+
* BOTH. This is what "playing the same role" means structurally: "Ice is
|
|
86
|
+
* cold" and "Steel is hard" share the learnt " is " frame even though they
|
|
87
|
+
* keep disjoint distributional company. Halos measure company by IDENTITY
|
|
88
|
+
* (company signatures — see sema.ts), so unrelated-company analogs must be
|
|
89
|
+
* validated by the frame itself, not by content leaking through halo
|
|
90
|
+
* vectors. Strength is the shared learnt coverage of the SHORTER side —
|
|
91
|
+
* a fraction, comparable to the cosine tiers above. Derived: the window
|
|
92
|
+
* is maxGroup, the same quantum differsByOneWindow and canonicalChunkId
|
|
93
|
+
* measure by; no tuned constants. */
|
|
94
|
+
export declare function sharedFrameStrength(ctx: MindContext, a: number, b: number): number;
|
|
95
|
+
/** FORWARD through a synonym: the continuation an edge-less node borrows from
|
|
96
|
+
* a concept (halo) sibling — resonate the node's halo, take the first
|
|
97
|
+
* sibling above the concept threshold that itself has a direct edge. */
|
|
98
|
+
export declare function conceptHop(ctx: MindContext, id: number): Promise<number | null>;
|
|
99
|
+
/** FORWARD projection: follow continuation edges from a node to its fixpoint.
|
|
100
|
+
* The first hop may cross a concept (halo) link — a synonym. The rest
|
|
101
|
+
* follow direct edges. Convergence is intrinsic: the seen set guards
|
|
102
|
+
* against cycles. `guide` disambiguates multi-continuation nodes by
|
|
103
|
+
* resonance. */
|
|
104
|
+
export declare function follow(ctx: MindContext, id: number, guide?: Vec | null): Promise<Uint8Array | null>;
|
|
105
|
+
/** REVERSE projection: the context a learnt continuation follows, voiced as
|
|
106
|
+
* bytes. A common continuation ("Yes.") follows MANY contexts; with a
|
|
107
|
+
* `guide` the context whose gist resonates with the query wins (seat
|
|
108
|
+
* symmetry) — without one, the most-corroborated context wins (poured halo
|
|
109
|
+
* MASS, the direct measure of how many episodes established it), falling
|
|
110
|
+
* back to first-learnt on equal mass. Among many predecessors RECIPROCAL
|
|
111
|
+
* ones (mutual edges) are preferred when any exist (RC5). Callers that
|
|
112
|
+
* HAVE a query gist must pass it, or they silently change disambiguation
|
|
113
|
+
* regime.
|
|
114
|
+
*
|
|
115
|
+
* `rev`, when the caller has already materialised prevOf (one read per
|
|
116
|
+
* relation — a hub's reverse fan-in is corpus-sized), is reused instead of
|
|
117
|
+
* refetched. Returns null when there is no predecessor or the picked
|
|
118
|
+
* context reads empty (a zero-length context is no grounding: an empty
|
|
119
|
+
* Uint8Array is truthy, and returning it would flow a hollow "answer"
|
|
120
|
+
* onward). */
|
|
121
|
+
export declare function reverseContext(ctx: MindContext, id: number, guide?: Vec | null, rev?: readonly number[]): Uint8Array | null;
|
|
122
|
+
/** THE projection: ground a matched node to answer bytes — FORWARD to its
|
|
123
|
+
* continuation fixpoint (which may cross a concept hop), else REVERSE to
|
|
124
|
+
* the context it follows. This is the direction ladder every mechanism's
|
|
125
|
+
* final grounding step reduces to. */
|
|
126
|
+
export declare function project(ctx: MindContext, id: number, guide?: Vec | null): Promise<Uint8Array | null>;
|