@hviana/sema 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/dist/example/demo.d.ts +1 -0
  2. package/dist/example/demo.js +39 -0
  3. package/dist/example/train_base.d.ts +87 -0
  4. package/dist/example/train_base.js +2216 -0
  5. package/dist/src/alphabet.d.ts +7 -0
  6. package/dist/src/alphabet.js +33 -0
  7. package/dist/src/alu/src/alu.d.ts +185 -0
  8. package/dist/src/alu/src/alu.js +440 -0
  9. package/dist/src/alu/src/expr.d.ts +61 -0
  10. package/dist/src/alu/src/expr.js +318 -0
  11. package/dist/src/alu/src/index.d.ts +11 -0
  12. package/dist/src/alu/src/index.js +19 -0
  13. package/dist/src/alu/src/kernel-arith.d.ts +16 -0
  14. package/dist/src/alu/src/kernel-arith.js +264 -0
  15. package/dist/src/alu/src/kernel-bits.d.ts +19 -0
  16. package/dist/src/alu/src/kernel-bits.js +152 -0
  17. package/dist/src/alu/src/kernel-logic.d.ts +4 -0
  18. package/dist/src/alu/src/kernel-logic.js +60 -0
  19. package/dist/src/alu/src/kernel-nd.d.ts +3 -0
  20. package/dist/src/alu/src/kernel-nd.js +208 -0
  21. package/dist/src/alu/src/kernel-numeric.d.ts +54 -0
  22. package/dist/src/alu/src/kernel-numeric.js +366 -0
  23. package/dist/src/alu/src/operation.d.ts +168 -0
  24. package/dist/src/alu/src/operation.js +189 -0
  25. package/dist/src/alu/src/parser.d.ts +212 -0
  26. package/dist/src/alu/src/parser.js +469 -0
  27. package/dist/src/alu/src/resonance.d.ts +55 -0
  28. package/dist/src/alu/src/resonance.js +126 -0
  29. package/dist/src/alu/src/text.d.ts +31 -0
  30. package/dist/src/alu/src/text.js +73 -0
  31. package/dist/src/alu/src/value.d.ts +109 -0
  32. package/dist/src/alu/src/value.js +300 -0
  33. package/dist/src/alu/test/alu.test.d.ts +1 -0
  34. package/dist/src/alu/test/alu.test.js +764 -0
  35. package/dist/src/bytes.d.ts +14 -0
  36. package/dist/src/bytes.js +59 -0
  37. package/dist/src/config.d.ts +114 -0
  38. package/dist/src/config.js +96 -0
  39. package/dist/src/derive/src/deduction.d.ts +125 -0
  40. package/dist/src/derive/src/deduction.js +155 -0
  41. package/dist/src/derive/src/index.d.ts +7 -0
  42. package/dist/src/derive/src/index.js +11 -0
  43. package/dist/src/derive/src/priority-queue.d.ts +20 -0
  44. package/dist/src/derive/src/priority-queue.js +73 -0
  45. package/dist/src/derive/src/rewrite.d.ts +56 -0
  46. package/dist/src/derive/src/rewrite.js +100 -0
  47. package/dist/src/derive/src/trie.d.ts +90 -0
  48. package/dist/src/derive/src/trie.js +217 -0
  49. package/dist/src/derive/test/derive.test.d.ts +1 -0
  50. package/dist/src/derive/test/derive.test.js +122 -0
  51. package/dist/src/extension.d.ts +37 -0
  52. package/dist/src/extension.js +7 -0
  53. package/dist/src/geometry.d.ts +137 -0
  54. package/dist/src/geometry.js +430 -0
  55. package/dist/src/index.d.ts +15 -0
  56. package/dist/src/index.js +21 -0
  57. package/dist/src/ingest-cache.d.ts +41 -0
  58. package/dist/src/ingest-cache.js +161 -0
  59. package/dist/src/mind/articulation.d.ts +6 -0
  60. package/dist/src/mind/articulation.js +99 -0
  61. package/dist/src/mind/attention.d.ts +72 -0
  62. package/dist/src/mind/attention.js +894 -0
  63. package/dist/src/mind/canonical.d.ts +29 -0
  64. package/dist/src/mind/canonical.js +88 -0
  65. package/dist/src/mind/graph-search.d.ts +270 -0
  66. package/dist/src/mind/graph-search.js +847 -0
  67. package/dist/src/mind/index.d.ts +5 -0
  68. package/dist/src/mind/index.js +5 -0
  69. package/dist/src/mind/junction.d.ts +95 -0
  70. package/dist/src/mind/junction.js +262 -0
  71. package/dist/src/mind/learning.d.ts +47 -0
  72. package/dist/src/mind/learning.js +201 -0
  73. package/dist/src/mind/match.d.ts +111 -0
  74. package/dist/src/mind/match.js +422 -0
  75. package/dist/src/mind/mechanisms/alu.d.ts +4 -0
  76. package/dist/src/mind/mechanisms/alu.js +29 -0
  77. package/dist/src/mind/mechanisms/cast.d.ts +35 -0
  78. package/dist/src/mind/mechanisms/cast.js +447 -0
  79. package/dist/src/mind/mechanisms/confluence.d.ts +24 -0
  80. package/dist/src/mind/mechanisms/confluence.js +213 -0
  81. package/dist/src/mind/mechanisms/cover.d.ts +6 -0
  82. package/dist/src/mind/mechanisms/cover.js +179 -0
  83. package/dist/src/mind/mechanisms/extraction.d.ts +67 -0
  84. package/dist/src/mind/mechanisms/extraction.js +342 -0
  85. package/dist/src/mind/mechanisms/recall.d.ts +13 -0
  86. package/dist/src/mind/mechanisms/recall.js +151 -0
  87. package/dist/src/mind/mind.d.ts +147 -0
  88. package/dist/src/mind/mind.js +300 -0
  89. package/dist/src/mind/pipeline-mechanism.d.ts +142 -0
  90. package/dist/src/mind/pipeline-mechanism.js +213 -0
  91. package/dist/src/mind/pipeline.d.ts +20 -0
  92. package/dist/src/mind/pipeline.js +185 -0
  93. package/dist/src/mind/primitives.d.ts +43 -0
  94. package/dist/src/mind/primitives.js +162 -0
  95. package/dist/src/mind/rationale.d.ts +134 -0
  96. package/dist/src/mind/rationale.js +162 -0
  97. package/dist/src/mind/reasoning.d.ts +15 -0
  98. package/dist/src/mind/reasoning.js +162 -0
  99. package/dist/src/mind/recognition.d.ts +20 -0
  100. package/dist/src/mind/recognition.js +223 -0
  101. package/dist/src/mind/resonance.d.ts +23 -0
  102. package/dist/src/mind/resonance.js +0 -0
  103. package/dist/src/mind/trace.d.ts +15 -0
  104. package/dist/src/mind/trace.js +73 -0
  105. package/dist/src/mind/traverse.d.ts +100 -0
  106. package/dist/src/mind/traverse.js +447 -0
  107. package/dist/src/mind/types.d.ts +174 -0
  108. package/dist/src/mind/types.js +84 -0
  109. package/dist/src/rabitq-hnsw/src/database.d.ts +200 -0
  110. package/dist/src/rabitq-hnsw/src/database.js +388 -0
  111. package/dist/src/rabitq-hnsw/src/heap.d.ts +22 -0
  112. package/dist/src/rabitq-hnsw/src/heap.js +89 -0
  113. package/dist/src/rabitq-hnsw/src/hnsw.d.ts +125 -0
  114. package/dist/src/rabitq-hnsw/src/hnsw.js +474 -0
  115. package/dist/src/rabitq-hnsw/src/index.d.ts +10 -0
  116. package/dist/src/rabitq-hnsw/src/index.js +6 -0
  117. package/dist/src/rabitq-hnsw/src/prng.d.ts +19 -0
  118. package/dist/src/rabitq-hnsw/src/prng.js +36 -0
  119. package/dist/src/rabitq-hnsw/src/rabitq.d.ts +95 -0
  120. package/dist/src/rabitq-hnsw/src/rabitq.js +283 -0
  121. package/dist/src/rabitq-hnsw/src/store.d.ts +162 -0
  122. package/dist/src/rabitq-hnsw/src/store.js +825 -0
  123. package/dist/src/rabitq-hnsw/test/hnsw.test.d.ts +1 -0
  124. package/dist/src/rabitq-hnsw/test/hnsw.test.js +948 -0
  125. package/dist/src/store-sqlite.d.ts +149 -0
  126. package/dist/src/store-sqlite.js +702 -0
  127. package/dist/src/store.d.ts +638 -0
  128. package/dist/src/store.js +1618 -0
  129. package/dist/src/vec.d.ts +31 -0
  130. package/dist/src/vec.js +109 -0
  131. package/package.json +1 -1
