@hviana/sema 0.1.4 → 0.1.5

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 (122) hide show
  1. package/dist/example/demo.js +25 -25
  2. package/dist/example/train_base.d.ts +21 -19
  3. package/dist/example/train_base.js +1952 -1684
  4. package/dist/src/alphabet.d.ts +3 -3
  5. package/dist/src/alphabet.js +27 -24
  6. package/dist/src/alu/src/alu.d.ts +194 -169
  7. package/dist/src/alu/src/alu.js +414 -374
  8. package/dist/src/alu/src/expr.d.ts +43 -36
  9. package/dist/src/alu/src/expr.js +278 -252
  10. package/dist/src/alu/src/index.d.ts +98 -9
  11. package/dist/src/alu/src/index.js +63 -9
  12. package/dist/src/alu/src/kernel-arith.d.ts +5 -1
  13. package/dist/src/alu/src/kernel-arith.js +285 -195
  14. package/dist/src/alu/src/kernel-bits.d.ts +5 -1
  15. package/dist/src/alu/src/kernel-bits.js +115 -81
  16. package/dist/src/alu/src/kernel-logic.js +63 -33
  17. package/dist/src/alu/src/kernel-nd.js +195 -155
  18. package/dist/src/alu/src/kernel-numeric.d.ts +80 -16
  19. package/dist/src/alu/src/kernel-numeric.js +331 -259
  20. package/dist/src/alu/src/operation.d.ts +132 -112
  21. package/dist/src/alu/src/operation.js +163 -149
  22. package/dist/src/alu/src/parser.d.ts +175 -168
  23. package/dist/src/alu/src/parser.js +421 -382
  24. package/dist/src/alu/src/resonance.d.ts +25 -16
  25. package/dist/src/alu/src/resonance.js +56 -49
  26. package/dist/src/alu/src/text.d.ts +7 -3
  27. package/dist/src/alu/src/text.js +37 -31
  28. package/dist/src/alu/src/value.d.ts +14 -14
  29. package/dist/src/alu/src/value.js +160 -150
  30. package/dist/src/alu/test/alu.test.js +656 -543
  31. package/dist/src/bytes.d.ts +5 -1
  32. package/dist/src/bytes.js +40 -33
  33. package/dist/src/config.d.ts +102 -102
  34. package/dist/src/config.js +83 -83
  35. package/dist/src/derive/src/deduction.d.ts +62 -60
  36. package/dist/src/derive/src/deduction.js +109 -103
  37. package/dist/src/derive/src/index.d.ts +7 -1
  38. package/dist/src/derive/src/priority-queue.d.ts +8 -8
  39. package/dist/src/derive/src/priority-queue.js +61 -57
  40. package/dist/src/derive/src/rewrite.d.ts +18 -15
  41. package/dist/src/derive/src/rewrite.js +67 -59
  42. package/dist/src/derive/src/trie.d.ts +56 -56
  43. package/dist/src/derive/src/trie.js +179 -175
  44. package/dist/src/derive/test/derive.test.js +100 -96
  45. package/dist/src/extension.d.ts +16 -13
  46. package/dist/src/geometry.d.ts +42 -17
  47. package/dist/src/geometry.js +266 -235
  48. package/dist/src/index.d.ts +17 -2
  49. package/dist/src/index.js +7 -1
  50. package/dist/src/ingest-cache.d.ts +30 -25
  51. package/dist/src/ingest-cache.js +127 -108
  52. package/dist/src/mind/articulation.d.ts +5 -1
  53. package/dist/src/mind/articulation.js +112 -77
  54. package/dist/src/mind/attention.d.ts +108 -40
  55. package/dist/src/mind/attention.js +871 -749
  56. package/dist/src/mind/canonical.d.ts +19 -4
  57. package/dist/src/mind/canonical.js +31 -27
  58. package/dist/src/mind/graph-search.d.ts +225 -201
  59. package/dist/src/mind/graph-search.js +821 -742
  60. package/dist/src/mind/index.d.ts +10 -2
  61. package/dist/src/mind/junction.d.ts +58 -31
  62. package/dist/src/mind/junction.js +237 -172
  63. package/dist/src/mind/learning.d.ts +52 -16
  64. package/dist/src/mind/learning.js +165 -143
  65. package/dist/src/mind/match.d.ts +69 -20
  66. package/dist/src/mind/match.js +318 -259
  67. package/dist/src/mind/mechanisms/alu.js +16 -16
  68. package/dist/src/mind/mechanisms/cast.d.ts +13 -9
  69. package/dist/src/mind/mechanisms/cast.js +456 -363
  70. package/dist/src/mind/mechanisms/confluence.d.ts +12 -8
  71. package/dist/src/mind/mechanisms/confluence.js +183 -152
  72. package/dist/src/mind/mechanisms/cover.d.ts +8 -2
  73. package/dist/src/mind/mechanisms/cover.js +210 -148
  74. package/dist/src/mind/mechanisms/extraction.d.ts +34 -8
  75. package/dist/src/mind/mechanisms/extraction.js +288 -234
  76. package/dist/src/mind/mechanisms/recall.d.ts +10 -6
  77. package/dist/src/mind/mechanisms/recall.js +185 -126
  78. package/dist/src/mind/mind.d.ts +154 -129
  79. package/dist/src/mind/mind.js +288 -258
  80. package/dist/src/mind/pipeline-mechanism.d.ts +124 -112
  81. package/dist/src/mind/pipeline-mechanism.js +172 -161
  82. package/dist/src/mind/pipeline.d.ts +14 -4
  83. package/dist/src/mind/pipeline.js +189 -125
  84. package/dist/src/mind/primitives.d.ts +32 -8
  85. package/dist/src/mind/primitives.js +117 -99
  86. package/dist/src/mind/rationale.d.ts +98 -86
  87. package/dist/src/mind/rationale.js +121 -113
  88. package/dist/src/mind/reasoning.d.ts +13 -2
  89. package/dist/src/mind/reasoning.js +166 -129
  90. package/dist/src/mind/recognition.d.ts +4 -1
  91. package/dist/src/mind/recognition.js +208 -183
  92. package/dist/src/mind/resonance.d.ts +22 -5
  93. package/dist/src/mind/resonance.js +0 -0
  94. package/dist/src/mind/trace.d.ts +25 -6
  95. package/dist/src/mind/trace.js +58 -50
  96. package/dist/src/mind/traverse.d.ts +58 -16
  97. package/dist/src/mind/traverse.js +357 -304
  98. package/dist/src/mind/types.d.ts +127 -120
  99. package/dist/src/mind/types.js +69 -60
  100. package/dist/src/rabitq-hnsw/src/database.d.ts +179 -177
  101. package/dist/src/rabitq-hnsw/src/database.js +359 -342
  102. package/dist/src/rabitq-hnsw/src/heap.d.ts +12 -12
  103. package/dist/src/rabitq-hnsw/src/heap.js +80 -75
  104. package/dist/src/rabitq-hnsw/src/hnsw.d.ts +103 -103
  105. package/dist/src/rabitq-hnsw/src/hnsw.js +454 -428
  106. package/dist/src/rabitq-hnsw/src/index.d.ts +6 -1
  107. package/dist/src/rabitq-hnsw/src/prng.d.ts +10 -10
  108. package/dist/src/rabitq-hnsw/src/prng.js +27 -25
  109. package/dist/src/rabitq-hnsw/src/rabitq.d.ts +69 -69
  110. package/dist/src/rabitq-hnsw/src/rabitq.js +262 -246
  111. package/dist/src/rabitq-hnsw/src/store.d.ts +132 -132
  112. package/dist/src/rabitq-hnsw/src/store.js +843 -752
  113. package/dist/src/rabitq-hnsw/test/hnsw.test.js +1054 -805
  114. package/dist/src/sema.d.ts +13 -9
  115. package/dist/src/sema.js +40 -26
  116. package/dist/src/store-sqlite.d.ts +166 -144
  117. package/dist/src/store-sqlite.js +660 -578
  118. package/dist/src/store.d.ts +630 -593
  119. package/dist/src/store.js +1581 -1440
  120. package/dist/src/vec.d.ts +9 -5
  121. package/dist/src/vec.js +73 -61
  122. package/package.json +2 -2
