@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.
Files changed (170) hide show
  1. package/AGENTS.md +6 -5
  2. package/CITATION.cff +49 -0
  3. package/HOW_IT_WORKS.md +11 -12
  4. package/README.md +7 -5
  5. package/dist/example/demo.js +25 -25
  6. package/dist/example/train_base.d.ts +19 -21
  7. package/dist/example/train_base.js +1700 -1952
  8. package/dist/src/alphabet.d.ts +3 -3
  9. package/dist/src/alphabet.js +24 -27
  10. package/dist/src/alu/src/alu.d.ts +169 -194
  11. package/dist/src/alu/src/alu.js +374 -414
  12. package/dist/src/alu/src/expr.d.ts +36 -43
  13. package/dist/src/alu/src/expr.js +252 -278
  14. package/dist/src/alu/src/index.d.ts +9 -98
  15. package/dist/src/alu/src/index.js +10 -64
  16. package/dist/src/alu/src/kernel-arith.d.ts +1 -5
  17. package/dist/src/alu/src/kernel-arith.js +195 -285
  18. package/dist/src/alu/src/kernel-bits.d.ts +1 -5
  19. package/dist/src/alu/src/kernel-bits.js +81 -115
  20. package/dist/src/alu/src/kernel-logic.js +33 -63
  21. package/dist/src/alu/src/kernel-nd.js +155 -195
  22. package/dist/src/alu/src/kernel-numeric.d.ts +16 -80
  23. package/dist/src/alu/src/kernel-numeric.js +259 -331
  24. package/dist/src/alu/src/operation.d.ts +112 -132
  25. package/dist/src/alu/src/operation.js +149 -163
  26. package/dist/src/alu/src/parser.d.ts +168 -175
  27. package/dist/src/alu/src/parser.js +382 -421
  28. package/dist/src/alu/src/resonance.d.ts +16 -25
  29. package/dist/src/alu/src/resonance.js +49 -56
  30. package/dist/src/alu/src/text.d.ts +3 -7
  31. package/dist/src/alu/src/text.js +31 -37
  32. package/dist/src/alu/src/value.d.ts +14 -14
  33. package/dist/src/alu/src/value.js +150 -160
  34. package/dist/src/alu/test/alu.test.js +543 -656
  35. package/dist/src/bytes.d.ts +1 -5
  36. package/dist/src/bytes.js +33 -40
  37. package/dist/src/config.d.ts +99 -102
  38. package/dist/src/config.js +78 -83
  39. package/dist/src/derive/src/deduction.d.ts +60 -62
  40. package/dist/src/derive/src/deduction.js +103 -109
  41. package/dist/src/derive/src/index.d.ts +1 -7
  42. package/dist/src/derive/src/priority-queue.d.ts +8 -8
  43. package/dist/src/derive/src/priority-queue.js +57 -61
  44. package/dist/src/derive/src/rewrite.d.ts +15 -18
  45. package/dist/src/derive/src/rewrite.js +59 -67
  46. package/dist/src/derive/src/trie.d.ts +56 -56
  47. package/dist/src/derive/src/trie.js +175 -179
  48. package/dist/src/derive/test/derive.test.js +96 -100
  49. package/dist/src/extension.d.ts +13 -16
  50. package/dist/src/geometry.d.ts +29 -43
  51. package/dist/src/geometry.js +324 -268
  52. package/dist/src/index.d.ts +2 -17
  53. package/dist/src/index.js +2 -12
  54. package/dist/src/ingest-cache.d.ts +25 -30
  55. package/dist/src/ingest-cache.js +108 -127
  56. package/dist/src/mind/articulation.d.ts +1 -5
  57. package/dist/src/mind/articulation.js +77 -112
  58. package/dist/src/mind/attention.d.ts +40 -108
  59. package/dist/src/mind/attention.js +754 -872
  60. package/dist/src/mind/canonical.d.ts +4 -19
  61. package/dist/src/mind/canonical.js +27 -31
  62. package/dist/src/mind/graph-search.d.ts +201 -225
  63. package/dist/src/mind/graph-search.js +742 -821
  64. package/dist/src/mind/index.d.ts +2 -10
  65. package/dist/src/mind/junction.d.ts +31 -58
  66. package/dist/src/mind/junction.js +172 -237
  67. package/dist/src/mind/learning.d.ts +16 -52
  68. package/dist/src/mind/learning.js +143 -165
  69. package/dist/src/mind/match.d.ts +20 -69
  70. package/dist/src/mind/match.js +259 -318
  71. package/dist/src/mind/mechanisms/alu.js +16 -16
  72. package/dist/src/mind/mechanisms/cast.d.ts +9 -13
  73. package/dist/src/mind/mechanisms/cast.js +363 -456
  74. package/dist/src/mind/mechanisms/confluence.d.ts +8 -12
  75. package/dist/src/mind/mechanisms/confluence.js +152 -183
  76. package/dist/src/mind/mechanisms/cover.d.ts +2 -8
  77. package/dist/src/mind/mechanisms/cover.js +148 -210
  78. package/dist/src/mind/mechanisms/extraction.d.ts +8 -34
  79. package/dist/src/mind/mechanisms/extraction.js +234 -288
  80. package/dist/src/mind/mechanisms/recall.d.ts +6 -10
  81. package/dist/src/mind/mechanisms/recall.js +141 -185
  82. package/dist/src/mind/mind.d.ts +194 -155
  83. package/dist/src/mind/mind.js +392 -289
  84. package/dist/src/mind/pipeline-mechanism.d.ts +112 -124
  85. package/dist/src/mind/pipeline-mechanism.js +161 -172
  86. package/dist/src/mind/pipeline.d.ts +4 -14
  87. package/dist/src/mind/pipeline.js +125 -189
  88. package/dist/src/mind/primitives.d.ts +20 -33
  89. package/dist/src/mind/primitives.js +124 -120
  90. package/dist/src/mind/rationale.d.ts +86 -98
  91. package/dist/src/mind/rationale.js +113 -121
  92. package/dist/src/mind/reasoning.d.ts +2 -13
  93. package/dist/src/mind/reasoning.js +129 -166
  94. package/dist/src/mind/recognition.d.ts +1 -4
  95. package/dist/src/mind/recognition.js +198 -210
  96. package/dist/src/mind/resonance.d.ts +5 -22
  97. package/dist/src/mind/resonance.js +0 -0
  98. package/dist/src/mind/trace.d.ts +6 -25
  99. package/dist/src/mind/trace.js +50 -58
  100. package/dist/src/mind/traverse.d.ts +29 -58
  101. package/dist/src/mind/traverse.js +344 -356
  102. package/dist/src/mind/types.d.ts +122 -127
  103. package/dist/src/mind/types.js +60 -69
  104. package/dist/src/rabitq-ivf/src/database.d.ts +113 -0
  105. package/dist/src/rabitq-ivf/src/database.js +201 -0
  106. package/dist/src/rabitq-ivf/src/index.d.ts +7 -0
  107. package/dist/src/{rabitq-hnsw → rabitq-ivf}/src/index.js +1 -3
  108. package/dist/src/rabitq-ivf/src/ivf.d.ts +200 -0
  109. package/dist/src/rabitq-ivf/src/ivf.js +1165 -0
  110. package/dist/src/rabitq-ivf/src/prng.d.ts +19 -0
  111. package/dist/src/rabitq-ivf/src/prng.js +36 -0
  112. package/dist/src/rabitq-ivf/src/rabitq.d.ts +95 -0
  113. package/dist/src/rabitq-ivf/src/rabitq.js +283 -0
  114. package/dist/src/sema.d.ts +9 -13
  115. package/dist/src/sema.js +26 -40
  116. package/dist/src/store-sqlite.d.ts +171 -166
  117. package/dist/src/store-sqlite.js +768 -662
  118. package/dist/src/store.d.ts +597 -630
  119. package/dist/src/store.js +1434 -1581
  120. package/dist/src/vec.d.ts +5 -9
  121. package/dist/src/vec.js +61 -73
  122. package/example/train_base.ts +33 -15
  123. package/index.html +65 -0
  124. package/package.json +1 -1
  125. package/src/alu/README.md +1 -1
  126. package/src/alu/src/index.ts +1 -1
  127. package/src/config.ts +19 -27
  128. package/src/geometry.ts +93 -1
  129. package/src/index.ts +6 -11
  130. package/src/mind/attention.ts +11 -6
  131. package/src/mind/mechanisms/recall.ts +29 -13
  132. package/src/mind/mind.ts +250 -19
  133. package/src/mind/primitives.ts +43 -6
  134. package/src/mind/recognition.ts +26 -8
  135. package/src/mind/traverse.ts +47 -0
  136. package/src/mind/types.ts +20 -21
  137. package/src/rabitq-ivf/README.md +56 -0
  138. package/src/rabitq-ivf/src/database.ts +276 -0
  139. package/src/{rabitq-hnsw → rabitq-ivf}/src/index.ts +2 -5
  140. package/src/rabitq-ivf/src/ivf.ts +1330 -0
  141. package/src/{rabitq-hnsw → rabitq-ivf}/src/prng.ts +1 -1
  142. package/src/store-sqlite.ts +204 -9
  143. package/src/store.ts +27 -34
  144. package/test/08-storage.test.mjs +3 -3
  145. package/test/13-conversation.test.mjs +190 -20
  146. package/test/14-scaling.test.mjs +2 -2
  147. package/test/35-ivf.test.mjs +263 -0
  148. package/test/36-bloom.test.mjs +123 -0
  149. package/dist/src/rabitq-hnsw/src/database.d.ts +0 -202
  150. package/dist/src/rabitq-hnsw/src/database.js +0 -405
  151. package/dist/src/rabitq-hnsw/src/heap.d.ts +0 -22
  152. package/dist/src/rabitq-hnsw/src/heap.js +0 -94
  153. package/dist/src/rabitq-hnsw/src/hnsw.d.ts +0 -125
  154. package/dist/src/rabitq-hnsw/src/hnsw.js +0 -500
  155. package/dist/src/rabitq-hnsw/src/index.d.ts +0 -15
  156. package/dist/src/rabitq-hnsw/src/prng.d.ts +0 -19
  157. package/dist/src/rabitq-hnsw/src/prng.js +0 -38
  158. package/dist/src/rabitq-hnsw/src/rabitq.d.ts +0 -95
  159. package/dist/src/rabitq-hnsw/src/rabitq.js +0 -299
  160. package/dist/src/rabitq-hnsw/src/store.d.ts +0 -162
  161. package/dist/src/rabitq-hnsw/src/store.js +0 -916
  162. package/dist/src/rabitq-hnsw/test/hnsw.test.d.ts +0 -1
  163. package/dist/src/rabitq-hnsw/test/hnsw.test.js +0 -1197
  164. package/src/rabitq-hnsw/README.md +0 -303
  165. package/src/rabitq-hnsw/src/database.ts +0 -492
  166. package/src/rabitq-hnsw/src/heap.ts +0 -90
  167. package/src/rabitq-hnsw/src/hnsw.ts +0 -514
  168. package/src/rabitq-hnsw/src/store.ts +0 -994
  169. package/src/rabitq-hnsw/test/hnsw.test.ts +0 -1213
  170. /package/src/{rabitq-hnsw → rabitq-ivf}/src/rabitq.ts +0 -0