@@ -0,0 +1,41 @@
1
+ import { Mind } from "./mind/index.js";
2
+ import { type Sema } from "./sema.js";
3
+ import type { Input } from "./mind/index.js";
4
+ /**
5
+ * An ingest cache layered over a Mind.
6
+ *
7
+ * Usage (drop-in for mind.ingest in training loops):
8
+ * const ci = new CachedIngest(mind);
9
+ * await ci.ingest(ctx, cont); // caches both sides
10
+ * await ci.ingest("some text"); // caches the single text
11
+ * await ci.ingest([[ctx, cont]]); // array form
12
+ *
13
+ * All other Mind methods (respond, save, …) are accessed on `ci.mind`.
14
+ */
15
+ export declare class CachedIngest {
16
+ readonly mind: Mind;
17
+ /** One unified, content-addressed memo of interned inputs. Each value holds
18
+ * Float32 root vector (D·4 bytes) plus a small id array, so the byte budget
19
+ * is spent on the inputs most worth remembering (LRU). */
20
+ private _memo;
21
+ hits: number;
22
+ misses: number;
23
+ constructor(mind: Mind);
24
+ private newMemo;
25
+ private keyOf;
26
+ ingest(input: Input | (Input | [Input, Input])[], second?: Input): Promise<(Sema & {
27
+ id: number;
28
+ }) | undefined>;
29
+ /** Resolve an input to its interned nodes, from the memo when its content has
30
+ * been seen before, else by the Mind's OWN untracked {@link deposit}
31
+ * (perceive + intern + sub-span/containment indexing — identical to the
32
+ * direct path; those writes are durable and idempotent, so a later memo hit
33
+ * legitimately skips them). This is the single expensive operation both
34
+ * ingest paths share; caching it here is what makes every repeated input —
35
+ * in any role — cheap. */
36
+ private resolveInput;
37
+ private ingestPair;
38
+ private ingestOne;
39
+ clear(): void;
40
+ get size(): number;
41
+ }
@@ -0,0 +1,161 @@
1
+ // ingest-cache.ts — ingest-level cache for Mind.
2
+ //
3
+ // Wraps a Mind and memoises the expensive, content-determined half of ingestion:
4
+ // turning ONE input (a context, a continuation, or a bare experience) into its
5
+ // interned graph nodes. Perception (riverFold) and interning are a PURE function
6
+ // of the input bytes — the same bytes always cut the same way and hash-cons to
7
+ // the same node ids — so the result can be cached by content and reused wherever
8
+ // those same bytes appear again, in ANY role.
9
+ //
10
+ // This is why the cache keys on the single input, not on the (context,
11
+ // continuation) pair: real training corpora repeat content at the INPUT level far
12
+ // more than at the pair level — a shared system/tool preamble in front of every
13
+ // row, a common answer ("Yes.", a refusal) under many questions, an accumulated
14
+ // dialogue prefix, an exactly-duplicated row. A pair-level key sees none of these
15
+ // (the pair as a whole is almost always unique); the input-level key catches them
16
+ // all, and a context that recurs as a continuation (or vice versa) hits too.
17
+ //
18
+ // On a cache hit only the cheap relational writes are replayed — the edge and the
19
+ // two halo pours for a pair, or the part-chain links for a single — while the
20
+ // perceive + internTree work (the dominant cost, and on a large store the dominant
21
+ // VECTOR-INDEX cost too) is skipped entirely. The interned node ids are stable
22
+ // across eviction: a re-perceive of evicted content reproduces the same ids by
23
+ // the store's hash-cons, so correctness never depends on a hit.
24
+ //
25
+ // DEPOSITION IS THE MIND'S OWN: every miss goes through the same
26
+ // {@link deposit} the direct Mind.ingest path uses — perception, interning,
27
+ // sub-span/window indexing, durable CONTAINMENT edges, whole-stream flat
28
+ // branch, changed-node tracking against the Mind's `_prevSeen` — so a store
29
+ // trained through this cache is structurally IDENTICAL to one trained by
30
+ // calling mind.ingest() directly (this class used to re-implement the deposit
31
+ // and drifted: no indexSubSpans/addContainer, wrong part-link stride). Only
32
+ // the memo layer lives here. Behaviour is identical to mind.ingest() (links
33
+ // and halos are reinforced on every call), just faster when content repeats.
34
+ import { deposit, dispatchIngest, ingestOne as depositOne, } from "./mind/learning.js";
35
+ import { bindSeat, companySignature } from "./sema.js";
36
+ import { BoundedMap } from "./store.js";
37
+ /**
38
+ * An ingest cache layered over a Mind.
39
+ *
40
+ * Usage (drop-in for mind.ingest in training loops):
41
+ * const ci = new CachedIngest(mind);
42
+ * await ci.ingest(ctx, cont); // caches both sides
43
+ * await ci.ingest("some text"); // caches the single text
44
+ * await ci.ingest([[ctx, cont]]); // array form
45
+ *
46
+ * All other Mind methods (respond, save, …) are accessed on `ci.mind`.
47
+ */
48
+ export class CachedIngest {
49
+ mind;
50
+ /** One unified, content-addressed memo of interned inputs. Each value holds
51
+ * Float32 root vector (D·4 bytes) plus a small id array, so the byte budget
52
+ * is spent on the inputs most worth remembering (LRU). */
53
+ _memo;
54
+ hits = 0;
55
+ misses = 0;
56
+ constructor(mind) {
57
+ this.mind = mind;
58
+ this._memo = this.newMemo();
59
+ }
60
+ newMemo() {
61
+ return new BoundedMap(this.mind.cfg.store.ingestCacheBytes, (c) => c.rootV.byteLength + c.partIds.length * 4 + 8 + c.keyBytes);
62
+ }
63
+ // ── cache key ───────────────────────────────────────────────────────────
64
+ // Content key for an input, or null when the input cannot be keyed reliably
65
+ // — in which case it BYPASSES the cache (recomputed every time) rather than
66
+ // risk a collision returning the wrong nodes. A string is its own key; raw
67
+ // bytes hash by FNV-1a (+ length, so a hash collision still needs an equal
68
+ // length to alias); a Grid / Grid[] has no cheap stable key, so it bypasses.
69
+ keyOf(input) {
70
+ if (typeof input === "string")
71
+ return "S:" + input;
72
+ if (input instanceof Uint8Array) {
73
+ // FNV-1a — no spread onto the call stack, safe on large binary inputs.
74
+ let h = 0x811c9dc5 >>> 0;
75
+ for (let i = 0; i < input.length; i++) {
76
+ h ^= input[i];
77
+ h = Math.imul(h, 0x01000193) >>> 0;
78
+ }
79
+ return "B:" + (h >>> 0).toString(16) + ":" + input.length;
80
+ }
81
+ return null; // Grid / Grid[] — bypass the cache
82
+ }
83
+ // ── public API ────────────────────────────────────────────────────────
84
+ async ingest(input, second) {
85
+ // One shape-reading for both ingest paths — see {@link dispatchIngest}.
86
+ return dispatchIngest(input, second, (i) => this.ingestOne(i), (a, b) => this.ingestPair(a, b));
87
+ }
88
+ // ── the one cached step: perceive + intern + index ONE input ──────────────
89
+ /** Resolve an input to its interned nodes, from the memo when its content has
90
+ * been seen before, else by the Mind's OWN untracked {@link deposit}
91
+ * (perceive + intern + sub-span/containment indexing — identical to the
92
+ * direct path; those writes are durable and idempotent, so a later memo hit
93
+ * legitimately skips them). This is the single expensive operation both
94
+ * ingest paths share; caching it here is what makes every repeated input —
95
+ * in any role — cheap. */
96
+ async resolveInput(input) {
97
+ const key = this.keyOf(input);
98
+ if (key !== null) {
99
+ const cached = this._memo.get(key);
100
+ if (cached) {
101
+ this.hits++;
102
+ return cached;
103
+ }
104
+ }
105
+ this.misses++;
106
+ // The full deposit, untracked (a continuation must not break the tracked
107
+ // deposit chain). `partIds` are the root's immediate children, already
108
+ // interned by the deposit — free to capture. Only the root vector and
109
+ // ids are retained; the tree is GC'd.
110
+ const { tree, rootId, ids } = await deposit(this.mind, input, false);
111
+ const partIds = tree.kids
112
+ ? tree.kids.map((k) => ids.get(k))
113
+ : [rootId];
114
+ const entry = {
115
+ rootV: tree.v,
116
+ rootId,
117
+ partIds,
118
+ // ~2 bytes per UTF-16 code unit — the key is retained by the map.
119
+ keyBytes: key !== null ? key.length * 2 : 0,
120
+ };
121
+ if (key !== null)
122
+ this._memo.set(key, entry);
123
+ return entry;
124
+ }
125
+ // ── pair ingest ───────────────────────────────────────────────────────
126
+ async ingestPair(ctx, cont) {
127
+ // The CONTEXT side is TRACKED (it continues the Mind's deposit chain and
128
+ // is the growing, unique-per-turn side — a cache miss anyway), via the
129
+ // same {@link deposit} the direct path uses; the continuation resolves
130
+ // through the memo.
131
+ const c = await deposit(this.mind, ctx, true);
132
+ const b = await this.resolveInput(cont);
133
+ // EDGE on the FULL context (disambiguates a shared pivot). HALO only on the
134
+ // CHANGED NODES — the coherent new subtrees this turn adds — so a recurring
135
+ // shared prefix never collects halo mass. (See Mind.ingestPair.)
136
+ await this.mind.store.link(c.rootId, b.rootId);
137
+ // Halos pour company SIGNATURES (identity), not gists (content) — see
138
+ // companySignature in sema.ts.
139
+ const contSeat = bindSeat(this.mind.space, companySignature(this.mind.space, b.rootId), 1);
140
+ for (const part of c.changed) {
141
+ const partId = c.ids.get(part);
142
+ await this.mind.store.pourHalo(partId, contSeat);
143
+ await this.mind.store.pourHalo(b.rootId, bindSeat(this.mind.space, companySignature(this.mind.space, partId), 0));
144
+ }
145
+ }
146
+ // ── one-side ingest ───────────────────────────────────────────────────
147
+ async ingestOne(input) {
148
+ // A bare experience is the direct path verbatim — tracked deposit, root
149
+ // marked a resonance target, part chain linked at the maxGroup stride.
150
+ // (The tracked side is a memo miss by design, so there is nothing for the
151
+ // cache to add here.)
152
+ return depositOne(this.mind, input);
153
+ }
154
+ // ── helpers ───────────────────────────────────────────────────────────
155
+ clear() {
156
+ this._memo = this.newMemo();
157
+ }
158
+ get size() {
159
+ return this._memo.size;
160
+ }
161
+ }
@@ -0,0 +1,6 @@
1
+ import type { MindContext } from "./types.js";
2
+ /** Re-voice an answer in the asker's own words. For each recognised form
3
+ * in the answer, find a concept-sibling in the query (by halo resonance)
4
+ * and substitute the asker's wording. The search's own cover mechanism
5
+ * splices the substitutes into the answer exactly where the forms sit. */
6
+ export declare function articulate(ctx: MindContext, answer: Uint8Array, query: Uint8Array | null): Promise<Uint8Array>;
@@ -0,0 +1,99 @@
1
+ // articulation.ts — re-voice an answer in the asker's wording (Section 5).
2
+ //
3
+ // articulate — substitute answer forms with the asker's synonyms,
4
+ // using concept (halo) resonance to match the voices.
5
+ import { spliceAll } from "./types.js";
6
+ import { recognise } from "./recognition.js";
7
+ import { contains } from "./traverse.js";
8
+ import { bestHaloMate } from "./match.js";
9
+ import { coverSequence } from "../derive/src/index.js";
10
+ import { rItem, rNode, traceDerivation } from "./trace.js";
11
+ /** Re-voice an answer in the asker's own words. For each recognised form
12
+ * in the answer, find a concept-sibling in the query (by halo resonance)
13
+ * and substitute the asker's wording. The search's own cover mechanism
14
+ * splices the substitutes into the answer exactly where the forms sit. */
15
+ export async function articulate(ctx, answer, query) {
16
+ if (!query || query.length < 2 || answer.length < 2)
17
+ return answer;
18
+ const store = ctx.store;
19
+ const t = ctx.trace?.enter("articulate", [
20
+ rItem(answer, "answer"),
21
+ rItem(query, "query"),
22
+ ]);
23
+ const keep = (note) => {
24
+ t?.done([rItem(answer, "answer")], note);
25
+ return answer;
26
+ };
27
+ const qCandidates = [];
28
+ for (const s of recognise(ctx, query).sites) {
29
+ // payload < 0 is a SINGLE-BYTE leaf (byte leaves occupy the implicit
30
+ // negative id range −256…−1 — see store.ts). A one-byte form's halo is
31
+ // promiscuous (it keeps company with everything it ever neighboured), so
32
+ // admitting it as a voice or a revoicing target lets e.g. the digit "4"
33
+ // be "re-voiced" into an unrelated digit the query happens to contain.
34
+ // Articulation therefore operates on multi-byte forms only.
35
+ if (s.payload < 0)
36
+ continue;
37
+ const h = store.halo(s.payload);
38
+ if (!h)
39
+ continue;
40
+ qCandidates.push({
41
+ start: s.start,
42
+ end: s.end,
43
+ payload: {
44
+ halo: h,
45
+ bytes: query.slice(s.start, s.end),
46
+ node: s.payload,
47
+ },
48
+ });
49
+ }
50
+ if (qCandidates.length === 0) {
51
+ return keep("no asker concept to revoice — answer unchanged");
52
+ }
53
+ if (coverSequence(query.length, qCandidates).spans.length === 0) {
54
+ return keep("no asker concept to revoice — answer unchanged");
55
+ }
56
+ const voices = qCandidates.map((s) => s.payload);
57
+ const ans = recognise(ctx, answer);
58
+ const substitutions = new Map();
59
+ for (const s of ans.sites) {
60
+ // Same single-byte-leaf exclusion as the query loop above.
61
+ if (s.payload < 0)
62
+ continue;
63
+ const h = store.halo(s.payload);
64
+ if (!h)
65
+ continue;
66
+ const found = bestHaloMate(ctx, h, voices, (v) => v.halo);
67
+ if (!found)
68
+ continue;
69
+ const voice = found.item;
70
+ if (voice.node === s.payload || contains(ctx, voice.node, s.payload)) {
71
+ continue;
72
+ }
73
+ substitutions.set(s.payload, voice.bytes);
74
+ }
75
+ if (substitutions.size === 0) {
76
+ return keep("no answer form is a synonym of an asker concept");
77
+ }
78
+ ctx.trace?.step("substitute", [...substitutions.keys()].map((n) => rNode(ctx, n, "answer-form")), [...substitutions.values()].map((b) => rItem(b, "asker-voice")), `revoice ${substitutions.size} answer form(s) in the asker's own words (synonym splice)`);
79
+ const voicedSites = ans.sites.filter((s) => substitutions.has(s.payload));
80
+ const tArtCover = ctx.trace?.enter("cover", [
81
+ ...voicedSites.map((s) => rItem(answer.subarray(s.start, s.end), "form", s.payload, [
82
+ s.start,
83
+ s.end,
84
+ ])),
85
+ ]);
86
+ const solved = ctx.search.cover(answer.length, voicedSites, new Map(), ans.leaves, ans.splits, substitutions, undefined, undefined, ctx.trace ? (steps) => traceDerivation(ctx, steps) : undefined);
87
+ const segs = solved && solved.segs;
88
+ tArtCover?.done(segs === null
89
+ ? []
90
+ : segs.map((s) => rItem(s.bytes, s.rec ? "voiced" : "kept", s.node, [s.i, s.j])), segs === null
91
+ ? "the revoiced cover did not compose"
92
+ : "lightest derivation of the revoiced answer");
93
+ const result = segs && spliceAll(segs);
94
+ if (result) {
95
+ t?.done([rItem(result, "voiced", ctx.store.findLeaf(result.subarray(0, 1)) ?? undefined)], "splice the asker's wording into the answer where the same concept appears");
96
+ return result;
97
+ }
98
+ return keep("the revoiced cover did not compose — answer unchanged");
99
+ }
@@ -0,0 +1,72 @@
1
+ import type { DerivationStep } from "./graph-search.js";
2
+ import type { AncestorReach, Attention, AttentionRead, DFMode, MindContext, Region, RegionVote, SaturationInfo } from "./types.js";
3
+ /** Climb the query's perceived byte regions up the structural DAG via
4
+ * resonance, pool the evidence, and return only the ROOT points of
5
+ * attention — those that cleared commitVotes' significance floor. */
6
+ export declare function climbAttention(ctx: MindContext, query: Uint8Array, k: number, mode?: DFMode): Promise<Attention[]>;
7
+ /** Full read-out of one consensus climb: both the roots (dominant points of
8
+ * attention) and the entire ranked list. Cached via ctx.climbMemo when
9
+ * ctx.trace is null. */
10
+ export declare function climbAttentionAll(ctx: MindContext, query: Uint8Array, k: number, mode?: DFMode): Promise<AttentionRead>;
11
+ export declare function computeAttention(ctx: MindContext, query: Uint8Array, k: number, mode: DFMode): Promise<AttentionRead>;
12
+ export declare function collectRegions(ctx: MindContext, query: Uint8Array): Region[];
13
+ export declare function voteRegions(ctx: MindContext, query: Uint8Array, regions: readonly Region[], k: number, mode: DFMode, N: number, reachMemo?: Map<number, AncestorReach>): Promise<{
14
+ votes: RegionVote[];
15
+ saturated: boolean[];
16
+ voters: Array<{
17
+ id: number;
18
+ score: number;
19
+ w: number;
20
+ } | null>;
21
+ }>;
22
+ /** The consensus vote as EVIDENCE POOLING, not shortest path: each surviving
23
+ * region is an axiom; it contributes to every root it climbed to (or, for a
24
+ * terminal answer node, to the contexts that lead to it) by a `combine:
25
+ * "sum"` rule, so independent regions corroborating the same anchor ADD
26
+ * rather than compete to be the cheapest route (see {@link Rule.combine} in
27
+ * derive/src/deduction.ts). Run through the very engine {@link
28
+ * GraphSearch} covers with — `lightestDerivation` — so a pooled-evidence
29
+ * decision is, like a followed edge or a spliced connector, one weighted
30
+ * rule of the SAME deduction system, not a separate hand-rolled tally that
31
+ * merely logs alongside it. `votesIdf`/`support` are the same two
32
+ * read-outs {@link commitVotes} always gated on; only how they accumulate
33
+ * changed. */
34
+ export declare function poolVotes(ctx: MindContext, regionVotes: readonly RegionVote[], sat: SaturationInfo, N: number): {
35
+ votes: Map<number, number>;
36
+ votesIdf: Map<number, number>;
37
+ support: Map<number, {
38
+ start: number;
39
+ end: number;
40
+ w: number;
41
+ }>;
42
+ steps: DerivationStep[];
43
+ };
44
+ export declare function commitVotes(ctx: MindContext, pooled: {
45
+ votes: Map<number, number>;
46
+ votesIdf: Map<number, number>;
47
+ support: Map<number, {
48
+ start: number;
49
+ end: number;
50
+ w: number;
51
+ }>;
52
+ steps: DerivationStep[];
53
+ }, sat: SaturationInfo, regions: readonly Region[], regionVoter: ReadonlyArray<{
54
+ id: number;
55
+ score: number;
56
+ w: number;
57
+ } | null>, N: number): AttentionRead;
58
+ export declare function detectSaturated(ctx: MindContext, regions: ReadonlyArray<{
59
+ start: number;
60
+ end: number;
61
+ chunk?: boolean;
62
+ }>, saturated: ReadonlyArray<boolean>): SaturationInfo;
63
+ export declare function canonicalChunkId(ctx: MindContext, regionBytes: Uint8Array, N: number, reachMemo?: Map<number, AncestorReach>): number | null;
64
+ export declare function naturalBreak(votes: number[]): number;
65
+ export declare function traceAttention(ctx: MindContext, regions: ReadonlyArray<{
66
+ start: number;
67
+ end: number;
68
+ }>, regionVoter: ReadonlyArray<{
69
+ id: number;
70
+ score: number;
71
+ w: number;
72
+ } | null>, roots: ReadonlyArray<Attention>, steps?: ReadonlyArray<DerivationStep>): void;