@hviana/sema 0.2.6 → 0.2.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 (131) 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 +125 -0
  42. package/dist/src/derive/src/deduction.js +155 -0
  43. package/dist/src/derive/src/index.d.ts +7 -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 +202 -0
  56. package/dist/src/geometry.js +575 -0
  57. package/dist/src/index.d.ts +16 -0
  58. package/dist/src/index.js +18 -0
  59. package/dist/src/ingest-cache.d.ts +41 -0
  60. package/dist/src/ingest-cache.js +161 -0
  61. package/dist/src/mind/articulation.d.ts +6 -0
  62. package/dist/src/mind/articulation.js +99 -0
  63. package/dist/src/mind/attention.d.ts +400 -0
  64. package/dist/src/mind/attention.js +1763 -0
  65. package/dist/src/mind/bridge.d.ts +30 -0
  66. package/dist/src/mind/bridge.js +569 -0
  67. package/dist/src/mind/canonical.d.ts +29 -0
  68. package/dist/src/mind/canonical.js +88 -0
  69. package/dist/src/mind/graph-search.d.ts +285 -0
  70. package/dist/src/mind/graph-search.js +956 -0
  71. package/dist/src/mind/index.d.ts +7 -0
  72. package/dist/src/mind/index.js +5 -0
  73. package/dist/src/mind/junction.d.ts +124 -0
  74. package/dist/src/mind/junction.js +317 -0
  75. package/dist/src/mind/learning.d.ts +47 -0
  76. package/dist/src/mind/learning.js +248 -0
  77. package/dist/src/mind/match.d.ts +126 -0
  78. package/dist/src/mind/match.js +441 -0
  79. package/dist/src/mind/mechanisms/alu.d.ts +4 -0
  80. package/dist/src/mind/mechanisms/alu.js +36 -0
  81. package/dist/src/mind/mechanisms/cast.d.ts +89 -0
  82. package/dist/src/mind/mechanisms/cast.js +716 -0
  83. package/dist/src/mind/mechanisms/confluence.d.ts +24 -0
  84. package/dist/src/mind/mechanisms/confluence.js +225 -0
  85. package/dist/src/mind/mechanisms/cover.d.ts +6 -0
  86. package/dist/src/mind/mechanisms/cover.js +203 -0
  87. package/dist/src/mind/mechanisms/extraction.d.ts +67 -0
  88. package/dist/src/mind/mechanisms/extraction.js +387 -0
  89. package/dist/src/mind/mechanisms/recall.d.ts +13 -0
  90. package/dist/src/mind/mechanisms/recall.js +325 -0
  91. package/dist/src/mind/mind.d.ts +276 -0
  92. package/dist/src/mind/mind.js +572 -0
  93. package/dist/src/mind/pipeline-mechanism.d.ts +142 -0
  94. package/dist/src/mind/pipeline-mechanism.js +213 -0
  95. package/dist/src/mind/pipeline.d.ts +20 -0
  96. package/dist/src/mind/pipeline.js +217 -0
  97. package/dist/src/mind/primitives.d.ts +70 -0
  98. package/dist/src/mind/primitives.js +287 -0
  99. package/dist/src/mind/rationale.d.ts +139 -0
  100. package/dist/src/mind/rationale.js +163 -0
  101. package/dist/src/mind/reasoning.d.ts +34 -0
  102. package/dist/src/mind/reasoning.js +240 -0
  103. package/dist/src/mind/recognition.d.ts +20 -0
  104. package/dist/src/mind/recognition.js +390 -0
  105. package/dist/src/mind/resonance.d.ts +23 -0
  106. package/dist/src/mind/resonance.js +0 -0
  107. package/dist/src/mind/trace.d.ts +15 -0
  108. package/dist/src/mind/trace.js +73 -0
  109. package/dist/src/mind/traverse.d.ts +113 -0
  110. package/dist/src/mind/traverse.js +568 -0
  111. package/dist/src/mind/types.d.ts +289 -0
  112. package/dist/src/mind/types.js +130 -0
  113. package/dist/src/rabitq-ivf/src/database.d.ts +113 -0
  114. package/dist/src/rabitq-ivf/src/database.js +201 -0
  115. package/dist/src/rabitq-ivf/src/index.d.ts +7 -0
  116. package/dist/src/rabitq-ivf/src/index.js +4 -0
  117. package/dist/src/rabitq-ivf/src/ivf.d.ts +200 -0
  118. package/dist/src/rabitq-ivf/src/ivf.js +1165 -0
  119. package/dist/src/rabitq-ivf/src/prng.d.ts +19 -0
  120. package/dist/src/rabitq-ivf/src/prng.js +36 -0
  121. package/dist/src/rabitq-ivf/src/rabitq.d.ts +95 -0
  122. package/dist/src/rabitq-ivf/src/rabitq.js +283 -0
  123. package/dist/src/sema.d.ts +31 -0
  124. package/dist/src/sema.js +63 -0
  125. package/dist/src/store-sqlite.d.ts +184 -0
  126. package/dist/src/store-sqlite.js +942 -0
  127. package/dist/src/store.d.ts +663 -0
  128. package/dist/src/store.js +1618 -0
  129. package/dist/src/vec.d.ts +31 -0
  130. package/dist/src/vec.js +109 -0
  131. package/package.json +1 -1
