@hviana/sema 0.4.2 → 0.4.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 (135) 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 +2252 -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 +221 -0
  26. package/dist/src/alu/src/parser.js +577 -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/canon.d.ts +26 -0
  38. package/dist/src/canon.js +57 -0
  39. package/dist/src/config.d.ts +111 -0
  40. package/dist/src/config.js +91 -0
  41. package/dist/src/derive/src/deduction.d.ts +136 -0
  42. package/dist/src/derive/src/deduction.js +159 -0
  43. package/dist/src/derive/src/index.d.ts +8 -0
  44. package/dist/src/derive/src/index.js +11 -0
  45. package/dist/src/derive/src/priority-queue.d.ts +20 -0
  46. package/dist/src/derive/src/priority-queue.js +73 -0
  47. package/dist/src/derive/src/rewrite.d.ts +56 -0
  48. package/dist/src/derive/src/rewrite.js +100 -0
  49. package/dist/src/derive/src/trie.d.ts +90 -0
  50. package/dist/src/derive/src/trie.js +217 -0
  51. package/dist/src/derive/test/derive.test.d.ts +1 -0
  52. package/dist/src/derive/test/derive.test.js +122 -0
  53. package/dist/src/extension.d.ts +37 -0
  54. package/dist/src/extension.js +7 -0
  55. package/dist/src/geometry.d.ts +175 -0
  56. package/dist/src/geometry.js +823 -0
  57. package/dist/src/index.d.ts +17 -0
  58. package/dist/src/index.js +19 -0
  59. package/dist/src/ingest-cache.d.ts +41 -0
  60. package/dist/src/ingest-cache.js +165 -0
  61. package/dist/src/meter.d.ts +176 -0
  62. package/dist/src/meter.js +274 -0
  63. package/dist/src/mind/articulation.d.ts +6 -0
  64. package/dist/src/mind/articulation.js +99 -0
  65. package/dist/src/mind/attention.d.ts +414 -0
  66. package/dist/src/mind/attention.js +2082 -0
  67. package/dist/src/mind/bridge.d.ts +39 -0
  68. package/dist/src/mind/bridge.js +972 -0
  69. package/dist/src/mind/canonical.d.ts +34 -0
  70. package/dist/src/mind/canonical.js +93 -0
  71. package/dist/src/mind/graph-search.d.ts +294 -0
  72. package/dist/src/mind/graph-search.js +996 -0
  73. package/dist/src/mind/index.d.ts +9 -0
  74. package/dist/src/mind/index.js +5 -0
  75. package/dist/src/mind/junction.d.ts +137 -0
  76. package/dist/src/mind/junction.js +342 -0
  77. package/dist/src/mind/learning.d.ts +75 -0
  78. package/dist/src/mind/learning.js +270 -0
  79. package/dist/src/mind/match.d.ts +181 -0
  80. package/dist/src/mind/match.js +655 -0
  81. package/dist/src/mind/mechanisms/alu.d.ts +4 -0
  82. package/dist/src/mind/mechanisms/alu.js +36 -0
  83. package/dist/src/mind/mechanisms/cast.d.ts +89 -0
  84. package/dist/src/mind/mechanisms/cast.js +784 -0
  85. package/dist/src/mind/mechanisms/confluence.d.ts +24 -0
  86. package/dist/src/mind/mechanisms/confluence.js +255 -0
  87. package/dist/src/mind/mechanisms/cover.d.ts +6 -0
  88. package/dist/src/mind/mechanisms/cover.js +227 -0
  89. package/dist/src/mind/mechanisms/extraction.d.ts +33 -0
  90. package/dist/src/mind/mechanisms/extraction.js +300 -0
  91. package/dist/src/mind/mechanisms/recall.d.ts +16 -0
  92. package/dist/src/mind/mechanisms/recall.js +364 -0
  93. package/dist/src/mind/mind.d.ts +337 -0
  94. package/dist/src/mind/mind.js +626 -0
  95. package/dist/src/mind/pipeline-mechanism.d.ts +172 -0
  96. package/dist/src/mind/pipeline-mechanism.js +465 -0
  97. package/dist/src/mind/pipeline.d.ts +49 -0
  98. package/dist/src/mind/pipeline.js +275 -0
  99. package/dist/src/mind/primitives.d.ts +66 -0
  100. package/dist/src/mind/primitives.js +306 -0
  101. package/dist/src/mind/rationale.d.ts +139 -0
  102. package/dist/src/mind/rationale.js +163 -0
  103. package/dist/src/mind/reasoning.d.ts +40 -0
  104. package/dist/src/mind/reasoning.js +280 -0
  105. package/dist/src/mind/recognition.d.ts +20 -0
  106. package/dist/src/mind/recognition.js +504 -0
  107. package/dist/src/mind/resonance.d.ts +23 -0
  108. package/dist/src/mind/resonance.js +0 -0
  109. package/dist/src/mind/trace.d.ts +15 -0
  110. package/dist/src/mind/trace.js +73 -0
  111. package/dist/src/mind/traverse.d.ts +126 -0
  112. package/dist/src/mind/traverse.js +650 -0
  113. package/dist/src/mind/types.d.ts +333 -0
  114. package/dist/src/mind/types.js +130 -0
  115. package/dist/src/rabitq-ivf/src/database.d.ts +113 -0
  116. package/dist/src/rabitq-ivf/src/database.js +201 -0
  117. package/dist/src/rabitq-ivf/src/index.d.ts +7 -0
  118. package/dist/src/rabitq-ivf/src/index.js +4 -0
  119. package/dist/src/rabitq-ivf/src/ivf.d.ts +200 -0
  120. package/dist/src/rabitq-ivf/src/ivf.js +1165 -0
  121. package/dist/src/rabitq-ivf/src/prng.d.ts +19 -0
  122. package/dist/src/rabitq-ivf/src/prng.js +36 -0
  123. package/dist/src/rabitq-ivf/src/rabitq.d.ts +95 -0
  124. package/dist/src/rabitq-ivf/src/rabitq.js +283 -0
  125. package/dist/src/sema.d.ts +31 -0
  126. package/dist/src/sema.js +63 -0
  127. package/dist/src/store-sqlite.d.ts +184 -0
  128. package/dist/src/store-sqlite.js +942 -0
  129. package/dist/src/store.d.ts +678 -0
  130. package/dist/src/store.js +1703 -0
  131. package/dist/src/vec.d.ts +31 -0
  132. package/dist/src/vec.js +109 -0
  133. package/package.json +1 -1
  134. package/src/mind/bridge.ts +55 -18
  135. package/src/mind/mind.ts +11 -2