@@ -11,4 +11,8 @@ 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(hay: Uint8Array, needle: Uint8Array, from: number): number;
14
+ export declare function indexOf(
15
+ hay: Uint8Array,
16
+ needle: Uint8Array,
17
+ from: number,
18
+ ): number;
package/dist/src/bytes.js CHANGED
@@ -6,54 +6,61 @@
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
- for (let i = 0; i < a.length; i++)
12
- if (a[i] !== b[i])
13
- return false;
14
- return true;
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;
15
18
  }
16
19
  /** Concatenate byte arrays. Takes an array rather than rest params so
17
20
  * a large segment list can never overflow the call stack via spread. */
18
21
  export function concatBytes(parts) {
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;
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;
29
33
  }
30
34
  /** Join two byte spans — the hot two-operand case of {@link concatBytes},
31
35
  * fused without the array wrapper for the search's inner fuse loop. */
32
36
  export function concat2(a, b) {
33
- const out = new Uint8Array(a.length + b.length);
34
- out.set(a, 0);
35
- out.set(b, a.length);
36
- return out;
37
+ const out = new Uint8Array(a.length + b.length);
38
+ out.set(a, 0);
39
+ out.set(b, a.length);
40
+ return out;
37
41
  }
38
42
  /** Latin-1 view of a byte span — a stable, lossless string key for chart
39
43
  * memoization (every byte 0–255 maps to one code unit). */