@@ -0,0 +1,184 @@
1
+ import { AbstractStore, type NodeId, type NodeRec, type Store } from "./store.js";
2
+ import { type StoreConfig } from "./config.js";
3
+ export interface SQliteStoreOptions extends Partial<StoreConfig> {
4
+ path?: string;
5
+ D?: number;
6
+ /** Fold group size used during training — tells indexSubtree how tight the
7
+ * reach-net epsilon should be (1 − 1/(2·maxGroup)). Defaults to the
8
+ * Mind's geometry.maxGroup. */
9
+ maxGroup?: number;
10
+ /** Query-side RaBitQ estimator precision for both vector indices. */
11
+ queryBits?: number;
12
+ }
13
+ export declare class SQliteStore extends AbstractStore implements Store {
14
+ private readonly opts;
15
+ private readonly vectorCacheMb;
16
+ private readonly sqliteCacheMb;
17
+ private readonly vectorSeed;
18
+ private content;
19
+ private halos;
20
+ private sqlite;
21
+ private _inTx;
22
+ /** Bloom filter over every node row's content hash `h`. The dedup probes
23
+ * consult it first: "definitely absent" answers the training hot path's
24
+ * dominant miss case in RAM (profiled: the SQLite probes were 38.7% of
25
+ * ingest wall at 2.9M nodes). INVARIANT: every inserted h is added
26
+ * before the probe that could see it — a false negative would mint a
27
+ * duplicate node and silently break hash-consing. */
28
+ private _bloom;
29
+ /** Dedup probes answered by the filter alone this session (observability). */
30
+ bloomSkips: number;
31
+ private _insertNode;
32
+ private _insertKid;
33
+ private _selContain;
34
+ private _selParents;
35
+ private _selHalo;
36
+ private _upHalo;
37
+ private _selLeaf;
38
+ private _selFlat;
39
+ private _selKids;
40
+ private _selNode;
41
+ private _insertEdge;
42
+ private _selNext;
43
+ private _selPrev;
44
+ private _setMeta;
45
+ private _getMeta;
46
+ private _insCanon;
47
+ private _selCanon;
48
+ private _cntCanon;
49
+ private _selContentFrom;
50
+ private _delMeta;
51
+ private _insSnapshot;
52
+ private _selSnapshot;
53
+ constructor(opts?: SQliteStoreOptions);
54
+ private vectorDbPath;
55
+ private openVectorDB;
56
+ protected _dbOpen(): Promise<void>;
57
+ /** Restore the persisted filter and top up the rows a crash left uncovered
58
+ * (id ≥ stored `upto`); a missing/undersized blob forces a full rebuild.
59
+ * Clean-close sessions restart with a 0-row top-up. */
60
+ private _bloomLoad;
61
+ /** Re-add the hashes of rows with id ≥ `from` (the tail a crash cut off).
62
+ * Re-adding a hash twice only re-sets its bits — never a correctness
63
+ * issue — so overlap with the persisted coverage is harmless. */
64
+ private _bloomTopUp;
65
+ /** Build a fresh filter sized for the current node count from one
66
+ * sequential scan of the h column. Called at open when no usable blob is
67
+ * stored, and again whenever growth saturates the bits-per-key budget. */
68
+ private _bloomRebuild;
69
+ /** Persist the filter with its coverage watermark. Runs inside the
70
+ * caller's transaction when one is open (checkpoint/close both flush
71
+ * first). */
72
+ private _bloomPersist;
73
+ protected _dbClose(): void;
74
+ protected _dbBeginTx(): void;
75
+ protected _dbCommitTx(): void;
76
+ protected _dbInsertNode(id: NodeId, leaf: Uint8Array | null, kids: Uint8Array | null, h: number): void;
77
+ protected _dbGetNode(id: NodeId): NodeRec | null;
78
+ protected _dbFindLeaf(h: number, bytes: Uint8Array): NodeId | null;
79
+ protected _dbFindBranchByLeaf(h: number, bytes: Uint8Array): NodeId | null;
80
+ protected _dbFindBranchByKids(h: number, packed: Uint8Array): NodeId | null;
81
+ protected _dbInsertKid(child: NodeId, parent: NodeId): void;
82
+ protected _dbGetParents(id: NodeId): NodeId[];
83
+ private _selParentsFirst;
84
+ protected _dbGetParentsFirst(id: NodeId, limit: number): NodeId[];
85
+ private _selChain;
86
+ /** {@link Store.chainRun}'s walk as ONE recursive CTE: the whole
87
+ * transparent chain (no edge in or out, exactly one parent) is descended
88
+ * inside SQLite — per-node work is the same three indexed probes as the
89
+ * base class's loop, but without a JS↔SQLite round trip per node, which
90
+ * dominates on the deep single-structure scaffolding this read exists
91
+ * for. */
92
+ protected _chainWalk(id: NodeId, cap: number): NodeId[];
93
+ /** Width of the seq band inside the packed contain rowid: rowid =
94
+ * child·SEQ_SPAN + seq. Page sizes are geometric, so a chain of k live
95
+ * pages needs a base of ≥ 2^k · 4 bytes — seq stays ≤ ~50 for any
96
+ * physically possible list; the append path guards the band anyway. */
97
+ private static readonly SEQ_SPAN;
98
+ private _selContainExists;
99
+ protected _dbContainExists(child: NodeId): boolean;
100
+ private _selContainPages;
101
+ /** The child's page directory — (seq, byte length) per page, O(log fan-in)
102
+ * rows, each read from the cell header without loading the blob. */
103
+ private containPages;
104
+ private _selContainPageSub;
105
+ private _selContainPage;
106
+ private containPage;
107
+ protected _dbGetContainParentsSlice(child: NodeId, offset: number, limit: number): NodeId[];
108
+ private _selContainCount;
109
+ protected _dbGetContainCount(child: NodeId): number;
110
+ protected _dbGetContainParents(child: NodeId): NodeId[];
111
+ private _upsContainPage;
112
+ private _delContainPage;
113
+ protected _dbAppendContain(child: NodeId, parents: NodeId[]): void;
114
+ protected _dbInsertEdge(src: NodeId, dst: NodeId): void;
115
+ protected _dbGetNextEdges(id: NodeId): NodeId[];
116
+ protected _dbGetPrevEdges(id: NodeId): NodeId[];
117
+ private _selNextFirst;
118
+ protected _dbGetNextEdgesFirst(id: NodeId, limit: number): NodeId[];
119
+ private _selPrevFirst;
120
+ protected _dbGetPrevEdgesFirst(id: NodeId, limit: number): NodeId[];
121
+ private _selPrevCount;
122
+ /** {@link Store.prevCount} — one indexed COUNT over idx_edge_dst, never a
123
+ * row materialisation (a common continuation's reverse fan-in is
124
+ * corpus-sized). */
125
+ prevCount(id: NodeId): number;
126
+ private _selSrcExists;
127
+ protected _dbEdgeSrcExists(src: NodeId): boolean;
128
+ protected _dbEdgeDistinctSrcCount(): number;
129
+ protected _dbGetHalo(id: NodeId): {
130
+ vec: Uint8Array;
131
+ mass: number;
132
+ } | null;
133
+ protected _dbUpsertHalo(id: NodeId, encodedVec: Uint8Array, mass: number): void;
134
+ protected _dbGetMeta(key: string): string | null;
135
+ protected _dbSetMeta(key: string, val: string): void;
136
+ protected _dbDeleteMeta(key: string): void;
137
+ canonAdd(h: number, id: number): void;
138
+ canonFind(h: number): number[];
139
+ canonCount(): number;
140
+ eachContent(cb: (id: number, bytes: Uint8Array) => void, fromId?: number): void;
141
+ protected _dbSaveSnapshot(bytes: Uint8Array): void;
142
+ protected _dbLoadSnapshot(): Uint8Array | null;
143
+ protected _vecContentUpsert(entries: Array<{
144
+ id: NodeId;
145
+ vector: Float32Array;
146
+ }>): void;
147
+ protected _vecContentQuery(v: Float32Array, k: number, ef: number): Array<{
148
+ id: number;
149
+ distance: number;
150
+ }>;
151
+ protected _vecContentHas(id: NodeId): boolean;
152
+ protected _vecContentSize(): number;
153
+ protected _vecContentLastReads(): number;
154
+ protected _vecContentPhysicalSize(): number;
155
+ protected _vecContentClusterCount(): number;
156
+ protected _vecContentCompact(): void;
157
+ protected _vecContentDeleteMany(ids: NodeId[]): void;
158
+ protected _vecContentEntriesSince(after: number): IterableIterator<{
159
+ ext: NodeId;
160
+ internal: number;
161
+ }>;
162
+ /** {@link AbstractStore._dbEdgeOrHaloIds} — one C-side scan; UNION dedups
163
+ * and (with the ORDER BY) sorts, so the result is ready for the binary-
164
+ * search membership probes and the ascending-id maintenance walks. */
165
+ protected _dbEdgeOrHaloIds(): NodeId[];
166
+ protected _vecHaloUpsert(entries: Array<{
167
+ id: NodeId;
168
+ vector: Float32Array;
169
+ }>): void;
170
+ protected _vecHaloQuery(v: Float32Array, k: number, ef: number): Array<{
171
+ id: number;
172
+ distance: number;
173
+ }>;
174
+ protected _vecHaloSize(): number;
175
+ protected _vecHaloPhysicalSize(): number;
176
+ protected _vecHaloClusterCount(): number;
177
+ protected _vecHaloCompact(): void;
178
+ /** Pre-fill both vector indices' RAM caches with sequential scans (up to
179
+ * their budget caps) — seconds of streaming instead of the minutes of
180
+ * random point reads a cold training/query session otherwise pays while
181
+ * warming. Optional; call once after open before sustained work.
182
+ * Returns rows warmed. */
183
+ warmVectorCaches(): Promise<number>;
184
+ }