@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
@@ -11,8 +11,4 @@ export declare function concat2(a: Uint8Array, b: Uint8Array): Uint8Array;
11
11
  export declare function latin1(b: Uint8Array): string;
12
12
  /** First index ≥ `from` at which `needle` occurs in `hay`, or -1. A short naive
13
13
  * scan — used only to locate a result span inside a learnt framing form. */
14
- export declare function indexOf(
15
- hay: Uint8Array,
16
- needle: Uint8Array,
17
- from: number,
18
- ): number;
14
+ export declare function indexOf(hay: Uint8Array, needle: Uint8Array, from: number): number;
package/dist/src/bytes.js CHANGED
@@ -6,61 +6,54 @@
6
6
  // hides a side effect.
7
7
  /** True when two byte spans are equal in length and content. */
8
8
  export function bytesEqual(a, b) {
9
- if (a.length !== b.length) {
10
- return false;
11
- }
12
- for (let i = 0; i < a.length; i++) {
13
- if (a[i] !== b[i]) {
14
- return false;
15
- }
16
- }
17
- return true;
9
+ if (a.length !== b.length)
10
+ return false;
11
+ for (let i = 0; i < a.length; i++)
12
+ if (a[i] !== b[i])
13
+ return false;
14
+ return true;
18
15
  }
19
16
  /** Concatenate byte arrays. Takes an array rather than rest params so
20
17
  * a large segment list can never overflow the call stack via spread. */
21
18
  export function concatBytes(parts) {
22
- let total = 0;
23
- for (const p of parts) {
24
- total += p.length;
25
- }
26
- const out = new Uint8Array(total);
27
- let off = 0;
28
- for (const p of parts) {
29
- out.set(p, off);
30
- off += p.length;
31
- }
32
- return out;
19
+ let total = 0;
20
+ for (const p of parts)
21
+ total += p.length;
22
+ const out = new Uint8Array(total);
23
+ let off = 0;
24
+ for (const p of parts) {
25
+ out.set(p, off);
26
+ off += p.length;
27
+ }
28
+ return out;
33
29
  }
34
30
  /** Join two byte spans — the hot two-operand case of {@link concatBytes},
35
31
  * fused without the array wrapper for the search's inner fuse loop. */
36
32
  export function concat2(a, b) {
37
- const out = new Uint8Array(a.length + b.length);
38
- out.set(a, 0);
39
- out.set(b, a.length);
40
- return out;
33
+ const out = new Uint8Array(a.length + b.length);
34
+ out.set(a, 0);
35
+ out.set(b, a.length);
36
+ return out;
41
37
  }
42
38
  /** Latin-1 view of a byte span — a stable, lossless string key for chart
43
39
  * memoization (every byte 0–255 maps to one code unit). */
44
40
  export function latin1(b) {
45
- let s = "";
46
- for (let k = 0; k < b.length; k++) {
47
- s += String.fromCharCode(b[k]);
48
- }
49
- return s;
41
+ let s = "";
42
+ for (let k = 0; k < b.length; k++)
43
+ s += String.fromCharCode(b[k]);
44
+ return s;
50
45
  }
51
46
  /** First index ≥ `from` at which `needle` occurs in `hay`, or -1. A short naive
52
47
  * scan — used only to locate a result span inside a learnt framing form. */