40
44
  export function latin1(b) {
41
- let s = "";
42
- for (let k = 0; k < b.length; k++)
43
- s += String.fromCharCode(b[k]);
44
- return s;
45
+ let s = "";
46
+ for (let k = 0; k < b.length; k++) {
47
+ s += String.fromCharCode(b[k]);
48
+ }
49
+ return s;
45
50
  }
46
51
  /** First index ≥ `from` at which `needle` occurs in `hay`, or -1. A short naive
47
52
  * scan — used only to locate a result span inside a learnt framing form. */
48
53
  export function indexOf(hay, needle, from) {
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;
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
+ }
57
62
  }
58
- return -1;
63
+ return i;
64
+ }
65
+ return -1;
59
66
  }
@@ -1,114 +1,114 @@
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
+ 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;
101
101
  }
102
102
  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;
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;
112
112
  }
113
113
  export declare const DEFAULT_CONFIG: MindConfig;
114
114
  export declare function resolveConfig(opts?: Partial<MindConfig>): MindConfig;
@@ -2,95 +2,95 @@
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,
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,
10
51
  alu: {
11
- enabled: true,
12
- tol: 1e-10,
13
- maxIter: 1000,
14
- precision: 6,
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,
15
56
  },
16
57
  geometry: {
17
- maxGroup: 4,
58
+ maxGroup: opts.geometry?.maxGroup ?? DEFAULT_CONFIG.geometry.maxGroup,
18
59
  },
19
60
  alphabet: {
20
- roughness: 0.65,
21
- seedMask: 0xa1fa17,
61
+ roughness: opts.alphabet?.roughness ?? DEFAULT_CONFIG.alphabet.roughness,
62
+ seedMask: opts.alphabet?.seedMask ?? DEFAULT_CONFIG.alphabet.seedMask,
22
63
  },
23
64
  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,
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,
41
94
  },
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,
51
- 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,
56
- },
57
- geometry: {
58
- maxGroup: opts.geometry?.maxGroup ?? DEFAULT_CONFIG.geometry.maxGroup,
59
- },
60
- alphabet: {
61
- roughness: opts.alphabet?.roughness ?? DEFAULT_CONFIG.alphabet.roughness,
62
- seedMask: opts.alphabet?.seedMask ?? DEFAULT_CONFIG.alphabet.seedMask,
63
- },
64
- 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,
94
- },
95
- };
95
+ };
96
96
  }