@hviana/sema 0.5.3 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/AGENTS.md +6 -6
  2. package/HOW_IT_WORKS.md +16 -0
  3. package/jsr.json +1 -1
  4. package/package.json +1 -1
  5. package/src/mind/match.ts +81 -0
  6. package/src/mind/mechanisms/recall.ts +29 -3
  7. package/test/76-reference-binding.test.mjs +72 -0
  8. package/dist/example/demo.d.ts +0 -1
  9. package/dist/example/demo.js +0 -39
  10. package/dist/example/train_base.d.ts +0 -93
  11. package/dist/example/train_base.js +0 -2269
  12. package/dist/src/alphabet.d.ts +0 -7
  13. package/dist/src/alphabet.js +0 -33
  14. package/dist/src/alu/src/alu.d.ts +0 -185
  15. package/dist/src/alu/src/alu.js +0 -440
  16. package/dist/src/alu/src/expr.d.ts +0 -61
  17. package/dist/src/alu/src/expr.js +0 -318
  18. package/dist/src/alu/src/index.d.ts +0 -11
  19. package/dist/src/alu/src/index.js +0 -19
  20. package/dist/src/alu/src/kernel-arith.d.ts +0 -16
  21. package/dist/src/alu/src/kernel-arith.js +0 -264
  22. package/dist/src/alu/src/kernel-bits.d.ts +0 -19
  23. package/dist/src/alu/src/kernel-bits.js +0 -152
  24. package/dist/src/alu/src/kernel-logic.d.ts +0 -4
  25. package/dist/src/alu/src/kernel-logic.js +0 -60
  26. package/dist/src/alu/src/kernel-nd.d.ts +0 -3
  27. package/dist/src/alu/src/kernel-nd.js +0 -208
  28. package/dist/src/alu/src/kernel-numeric.d.ts +0 -54
  29. package/dist/src/alu/src/kernel-numeric.js +0 -366
  30. package/dist/src/alu/src/operation.d.ts +0 -168
  31. package/dist/src/alu/src/operation.js +0 -189
  32. package/dist/src/alu/src/parser.d.ts +0 -221
  33. package/dist/src/alu/src/parser.js +0 -577
  34. package/dist/src/alu/src/resonance.d.ts +0 -55
  35. package/dist/src/alu/src/resonance.js +0 -126
  36. package/dist/src/alu/src/text.d.ts +0 -31
  37. package/dist/src/alu/src/text.js +0 -73
  38. package/dist/src/alu/src/value.d.ts +0 -109
  39. package/dist/src/alu/src/value.js +0 -300
  40. package/dist/src/alu/test/alu.test.d.ts +0 -1
  41. package/dist/src/alu/test/alu.test.js +0 -764
  42. package/dist/src/bytes.d.ts +0 -14
  43. package/dist/src/bytes.js +0 -59
  44. package/dist/src/canon.d.ts +0 -45
  45. package/dist/src/canon.js +0 -85
  46. package/dist/src/config.d.ts +0 -111
  47. package/dist/src/config.js +0 -91
  48. package/dist/src/derive/src/deduction.d.ts +0 -136
  49. package/dist/src/derive/src/deduction.js +0 -159
  50. package/dist/src/derive/src/index.d.ts +0 -8
  51. package/dist/src/derive/src/index.js +0 -11
  52. package/dist/src/derive/src/priority-queue.d.ts +0 -20
  53. package/dist/src/derive/src/priority-queue.js +0 -73
  54. package/dist/src/derive/src/rewrite.d.ts +0 -56
  55. package/dist/src/derive/src/rewrite.js +0 -100
  56. package/dist/src/derive/src/trie.d.ts +0 -90
  57. package/dist/src/derive/src/trie.js +0 -217
  58. package/dist/src/derive/test/derive.test.d.ts +0 -1
  59. package/dist/src/derive/test/derive.test.js +0 -122
  60. package/dist/src/extension.d.ts +0 -37
  61. package/dist/src/extension.js +0 -7
  62. package/dist/src/geometry.d.ts +0 -233
  63. package/dist/src/geometry.js +0 -1089
  64. package/dist/src/index.d.ts +0 -17
  65. package/dist/src/index.js +0 -19
  66. package/dist/src/ingest-cache.d.ts +0 -41
  67. package/dist/src/ingest-cache.js +0 -165
  68. package/dist/src/meter.d.ts +0 -176
  69. package/dist/src/meter.js +0 -274
  70. package/dist/src/mind/articulation.d.ts +0 -6
  71. package/dist/src/mind/articulation.js +0 -99
  72. package/dist/src/mind/attention.d.ts +0 -430
  73. package/dist/src/mind/attention.js +0 -2418
  74. package/dist/src/mind/bridge.d.ts +0 -37
  75. package/dist/src/mind/bridge.js +0 -907
  76. package/dist/src/mind/canonical.d.ts +0 -34
  77. package/dist/src/mind/canonical.js +0 -93
  78. package/dist/src/mind/graph-search.d.ts +0 -294
  79. package/dist/src/mind/graph-search.js +0 -996
  80. package/dist/src/mind/index.d.ts +0 -9
  81. package/dist/src/mind/index.js +0 -5
  82. package/dist/src/mind/junction.d.ts +0 -137
  83. package/dist/src/mind/junction.js +0 -358
  84. package/dist/src/mind/learning.d.ts +0 -75
  85. package/dist/src/mind/learning.js +0 -265
  86. package/dist/src/mind/match.d.ts +0 -351
  87. package/dist/src/mind/match.js +0 -959
  88. package/dist/src/mind/mechanisms/alu.d.ts +0 -4
  89. package/dist/src/mind/mechanisms/alu.js +0 -36
  90. package/dist/src/mind/mechanisms/cast.d.ts +0 -89
  91. package/dist/src/mind/mechanisms/cast.js +0 -1186
  92. package/dist/src/mind/mechanisms/confluence.d.ts +0 -24
  93. package/dist/src/mind/mechanisms/confluence.js +0 -271
  94. package/dist/src/mind/mechanisms/cover.d.ts +0 -6
  95. package/dist/src/mind/mechanisms/cover.js +0 -232
  96. package/dist/src/mind/mechanisms/extraction.d.ts +0 -33
  97. package/dist/src/mind/mechanisms/extraction.js +0 -327
  98. package/dist/src/mind/mechanisms/prefix-completion.d.ts +0 -22
  99. package/dist/src/mind/mechanisms/prefix-completion.js +0 -243
  100. package/dist/src/mind/mechanisms/recall.d.ts +0 -16
  101. package/dist/src/mind/mechanisms/recall.js +0 -460
  102. package/dist/src/mind/mechanisms/reference.d.ts +0 -6
  103. package/dist/src/mind/mechanisms/reference.js +0 -296
  104. package/dist/src/mind/mind.d.ts +0 -386
  105. package/dist/src/mind/mind.js +0 -754
  106. package/dist/src/mind/pipeline-mechanism.d.ts +0 -238
  107. package/dist/src/mind/pipeline-mechanism.js +0 -622
  108. package/dist/src/mind/pipeline.d.ts +0 -49
  109. package/dist/src/mind/pipeline.js +0 -343
  110. package/dist/src/mind/primitives.d.ts +0 -85
  111. package/dist/src/mind/primitives.js +0 -333
  112. package/dist/src/mind/rationale.d.ts +0 -139
  113. package/dist/src/mind/rationale.js +0 -163
  114. package/dist/src/mind/reasoning.d.ts +0 -42
  115. package/dist/src/mind/reasoning.js +0 -305
  116. package/dist/src/mind/recognition.d.ts +0 -20
  117. package/dist/src/mind/recognition.js +0 -696
  118. package/dist/src/mind/resonance.d.ts +0 -35
  119. package/dist/src/mind/resonance.js +0 -365
  120. package/dist/src/mind/trace.d.ts +0 -15
  121. package/dist/src/mind/trace.js +0 -73
  122. package/dist/src/mind/traverse.d.ts +0 -196
  123. package/dist/src/mind/traverse.js +0 -806
  124. package/dist/src/mind/types.d.ts +0 -418
  125. package/dist/src/mind/types.js +0 -179
  126. package/dist/src/rabitq-ivf/src/database.d.ts +0 -113
  127. package/dist/src/rabitq-ivf/src/database.js +0 -201
  128. package/dist/src/rabitq-ivf/src/index.d.ts +0 -7
  129. package/dist/src/rabitq-ivf/src/index.js +0 -4
  130. package/dist/src/rabitq-ivf/src/ivf.d.ts +0 -200
  131. package/dist/src/rabitq-ivf/src/ivf.js +0 -1165
  132. package/dist/src/rabitq-ivf/src/prng.d.ts +0 -19
  133. package/dist/src/rabitq-ivf/src/prng.js +0 -36
  134. package/dist/src/rabitq-ivf/src/rabitq.d.ts +0 -95
  135. package/dist/src/rabitq-ivf/src/rabitq.js +0 -313
  136. package/dist/src/sema.d.ts +0 -41
  137. package/dist/src/sema.js +0 -77
  138. package/dist/src/store-sqlite.d.ts +0 -184
  139. package/dist/src/store-sqlite.js +0 -942
  140. package/dist/src/store.d.ts +0 -762
  141. package/dist/src/store.js +0 -1823
  142. package/dist/src/vec.d.ts +0 -31
  143. package/dist/src/vec.js +0 -109
