@hviana/sema 0.1.7 → 0.1.9

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 (145) hide show
  1. package/example/train_base.ts +29 -4
  2. package/package.json +1 -1
  3. package/src/alu/src/parser.ts +105 -4
  4. package/src/canon.ts +65 -0
  5. package/src/geometry.ts +26 -30
  6. package/src/index.ts +1 -0
  7. package/src/mind/learning.ts +39 -1
  8. package/src/mind/match.ts +29 -6
  9. package/src/mind/mechanisms/cast.ts +33 -13
  10. package/src/mind/mechanisms/confluence.ts +15 -1
  11. package/src/mind/mechanisms/recall.ts +116 -41
  12. package/src/mind/mind.ts +172 -29
  13. package/src/mind/primitives.ts +66 -1
  14. package/src/mind/recognition.ts +10 -0
  15. package/src/mind/types.ts +10 -0
  16. package/src/store-sqlite.ts +68 -0
  17. package/src/store.ts +27 -0
  18. package/test/13-conversation.test.mjs +77 -27
  19. package/test/35-prefix-edge.test.mjs +86 -0
  20. package/dist/example/demo.d.ts +0 -1
  21. package/dist/example/demo.js +0 -39
  22. package/dist/example/train_base.d.ts +0 -87
  23. package/dist/example/train_base.js +0 -2232
  24. package/dist/src/alphabet.d.ts +0 -7
  25. package/dist/src/alphabet.js +0 -33
  26. package/dist/src/alu/src/alu.d.ts +0 -185
  27. package/dist/src/alu/src/alu.js +0 -440
  28. package/dist/src/alu/src/expr.d.ts +0 -61
  29. package/dist/src/alu/src/expr.js +0 -318
  30. package/dist/src/alu/src/index.d.ts +0 -11
  31. package/dist/src/alu/src/index.js +0 -19
  32. package/dist/src/alu/src/kernel-arith.d.ts +0 -16
  33. package/dist/src/alu/src/kernel-arith.js +0 -264
  34. package/dist/src/alu/src/kernel-bits.d.ts +0 -19
  35. package/dist/src/alu/src/kernel-bits.js +0 -152
  36. package/dist/src/alu/src/kernel-logic.d.ts +0 -4
  37. package/dist/src/alu/src/kernel-logic.js +0 -60
  38. package/dist/src/alu/src/kernel-nd.d.ts +0 -3
  39. package/dist/src/alu/src/kernel-nd.js +0 -208
  40. package/dist/src/alu/src/kernel-numeric.d.ts +0 -54
  41. package/dist/src/alu/src/kernel-numeric.js +0 -366
  42. package/dist/src/alu/src/operation.d.ts +0 -168
  43. package/dist/src/alu/src/operation.js +0 -189
  44. package/dist/src/alu/src/parser.d.ts +0 -212
  45. package/dist/src/alu/src/parser.js +0 -469
  46. package/dist/src/alu/src/resonance.d.ts +0 -55
  47. package/dist/src/alu/src/resonance.js +0 -126
  48. package/dist/src/alu/src/text.d.ts +0 -31
  49. package/dist/src/alu/src/text.js +0 -73
  50. package/dist/src/alu/src/value.d.ts +0 -109
  51. package/dist/src/alu/src/value.js +0 -300
  52. package/dist/src/alu/test/alu.test.d.ts +0 -1
  53. package/dist/src/alu/test/alu.test.js +0 -764
  54. package/dist/src/bytes.d.ts +0 -14
  55. package/dist/src/bytes.js +0 -59
  56. package/dist/src/config.d.ts +0 -111
  57. package/dist/src/config.js +0 -91
  58. package/dist/src/derive/src/deduction.d.ts +0 -125
  59. package/dist/src/derive/src/deduction.js +0 -155
  60. package/dist/src/derive/src/index.d.ts +0 -7
  61. package/dist/src/derive/src/index.js +0 -11
  62. package/dist/src/derive/src/priority-queue.d.ts +0 -20
  63. package/dist/src/derive/src/priority-queue.js +0 -73
  64. package/dist/src/derive/src/rewrite.d.ts +0 -56
  65. package/dist/src/derive/src/rewrite.js +0 -100
  66. package/dist/src/derive/src/trie.d.ts +0 -90
  67. package/dist/src/derive/src/trie.js +0 -217
  68. package/dist/src/derive/test/derive.test.d.ts +0 -1
  69. package/dist/src/derive/test/derive.test.js +0 -122
  70. package/dist/src/extension.d.ts +0 -37
  71. package/dist/src/extension.js +0 -7
  72. package/dist/src/geometry.d.ts +0 -148
  73. package/dist/src/geometry.js +0 -517
  74. package/dist/src/index.d.ts +0 -15
  75. package/dist/src/index.js +0 -17
  76. package/dist/src/ingest-cache.d.ts +0 -41
  77. package/dist/src/ingest-cache.js +0 -161
  78. package/dist/src/mind/articulation.d.ts +0 -6
  79. package/dist/src/mind/articulation.js +0 -99
  80. package/dist/src/mind/attention.d.ts +0 -72
  81. package/dist/src/mind/attention.js +0 -898
  82. package/dist/src/mind/canonical.d.ts +0 -29
  83. package/dist/src/mind/canonical.js +0 -88
  84. package/dist/src/mind/graph-search.d.ts +0 -270
  85. package/dist/src/mind/graph-search.js +0 -847
  86. package/dist/src/mind/index.d.ts +0 -5
  87. package/dist/src/mind/index.js +0 -5
  88. package/dist/src/mind/junction.d.ts +0 -95
  89. package/dist/src/mind/junction.js +0 -262
  90. package/dist/src/mind/learning.d.ts +0 -47
  91. package/dist/src/mind/learning.js +0 -201
  92. package/dist/src/mind/match.d.ts +0 -111
  93. package/dist/src/mind/match.js +0 -422
  94. package/dist/src/mind/mechanisms/alu.d.ts +0 -4
  95. package/dist/src/mind/mechanisms/alu.js +0 -29
  96. package/dist/src/mind/mechanisms/cast.d.ts +0 -35
  97. package/dist/src/mind/mechanisms/cast.js +0 -447
  98. package/dist/src/mind/mechanisms/confluence.d.ts +0 -24
  99. package/dist/src/mind/mechanisms/confluence.js +0 -213
  100. package/dist/src/mind/mechanisms/cover.d.ts +0 -6
  101. package/dist/src/mind/mechanisms/cover.js +0 -179
  102. package/dist/src/mind/mechanisms/extraction.d.ts +0 -67
  103. package/dist/src/mind/mechanisms/extraction.js +0 -342
  104. package/dist/src/mind/mechanisms/recall.d.ts +0 -13
  105. package/dist/src/mind/mechanisms/recall.js +0 -166
  106. package/dist/src/mind/mind.d.ts +0 -211
  107. package/dist/src/mind/mind.js +0 -433
  108. package/dist/src/mind/pipeline-mechanism.d.ts +0 -142
  109. package/dist/src/mind/pipeline-mechanism.js +0 -213
  110. package/dist/src/mind/pipeline.d.ts +0 -20
  111. package/dist/src/mind/pipeline.js +0 -185
  112. package/dist/src/mind/primitives.d.ts +0 -54
  113. package/dist/src/mind/primitives.js +0 -184
  114. package/dist/src/mind/rationale.d.ts +0 -134
  115. package/dist/src/mind/rationale.js +0 -162
  116. package/dist/src/mind/reasoning.d.ts +0 -15
  117. package/dist/src/mind/reasoning.js +0 -162
  118. package/dist/src/mind/recognition.d.ts +0 -20
  119. package/dist/src/mind/recognition.js +0 -236
  120. package/dist/src/mind/resonance.d.ts +0 -23
  121. package/dist/src/mind/resonance.js +0 -0
  122. package/dist/src/mind/trace.d.ts +0 -15
  123. package/dist/src/mind/trace.js +0 -73
  124. package/dist/src/mind/traverse.d.ts +0 -113
  125. package/dist/src/mind/traverse.js +0 -488
  126. package/dist/src/mind/types.d.ts +0 -176
  127. package/dist/src/mind/types.js +0 -84
  128. package/dist/src/rabitq-ivf/src/database.d.ts +0 -113
  129. package/dist/src/rabitq-ivf/src/database.js +0 -201
  130. package/dist/src/rabitq-ivf/src/index.d.ts +0 -7
  131. package/dist/src/rabitq-ivf/src/index.js +0 -4
  132. package/dist/src/rabitq-ivf/src/ivf.d.ts +0 -200
  133. package/dist/src/rabitq-ivf/src/ivf.js +0 -1165
  134. package/dist/src/rabitq-ivf/src/prng.d.ts +0 -19
  135. package/dist/src/rabitq-ivf/src/prng.js +0 -36
  136. package/dist/src/rabitq-ivf/src/rabitq.d.ts +0 -95
  137. package/dist/src/rabitq-ivf/src/rabitq.js +0 -283
  138. package/dist/src/sema.d.ts +0 -31
  139. package/dist/src/sema.js +0 -63
  140. package/dist/src/store-sqlite.d.ts +0 -176
  141. package/dist/src/store-sqlite.js +0 -890
  142. package/dist/src/store.d.ts +0 -642
  143. package/dist/src/store.js +0 -1612
  144. package/dist/src/vec.d.ts +0 -31
  145. package/dist/src/vec.js +0 -109