@@ -6,9 +6,9 @@ export type ApplyScalar = (name: string, args: number[]) => number;
6
6
  /** Whether a name is a registered unary function the evaluator may call. */
7
7
  export type IsUnaryFn = (name: string) => boolean;
8
8
  export interface Token {
9
- kind: "num" | "name" | "op" | "lparen" | "rparen";
10
- text: string;
11
- value?: number;
9
+ kind: "num" | "name" | "op" | "lparen" | "rparen";
10
+ text: string;
11
+ value?: number;
12
12
  }
13
13
  /** Tokenize an expression string: numerals (the irreducible floor), operator
14
14
  * tokens (matched longest-first against `operators` — the registry's own
@@ -16,53 +16,46 @@ export interface Token {
16
16
  * vocabulary is given, each symbolic character stands alone (enough for name
17
17
  * extraction). Returns null when a character fits none of these — the span is
18
18
  * not a clean expression. */
19
- export declare function tokenize(
20
- s: string,
21
- operators?: readonly string[],
22
- ): Token[] | null;
19
+ export declare function tokenize(s: string, operators?: readonly string[]): Token[] | null;
23
20
  /** The identifiers in `s` that are NOT known unary functions and NOT registered
24
21
  * constants — the free-variable candidates. Used to auto-detect the variable
25
22
  * when the caller did not name one. */