@@ -1,238 +0,0 @@
1
- import type { AncestorReach, MindContext, Recognition } from "./types.js";
2
- import type { AttentionRead } from "./types.js";
3
- import type { ComputedSpan } from "../extension.js";
4
- import type { Hit } from "../store.js";
5
- import type { Vec } from "../vec.js";
6
- import { type FrameInstance, type GradedRun } from "./match.js";
7
- export declare class Precomputed {
8
- readonly ctx: MindContext;
9
- readonly query: Uint8Array;
10
- /** Recognition result (structural + canonical). */
11
- readonly rec: Recognition;
12
- /** Computed spans from mechanisms that implement `parse()` (e.g. ALU). */
13
- readonly computed: ComputedSpan[];
14
- /** The query's gist — the response-wide disambiguation guide. */
15
- readonly guide: Vec;
16
- /** The response's evidence-breadth constant: how many ranked candidates the
17
- * resonance probes, the weave alignment, and the climb all consider.
18
- * Derived once from config; every consumer reads it here. */
19
- readonly k: number;
20
- constructor(ctx: MindContext, query: Uint8Array,
21
- /** Recognition result (structural + canonical). */
22
- rec: Recognition,
23
- /** Computed spans from mechanisms that implement `parse()` (e.g. ALU). */
24
- computed: ComputedSpan[],
25
- /** The query's gist — the response-wide disambiguation guide. */
26
- guide: Vec);
27
- private _windows?;
28
- /** Content-addressed W-window identities for every position in the query
29
- * (offset → node id). O(|query|) probes. */
30
- get queryWindows(): Map<number, number>;
31
- private _resolved?;
32
- /** The node id of the query itself, or null when it is not a stored form.
33
- * O(|query|) probes. */
34
- get queryResolved(): number | null;
35
- private _anchorWindows;
36
- /** Content-addressed W-window identities of one anchor's own bytes
37
- * (offset → node id), memoised per anchor. Confluence intersects these;
38
- * any future identity-based mechanism reads the same cache. */
39
- windowsOf(anchor: number): Map<number, number>;
40
- /** Shared memo for {@link reachOf} (structural-IDF reads): a window's
41
- * ancestor reach is a pure function of the read-only store, so one memo
42
- * serves every mechanism that prices commonality — AND the consensus
43
- * climb, which is the largest consumer and used to build its own. The
44
- * ONE definition of its lifetime lives in traverse.ts
45
- * ({@link sharedReachMemo}): session-scoped between writes and always cold
46
- * under a trace. */
47
- private _reach?;
48
- get reachMemo(): Map<number, AncestorReach>;
49
- /** Charge a lazily-shared analysis to its OWN phase rather than to the
50
- * mechanism that happened to first-touch it. Without this the profile
51
- * reads as "cast.floor costs 2 s" when what actually cost 2 s is the
52
- * consensus climb — which cast merely paid for on everyone's behalf, and
53
- * which every later consumer then got free. Attribution must follow the
54
- * work, not the caller. */
55
- private shared;
56
- private _resonance?;
57
- /** The response's ONE top-k content-index read: the k learnt forms nearest
58
- * the whole-query gist, ranked. Recall's every gist tier is built on it,
59
- * and {@link frames} assembles the frame inventory from it.
60
- *
61
- * An ANN query is the single most expensive read in the engine, and two
62
- * mechanisms asking the same question of the same gist is the one
63
- * duplication a profile shows as doubled `annVectorReads` with nothing to
64
- * account for it. Cached BY PROMISE, so a second caller awaits the first. */
65
- resonance(): Promise<ReadonlyArray<Hit>>;
66
- private _wide?;
67
- /** The response's WIDE candidate list — the top-k when the query's gist has
68
- * no concept-level match anywhere, and an exhaustive √N read when it does.
69
- *
70
- * Every mechanism that has to look PAST the top-k reads this one list: the
71
- * substitution bridge, prefix completion and the frame filler all did, and
72
- * it was memoised inside recall for exactly that reason (measured: 490 ms
73
- * median re-issued against 13 ms non-exhaustive, 36x). A memo inside one
74
- * mechanism only serves that mechanism's own tiers, so it lives here now —
75
- * the same move `resonance` made for the top-k.
76
- *
77
- * THE CONDITION IS THE TOP HIT'S SCORE, NOT THE CORPUS SIZE. When nothing
78
- * ranks at concept level, an exhaustive ANN only scores more vectors below
79
- * the bar (profiled at 38K–40K annVectorReads per refusing query on a 325K-
80
- * context store); the structural channels — junction walks, anchor climbs,
81
- * the write side's window index — are the correct proposal source there,
82
- * because the ANN cannot propose what the gist cannot rank. This was once
83
- * spelled `corpusN(ctx) <= (k · W)³`, which asks a different question and
84
- * answers it wrongly at exactly the scale it was written from: at N =
85
- * 325,608 with k = 24 and W = 4 the cube is 884,736, so that store took the
86
- * exhaustive branch — the very branch measured above. Measured cost of the
87
- * mismatch: substitutionBridge 8,544 ms of a 19,548 ms think (44%), against
88
- * 1,248 ms and 14,218 ms without it, every answer byte-identical. */
89
- wideResonance(): Promise<ReadonlyArray<number>>;
90
- private _frames?;
91
- /** THE FRAME INVENTORY — every ranked candidate that reads as an instance of
92
- * the same frame as the query, each with the query spans it leaves VARIABLE
93
- * ({@link FrameInstance}). The one place the engine represents "a position
94
- * whose occupant comes from the context rather than the corpus".
95
- *
96
- * AN INVENTORY, NOT AN ELECTION. It reports every pairing and elects no
97
- * frame, deliberately: a slot is a property of a PAIRING, not of the query,
98
- * and different candidates put slots in different places. Committing to one
99
- * reading here would push whichever consumer asked first onto everyone else
100
- * — the market's decoupling (§2.6) broken from inside the shared container,
101
- * and the population error §2.7 names. Each consumer groups and commits
102
- * for its own question; reference elects the modal slot signature, and a
103
- * consumer wanting a different reading is not fighting this one.
104
- *
105
- * NO LICENCE EITHER. Knowing a span is variable is safe for every consumer
106
- * — it can only improve an alignment. Knowing one may be VOICED through is
107
- * a different and much stronger claim, gated separately by
108
- * {@link carriesFillers}, which needs projections this must not perform. */
109
- frames(): Promise<ReadonlyArray<FrameInstance>>;
110
- private _attention?;
111
- /** The full consensus climb (roots + ranked anchors) — the query-level
112
- * evidence CAST, confluence, extraction, recall's scaffolding tier, and
113
- * fusion all share. Computed on first access; a query no mechanism
114
- * climbs for (e.g. one an extension decided outright) never pays for it. */
115
- attention(): Promise<AttentionRead>;
116
- private _weave?;
117
- /** Result of {@link alignGraded} for the first k ranked anchors —
118
- * O(k · |query| · |ctx|). Consumed by CAST; reusable by any future
119
- * mechanism doing analogical transfer. */
120
- weave(): Promise<WeaveInfo>;
121
- /** Span-shaped classification of one ranked anchor, memoised per anchor id
122
- * so repeated calls (extraction's own early-exit scan, any future
123
- * template-based mechanism) never redo the work. Deliberately NOT an
124
- * eager all-anchors map: `skillExemplar` is the expensive part of
125
- * extraction (capped fan-out reads plus an O(|ctx|) scan), and most
126
- * queries are answered by the FIRST ranked anchor that qualifies — paying
127
- * for every ranked anchor regardless of where the scan stops would turn
128
- * an early-exit lookup into full O(k) work on every query. */
129
- private _spanShaped;
130
- spanShapedOf(anchor: number): Promise<SkillInfo | null>;
131
- /** Every ranked anchor's classification at once, sharing the same
132
- * per-anchor cache as {@link spanShapedOf} — for a mechanism that
133
- * genuinely needs the full picture (not an early-exit scan). Mixing
134
- * access patterns across mechanisms never duplicates work: whichever
135
- * anchors an early-exit consumer already asked for are reused here, and
136
- * whichever this computes first are reused by a later early-exit scan. */
137
- spanShapedAll(): Promise<Map<number, SkillInfo | null>>;
138
- }
139
- /** The weave-local structural alignment, computed once and consumed by CAST
140
- * (and any future mechanism doing analogical transfer). */
141
- export interface WeaveInfo {
142
- /** Per-anchor alignment: context bytes, vote weight, and graded runs. */
143
- points: Array<{
144
- anchor: number;
145
- vote: number;
146
- ctx: Uint8Array;
147
- runs: GradedRun[];
148
- /** The query span the CLIMB elected this anchor from — its evidence,
149
- * independent of any literal run alignment (see Attention.start/end). */
150
- start: number;
151
- end: number;
152
- }>;
153
- /** Weighted depth at each query byte — sum of alignment weights.
154
- * `depth[i]` is the total evidence that byte i is shared among the
155
- * aligned structures. */
156
- depth: Float64Array;
157
- }
158
- /** Span-shaped classification of one anchor — the structural information
159
- * extraction uses to decide whether a learned fact can serve as a template
160
- * for reading an analogous span out of the query. */
161
- export interface SkillInfo {
162
- contextBytes: Uint8Array;
163
- answerBytes: Uint8Array;
164
- }
165
- /** Raw result from a mechanism's `run()`. The pipeline computes the weight
166
- * from `moves` + `PASS * unaccounted(accounted)` — the mechanism does not
167
- * know about the cost ladder.
168
- *
169
- * When `weight` is present, the pipeline uses it directly instead of
170
- * computing `weigh(accounted, moves)`. This is for mechanisms whose cost
171
- * is derived externally (e.g. cover: the A*LD derivation's g-value). */
172
- export interface MechanismResult {
173
- bytes: Uint8Array;
174
- accounted: Array<[number, number]>;
175
- moves: number;
176
- used?: ReadonlySet<number>;
177
- unexplained: string;
178
- /** Explicit weight override. When absent, weight = moves + PASS·unaccounted. */
179
- weight?: number;
180
- /** Bytes of `bytes` that came from spans nothing recognised — the asker's
181
- * own words carried through verbatim rather than derived (see
182
- * {@link liftedScaffolding}). Reported, not priced: the ladder prices what
183
- * a candidate leaves UNACCOUNTED, and this orders candidates that tie on
184
- * exactly that. Omit when a mechanism composes its answer entirely from
185
- * recognised material, which is the usual case. */
186
- scaffolding?: number;
187
- /** Override the mechanism's default provenance for this result.
188
- * When absent, the pipeline uses `mech.provenance`. */
189
- provenance?: string;
190
- /** This grounding is a COMPLETE trained answer — post-grounding must not
191
- * extend it. Declared by the mechanism about its own result, exactly like
192
- * `accounted`/`used`/`unexplained`; the decider honours the property and
193
- * never asks which mechanism set it, so the market stays uniform.
194
- *
195
- * Set it only when the answer is a stored form's OWN continuation reached
196
- * through an identity claim about the query — i.e. the query IS some
197
- * trained context, so its continuation is the whole read-out and a further
198
- * multi-hop pivot would chain PAST the fact that produced the answer.
199
- * That is the same reasoning `reason`'s echo guard already applies to a
200
- * query that resolves exactly (see reasoning.ts); this carries the claim
201
- * for the mechanisms that establish the identity by another route.
202
- *
203
- * Observed without it: the correct "What is the process of
204
- * photosynthesis?" grounding was pivoted forward four times, out of the
205
- * fact that answered it and into an unrelated "Hello! How can I assist you
206
- * today?" conversational turn. */
207
- complete?: boolean;
208
- }
209
- export interface PipelineMechanism {
210
- /** Stable identifier for trace/debug. */
211
- readonly name: string;
212
- /** Which provenance tag the pipeline attaches to this mechanism's answers. */
213
- readonly provenance: string;
214
- /** Parse authoritative spans BEFORE the grounding loop.
215
- * Only needed by computational mechanisms (e.g. ALU). Results from ALL
216
- * mechanisms that implement this are collected into `Precomputed.computed`
217
- * before any `floor()` or `run()` is called. */
218
- parse?(query: Uint8Array): Promise<ComputedSpan[]>;
219
- /** Admissible lower bound on this mechanism's weight.
220
- * Returns `null` when the mechanism structurally cannot fire.
221
- *
222
- * `worthRunning(cheapFloor)` reports whether the CURRENT incumbent
223
- * (established by mechanisms that already ran this response, cover being
224
- * first — see `defaultMechanisms`) could still be beaten by a floor no
225
- * tighter than `cheapFloor`. THE INVESTMENT DISCIPLINE: before
226
- * first-touching an expensive shared analysis (`pre.attention()`,
227
- * `pre.weave()`, …), check `worthRunning(bound)` with this mechanism's
228
- * cheapest possible bound — and when it fails, RETURN THE BOUND rather
229
- * than null. The bound is still admissible (it never overstates cost),
230
- * the pipeline's own check then prunes `run()` and records the truthful
231
- * "cannot beat incumbent" trace note, and no analysis was computed just
232
- * to be discarded. This is uniform: no mechanism asks what produced the
233
- * incumbent — a computed extension result and an ordinary cheap cover
234
- * prune the same way. */
235
- floor(ctx: MindContext, query: Uint8Array, pre: Precomputed, worthRunning: (floor: number) => boolean): Promise<number | null>;
236
- /** Produce candidate answers. */
237
- run(ctx: MindContext, query: Uint8Array, pre: Precomputed): Promise<MechanismResult[]>;
238
- }