package/dist/src/vec.d.ts DELETED
@@ -1,31 +0,0 @@
1
- export type Vec = Float32Array;
2
- /** Deterministic PRNG (32-bit mixer). */
3
- export declare function rng(seed: number): () => number;
4
- export declare const zeros: (D: number) => Vec;
5
- export declare const copy: (v: Vec) => Vec;
6
- /** Random point on the unit sphere. */
7
- export declare function randomUnit(D: number, rand: () => number): Vec;
8
- /** target += src * scale (in place). */
9
- export declare function addInto(target: Vec, src: Vec, scale?: number): Vec;
10
- export declare function dot(a: Vec, b: Vec): number;
11
- /** In-place normalization. */
12
- export declare function normalize(v: Vec): Vec;
13
- /** Resonance: 1 = same, 0 = unrelated. */
14
- export declare function cosine(a: Vec, b: Vec): number;
15
- /** Set vector epsilon thresholds. Called once by Mind at construction. */
16
- export declare function setVecConfig(cfg: {
17
- normalizeEpsilon?: number;
18
- cosineEpsilon?: number;
19
- }): void;
20
- export interface Permutation {
21
- fwd: Uint32Array;
22
- inv: Uint32Array;
23
- }
24
- /** The keyring: one independent permutation per seat.
25
- * Independent keys do not commute, so an address in a tree is the
26
- * path itself — "seat 2 inside seat 1" ≠ "seat 1 inside seat 2". */
27
- export declare function makeKeyring(D: number, seats: number, rand: () => number): Permutation[];
28
- /** Apply permutation: out[i] = v[table[i]]. */
29
- export declare function permute(v: Vec, table: Uint32Array): Vec;
30
- /** Permute into existing buffer — zero allocation. */
31
- export declare function permuteInto(out: Vec, v: Vec, table: Uint32Array): Vec;
package/dist/src/vec.js DELETED
@@ -1,109 +0,0 @@
1
- // vec.ts — vector primitives.
2
- // Superposition (add), normalization (stay on the sphere),
3
- // resonance (cosine), and seat binding (a keyring of fixed permutations).
4
- // No weights. No gradients.
5
- /** Deterministic PRNG (32-bit mixer). */
6
- export function rng(seed) {
7
- let s = seed >>> 0;
8
- return () => {
9
- s = (s + 0x6d2b79f5) >>> 0;
10
- let t = s;
11
- t = Math.imul(t ^ (t >>> 15), t | 1);
12
- t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
13
- return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
14
- };
15
- }
16
- /** Standard normal sample (Box–Muller). */
17
- function gaussian(rand) {
18
- let u = 0, v = 0;
19
- while (u === 0)
20
- u = rand();
21
- while (v === 0)
22
- v = rand();
23
- return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
24
- }
25
- export const zeros = (D) => new Float32Array(D);
26
- export const copy = (v) => new Float32Array(v);
27
- /** Random point on the unit sphere. */
28
- export function randomUnit(D, rand) {
29
- const v = zeros(D);
30
- for (let i = 0; i < D; i++)
31
- v[i] = gaussian(rand);
32
- return normalize(v);
33
- }
34
- /** target += src * scale (in place). */
35
- export function addInto(target, src, scale = 1) {
36
- for (let i = 0; i < target.length; i++)
37
- target[i] += src[i] * scale;
38
- return target;
39
- }
40
- export function dot(a, b) {
41
- let s = 0;
42
- for (let i = 0; i < a.length; i++)
43
- s += a[i] * b[i];
44
- return s;
45
- }
46
- const norm = (v) => Math.sqrt(dot(v, v));
47
- // Epsilon thresholds (settable once via setVecConfig).
48
- let _normalizeEpsilon = 1e-12;
49
- let _cosineEpsilon = 1e-12;
50
- /** In-place normalization. */
51
- export function normalize(v) {
52
- const n = norm(v);
53
- if (n > _normalizeEpsilon) {
54
- for (let i = 0; i < v.length; i++)
55
- v[i] /= n;
56
- }
57
- return v;
58
- }
59
- /** Resonance: 1 = same, 0 = unrelated. */
60
- export function cosine(a, b) {
61
- const na = norm(a), nb = norm(b);
62
- return na > _cosineEpsilon && nb > _cosineEpsilon ? dot(a, b) / (na * nb) : 0;
63
- }
64
- /** Set vector epsilon thresholds. Called once by Mind at construction. */
65
- export function setVecConfig(cfg) {
66
- if (cfg.normalizeEpsilon !== undefined) {
67
- _normalizeEpsilon = cfg.normalizeEpsilon;
68
- }
69
- if (cfg.cosineEpsilon !== undefined)
70
- _cosineEpsilon = cfg.cosineEpsilon;
71
- }
72
- /** One fixed random permutation (Fisher–Yates). */
73
- function makePermutation(D, rand) {
74
- const fwd = new Uint32Array(D);
75
- for (let i = 0; i < D; i++)
76
- fwd[i] = i;
77
- for (let i = D - 1; i > 0; i--) {
78
- const j = Math.floor(rand() * (i + 1));
79
- const t = fwd[i];
80
- fwd[i] = fwd[j];
81
- fwd[j] = t;
82
- }
83
- const inv = new Uint32Array(D);
84
- for (let i = 0; i < D; i++)
85
- inv[fwd[i]] = i;
86
- return { fwd, inv };
87
- }
88
- /** The keyring: one independent permutation per seat.
89
- * Independent keys do not commute, so an address in a tree is the
90
- * path itself — "seat 2 inside seat 1" ≠ "seat 1 inside seat 2". */
91
- export function makeKeyring(D, seats, rand) {
92
- const ring = [];
93
- for (let s = 0; s < seats; s++)
94
- ring.push(makePermutation(D, rand));
95
- return ring;
96
- }
97
- /** Apply permutation: out[i] = v[table[i]]. */
98
- export function permute(v, table) {
99
- const out = new Float32Array(v.length);
100
- for (let i = 0; i < v.length; i++)
101
- out[i] = v[table[i]];
102
- return out;
103
- }
104
- /** Permute into existing buffer — zero allocation. */
105
- export function permuteInto(out, v, table) {
106
- for (let i = 0; i < v.length; i++)
107
- out[i] = v[table[i]];
108
- return out;
109
- }