53
48
  export function indexOf(hay, needle, from) {
54
- if (needle.length === 0) {
55
- return from;
56
- }
57
- outer: for (let i = Math.max(0, from); i + needle.length <= hay.length; i++) {
58
- for (let j = 0; j < needle.length; j++) {
59
- if (hay[i + j] !== needle[j]) {
60
- continue outer;
61
- }
49
+ if (needle.length === 0)
50
+ return from;
51
+ outer: for (let i = Math.max(0, from); i + needle.length <= hay.length; i++) {
52
+ for (let j = 0; j < needle.length; j++) {
53
+ if (hay[i + j] !== needle[j])
54
+ continue outer;
55
+ }
56
+ return i;
62
57
  }
63
- return i;
64
- }
65
- return -1;
58
+ return -1;
66
59
  }
@@ -1,114 +1,111 @@
1
1
  export interface AluConfig {
2
- /** Whether the ALU sub-lib contributes computation rules to the graph search.
3
- * When false, no operator/operand pre-resolution runs and no ALU rule fires —
4
- * thinking behaves exactly as it did before ALU existed. */
5
- enabled: boolean;
6
- /** Convergence tolerance ε for the numerical limit layer (diff/solve/exp/…). */
7
- tol: number;
8
- /** Hard iteration ceiling for any convergence loop, so a non-converging
9
- * refinement still terminates. */
10
- maxIter: number;
11
- /** Decimal places a real result is rounded to before it is encoded to bytes.
12
- * Determinism here is load-bearing: the search keys an output span by its
13
- * bytes, so two derivations of the same value must spell it identically. */
14
- precision: number;
2
+ /** Whether the ALU sub-lib contributes computation rules to the graph search.
3
+ * When false, no operator/operand pre-resolution runs and no ALU rule fires —
4
+ * thinking behaves exactly as it did before ALU existed. */
5
+ enabled: boolean;
6
+ /** Convergence tolerance ε for the numerical limit layer (diff/solve/exp/…). */
7
+ tol: number;
8
+ /** Hard iteration ceiling for any convergence loop, so a non-converging
9
+ * refinement still terminates. */
10
+ maxIter: number;
11
+ /** Decimal places a real result is rounded to before it is encoded to bytes.
12
+ * Determinism here is load-bearing: the search keys an output span by its
13
+ * bytes, so two derivations of the same value must spell it identically. */
14
+ precision: number;
15
15
  }
16
16
  export interface GeometryConfig {
17
- /** Maximum siblings per tree fold. */
18
- maxGroup: number;
17
+ /** Maximum siblings per tree fold. */
18
+ maxGroup: number;
19
19
  }
20
20
  export interface AlphabetConfig {
21
- /** How different neighbouring byte vectors are from their coarse ancestors
22
- * (0 = identical, 1 = independent). */
23
- roughness: number;
24
- /** Seed XOR mask for the alphabet's PRNG derivation. */
25
- seedMask: number;
21
+ /** How different neighbouring byte vectors are from their coarse ancestors
22
+ * (0 = identical, 1 = independent). */
23
+ roughness: number;
24
+ /** Seed XOR mask for the alphabet's PRNG derivation. */
25
+ seedMask: number;
26
26
  }
27
27
  export interface StoreConfig {
28
- minHaloMass: number;
29
- m: number;
30
- efConstruction: number;
31
- /** Construction budget for REACH-ONLY interior gists the ~90% of content
32
- * index inserts that exist so a partial query can resonate a sub-region
33
- * and climb, never as dedup targets. Deposit roots and halo-bearing
34
- * targets always build with the full `efConstruction`. A smaller budget
35
- * here is the one deliberate speed-for-quality trade in ingestion (an
36
- * interior's layer-0 wiring is built from a narrower candidate beam);
37
- * the recall suite (partial recall, multi-topic attention, counterfactual
38
- * anchoring) is the gate for its value. Set equal to `efConstruction`
39
- * to disable the trade. */
40
- efConstructionInterior: number;
41
- efSearch: number;
42
- /** Compact the in-memory vector indices after this many vectors are written.
43
- * Compaction rebuilds an index from its live codes to reclaim the slots left
44
- * by tombstoned (updated/deleted) halo entries; pacing it on write VOLUME
45
- * (not on a flush count that goes quiet during repeat-heavy training) keeps
46
- * the index dense and query cost bounded. */
47
- compactEveryNWrites: number;
48
- /** Over-fetch factor for HNSW queries (ANN recall cushion). */
49
- overfetch: number;
50
- /** Combined buffered-write ceiling before a flush of both vector indices
51
- * (content + halo). Higher ⇒ fewer, larger flushes into the in-memory
52
- * indices and fewer write-transaction commits. */
53
- batchSize: number;
54
- /** Max entries in the store's exact-content dedup map (bounds RAM on huge
55
- * corpora; a miss only risks a duplicate node, never incorrectness). */
56
- dedupCacheMax: number;
57
- /** Max bytes of reconstructed content cached in memory (regenerable).
58
- * Large branch nodes cost more budget than small leaves, so the cache
59
- * naturally favours cheap, frequently-hit entries. */
60
- bytesCacheMax: number;
61
- /** Max bytes of node-record cache (avoids repeated SQLite lookups for
62
- * shared DAG nodes). Each record is ~30-50 bytes. */
63
- recCacheBytes: number;
64
- /** Max bytes of ingest-result cache used by {@link CachedIngest}. */
65
- ingestCacheBytes: number;
66
- /** Max bytes of captured-but-not-yet-indexed node gists (D·4 each). A node's
67
- * gist enters the content index lazily, only when it first becomes a
68
- * resonance target (gains a continuation edge or a halo); until then its gist
69
- * waits here. A deposit links/pours a node right after interning it, so the
70
- * working set is one deposit's nodes a modest budget captures ~all of it.
71
- * An eviction only means a node is reached by the structural DAG climb instead
72
- * of by direct resonance a little recall reach, never correctness. */
73
- pendingGistBytes: number;
74
- /** Max bytes of EXACT halo accumulators kept in memory (D·4 each). The
75
- * durable halo row is 2-bit quantized; this cache keeps the accumulators a
76
- * session is actively pouring into at full precision, so within-session
77
- * accumulate-then-compare (concept formation as it happens) never
78
- * round-trips through the quantizer. An eviction or a reopen reads the
79
- * 2-bit row the fidelity every cross-session consumer already gets. */
80
- haloCacheBytes: number;
81
- /** Size, in MiB, of each `rabitq-hnsw` `VectorDatabase`'s memory budget
82
- * (forwarded as its `cacheSizeMb`). It is the index's SINGLE memory knob: it
83
- * sizes both SQLite's page cache and the derived immutable-code LRU. A PURE
84
- * latency optimisation the index reads codes from SQLite on demand, so its
85
- * correctness and its asymptotic per-operation storage-read count are identical
86
- * with the budget at 0. Exposed so a scaling test can set it to 0 and measure
87
- * the honest, cache-independent cost. */
88
- vectorCacheMb: number;
89
- /** Max entries in the skipped-interior LRU set. Interiors that
90
- * {@link Store.indexSubtree} has already visited (indexed or skipped) are
91
- * remembered here so subsequent calls prune their subtrees. Session-local
92
- * (regenerable). */
93
- coveredIdsMax: number;
94
- /** Max bytes of transparent-chain runs ({@link Store.chainRun}) cached for
95
- * the store's lifetime (~4 bytes per chain node). Valid until any write
96
- * could break a node's transparency (a new structural parent or a new
97
- * continuation edge), when the whole cache is dropped — writes happen in
98
- * training bursts, reads in read-only query phases, so the cache pays for
99
- * itself exactly where it matters. Regenerable; a miss re-walks. */
100
- chainCacheBytes: number;
28
+ minHaloMass: number;
29
+ /** Query breadth of the IVF vector indices: clusters probed per query =
30
+ * ceil(efSearch / 4). Inserts have no quality knob — the partitioned
31
+ * index routes and appends, so ingestion cost is flat by construction. */
32
+ efSearch: number;
33
+ /** Compact the in-memory vector indices after this many vectors are written.
34
+ * Compaction rebuilds an index from its live codes to reclaim the slots left
35
+ * by tombstoned (updated/deleted) halo entries; pacing it on write VOLUME
36
+ * (not on a flush count that goes quiet during repeat-heavy training) keeps
37
+ * the index dense and query cost bounded. */
38
+ compactEveryNWrites: number;
39
+ /** Over-fetch factor for vector-index queries (ANN recall cushion). */
40
+ overfetch: number;
41
+ /** Combined buffered-write ceiling before a flush of both vector indices
42
+ * (content + halo). Higher fewer, larger flushes into the in-memory
43
+ * indices and fewer write-transaction commits. */
44
+ batchSize: number;
45
+ /** Max entries in the store's exact-content dedup map (bounds RAM on huge
46
+ * corpora; a miss only risks a duplicate node, never incorrectness). */
47
+ dedupCacheMax: number;
48
+ /** Max bytes of reconstructed content cached in memory (regenerable).
49
+ * Large branch nodes cost more budget than small leaves, so the cache
50
+ * naturally favours cheap, frequently-hit entries. */
51
+ bytesCacheMax: number;
52
+ /** Max bytes of node-record cache (avoids repeated SQLite lookups for
53
+ * shared DAG nodes). Each record is ~30-50 bytes. */
54
+ recCacheBytes: number;
55
+ /** Max bytes of ingest-result cache used by {@link CachedIngest}. */
56
+ ingestCacheBytes: number;
57
+ /** Max bytes of captured-but-not-yet-indexed node gists (D·4 each). A node's
58
+ * gist enters the content index lazily, only when it first becomes a
59
+ * resonance target (gains a continuation edge or a halo); until then its gist
60
+ * waits here. A deposit links/pours a node right after interning it, so the
61
+ * working set is one deposit's nodes a modest budget captures ~all of it.
62
+ * An eviction only means a node is reached by the structural DAG climb instead
63
+ * of by direct resonance — a little recall reach, never correctness. */
64
+ pendingGistBytes: number;
65
+ /** Max bytes of EXACT halo accumulators kept in memory (D·4 each). The
66
+ * durable halo row is 2-bit quantized; this cache keeps the accumulators a
67
+ * session is actively pouring into at full precision, so within-session
68
+ * accumulate-then-compare (concept formation as it happens) never
69
+ * round-trips through the quantizer. An eviction or a reopen reads the
70
+ * 2-bit rowthe fidelity every cross-session consumer already gets. */
71
+ haloCacheBytes: number;
72
+ /** Size, in MiB, of each `rabitq-ivf` `VectorDatabase`'s memory budget
73
+ * (forwarded as its `cacheSizeMb` — its SQLite page cache). A PURE latency
74
+ * optimisation the index reads chunk blobs from SQLite on demand, so its
75
+ * correctness and its per-operation storage-read count are identical with
76
+ * the budget at 0. Exposed so a scaling test can set it to 0 and measure
77
+ * the honest, cache-independent cost. */
78
+ vectorCacheMb: number;
79
+ /** Size, in MiB, of the MAIN DAG database's SQLite page cache. The node /
80
+ * kid / edge / contain tables serve millions of point probes per training
81
+ * session (content-addressed findLeaf/findBranch, parent probes, contain
82
+ * appends); SQLite's default cache (~2 MiB) thrashes once the DB outgrows
83
+ * it, so every probe pays a file read. A PURE latency knob — correctness
84
+ * and result identical at any value. */
85
+ sqliteCacheMb: number;
86
+ /** Max entries in the skipped-interior LRU set. Interiors that
87
+ * {@link Store.indexSubtree} has already visited (indexed or skipped) are
88
+ * remembered here so subsequent calls prune their subtrees. Session-local
89
+ * (regenerable). */
90
+ coveredIdsMax: number;
91
+ /** Max bytes of transparent-chain runs ({@link Store.chainRun}) cached for
92
+ * the store's lifetime (~4 bytes per chain node). Valid until any write
93
+ * could break a node's transparency (a new structural parent or a new
94
+ * continuation edge), when the whole cache is dropped writes happen in
95
+ * training bursts, reads in read-only query phases, so the cache pays for
96
+ * itself exactly where it matters. Regenerable; a miss re-walks. */
97
+ chainCacheBytes: number;
101
98
  }
102
99
  export interface MindConfig {
103
- seed: number;
104
- recallQueryK: number;
105
- haloQueryK: number;
106
- normalizeEpsilon: number;
107
- cosineEpsilon: number;
108
- alu: AluConfig;
109
- geometry: GeometryConfig;
110
- alphabet: AlphabetConfig;
111
- store: StoreConfig;
100
+ seed: number;
101
+ recallQueryK: number;
102
+ haloQueryK: number;
103
+ normalizeEpsilon: number;
104
+ cosineEpsilon: number;
105
+ alu: AluConfig;
106
+ geometry: GeometryConfig;
107
+ alphabet: AlphabetConfig;
108
+ store: StoreConfig;
112
109
  }
113
110
  export declare const DEFAULT_CONFIG: MindConfig;
114
111
  export declare function resolveConfig(opts?: Partial<MindConfig>): MindConfig;
@@ -2,95 +2,90 @@
2
2
  // Every tunable parameter lives here. Subsystems receive their subset.
3
3
  // ── Defaults ──
4
4
  export const DEFAULT_CONFIG = {
5
- seed: 42,
6
- recallQueryK: 12,
7
- haloQueryK: 12,
8
- normalizeEpsilon: 1e-12,
9
- cosineEpsilon: 1e-12,
10
- alu: {
11
- enabled: true,
12
- tol: 1e-10,
13
- maxIter: 1000,
14
- precision: 6,
15
- },
16
- geometry: {
17
- maxGroup: 4,
18
- },
19
- alphabet: {
20
- roughness: 0.65,
21
- seedMask: 0xa1fa17,
22
- },
23
- store: {
24
- minHaloMass: 1,
25
- m: 8,
26
- efConstruction: 64,
27
- efConstructionInterior: 16,
28
- efSearch: 64,
29
- compactEveryNWrites: 50_000,
30
- overfetch: 4,
31
- batchSize: 256,
32
- dedupCacheMax: 1_000_000,
33
- bytesCacheMax: 20_000_000,
34
- recCacheBytes: 10_000_000,
35
- ingestCacheBytes: 50_000_000,
36
- pendingGistBytes: 16_000_000,
37
- haloCacheBytes: 16_000_000,
38
- vectorCacheMb: 64,
39
- coveredIdsMax: 100_000,
40
- chainCacheBytes: 16_000_000,
41
- },
42
- };
43
- // ── Config resolver: partial input + defaults = full config ──
44
- export function resolveConfig(opts = {}) {
45
- return {
46
- seed: opts.seed ?? DEFAULT_CONFIG.seed,
47
- recallQueryK: opts.recallQueryK ?? DEFAULT_CONFIG.recallQueryK,
48
- haloQueryK: opts.haloQueryK ?? DEFAULT_CONFIG.haloQueryK,
49
- normalizeEpsilon: opts.normalizeEpsilon ?? DEFAULT_CONFIG.normalizeEpsilon,
50
- cosineEpsilon: opts.cosineEpsilon ?? DEFAULT_CONFIG.cosineEpsilon,
5
+ seed: 42,
6
+ recallQueryK: 12,
7
+ haloQueryK: 12,
8
+ normalizeEpsilon: 1e-12,
9
+ cosineEpsilon: 1e-12,
51
10
  alu: {
52
- enabled: opts.alu?.enabled ?? DEFAULT_CONFIG.alu.enabled,
53
- tol: opts.alu?.tol ?? DEFAULT_CONFIG.alu.tol,
54
- maxIter: opts.alu?.maxIter ?? DEFAULT_CONFIG.alu.maxIter,
55
- precision: opts.alu?.precision ?? DEFAULT_CONFIG.alu.precision,
11
+ enabled: true,
12
+ tol: 1e-10,
13
+ maxIter: 1000,
14
+ precision: 6,
56
15
  },
57
16
  geometry: {
58
- maxGroup: opts.geometry?.maxGroup ?? DEFAULT_CONFIG.geometry.maxGroup,
17
+ maxGroup: 4,
59
18
  },
60
19
  alphabet: {
61
- roughness: opts.alphabet?.roughness ?? DEFAULT_CONFIG.alphabet.roughness,
62
- seedMask: opts.alphabet?.seedMask ?? DEFAULT_CONFIG.alphabet.seedMask,
20
+ roughness: 0.65,
21
+ seedMask: 0xa1fa17,
63
22
  },
64
23
  store: {
65
- minHaloMass: opts.store?.minHaloMass ?? DEFAULT_CONFIG.store.minHaloMass,
66
- m: opts.store?.m ?? DEFAULT_CONFIG.store.m,
67
- efConstruction: opts.store?.efConstruction ??
68
- DEFAULT_CONFIG.store.efConstruction,
69
- efConstructionInterior: opts.store?.efConstructionInterior ??
70
- DEFAULT_CONFIG.store.efConstructionInterior,
71
- efSearch: opts.store?.efSearch ?? DEFAULT_CONFIG.store.efSearch,
72
- compactEveryNWrites: opts.store?.compactEveryNWrites ??
73
- DEFAULT_CONFIG.store.compactEveryNWrites,
74
- overfetch: opts.store?.overfetch ?? DEFAULT_CONFIG.store.overfetch,
75
- batchSize: opts.store?.batchSize ?? DEFAULT_CONFIG.store.batchSize,
76
- dedupCacheMax: opts.store?.dedupCacheMax ??
77
- DEFAULT_CONFIG.store.dedupCacheMax,
78
- bytesCacheMax: opts.store?.bytesCacheMax ??
79
- DEFAULT_CONFIG.store.bytesCacheMax,
80
- recCacheBytes: opts.store?.recCacheBytes ??
81
- DEFAULT_CONFIG.store.recCacheBytes,
82
- ingestCacheBytes: opts.store?.ingestCacheBytes ??
83
- DEFAULT_CONFIG.store.ingestCacheBytes,
84
- pendingGistBytes: opts.store?.pendingGistBytes ??
85
- DEFAULT_CONFIG.store.pendingGistBytes,
86
- haloCacheBytes: opts.store?.haloCacheBytes ??
87
- DEFAULT_CONFIG.store.haloCacheBytes,
88
- vectorCacheMb: opts.store?.vectorCacheMb ??
89
- DEFAULT_CONFIG.store.vectorCacheMb,
90
- coveredIdsMax: opts.store?.coveredIdsMax ??
91
- DEFAULT_CONFIG.store.coveredIdsMax,
92
- chainCacheBytes: opts.store?.chainCacheBytes ??
93
- DEFAULT_CONFIG.store.chainCacheBytes,
24
+ minHaloMass: 1,
25
+ efSearch: 64,
26
+ compactEveryNWrites: 50_000,
27
+ overfetch: 4,
28
+ batchSize: 256,
29
+ dedupCacheMax: 1_000_000,
30
+ bytesCacheMax: 20_000_000,
31
+ recCacheBytes: 10_000_000,
32
+ ingestCacheBytes: 50_000_000,
33
+ pendingGistBytes: 16_000_000,
34
+ haloCacheBytes: 16_000_000,
35
+ vectorCacheMb: 64,
36
+ sqliteCacheMb: 64,
37
+ coveredIdsMax: 100_000,
38
+ chainCacheBytes: 16_000_000,
94
39
  },
95
- };
40
+ };
41
+ // ── Config resolver: partial input + defaults = full config ──
42
+ export function resolveConfig(opts = {}) {
43
+ return {
44
+ seed: opts.seed ?? DEFAULT_CONFIG.seed,
45
+ recallQueryK: opts.recallQueryK ?? DEFAULT_CONFIG.recallQueryK,
46
+ haloQueryK: opts.haloQueryK ?? DEFAULT_CONFIG.haloQueryK,
47
+ normalizeEpsilon: opts.normalizeEpsilon ?? DEFAULT_CONFIG.normalizeEpsilon,
48
+ cosineEpsilon: opts.cosineEpsilon ?? DEFAULT_CONFIG.cosineEpsilon,
49
+ alu: {
50
+ enabled: opts.alu?.enabled ?? DEFAULT_CONFIG.alu.enabled,
51
+ tol: opts.alu?.tol ?? DEFAULT_CONFIG.alu.tol,
52
+ maxIter: opts.alu?.maxIter ?? DEFAULT_CONFIG.alu.maxIter,
53
+ precision: opts.alu?.precision ?? DEFAULT_CONFIG.alu.precision,
54
+ },
55
+ geometry: {
56
+ maxGroup: opts.geometry?.maxGroup ?? DEFAULT_CONFIG.geometry.maxGroup,
57
+ },
58
+ alphabet: {
59
+ roughness: opts.alphabet?.roughness ?? DEFAULT_CONFIG.alphabet.roughness,
60
+ seedMask: opts.alphabet?.seedMask ?? DEFAULT_CONFIG.alphabet.seedMask,
61
+ },
62
+ store: {
63
+ minHaloMass: opts.store?.minHaloMass ?? DEFAULT_CONFIG.store.minHaloMass,
64
+ efSearch: opts.store?.efSearch ?? DEFAULT_CONFIG.store.efSearch,
65
+ compactEveryNWrites: opts.store?.compactEveryNWrites ??
66
+ DEFAULT_CONFIG.store.compactEveryNWrites,
67
+ overfetch: opts.store?.overfetch ?? DEFAULT_CONFIG.store.overfetch,
68
+ batchSize: opts.store?.batchSize ?? DEFAULT_CONFIG.store.batchSize,
69
+ dedupCacheMax: opts.store?.dedupCacheMax ??
70
+ DEFAULT_CONFIG.store.dedupCacheMax,
71
+ bytesCacheMax: opts.store?.bytesCacheMax ??
72
+ DEFAULT_CONFIG.store.bytesCacheMax,
73
+ recCacheBytes: opts.store?.recCacheBytes ??
74
+ DEFAULT_CONFIG.store.recCacheBytes,
75
+ ingestCacheBytes: opts.store?.ingestCacheBytes ??
76
+ DEFAULT_CONFIG.store.ingestCacheBytes,
77
+ pendingGistBytes: opts.store?.pendingGistBytes ??
78
+ DEFAULT_CONFIG.store.pendingGistBytes,
79
+ haloCacheBytes: opts.store?.haloCacheBytes ??
80
+ DEFAULT_CONFIG.store.haloCacheBytes,
81
+ vectorCacheMb: opts.store?.vectorCacheMb ??
82
+ DEFAULT_CONFIG.store.vectorCacheMb,
83
+ sqliteCacheMb: opts.store?.sqliteCacheMb ??
84
+ DEFAULT_CONFIG.store.sqliteCacheMb,
85
+ coveredIdsMax: opts.store?.coveredIdsMax ??
86
+ DEFAULT_CONFIG.store.coveredIdsMax,
87
+ chainCacheBytes: opts.store?.chainCacheBytes ??
88
+ DEFAULT_CONFIG.store.chainCacheBytes,
89
+ },
90
+ };
96
91
  }