@hviana/sema 0.1.3 → 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.
- package/dist/example/demo.js +25 -25
- package/dist/example/train_base.d.ts +21 -19
- package/dist/example/train_base.js +1952 -1684
- package/dist/src/alphabet.d.ts +3 -3
- package/dist/src/alphabet.js +27 -24
- package/dist/src/alu/src/alu.d.ts +194 -169
- package/dist/src/alu/src/alu.js +414 -374
- package/dist/src/alu/src/expr.d.ts +43 -36
- package/dist/src/alu/src/expr.js +278 -252
- package/dist/src/alu/src/index.d.ts +98 -9
- package/dist/src/alu/src/index.js +63 -9
- package/dist/src/alu/src/kernel-arith.d.ts +5 -1
- package/dist/src/alu/src/kernel-arith.js +285 -195
- package/dist/src/alu/src/kernel-bits.d.ts +5 -1
- package/dist/src/alu/src/kernel-bits.js +115 -81
- package/dist/src/alu/src/kernel-logic.js +63 -33
- package/dist/src/alu/src/kernel-nd.js +195 -155
- package/dist/src/alu/src/kernel-numeric.d.ts +80 -16
- package/dist/src/alu/src/kernel-numeric.js +331 -259
- package/dist/src/alu/src/operation.d.ts +132 -112
- package/dist/src/alu/src/operation.js +163 -149
- package/dist/src/alu/src/parser.d.ts +175 -168
- package/dist/src/alu/src/parser.js +421 -382
- package/dist/src/alu/src/resonance.d.ts +25 -16
- package/dist/src/alu/src/resonance.js +56 -49
- package/dist/src/alu/src/text.d.ts +7 -3
- package/dist/src/alu/src/text.js +37 -31
- package/dist/src/alu/src/value.d.ts +14 -14
- package/dist/src/alu/src/value.js +160 -150
- package/dist/src/alu/test/alu.test.js +656 -543
- package/dist/src/bytes.d.ts +5 -1
- package/dist/src/bytes.js +40 -33
- package/dist/src/config.d.ts +102 -102
- package/dist/src/config.js +83 -83
- package/dist/src/derive/src/deduction.d.ts +62 -60
- package/dist/src/derive/src/deduction.js +109 -103
- package/dist/src/derive/src/index.d.ts +7 -1
- package/dist/src/derive/src/priority-queue.d.ts +8 -8
- package/dist/src/derive/src/priority-queue.js +61 -57
- package/dist/src/derive/src/rewrite.d.ts +18 -15
- package/dist/src/derive/src/rewrite.js +67 -59
- package/dist/src/derive/src/trie.d.ts +56 -56
- package/dist/src/derive/src/trie.js +179 -175
- package/dist/src/derive/test/derive.test.js +100 -96
- package/dist/src/extension.d.ts +16 -13
- package/dist/src/geometry.d.ts +42 -17
- package/dist/src/geometry.js +266 -235
- package/dist/src/index.d.ts +17 -2
- package/dist/src/index.js +7 -1
- package/dist/src/ingest-cache.d.ts +30 -25
- package/dist/src/ingest-cache.js +127 -108
- package/dist/src/mind/articulation.d.ts +5 -1
- package/dist/src/mind/articulation.js +112 -77
- package/dist/src/mind/attention.d.ts +108 -40
- package/dist/src/mind/attention.js +871 -749
- package/dist/src/mind/canonical.d.ts +19 -4
- package/dist/src/mind/canonical.js +31 -27
- package/dist/src/mind/graph-search.d.ts +225 -201
- package/dist/src/mind/graph-search.js +821 -742
- package/dist/src/mind/index.d.ts +10 -2
- package/dist/src/mind/junction.d.ts +58 -31
- package/dist/src/mind/junction.js +237 -172
- package/dist/src/mind/learning.d.ts +52 -16
- package/dist/src/mind/learning.js +165 -143
- package/dist/src/mind/match.d.ts +69 -20
- package/dist/src/mind/match.js +318 -259
- package/dist/src/mind/mechanisms/alu.js +16 -16
- package/dist/src/mind/mechanisms/cast.d.ts +13 -9
- package/dist/src/mind/mechanisms/cast.js +456 -363
- package/dist/src/mind/mechanisms/confluence.d.ts +12 -8
- package/dist/src/mind/mechanisms/confluence.js +183 -152
- package/dist/src/mind/mechanisms/cover.d.ts +8 -2
- package/dist/src/mind/mechanisms/cover.js +210 -148
- package/dist/src/mind/mechanisms/extraction.d.ts +34 -8
- package/dist/src/mind/mechanisms/extraction.js +288 -234
- package/dist/src/mind/mechanisms/recall.d.ts +10 -6
- package/dist/src/mind/mechanisms/recall.js +185 -126
- package/dist/src/mind/mind.d.ts +154 -129
- package/dist/src/mind/mind.js +288 -258
- package/dist/src/mind/pipeline-mechanism.d.ts +124 -112
- package/dist/src/mind/pipeline-mechanism.js +172 -161
- package/dist/src/mind/pipeline.d.ts +14 -4
- package/dist/src/mind/pipeline.js +189 -125
- package/dist/src/mind/primitives.d.ts +32 -8
- package/dist/src/mind/primitives.js +117 -99
- package/dist/src/mind/rationale.d.ts +98 -86
- package/dist/src/mind/rationale.js +121 -113
- package/dist/src/mind/reasoning.d.ts +13 -2
- package/dist/src/mind/reasoning.js +166 -129
- package/dist/src/mind/recognition.d.ts +4 -1
- package/dist/src/mind/recognition.js +208 -183
- package/dist/src/mind/resonance.d.ts +22 -5
- package/dist/src/mind/resonance.js +0 -0
- package/dist/src/mind/trace.d.ts +25 -6
- package/dist/src/mind/trace.js +58 -50
- package/dist/src/mind/traverse.d.ts +58 -16
- package/dist/src/mind/traverse.js +357 -304
- package/dist/src/mind/types.d.ts +127 -120
- package/dist/src/mind/types.js +69 -60
- package/dist/src/rabitq-hnsw/src/database.d.ts +179 -177
- package/dist/src/rabitq-hnsw/src/database.js +359 -342
- package/dist/src/rabitq-hnsw/src/heap.d.ts +12 -12
- package/dist/src/rabitq-hnsw/src/heap.js +80 -75
- package/dist/src/rabitq-hnsw/src/hnsw.d.ts +103 -103
- package/dist/src/rabitq-hnsw/src/hnsw.js +454 -428
- package/dist/src/rabitq-hnsw/src/index.d.ts +6 -1
- package/dist/src/rabitq-hnsw/src/prng.d.ts +10 -10
- package/dist/src/rabitq-hnsw/src/prng.js +27 -25
- package/dist/src/rabitq-hnsw/src/rabitq.d.ts +69 -69
- package/dist/src/rabitq-hnsw/src/rabitq.js +262 -246
- package/dist/src/rabitq-hnsw/src/store.d.ts +132 -132
- package/dist/src/rabitq-hnsw/src/store.js +843 -752
- package/dist/src/rabitq-hnsw/test/hnsw.test.js +1054 -805
- package/dist/src/sema.d.ts +35 -0
- package/dist/src/sema.js +77 -0
- package/dist/src/store-sqlite.d.ts +166 -144
- package/dist/src/store-sqlite.js +660 -578
- package/dist/src/store.d.ts +630 -593
- package/dist/src/store.js +1581 -1440
- package/dist/src/vec.d.ts +9 -5
- package/dist/src/vec.js +73 -61
- package/package.json +2 -2
- package/src/sema.ts +102 -0
|
@@ -20,143 +20,143 @@ import { DatabaseSync } from "node:sqlite";
|
|
|
20
20
|
* descent landing on the inline BLOB.
|
|
21
21
|
*/
|
|
22
22
|
export interface StoreConfig {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
dim: number;
|
|
24
|
+
m: number;
|
|
25
|
+
efConstruction: number;
|
|
26
|
+
efSearch: number;
|
|
27
|
+
queryBits: number;
|
|
28
|
+
rotationRounds: number;
|
|
29
|
+
seed: number;
|
|
30
|
+
centroid: Float64Array | null;
|
|
31
|
+
codeWords: number;
|
|
32
|
+
paddedDim: number;
|
|
33
33
|
}
|
|
34
34
|
export interface GlobalState {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
entryPoint: number;
|
|
36
|
+
maxLevel: number;
|
|
37
|
+
live: number;
|
|
38
|
+
total: number;
|
|
39
|
+
rng: number;
|
|
40
40
|
}
|
|
41
41
|
/** A node as the graph algorithms need it: code bytes, tombstone, external id. */
|
|
42
42
|
export interface NodeRec {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
code: Uint8Array;
|
|
44
|
+
deleted: number;
|
|
45
|
+
ext: number | null;
|
|
46
46
|
}
|
|
47
47
|
export declare class Store {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
48
|
+
readonly db: DatabaseSync;
|
|
49
|
+
/**
|
|
50
|
+
* Number of row reads served from the database (node and neighbour-list
|
|
51
|
+
* fetches). This counts *storage* accesses only, so it is unaffected by any
|
|
52
|
+
* caching layer above it -- the honest measure of how the engine scales.
|
|
53
|
+
*/
|
|
54
|
+
reads: number;
|
|
55
|
+
private sInsNode;
|
|
56
|
+
private sNode;
|
|
57
|
+
private sIdByExt;
|
|
58
|
+
private sTombstone;
|
|
59
|
+
private sNbrs;
|
|
60
|
+
private sSetNbrs;
|
|
61
|
+
private sState;
|
|
62
|
+
private readonly cacheBudgetBytes;
|
|
63
|
+
/** Whether the shared memory budget is non-zero — consumers that trade RAM
|
|
64
|
+
* for speed (the graph's visited-tag array) key off this so the
|
|
65
|
+
* `cacheSizeMb: 0` flat-memory mode stays exactly flat. */
|
|
66
|
+
get cacheEnabled(): boolean;
|
|
67
|
+
private slab;
|
|
68
|
+
private slabHot;
|
|
69
|
+
private nbrSlab;
|
|
70
|
+
private slabsDerived;
|
|
71
|
+
/**
|
|
72
|
+
* @param dbPath path to the SQLite file (":memory:" for transient).
|
|
73
|
+
* @param cacheSizeMb the ONE memory knob (MiB). It sizes BOTH SQLite's page
|
|
74
|
+
* cache AND the immutable-code LRU above (whose entry-capacity is derived
|
|
75
|
+
* from this budget and the code size — no second knob). Both are pure
|
|
76
|
+
* speed enhancements: correctness and the per-operation storage-read
|
|
77
|
+
* count do not depend on them. Pass 0 to run with essentially no cache,
|
|
78
|
+
* which is how the tests run so a poor access pattern can never hide
|
|
79
|
+
* behind a warm cache.
|
|
80
|
+
*/
|
|
81
|
+
constructor(dbPath: string, cacheSizeMb?: number);
|
|
82
|
+
private tableExists;
|
|
83
|
+
/** (Re)compile the hot statements against the current schema. */
|
|
84
|
+
private prepareAll;
|
|
85
|
+
/** Load the persisted configuration, or null for a fresh database. */
|
|
86
|
+
loadConfig(): StoreConfig | null;
|
|
87
|
+
/** Initialise the meta row for a new database. */
|
|
88
|
+
initConfig(c: StoreConfig): void;
|
|
89
|
+
loadState(): GlobalState;
|
|
90
|
+
saveState(s: GlobalState): void;
|
|
91
|
+
setEfSearch(ef: number): void;
|
|
92
|
+
setQueryBits(bits: number): void;
|
|
93
|
+
resetReads(): void;
|
|
94
|
+
/** Stream every live external id in id order, in bounded-memory batches. */
|
|
95
|
+
liveExts(batch?: number): IterableIterator<number>;
|
|
96
|
+
/** Size the two slabs from the shared memory budget and the actual code
|
|
97
|
+
* size (known on the first record cached): total slots = budget / bytes
|
|
98
|
+
* per slot, the upper-layer slab taking half. A slot is the code bytes
|
|
99
|
+
* plus 17 B of typed-array bookkeeping (key + ext + deleted). */
|
|
100
|
+
private deriveSlabs;
|
|
101
|
+
/** Record a node in the slab cache. Upper-layer nodes (level ≥ 1) go to
|
|
102
|
+
* the pinned section layer-0 traffic never touches; a colliding slot is
|
|
103
|
+
* simply overwritten (direct-mapped eviction — no bookkeeping). */
|
|
104
|
+
private cacheRec;
|
|
105
|
+
/** Insert a node, returning its assigned id (rowid). */
|
|
106
|
+
addNode(ext: number | null, level: number, code: Uint8Array): number;
|
|
107
|
+
/** Fetch a node's code (copied), tombstone flag and external id, or null.
|
|
108
|
+
* Served from the slab cache when present; a miss reads SQLite, counts
|
|
109
|
+
* one `reads` (the cache-independent scalability witness), and caches the
|
|
110
|
+
* result. The cache is a latency layer ONLY — `reads` does not count hits, so
|
|
111
|
+
* the index's storage-read scaling is identical with the cache off. */
|
|
112
|
+
getNode(id: number): NodeRec | null;
|
|
113
|
+
idByExt(ext: number): number | null;
|
|
114
|
+
private readonly batchStmts;
|
|
115
|
+
private static readonly BATCH_MAX;
|
|
116
|
+
private batchStmt;
|
|
117
|
+
/** Fetch several nodes into `out` (skipping ids already present). Serves
|
|
118
|
+
* from the code LRU first; the misses are read with one IN query per
|
|
119
|
+
* chunk. Ids with no row are simply absent from `out`. Each id that
|
|
120
|
+
* reaches SQLite counts one `reads`, exactly like a getNode miss. */
|
|
121
|
+
getNodesInto(ids: number[], out: Map<number, NodeRec>, count?: number): void;
|
|
122
|
+
/** Pre-fill the code and neighbour-list caches with ONE sequential table
|
|
123
|
+
* scan each, up to their existing budget-derived caps. A cold session
|
|
124
|
+
* otherwise warms the caches through hundreds of thousands of RANDOM point
|
|
125
|
+
* reads spread across its first minutes of inserts/queries; a sequential
|
|
126
|
+
* scan streams the same rows at C speed in seconds. A pure latency
|
|
127
|
+
* optimisation with the exact same caps and coherence rules as demand
|
|
128
|
+
* filling — nothing about results, `reads` discipline, or memory ceilings
|
|
129
|
+
* changes. Two passes over `nodes` so the upper-layer pinned section is
|
|
130
|
+
* filled before layer-0 rows compete for the LRU. Returns rows warmed. */
|
|
131
|
+
warmCache(): number;
|
|
132
|
+
tombstone(id: number): void;
|
|
133
|
+
/** A node's neighbour ids at a layer, or null if it has no list there. */
|
|
134
|
+
getNeighbors(node: number, layer: number): Uint32Array | null;
|
|
135
|
+
setNeighbors(node: number, layer: number, ids: number[]): void;
|
|
136
|
+
begin(): void;
|
|
137
|
+
commit(): void;
|
|
138
|
+
rollback(): void;
|
|
139
|
+
/** Encode a neighbour id list to the delta-varint blob format. */
|
|
140
|
+
private encodeNbrs;
|
|
141
|
+
/** Decode a delta-varint neighbour blob into a number[]. */
|
|
142
|
+
private decodeNbrs;
|
|
143
|
+
/** Tombstone-splice compaction. `M`/`Mmax0` cap a rewritten list on upper
|
|
144
|
+
* layers / layer 0. Returns the new global state scalars (internal ids are
|
|
145
|
+
* preserved, so `entry` survives unless it was itself dead). The caller
|
|
146
|
+
* persists state and vacuums. */
|
|
147
|
+
spliceCompact(M: number, Mmax0: number, entry: number): {
|
|
148
|
+
entry: number;
|
|
149
|
+
maxLevel: number;
|
|
150
|
+
live: number;
|
|
151
|
+
};
|
|
152
|
+
/** Stream live external ids with internal id > `after`, in internal-id
|
|
153
|
+
* order, in bounded batches. Internal ids are assigned monotonically and
|
|
154
|
+
* PRESERVED by {@link spliceCompact}, so a caller can use the largest
|
|
155
|
+
* internal id it has seen as a durable incremental watermark. */
|
|
156
|
+
liveExtsSince(after: number, batch?: number): IterableIterator<{
|
|
157
|
+
ext: number;
|
|
158
|
+
internal: number;
|
|
159
|
+
}>;
|
|
160
|
+
vacuum(): void;
|
|
161
|
+
close(): void;
|
|
162
162
|
}
|