@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
@@ -1,176 +0,0 @@
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 _delMeta;
47
- private _insSnapshot;
48
- private _selSnapshot;
49
- constructor(opts?: SQliteStoreOptions);
50
- private vectorDbPath;
51
- private openVectorDB;
52
- protected _dbOpen(): Promise<void>;
53
- /** Restore the persisted filter and top up the rows a crash left uncovered
54
- * (id ≥ stored `upto`); a missing/undersized blob forces a full rebuild.
55
- * Clean-close sessions restart with a 0-row top-up. */
56
- private _bloomLoad;
57
- /** Re-add the hashes of rows with id ≥ `from` (the tail a crash cut off).
58
- * Re-adding a hash twice only re-sets its bits — never a correctness
59
- * issue — so overlap with the persisted coverage is harmless. */
60
- private _bloomTopUp;
61
- /** Build a fresh filter sized for the current node count from one
62
- * sequential scan of the h column. Called at open when no usable blob is
63
- * stored, and again whenever growth saturates the bits-per-key budget. */
64
- private _bloomRebuild;
65
- /** Persist the filter with its coverage watermark. Runs inside the
66
- * caller's transaction when one is open (checkpoint/close both flush
67
- * first). */
68
- private _bloomPersist;
69
- protected _dbClose(): void;
70
- protected _dbBeginTx(): void;
71
- protected _dbCommitTx(): void;
72
- protected _dbInsertNode(id: NodeId, leaf: Uint8Array | null, kids: Uint8Array | null, h: number): void;
73
- protected _dbGetNode(id: NodeId): NodeRec | null;
74
- protected _dbFindLeaf(h: number, bytes: Uint8Array): NodeId | null;
75
- protected _dbFindBranchByLeaf(h: number, bytes: Uint8Array): NodeId | null;
76
- protected _dbFindBranchByKids(h: number, packed: Uint8Array): NodeId | null;
77
- protected _dbInsertKid(child: NodeId, parent: NodeId): void;
78
- protected _dbGetParents(id: NodeId): NodeId[];
79
- private _selParentsFirst;
80
- protected _dbGetParentsFirst(id: NodeId, limit: number): NodeId[];
81
- private _selChain;
82
- /** {@link Store.chainRun}'s walk as ONE recursive CTE: the whole
83
- * transparent chain (no edge in or out, exactly one parent) is descended
84
- * inside SQLite — per-node work is the same three indexed probes as the
85
- * base class's loop, but without a JS↔SQLite round trip per node, which
86
- * dominates on the deep single-structure scaffolding this read exists
87
- * for. */
88
- protected _chainWalk(id: NodeId, cap: number): NodeId[];
89
- /** Width of the seq band inside the packed contain rowid: rowid =
90
- * child·SEQ_SPAN + seq. Page sizes are geometric, so a chain of k live
91
- * pages needs a base of ≥ 2^k · 4 bytes — seq stays ≤ ~50 for any
92
- * physically possible list; the append path guards the band anyway. */
93
- private static readonly SEQ_SPAN;
94
- private _selContainExists;
95
- protected _dbContainExists(child: NodeId): boolean;
96
- private _selContainPages;
97
- /** The child's page directory — (seq, byte length) per page, O(log fan-in)
98
- * rows, each read from the cell header without loading the blob. */
99
- private containPages;
100
- private _selContainPageSub;
101
- private _selContainPage;
102
- private containPage;
103
- protected _dbGetContainParentsSlice(child: NodeId, offset: number, limit: number): NodeId[];
104
- private _selContainCount;
105
- protected _dbGetContainCount(child: NodeId): number;
106
- protected _dbGetContainParents(child: NodeId): NodeId[];
107
- private _upsContainPage;
108
- private _delContainPage;
109
- protected _dbAppendContain(child: NodeId, parents: NodeId[]): void;
110
- protected _dbInsertEdge(src: NodeId, dst: NodeId): void;
111
- protected _dbGetNextEdges(id: NodeId): NodeId[];
112
- protected _dbGetPrevEdges(id: NodeId): NodeId[];
113
- private _selNextFirst;
114
- protected _dbGetNextEdgesFirst(id: NodeId, limit: number): NodeId[];
115
- private _selPrevFirst;
116
- protected _dbGetPrevEdgesFirst(id: NodeId, limit: number): NodeId[];
117
- private _selPrevCount;
118
- /** {@link Store.prevCount} — one indexed COUNT over idx_edge_dst, never a
119
- * row materialisation (a common continuation's reverse fan-in is
120
- * corpus-sized). */
121
- prevCount(id: NodeId): number;
122
- private _selSrcExists;
123
- protected _dbEdgeSrcExists(src: NodeId): boolean;
124
- protected _dbEdgeDistinctSrcCount(): number;
125
- protected _dbGetHalo(id: NodeId): {
126
- vec: Uint8Array;
127
- mass: number;
128
- } | null;
129
- protected _dbUpsertHalo(id: NodeId, encodedVec: Uint8Array, mass: number): void;
130
- protected _dbGetMeta(key: string): string | null;
131
- protected _dbSetMeta(key: string, val: string): void;
132
- protected _dbDeleteMeta(key: string): void;
133
- protected _dbSaveSnapshot(bytes: Uint8Array): void;
134
- protected _dbLoadSnapshot(): Uint8Array | null;
135
- protected _vecContentUpsert(entries: Array<{
136
- id: NodeId;
137
- vector: Float32Array;
138
- }>): void;
139
- protected _vecContentQuery(v: Float32Array, k: number, ef: number): Array<{
140
- id: number;
141
- distance: number;
142
- }>;
143
- protected _vecContentHas(id: NodeId): boolean;
144
- protected _vecContentSize(): number;
145
- protected _vecContentLastReads(): number;
146
- protected _vecContentPhysicalSize(): number;
147
- protected _vecContentClusterCount(): number;
148
- protected _vecContentCompact(): void;
149
- protected _vecContentDeleteMany(ids: NodeId[]): void;
150
- protected _vecContentEntriesSince(after: number): IterableIterator<{
151
- ext: NodeId;
152
- internal: number;
153
- }>;
154
- /** {@link AbstractStore._dbEdgeOrHaloIds} — one C-side scan; UNION dedups
155
- * and (with the ORDER BY) sorts, so the result is ready for the binary-
156
- * search membership probes and the ascending-id maintenance walks. */
157
- protected _dbEdgeOrHaloIds(): NodeId[];
158
- protected _vecHaloUpsert(entries: Array<{
159
- id: NodeId;
160
- vector: Float32Array;
161
- }>): void;
162
- protected _vecHaloQuery(v: Float32Array, k: number, ef: number): Array<{
163
- id: number;
164
- distance: number;
165
- }>;
166
- protected _vecHaloSize(): number;
167
- protected _vecHaloPhysicalSize(): number;
168
- protected _vecHaloClusterCount(): number;
169
- protected _vecHaloCompact(): void;
170
- /** Pre-fill both vector indices' RAM caches with sequential scans (up to
171
- * their budget caps) — seconds of streaming instead of the minutes of
172
- * random point reads a cold training/query session otherwise pays while
173
- * warming. Optional; call once after open before sustained work.
174
- * Returns rows warmed. */
175
- warmVectorCaches(): Promise<number>;
176
- }