@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
|
@@ -12,72 +12,36 @@ import type { Input, MindContext } from "./types.js";
|
|
|
12
12
|
* O(new nodes) per deposit instead of O(context). Only the hit node
|
|
13
13
|
* itself enters `ids`; descendants stay reachable via the memo (see
|
|
14
14
|
* idOf in indexSubSpans and the changedNodes prune). */
|
|
15
|
-
export declare function internTreeIds(
|
|
16
|
-
ctx: MindContext,
|
|
17
|
-
node: Sema,
|
|
18
|
-
ids: Map<Sema, number>,
|
|
19
|
-
): Promise<number>;
|
|
15
|
+
export declare function internTreeIds(ctx: MindContext, node: Sema, ids: Map<Sema, number>): Promise<number>;
|
|
20
16
|
/** Index flat branches for sub-spans of a deposit's byte stream, linked to
|
|
21
17
|
* their structural chunks via durable CONTAINMENT edges. */
|
|
22
|
-
export declare function indexSubSpans(
|
|
23
|
-
ctx: MindContext,
|
|
24
|
-
tree: Sema,
|
|
25
|
-
ids: Map<Sema, number>,
|
|
26
|
-
): Promise<boolean>;
|
|
18
|
+
export declare function indexSubSpans(ctx: MindContext, tree: Sema, ids: Map<Sema, number>): Promise<boolean>;
|
|
27
19
|
/** Perceive, intern, and index a single input. Returns the perceived tree,
|
|
28
20
|
* root id, id map, and the changed (new) subtrees for halo reinforcement. */
|
|
29
|
-
export declare function deposit(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
tree: Sema;
|
|
35
|
-
rootId: number;
|
|
36
|
-
ids: Map<Sema, number>;
|
|
37
|
-
changed: Sema[];
|
|
21
|
+
export declare function deposit(ctx: MindContext, input: Input, track: boolean): Promise<{
|
|
22
|
+
tree: Sema;
|
|
23
|
+
rootId: number;
|
|
24
|
+
ids: Map<Sema, number>;
|
|
25
|
+
changed: Sema[];
|
|
38
26
|
}>;
|
|
39
27
|
/** Ingest a single input (a bare experience, no continuation). */
|
|
40
|
-
export declare function ingestOne(
|
|
41
|
-
ctx: MindContext,
|
|
42
|
-
input: Input,
|
|
43
|
-
): Promise<
|
|
44
|
-
Sema & {
|
|
28
|
+
export declare function ingestOne(ctx: MindContext, input: Input): Promise<Sema & {
|
|
45
29
|
id: number;
|
|
46
|
-
|
|
47
|
-
>;
|
|
30
|
+
}>;
|
|
48
31
|
/** Ingest a pair (context, continuation) — learn an edge and pour halos. */
|
|
49
|
-
export declare function ingestPair(
|
|
50
|
-
ctx: MindContext,
|
|
51
|
-
ctxInput: Input,
|
|
52
|
-
cont: Input,
|
|
53
|
-
): Promise<void>;
|
|
32
|
+
export declare function ingestPair(ctx: MindContext, ctxInput: Input, cont: Input): Promise<void>;
|
|
54
33
|
/** Dispatch the public ingest input shapes onto one-input / pair handlers —
|
|
55
34
|
* THE one reading of ingest's polymorphic surface (scalar, (context,
|
|
56
35
|
* continuation) pair, or a list mixing bare inputs and pairs). Both ingest
|
|
57
36
|
* paths — the direct one below and {@link CachedIngest} — route through
|
|
58
37
|
* this, so the shape-detection can never drift between them again (the
|
|
59
38
|
* ingest cache once re-implemented it and drifted). */
|
|
60
|
-
export declare function dispatchIngest(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
onOne: (input: Input) => Promise<
|
|
64
|
-
Sema & {
|
|
65
|
-
id: number;
|
|
66
|
-
}
|
|
67
|
-
>,
|
|
68
|
-
onPair: (ctxInput: Input, cont: Input) => Promise<void>,
|
|
69
|
-
): Promise<
|
|
70
|
-
(Sema & {
|
|
39
|
+
export declare function dispatchIngest(input: Input | (Input | [Input, Input])[], second: Input | undefined, onOne: (input: Input) => Promise<Sema & {
|
|
40
|
+
id: number;
|
|
41
|
+
}>, onPair: (ctxInput: Input, cont: Input) => Promise<void>): Promise<(Sema & {
|
|
71
42
|
id: number;
|
|
72
|
-
|
|
73
|
-
>;
|
|
43
|
+
}) | undefined>;
|
|
74
44
|
/** Ingest an input or array of inputs/pairs. The public ingest entry point. */
|
|
75
|
-
export declare function ingest(
|
|
76
|
-
ctx: MindContext,
|
|
77
|
-
input: Input | (Input | [Input, Input])[],
|
|
78
|
-
second?: Input,
|
|
79
|
-
): Promise<
|
|
80
|
-
(Sema & {
|
|
45
|
+
export declare function ingest(ctx: MindContext, input: Input | (Input | [Input, Input])[], second?: Input): Promise<(Sema & {
|
|
81
46
|
id: number;
|
|
82
|
-
|
|
83
|
-
>;
|
|
47
|
+
}) | undefined>;
|
|
@@ -20,166 +20,152 @@ import { fold as foldVecs } from "../sema.js";
|
|
|
20
20
|
* itself enters `ids`; descendants stay reachable via the memo (see
|
|
21
21
|
* idOf in indexSubSpans and the changedNodes prune). */
|
|
22
22
|
export async function internTreeIds(ctx, node, ids) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
let id;
|
|
29
|
-
if (node.kids === null) {
|
|
30
|
-
id = await ctx.store.putLeaf(node.leaf ?? new Uint8Array(0), node.v);
|
|
31
|
-
} else {
|
|
32
|
-
const kds = [];
|
|
33
|
-
for (const k of node.kids) {
|
|
34
|
-
kds.push(await internTreeIds(ctx, k, ids));
|
|
23
|
+
const known = ctx._internIds.get(node);
|
|
24
|
+
if (known !== undefined) {
|
|
25
|
+
ids.set(node, known);
|
|
26
|
+
return known;
|
|
35
27
|
}
|
|
36
|
-
id
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
41
|
}
|
|
42
42
|
/** Index flat branches for sub-spans of a deposit's byte stream, linked to
|
|
43
43
|
* their structural chunks via durable CONTAINMENT edges. */
|
|
44
44
|
export async function indexSubSpans(ctx, tree, ids) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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;
|
|
58
63
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
if (n.kids) {
|
|
66
|
-
for (const k of n.kids) {
|
|
67
|
-
if (!collect(k)) {
|
|
68
|
-
return false;
|
|
64
|
+
if (n.kids) {
|
|
65
|
+
for (const k of n.kids)
|
|
66
|
+
if (!collect(k))
|
|
67
|
+
return false;
|
|
69
68
|
}
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
};
|
|
74
|
-
if (!collect(tree)) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
const W = ctx.space.maxGroup; // write side of the canonical contract
|
|
78
|
-
const prev = ctx._prevSeen;
|
|
79
|
-
const seenBefore = (off, len) => {
|
|
80
|
-
if (!prev) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
for (let i = off; i < off + len; i++) {
|
|
84
|
-
const c = chunkOf[i];
|
|
85
|
-
if (c === undefined || !prev.has(c)) {
|
|
69
|
+
return true;
|
|
70
|
+
};
|
|
71
|
+
if (!collect(tree))
|
|
86
72
|
return false;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
+
}
|
|
110
100
|
}
|
|
111
|
-
}
|
|
112
101
|
}
|
|
113
|
-
|
|
114
|
-
return true;
|
|
102
|
+
return true;
|
|
115
103
|
}
|
|
116
104
|
/** Perceive, intern, and index a single input. Returns the perceived tree,
|
|
117
105
|
* root id, id map, and the changed (new) subtrees for halo reinforcement. */
|
|
118
106
|
export async function deposit(ctx, input, track) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return { tree, rootId, ids, changed };
|
|
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.
|
|
115
|
+
const tree = perceiveDeposit(ctx, bytes);
|
|
116
|
+
const ids = new Map();
|
|
117
|
+
const rootId = await internTreeIds(ctx, tree, ids);
|
|
118
|
+
const indexed = await indexSubSpans(ctx, tree, ids);
|
|
119
|
+
const leafIds = leafIdPrefix(ctx, bytes);
|
|
120
|
+
if (leafIds.length === bytes.length && leafIds.length >= 2) {
|
|
121
|
+
await ctx.store.putBranch(leafIds, tree.v);
|
|
122
|
+
}
|
|
123
|
+
const changed = (track && ctx._prevSeen)
|
|
124
|
+
? changedNodes(tree, ids, ctx._prevSeen)
|
|
125
|
+
: [tree];
|
|
126
|
+
if (track)
|
|
127
|
+
ctx._prevSeen = indexed ? new Set(ids.values()) : null;
|
|
128
|
+
return { tree, rootId, ids, changed };
|
|
142
129
|
}
|
|
143
130
|
/** Ingest a single input (a bare experience, no continuation). */
|
|
144
131
|
export async function ingestOne(ctx, input) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
132
|
+
const { tree, rootId, ids } = await deposit(ctx, input, true);
|
|
133
|
+
ctx.store.indexTarget(rootId);
|
|
134
|
+
const parts = tree.kids
|
|
135
|
+
? tree.kids.map((k) => ids.get(k))
|
|
136
|
+
: [rootId];
|
|
137
|
+
const stride = ctx.space.maxGroup;
|
|
138
|
+
if (parts.length > stride) {
|
|
139
|
+
for (let i = 0; i + stride < parts.length; i += stride) {
|
|
140
|
+
await ctx.store.link(parts[i], parts[i + stride]);
|
|
141
|
+
}
|
|
142
|
+
if ((parts.length - 1) % stride !== 0) {
|
|
143
|
+
const lastStart = Math.floor((parts.length - 1) / stride) * stride;
|
|
144
|
+
if (lastStart < parts.length - 1) {
|
|
145
|
+
await ctx.store.link(parts[lastStart], parts[parts.length - 1]);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
158
148
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
149
|
+
else {
|
|
150
|
+
for (const id of parts)
|
|
151
|
+
ctx.store.indexTarget(id);
|
|
162
152
|
}
|
|
163
|
-
|
|
164
|
-
return Object.assign(tree, { id: rootId });
|
|
153
|
+
return Object.assign(tree, { id: rootId });
|
|
165
154
|
}
|
|
166
155
|
/** Ingest a pair (context, continuation) — learn an edge and pour halos. */
|
|
167
156
|
export async function ingestPair(ctx, ctxInput, cont) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
bindSeat(ctx.space, companySignature(ctx.space, partId), 0),
|
|
181
|
-
);
|
|
182
|
-
}
|
|
157
|
+
const c = await deposit(ctx, ctxInput, true);
|
|
158
|
+
const cont_ = await deposit(ctx, cont, false);
|
|
159
|
+
const ctxId = c.rootId, contId = cont_.rootId;
|
|
160
|
+
await ctx.store.link(ctxId, contId);
|
|
161
|
+
// Halos pour company SIGNATURES (identity), not gists (content) — see
|
|
162
|
+
// companySignature in sema.ts.
|
|
163
|
+
const contSeat = bindSeat(ctx.space, companySignature(ctx.space, contId), 1);
|
|
164
|
+
for (const part of c.changed) {
|
|
165
|
+
const partId = c.ids.get(part);
|
|
166
|
+
await ctx.store.pourHalo(partId, contSeat);
|
|
167
|
+
await ctx.store.pourHalo(contId, bindSeat(ctx.space, companySignature(ctx.space, partId), 0));
|
|
168
|
+
}
|
|
183
169
|
}
|
|
184
170
|
/** Dispatch the public ingest input shapes onto one-input / pair handlers —
|
|
185
171
|
* THE one reading of ingest's polymorphic surface (scalar, (context,
|
|
@@ -188,36 +174,28 @@ export async function ingestPair(ctx, ctxInput, cont) {
|
|
|
188
174
|
* this, so the shape-detection can never drift between them again (the
|
|
189
175
|
* ingest cache once re-implemented it and drifted). */
|
|
190
176
|
export async function dispatchIngest(input, second, onOne, onPair) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
177
|
+
if (Array.isArray(input) && !(input instanceof Uint8Array) &&
|
|
178
|
+
input.width === undefined) {
|
|
179
|
+
const arr = input;
|
|
180
|
+
if (arr.length === 2 && !Array.isArray(arr[0]) && !Array.isArray(arr[1])) {
|
|
181
|
+
await onPair(arr[0], arr[1]);
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
for (const item of arr) {
|
|
185
|
+
if (Array.isArray(item) && item.length === 2) {
|
|
186
|
+
await onPair(item[0], item[1]);
|
|
187
|
+
}
|
|
188
|
+
else
|
|
189
|
+
await onOne(item);
|
|
190
|
+
}
|
|
191
|
+
return undefined;
|
|
206
192
|
}
|
|
193
|
+
if (second === undefined)
|
|
194
|
+
return onOne(input);
|
|
195
|
+
await onPair(input, second);
|
|
207
196
|
return undefined;
|
|
208
|
-
}
|
|
209
|
-
if (second === undefined) {
|
|
210
|
-
return onOne(input);
|
|
211
|
-
}
|
|
212
|
-
await onPair(input, second);
|
|
213
|
-
return undefined;
|
|
214
197
|
}
|
|
215
198
|
/** Ingest an input or array of inputs/pairs. The public ingest entry point. */
|
|
216
199
|
export async function ingest(ctx, input, second) {
|
|
217
|
-
|
|
218
|
-
input,
|
|
219
|
-
second,
|
|
220
|
-
(i) => ingestOne(ctx, i),
|
|
221
|
-
(a, b) => ingestPair(ctx, a, b),
|
|
222
|
-
);
|
|
200
|
+
return dispatchIngest(input, second, (i) => ingestOne(ctx, i), (a, b) => ingestPair(ctx, a, b));
|
|
223
201
|
}
|
package/dist/src/mind/match.d.ts
CHANGED
|
@@ -14,27 +14,17 @@ import type { Site } from "./graph-search.js";
|
|
|
14
14
|
* (gate: identityBar — scale-aware).
|
|
15
15
|
*
|
|
16
16
|
* Returns the absolute byte position, or −1. */
|
|
17
|
-
export declare function locate(
|
|
18
|
-
ctx: MindContext,
|
|
19
|
-
haystack: Uint8Array,
|
|
20
|
-
needle: Uint8Array,
|
|
21
|
-
fromPos: number,
|
|
22
|
-
sites?: ReadonlyArray<Site>,
|
|
23
|
-
): number;
|
|
17
|
+
export declare function locate(ctx: MindContext, haystack: Uint8Array, needle: Uint8Array, fromPos: number, sites?: ReadonlyArray<Site>): number;
|
|
24
18
|
/** The ALIGNED matcher: maximal literal matching runs between `query` and
|
|
25
19
|
* `ct` (a learned context's bytes), by seed-and-extend over
|
|
26
20
|
* `space.maxGroup`-sized n-gram seeds. Where locate() finds ONE position of
|
|
27
21
|
* a short frame, this finds EVERY run two whole structures share — the
|
|
28
22
|
* matcher CAST detects a woven query with. Returns non-overlapping runs
|
|
29
23
|
* sorted by query position. */
|
|
30
|
-
export declare function alignRuns(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
): Array<{
|
|
35
|
-
qs: number;
|
|
36
|
-
qe: number;
|
|
37
|
-
cs: number;
|
|
24
|
+
export declare function alignRuns(ctx: MindContext, query: Uint8Array, ct: Uint8Array): Array<{
|
|
25
|
+
qs: number;
|
|
26
|
+
qe: number;
|
|
27
|
+
cs: number;
|
|
38
28
|
}>;
|
|
39
29
|
/** A run from {@link alignGraded} — the ALIGNED matcher extended with the
|
|
40
30
|
* same graded-evidence ladder as {@link locate}. Literal runs carry
|
|
@@ -44,10 +34,10 @@ export declare function alignRuns(
|
|
|
44
34
|
* kind, so the substitution/redirection schemas work unchanged on conceptual
|
|
45
35
|
* alignment. */
|
|
46
36
|
export interface GradedRun {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
qs: number;
|
|
38
|
+
qe: number;
|
|
39
|
+
cs: number;
|
|
40
|
+
weight: number;
|
|
51
41
|
}
|
|
52
42
|
/** The GRADED alignment matcher: extends literal W-gram alignment
|
|
53
43
|
* ({@link alignRuns}) with halo-matched recognised sites in query regions
|
|
@@ -59,42 +49,23 @@ export interface GradedRun {
|
|
|
59
49
|
* `querySites` are the pre-computed recognition sites for the query
|
|
60
50
|
* (optional — when absent, only literal alignment fires and graded degrades
|
|
61
51
|
* to the original behaviour). Context sites are recognised internally. */
|
|
62
|
-
export declare function alignGraded(
|
|
63
|
-
ctx: MindContext,
|
|
64
|
-
query: Uint8Array,
|
|
65
|
-
contextBytes: Uint8Array,
|
|
66
|
-
querySites?: ReadonlyArray<Site>,
|
|
67
|
-
): GradedRun[];
|
|
52
|
+
export declare function alignGraded(ctx: MindContext, query: Uint8Array, contextBytes: Uint8Array, querySites?: ReadonlyArray<Site>): GradedRun[];
|
|
68
53
|
/** The IN-LIST halo matcher: the best halo-mate for `halo` among EXPLICIT
|
|
69
54
|
* candidates, above the concept threshold — the list counterpart of
|
|
70
55
|
* {@link haloSiblings}, which asks the halo INDEX for candidates instead.
|
|
71
56
|
* Behind locate()'s halo step and articulation's voice matching; a third
|
|
72
57
|
* "best halo among these" decision must come here, not inline. */
|
|
73
|
-
export declare function bestHaloMate<T>(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
items: Iterable<T>,
|
|
77
|
-
haloOf: (item: T) => Vec | null | undefined,
|
|
78
|
-
): {
|
|
79
|
-
item: T;
|
|
80
|
-
score: number;
|
|
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;
|
|
81
61
|
} | null;
|
|
82
|
-
export declare function haloSiblings(
|
|
83
|
-
ctx: MindContext,
|
|
84
|
-
id: number,
|
|
85
|
-
halo?: Vec | null,
|
|
86
|
-
bar?: number,
|
|
87
|
-
): Promise<Hit[]>;
|
|
62
|
+
export declare function haloSiblings(ctx: MindContext, id: number, halo?: Vec | null, bar?: number): Promise<Hit[]>;
|
|
88
63
|
/** The DISTRIBUTIONAL matcher between two nodes: mutual-nearest-neighbour
|
|
89
64
|
* strength, not a pick. Returns the direct halo cosine, or failing that the
|
|
90
65
|
* highest mutual-halo-sibling min-score (second-order analogy), or failing
|
|
91
66
|
* that the SHARED-FRAME strength (below) — the gate CAST's comparison
|
|
92
67
|
* schema validates genuine analogs with (bar: significanceBar). */
|
|
93
|
-
export declare function analogyStrength(
|
|
94
|
-
ctx: MindContext,
|
|
95
|
-
a: number,
|
|
96
|
-
b: number,
|
|
97
|
-
): Promise<number>;
|
|
68
|
+
export declare function analogyStrength(ctx: MindContext, a: number, b: number): Promise<number>;
|
|
98
69
|
/** The STRUCTURAL analogy tier: two nodes are analogs when their byte
|
|
99
70
|
* streams share a LEARNT frame — a content-addressed flat form of at least
|
|
100
71
|
* one full river window (W bytes, the perception quantum) that occurs in
|
|
@@ -107,28 +78,17 @@ export declare function analogyStrength(
|
|
|
107
78
|
* a fraction, comparable to the cosine tiers above. Derived: the window
|
|
108
79
|
* is maxGroup, the same quantum differsByOneWindow and canonicalChunkId
|
|
109
80
|
* measure by; no tuned constants. */
|
|
110
|
-
export declare function sharedFrameStrength(
|
|
111
|
-
ctx: MindContext,
|
|
112
|
-
a: number,
|
|
113
|
-
b: number,
|
|
114
|
-
): number;
|
|
81
|
+
export declare function sharedFrameStrength(ctx: MindContext, a: number, b: number): number;
|
|
115
82
|
/** FORWARD through a synonym: the continuation an edge-less node borrows from
|
|
116
83
|
* a concept (halo) sibling — resonate the node's halo, take the first
|
|
117
84
|
* sibling above the concept threshold that itself has a direct edge. */
|
|
118
|
-
export declare function conceptHop(
|
|
119
|
-
ctx: MindContext,
|
|
120
|
-
id: number,
|
|
121
|
-
): Promise<number | null>;
|
|
85
|
+
export declare function conceptHop(ctx: MindContext, id: number): Promise<number | null>;
|
|
122
86
|
/** FORWARD projection: follow continuation edges from a node to its fixpoint.
|
|
123
87
|
* The first hop may cross a concept (halo) link — a synonym. The rest
|
|
124
88
|
* follow direct edges. Convergence is intrinsic: the seen set guards
|
|
125
89
|
* against cycles. `guide` disambiguates multi-continuation nodes by
|
|
126
90
|
* resonance. */
|
|
127
|
-
export declare function follow(
|
|
128
|
-
ctx: MindContext,
|
|
129
|
-
id: number,
|
|
130
|
-
guide?: Vec | null,
|
|
131
|
-
): Promise<Uint8Array | null>;
|
|
91
|
+
export declare function follow(ctx: MindContext, id: number, guide?: Vec | null): Promise<Uint8Array | null>;
|
|
132
92
|
/** REVERSE projection: the context a learnt continuation follows, voiced as
|
|
133
93
|
* bytes. A common continuation ("Yes.") follows MANY contexts; with a
|
|
134
94
|
* `guide` the context whose gist resonates with the query wins (seat
|
|
@@ -143,18 +103,9 @@ export declare function follow(
|
|
|
143
103
|
* context reads empty (a zero-length context is no grounding: an empty
|
|
144
104
|
* Uint8Array is truthy, and returning it would flow a hollow "answer"
|
|
145
105
|
* onward). */
|
|
146
|
-
export declare function reverseContext(
|
|
147
|
-
ctx: MindContext,
|
|
148
|
-
id: number,
|
|
149
|
-
guide?: Vec | null,
|
|
150
|
-
rev?: readonly number[],
|
|
151
|
-
): Uint8Array | null;
|
|
106
|
+
export declare function reverseContext(ctx: MindContext, id: number, guide?: Vec | null, rev?: readonly number[]): Uint8Array | null;
|
|
152
107
|
/** THE projection: ground a matched node to answer bytes — FORWARD to its
|
|
153
108
|
* continuation fixpoint (which may cross a concept hop), else REVERSE to
|
|
154
109
|
* the context it follows. This is the direction ladder every mechanism's
|
|
155
110
|
* final grounding step reduces to. */
|
|
156
|
-
export declare function project(
|
|
157
|
-
ctx: MindContext,
|
|
158
|
-
id: number,
|
|
159
|
-
guide?: Vec | null,
|
|
160
|
-
): Promise<Uint8Array | null>;
|
|
111
|
+
export declare function project(ctx: MindContext, id: number, guide?: Vec | null): Promise<Uint8Array | null>;
|