@@ -0,0 +1,126 @@
1
+ import { Vec } from "../vec.js";
2
+ import type { AncestorReach, MindContext } from "./types.js";
3
+ /** The reach memo this ask should use — see the note above.
4
+ *
5
+ * A TRACED response always gets a fresh, empty one. `AncestorReach`'s
6
+ * `visited`/`maxDepth`/`saturation` fields are populated only when a trace
7
+ * is attached, so an entry deposited by an untraced earlier turn would
8
+ * silently black out the reach detail of a later traced one; and the trace's
9
+ * reach payload is serialised by ITERATING this map, which must therefore
10
+ * hold what THIS climb consulted, not the whole conversation's history.
11
+ * Consistent with AGENTS §2.11: a traced response is a different machine —
12
+ * never benchmark with a trace attached. */
13
+ export declare function sharedReachMemo(ctx: MindContext): Map<number, AncestorReach>;
14
+ /** Invalidate every session-lifetime structural read after a write. */
15
+ export declare function invalidateStructuralCaches(ctx: MindContext): void;
16
+ /** Climb the structural DAG from a node to its edge-bearing ancestor contexts.
17
+ * Ascent stops at hub nodes (parents > √N) — their reach is non-discriminative.
18
+ * When the start node has no structural parents, climbs from containment parents
19
+ * (sub-span flat branches inheriting their chunks' context).
20
+ *
21
+ * `memo`, when given, caches whole climbs by start id for the duration of ONE
22
+ * query (the store is read-only while a query is in flight, so a climb is a
23
+ * pure function of the id). The consensus pipeline climbs the SAME anchors
24
+ * repeatedly — regions sharing a chunk, and canonicalChunkId probing each
25
+ * chunk's prefixes — so without the memo every repeat re-pays the full
26
+ * fan-out reads. */
27
+ export declare function edgeAncestors(ctx: MindContext, id: number, contextCount: number, memo?: Map<number, AncestorReach>): AncestorReach;
28
+ /** Convenience: forward edges of a node. */
29
+ export declare function nextOf(ctx: MindContext, id: number): number[];
30
+ /** Convenience: reverse edges of a node. */
31
+ export declare function prevOf(ctx: MindContext, id: number): number[];
32
+ /** The uniform-expectation floor on a byte atom's corpus commonality: N
33
+ * learnt contexts, each at least one perception chunk of up to W of the 256
34
+ * possible byte values, contain a given atom in ≥ N·W/256 contexts on
35
+ * average. An atom's TRUE containment is unmeasurable (atoms carry no
36
+ * kid/contain links by construction), so this floor is the honest stand-in:
37
+ * derived entirely from the corpus scale N, the perception window W, and
38
+ * the alphabet size — never tuned. */
39
+ export declare function atomReach(ctx: MindContext, contextCount: number): number;
40
+ /** Whether a byte atom is a hub at this corpus scale — its commonality floor
41
+ * {@link atomReach} exceeds the hub bound √N. Below it (small stores) an
42
+ * atom votes and is recognised exactly as any stored form; above it the
43
+ * alphabet is scaffolding everywhere and abstains. */
44
+ export declare function atomIsHub(ctx: MindContext, contextCount: number): boolean;
45
+ /** Whether a node LEADS SOMEWHERE — it bears a continuation edge or a halo.
46
+ * The admission predicate recognition filters sites with (HOW_IT_WORKS
47
+ * §15.3): a form that leads nowhere contributes nothing to any derivation.
48
+ * Runs once per candidate span on the recognition hot path — `hasNext` is
49
+ * cached per response (the same flat-branch ids are probed across prefix
50
+ * variants by canonicalChunkId). `hasHalo` is not cached: it's a single
51
+ * indexed point probe per candidate, and the candidates that reach this
52
+ * check have already been filtered by hasNext above in edgeAncestors. */
53
+ export declare function leadsSomewhere(ctx: MindContext, id: number): boolean;
54
+ /** The structural IDF read of ONE node: how many distinct learnt contexts
55
+ * its containment/edge climb reaches, or Infinity when it reaches none or
56
+ * saturates (no usable identity evidence). The number every
57
+ * discriminative-vs-scaffolding decision derives from — paired with the
58
+ * half-dominance convention (geometry.dominates(reach, N)): content
59
+ * reaching a corpus MINORITY of contexts discriminates (an entity, a
60
+ * filler); content reaching a majority is frame scaffolding. */
61
+ export declare function reachOf(ctx: MindContext, id: number, contextCount: number, memo?: Map<number, AncestorReach>): number;
62
+ /** The corpus scale N — the count of DISTINCT learnt contexts, floored at 2
63
+ * so its derived readings (ln N in the consensus floor, √N in the hub bound)
64
+ * stay meaningful on a near-empty store. The one definition every consumer
65
+ * of "how big is this corpus?" reads. */
66
+ export declare function corpusN(ctx: MindContext): number;
67
+ /** The hub bound √N itself (≥ 2 always, since N is floored at 2) — for
68
+ * consumers that pass it to the store's LIMITed reads instead of capping a
69
+ * materialised list. {@link hubCap} is the list-side reading of the same
70
+ * convention. */
71
+ export declare function hubBound(ctx: MindContext): number;
72
+ /** Cap a candidate list at the hub bound √N (insertion order) — the ONE
73
+ * fan-out convention every walk and disambiguation uses (see HOW_IT_WORKS
74
+ * §8.6). A node connected to more than √N others is a hub whose individual
75
+ * connections carry ~no discriminative information; materialising or scoring
76
+ * them all would make single decisions scale with the corpus. */
77
+ export declare function hubCap<T>(ctx: MindContext, ids: readonly T[]): readonly T[];
78
+ /** Whether `descendant` lies within `ancestor`'s subtree — a structural DAG
79
+ * relation read off the hash-consed `kids` lists, by a bounded explicit-stack
80
+ * descent. Used by articulation to keep a voice from revoicing a fragment
81
+ * OF that voice. */
82
+ export declare function contains(ctx: MindContext, ancestor: number, descendant: number): boolean;
83
+ /** The best-scoring item by cosine against `query`, among items scoring at
84
+ * or above `threshold` — the shared arg-max every Pattern-A "which of these
85
+ * resonates best" decision reduces to. `strict` picks the tie-break a
86
+ * caller needs: `true` keeps the first-seen leader on a tie (`>`), the
87
+ * default lets a later equal score take it (`>=`). */
88
+ export declare function argmaxBy<T>(items: Iterable<T>, scoreOf: (item: T) => number, threshold: number, strict?: boolean): {
89
+ item: T;
90
+ score: number;
91
+ } | null;
92
+ export declare function argmaxCosine<T>(query: Vec, items: Iterable<T>, vecOf: (item: T) => Vec | null | undefined, threshold: number, strict?: boolean): {
93
+ item: T;
94
+ score: number;
95
+ } | null;
96
+ /** The guided-or-first continuation of a node, as answer-shaped bytes source:
97
+ * chooseNext under the response guide, falling back to the FIRST-inserted
98
+ * edge — the one no-guide convention chooseNext, project() and the search's
99
+ * formRules all share. undefined when the node has no continuation. */
100
+ export declare function guidedFirst(ctx: MindContext, id: number): number | undefined;
101
+ export declare function guidedNext(ctx: MindContext, node: number): number | undefined;
102
+ /** Disambiguate among a node's learnt continuations by distributional
103
+ * support. NOTE the `guide` contract: its VALUE is deliberately unused —
104
+ * only its PRESENCE gates disambiguation (a null guide means no query is in
105
+ * flight, so structural walkers keep plain first-edge behaviour). The
106
+ * gist-cosine of short answer candidates against a query guide is dominated
107
+ * by accidental byte-pattern correlations, not semantic relatedness, so the
108
+ * evidence consulted is structural: each candidate's reverse-edge support
109
+ * count (see below). Contrast {@link chooseAmong}, the REVERSE-direction
110
+ * disambiguator, whose candidates are whole learnt contexts — long enough
111
+ * that their perceived gists ARE semantically meaningful — and which
112
+ * therefore scores by guide cosine. The two directions consult different
113
+ * halves of the evidence on purpose. */
114
+ export declare function chooseNext(ctx: MindContext, id: number, guide?: Vec | null): number | undefined;
115
+ /** The perceived gist of a candidate node, through the session gist cache.
116
+ * Re-gisting a candidate is a full river fold of its bytes — the measured
117
+ * recall bottleneck (a hub context offers up to √N continuations, EACH
118
+ * re-perceived per pick). A node's bytes are immutable and perception is
119
+ * pure, so the cached gist is valid for the store's lifetime. Exported for
120
+ * every "score node ids against a guide" decision (chooseAmong here, the
121
+ * bridge's junction pick) so they share ONE cache and one convention. */
122
+ export declare function candidateGist(ctx: MindContext, c: number): Vec | null;
123
+ export declare function chooseAmong(ctx: MindContext, candidates: readonly number[], guide: Vec): {
124
+ id: number;
125
+ score: number;
126
+ };