26
- export declare function freeVariables(
27
- s: string,
28
- isUnaryFn: IsUnaryFn,
29
- isConstant?: (name: string) => boolean,
30
- ): string[];
23
+ export declare function freeVariables(s: string, isUnaryFn: IsUnaryFn, isConstant?: (name: string) => boolean): string[];
31
24
  /** The expression grammar, read off an operation registry once and reused for
32
25
  * every evaluation. It resolves each token through the registry's own form
33
26
  * index — infix binding from the `infix` trait, a prefix operator as the
34
27
  * arity-1 claimant of a shared symbol, functions as arity-1 ops, constants as
35
28
  * arity-0 ops — so the grammar and the kernel can never drift apart. */
36
29
  export declare class ExprGrammar {
37
- private readonly registry;
38
- private readonly applyScalar;
39
- /** Symbolic operator tokens, longest first (so "<=" wins over "<"). */
40
- private readonly operatorTokens;
41
- /** token → the infix op it names and its declared binding. */
42
- private readonly infixTable;
43
- /** token → the arity-1 (prefix) op it names. */
44
- private readonly prefixTable;
45
- /** The tightest infix tier — a prefix operator binds its operand up through
46
- * it, so "-x^2" reads -(x^2) without a hardcoded rule. */
47
- private readonly maxPrecedence;
48
- constructor(registry: OperationRegistry, applyScalar: ApplyScalar);
49
- /** Resolve an identifier to a registered op of the given arity: a surface
50
- * form claimant of that arity first, else the canonical name itself. */
51
- private resolveName;
52
- /** Whether an identifier names a unary function. */
53
- isFunction(name: string): boolean;
54
- /** Whether an identifier names a nullary constant (an arity-0 op). */
55
- isConstant(name: string): boolean;
56
- /** Tokenize with this grammar's operator vocabulary. */
57
- tokenize(s: string): Token[] | null;
58
- /** The free-variable candidates of `s` under this grammar. */
59
- freeVariables(s: string): string[];
60
- /** Evaluate expression `s` with `variable` bound to `at`. Returns a number,
61
- * or null if `s` is not a well-formed expression. Every binary/function/
62
- * constant step is applied through the kernel, so the arithmetic is the
63
- * kernel's own. When `variable` is empty, the single free variable is
64
- * auto-detected; if there is more than one and none was named, evaluation
65
- * declines (null) — a genuinely multivariate expression needs an explicit
66
- * binding. */
67
- eval(s: string, variable: string, at: number): number | null;
30
+ private readonly registry;
31
+ private readonly applyScalar;
32
+ /** Symbolic operator tokens, longest first (so "<=" wins over "<"). */
33
+ private readonly operatorTokens;
34
+ /** token → the infix op it names and its declared binding. */
35
+ private readonly infixTable;
36
+ /** token → the arity-1 (prefix) op it names. */
37
+ private readonly prefixTable;
38
+ /** The tightest infix tier — a prefix operator binds its operand up through
39
+ * it, so "-x^2" reads -(x^2) without a hardcoded rule. */
40
+ private readonly maxPrecedence;
41
+ constructor(registry: OperationRegistry, applyScalar: ApplyScalar);
42
+ /** Resolve an identifier to a registered op of the given arity: a surface
43
+ * form claimant of that arity first, else the canonical name itself. */
44
+ private resolveName;
45
+ /** Whether an identifier names a unary function. */
46
+ isFunction(name: string): boolean;
47
+ /** Whether an identifier names a nullary constant (an arity-0 op). */
48
+ isConstant(name: string): boolean;
49
+ /** Tokenize with this grammar's operator vocabulary. */
50
+ tokenize(s: string): Token[] | null;
51
+ /** The free-variable candidates of `s` under this grammar. */
52
+ freeVariables(s: string): string[];
53
+ /** Evaluate expression `s` with `variable` bound to `at`. Returns a number,
54
+ * or null if `s` is not a well-formed expression. Every binary/function/
55
+ * constant step is applied through the kernel, so the arithmetic is the
56
+ * kernel's own. When `variable` is empty, the single free variable is
57
+ * auto-detected; if there is more than one and none was named, evaluation
58
+ * declines (null) — a genuinely multivariate expression needs an explicit
59
+ * binding. */
60
+ eval(s: string, variable: string, at: number): number | null;
68
61
  }