@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,663 @@
1
+ import { Vec } from "./vec.js";
2
+ import { type StoreConfig } from "./config.js";
3
+ /** A node id: a dense, non-negative integer assigned in creation order. */
4
+ export type NodeId = number;
5
+ /** A node in the graph. Exactly one of `leaf` / `kids` is set. */
6
+ export interface NodeRec {
7
+ id: NodeId;
8
+ leaf: Uint8Array | null;
9
+ kids: NodeId[] | null;
10
+ }
11
+ /** A soft-resonance hit. */
12
+ export interface Hit {
13
+ id: NodeId;
14
+ /** Estimated cosine (1 − RaBitQ estimated distance) — an APPROXIMATION,
15
+ * never an exact rerank. Identity decisions must use content-addressed
16
+ * resolve(), never `score >= 1`. */
17
+ score: number;
18
+ /** This node's halo, when a producer chooses to attach it. NOT populated
19
+ * by {@link Store.resonate}/{@link Store.resonateHalo}: no consumer read
20
+ * it there, and eagerly fetching k halo rows per query was pure waste.
21
+ * Call {@link Store.halo} on the hits that actually need it. */
22
+ halo?: Vec;
23
+ }
24
+ /** Eviction strategy for a {@link BoundedMap}.
25
+ *
26
+ * - `"lru"`: evict the least-recently-used entry. Best when every entry
27
+ * saves roughly the same work (dedup, leaf vectors, node records).
28
+ * - `"smallest"`: among the oldest few LRU candidates, evict the smallest.
29
+ * This protects expensive-to-reconstruct entries (large branches) at the
30
+ * expense of cheap ones (small leaves) — useful for reconstruction caches
31
+ * where rebuild cost varies by orders of magnitude. */
32
+ export type Evict = "lru" | "smallest";
33
+ /** Bounded map with LRU eviction and byte accounting. On get the entry
34
+ * moves to the most-recent end; on set the least-recently-used entries are
35
+ * evicted until total bytes ≤ `maxBytes`. The optional `sizeOf` callback
36
+ * measures each value in bytes (defaults to 1, so `maxBytes` = max entries
37
+ * for uniform caches). A miss only costs a little extra work later, never
38
+ * correctness. */
39
+ export declare class BoundedMap<K, V> {
40
+ readonly maxBytes: number;
41
+ private readonly sizeOf;
42
+ private readonly evict;
43
+ private m;
44
+ private _bytes;
45
+ private _cursor;
46
+ private _candidates;
47
+ constructor(maxBytes: number, sizeOf?: (v: V) => number, evict?: Evict);
48
+ /** Next key in insertion (≈ LRU) order, resuming where the last call left
49
+ * off; wraps to the front when exhausted. Undefined only when empty. */
50
+ private nextOldest;
51
+ get(k: K): V | undefined;
52
+ /** Membership without touching LRU order — a pure peek, for callers that only
53
+ * need "is this key present?" and must not promote it to most-recent. */
54
+ has(k: K): boolean;
55
+ set(k: K, v: V): void;
56
+ get size(): number;
57
+ get bytes(): number;
58
+ /** Remove one entry (point invalidation), with byte accounting. */
59
+ delete(k: K): void;
60
+ /** Drop every entry (bulk invalidation) — O(1) amortised via fresh maps. */
61
+ clear(): void;
62
+ }
63
+ export interface Store {
64
+ readonly D: number;
65
+ /** Insert a leaf, returning its content id. Idempotent. */
66
+ putLeaf(bytes: Uint8Array, gist: Vec): Promise<NodeId>;
67
+ /** Insert a branch over child ids, returning its content id. Idempotent. */
68
+ putBranch(kids: NodeId[], gist: Vec): Promise<NodeId>;
69
+ /** Whether a node with this id already exists. O(1). */
70
+ has(id: NodeId): boolean;
71
+ /** The node record, or null. */
72
+ get(id: NodeId): NodeRec | null;
73
+ /** The bytes a node spans, reconstructed by traversal (cached). */
74
+ bytes(id: NodeId): Uint8Array;
75
+ /** First `maxLen` bytes of a node, stopping early — far cheaper than
76
+ * `bytes()` for large branches when only a prefix is needed. */
77
+ bytesPrefix(id: NodeId, maxLen: number): Uint8Array;
78
+ /** The CONTENT LENGTH of a node in bytes — under the linear river fold
79
+ * this IS the node's gist magnitude, squared: seat permutations
80
+ * decorrelate siblings, so ‖gist‖ = √(content bytes) up to decorrelation
81
+ * noise. The magnitude is therefore never persisted beside the vector
82
+ * (that would duplicate what the content already determines; the ANN
83
+ * index keeps unit directions), it is READ here in O(1) amortized — the
84
+ * store-side half of angle+magnitude semantics. Mechanisms use it to
85
+ * convert a scale-free cosine into the absolute quantities the linear
86
+ * geometry carries: shared bytes ≈ cos·√(lenA·lenB), fraction of A
87
+ * explained ≈ cos·√(lenB/lenA). `cap`, when given, SATURATES the walk:
88
+ * the return value is exact below the cap and merely ≥ cap otherwise —
89
+ * for decisions that stop caring past a bound (a fraction that caps at 1,
90
+ * a weight that is sub-noise beyond a ratio), so one huge conversation
91
+ * root never costs a full subtree walk. Only complete walks are
92
+ * memoized. */
93
+ contentLen(id: NodeId, cap?: number): number;
94
+ findLeaf(bytes: Uint8Array): NodeId | null;
95
+ findBranch(kids: NodeId[]): NodeId | null;
96
+ /** The branch nodes that list `id` among their children — the reverse of
97
+ * `get(id).kids`. Lets the structural DAG be climbed upward, from a
98
+ * recognised fragment to the larger learned forms that contain it. */
99
+ parents(id: NodeId): NodeId[];
100
+ /** The first `limit` structural parents of `id` — the CAPPED read for the
101
+ * climb. A heavily shared subtree's parent set grows with the corpus;
102
+ * reading `bound + 1` decides "hub or not" exactly (a result of length
103
+ * bound + 1 means MORE than bound) while the read stays bounded by the
104
+ * bound, never by the fan-in. */
105
+ parentsFirst(id: NodeId, limit: number): NodeId[];
106
+ /** Whether `id` has ANY structural parent — one LIMITed point probe. */
107
+ hasParents(id: NodeId): boolean;
108
+ /** The TRANSPARENT CHAIN from `id` upward: `run[0] === id`, and while the
109
+ * current node is transparent — no continuation edge in or out and exactly
110
+ * ONE structural parent — the run steps to that parent. The last element
111
+ * is the first NON-transparent ancestor (or a parentless top). Transparent
112
+ * nodes are invisible to the edge climb (they contribute no roots, no
113
+ * contexts and no lateral branching), so a climber may hop a whole run in
114
+ * one read where a node-at-a-time ascent pays three probes per node — the
115
+ * dominant cost of climbing deep single-structure scaffolding. Results
116
+ * are cached for the store's LIFETIME (reads are pure between writes) and
117
+ * the cache is dropped whenever a write could break transparency: a node
118
+ * gaining a structural parent (fresh mint) or a continuation edge (link).
119
+ * The run may be truncated at an internal safety depth; a truncated run's
120
+ * last element is then still transparent, and a climber that treats the
121
+ * terminal generically simply continues from it — semantics never depend
122
+ * on completeness. */
123
+ chainRun(id: NodeId): readonly NodeId[];
124
+ /** Record a CONTAINMENT edge: `parent`'s byte content contains `child`'s,
125
+ * even though `child` is not among `parent`'s kids (a sub-span flat branch
126
+ * inside a leaf-parent chunk). Kept apart from {@link parents} — the
127
+ * structural climb is untouched; {@link containers} serves the climbing
128
+ * surface of orphan flat branches durably, where a session-local side
129
+ * table would be lost on restart or an ingest-cache replay. Idempotent. */
130
+ addContainer(child: NodeId, parent: NodeId): void;
131
+ /** The chunks recorded by {@link addContainer} as containing `child`. */
132
+ containers(child: NodeId): NodeId[];
133
+ /** Whether `child` has ANY containment parent — an EXISTS probe that never
134
+ * unpacks the (occurrence-proportional) packed parents blob. */
135
+ hasContainers(child: NodeId): boolean;
136
+ /** A PAGE of containment parents — `limit` entries starting at `offset`
137
+ * (the buffered adds follow the stored ones), so a consumer can STREAM a
138
+ * common window's corpus-sized parent list and stop the moment its
139
+ * question is decided, with per-page work bounded by `limit`. */
140
+ containersSlice(child: NodeId, offset: number, limit: number): NodeId[];
141
+ nodeCount(): number;
142
+ /** The k nodes whose gist resonates most with v. `exhaustive` widens the
143
+ * IVF probe to every cluster (see {@link AbstractStore.efFor}'s doc) —
144
+ * for refusal-path-only callers where an approximate top-√C-clusters
145
+ * search is not the same discriminator as the caller's own byte-exact
146
+ * verification (the substitution bridge's proposal channel): a rarer
147
+ * paraphrase can score lower than hundreds of unrelated hits by pure
148
+ * fold-geometry structural distance (a middle-of-string mismatch
149
+ * perturbs the tree hash far more than a tail mismatch of the same
150
+ * byte length) and so never even reach a probed cluster, no matter how
151
+ * large k is — k only reorders WITHIN the clusters already probed. */
152
+ resonate(v: Vec, k: number, exhaustive?: boolean): Promise<Hit[]>;
153
+ /** Mark a node as a RESONANCE TARGET — promote its gist into the content
154
+ * index so {@link resonate} can find it. A node's gist is captured at intern
155
+ * but indexed LAZILY (only targets are indexed; the ~99.5% intermediate DAG
156
+ * is not — that is the store's compression). A node becomes a target
157
+ * implicitly via {@link link}/{@link pourHalo}; this is the EXPLICIT hook for
158
+ * the one target those do not cover — a DEPOSIT ROOT, the node `express`,
159
+ * `bridge`, and whole-query recall resonate the input to. Idempotent; a
160
+ * no-op once a node is indexed or if its captured gist has been evicted. */
161
+ indexTarget(id: NodeId): void;
162
+ /** Remove content-index entries for nodes that are structurally isolated
163
+ * (fewer than `minParents` structural parents) and are not roots of any
164
+ * experience (no edges, no halo). These nodes are unique to one tree and
165
+ * bridge nothing between experiences — their index slots are wasted.
166
+ *
167
+ * This is a POST-HOC batch operation, not on the training hot path. Run it
168
+ * at checkpoints or after training to reclaim index space. The underlying
169
+ * vector DB is compacted after deletion to physically free the space.
170
+ *
171
+ * INCREMENTAL: keep decisions are monotone (parents, edges and halos only
172
+ * ever grow), so entries examined by a previous pass are settled; each
173
+ * pass scans only entries indexed since the last one (a durable watermark
174
+ * over the index's monotone internal ids), making the checkpoint-cadence
175
+ * call cheap on a large trained store.
176
+ *
177
+ * @param minParents keep only nodes with ≥ this many structural parents
178
+ * (default 2 — keep nodes that bridge ≥2 experiences)
179
+ * @returns number of entries removed */
180
+ compactContentIndex(minParents?: number): Promise<number>;
181
+ /** Re-index structurally-important nodes whose gists were evicted from the
182
+ * pending cache before they could be indexed — the inverse of {@link
183
+ * compactContentIndex}. Walks the edge/halo-bearing id set (a repairable
184
+ * node must carry edges or a halo, so that set IS the candidate set —
185
+ * corpus-of-experiences-sized, not node-count-sized); for each candidate
186
+ * that (a) has ≥ `minParents` structural parents and (b) is NOT already
187
+ * in the content index, regenerates its gist via `regenerateGist` and adds
188
+ * it. Intended as a post-training batch operation, not on the hot path.
189
+ *
190
+ * `regenerateGist` receives a node id and must return its perceived gist
191
+ * vector (or `null` to skip). The store has no access to the
192
+ * {@link Space}/{@link Alphabet} needed for perception — the caller (the
193
+ * {@link Mind}) wires those in.
194
+ *
195
+ * @param regenerateGist async callback that regenerates a node's gist
196
+ * @param minParents only repair nodes with ≥ this many parents
197
+ * (default 2 — structural bridges)
198
+ * @returns number of nodes added to the index */
199
+ repairContentIndex(regenerateGist: (id: NodeId) => Promise<Vec | null>, minParents?: number): Promise<number>;
200
+ /** Learn that `to` follows `from`. Idempotent. */
201
+ link(from: NodeId, to: NodeId): Promise<void>;
202
+ /** What follows `id` (in insertion order). */
203
+ next(id: NodeId): NodeId[];
204
+ /** Whether ANY edge leaves `id` — the EXISTENCE probe for the forward
205
+ * relation. Decision points that only ask "does this lead anywhere?"
206
+ * must use this instead of materialising {@link next} (a context's edge
207
+ * list is a range read; a hub's is large) — the same
208
+ * count-instead-of-materialise principle {@link prevCount} serves for the
209
+ * reverse relation. One indexed point probe. */
210
+ hasNext(id: NodeId): boolean;
211
+ /** What `id` follows (for reverse recall). */
212
+ prev(id: NodeId): NodeId[];
213
+ /** The first `limit` continuations of `id`, in the SAME order {@link next}
214
+ * returns (insertion order) — the CAPPED read for consumers bounded by the
215
+ * hub convention. A LIMITed statement, never a full materialisation: no
216
+ * read through this may grow with the corpus. */
217
+ nextFirst(id: NodeId, limit: number): NodeId[];
218
+ /** The first `limit` predecessors of `id`, in the SAME order {@link prev}
219
+ * returns (NEWEST-first — prev is seq-descending; see the adapter) — the
220
+ * capped read for reverse fan-ins, which are corpus-sized on a common
221
+ * continuation. */
222
+ prevFirst(id: NodeId, limit: number): NodeId[];
223
+ /** How many nodes `id` follows — the reverse-edge SUPPORT count. Decision
224
+ * points that only weigh evidence (chooseNext) must use this instead of
225
+ * materialising {@link prev}, whose list is corpus-sized for a common
226
+ * continuation ("Yes."). One indexed COUNT, never a row materialisation. */
227
+ prevCount(id: NodeId): number;
228
+ /** How many DISTINCT nodes bear a continuation edge — the number of learnt
229
+ * contexts (the document count for inverse-document-frequency weighting in
230
+ * the consensus climb). O(1) from an index; a coarse count is fine. */
231
+ edgeSourceCount(): number;
232
+ /** Pour a partner's signature into a node's halo. */
233
+ pourHalo(id: NodeId, add: Vec): Promise<void>;
234
+ /** Nodes whose halo resonates with `v` (the concept's siblings). */
235
+ resonateHalo(v: Vec, k: number): Promise<Hit[]>;
236
+ /** A node's halo, or null if it has none / too little mass. */
237
+ halo(id: NodeId): Vec | null;
238
+ /** Whether {@link halo} would return non-null — the EXISTENCE probe.
239
+ * {@link halo} decodes and normalizes the full D-element quantized row on
240
+ * every call; existence-only consumers (recognition's admission predicate,
241
+ * the search's fuse guard) must ask this instead: one row read, a mass
242
+ * compare, no decode. */
243
+ hasHalo(id: NodeId): boolean;
244
+ /** How many episode signatures were poured into `id`'s halo — the DIRECT
245
+ * measure of distributional evidence (each training pair pours once, so
246
+ * repetition counts, unlike {@link prevCount}, which counts DISTINCT
247
+ * contexts). Consulted at disambiguation decision points as the tie-break
248
+ * behind distinct-context support: diversity of evidence outranks sheer
249
+ * repetition, but repetition outranks insertion-order accident. 0 when
250
+ * the node has no halo row. */
251
+ haloMass(id: NodeId): number;
252
+ /** Record that node `id`'s canonical key hashes to `h`. Idempotent. */
253
+ canonAdd?(h: number, id: NodeId): void;
254
+ /** All candidate node ids whose canonical key hashes to `h` (collisions
255
+ * included — the caller verifies). */
256
+ canonFind?(h: number): NodeId[];
257
+ /** Number of (h, id) rows in the canon index — 0 means never built. */
258
+ canonCount?(): number;
259
+ /** Visit every content-bearing node (flat branch: `leaf` present, no
260
+ * kids) — the population a canonical index is built over. `fromId`
261
+ * restricts the scan to ids ≥ fromId, so an index refresh after further
262
+ * training only visits the new rows. */
263
+ eachContent?(cb: (id: NodeId, bytes: Uint8Array) => void, fromId?: NodeId): void;
264
+ size(): Promise<number>;
265
+ saveSnapshot(bytes: Uint8Array): Promise<void>;
266
+ loadSnapshot(): Promise<Uint8Array | null>;
267
+ /** Free-form provenance metadata (e.g. training dataset name). */
268
+ setMeta(key: string, val: string): Promise<void>;
269
+ getMeta(key: string): Promise<string | null>;
270
+ deleteMeta(key: string): Promise<void>;
271
+ /** Commit any deferred writes — makes metadata, edges, and node writes
272
+ * durable immediately. Safe to call frequently; a no-op if nothing is
273
+ * pending. */
274
+ commit(): void;
275
+ close(): Promise<void>;
276
+ }
277
+ /** The implicit kid list of a flat branch — the inverse of
278
+ * {@link flatKidsBytes}. */
279
+ export declare function flatBytesKids(bytes: Uint8Array): NodeId[];
280
+ /** Pack a child-id list as little-endian int32s — 4 bytes per child, far more
281
+ * compact than a space-joined decimal string and trivial to read back. */
282
+ export declare function packKids(kids: NodeId[]): Uint8Array;
283
+ export declare function unpackKids(blob: Uint8Array): NodeId[];
284
+ /**
285
+ * Template-method base class that contains ALL domain logic for the content-
286
+ * addressed DAG store — caching, dedup/merge decisions, structural-compaction
287
+ * geometric halo scheduling, buffer management. A concrete persistence adapter
288
+ * (e.g. {@link SQliteStore}) extends it and implements only the ~35 one-liner
289
+ * protected abstract methods that talk to the actual storage backend.
290
+ */
291
+ export declare abstract class AbstractStore implements Store {
292
+ /** Open the storage backend. Must set `this._nextId`, `this._D`, and
293
+ * `this._maxGroup` from the stored state (or defaults for a fresh store). */
294
+ protected abstract _dbOpen(): Promise<void>;
295
+ /** Close the storage backend and release all resources. */
296
+ protected abstract _dbClose(): void;
297
+ protected abstract _dbBeginTx(): void;
298
+ protected abstract _dbCommitTx(): void;
299
+ protected abstract _dbInsertNode(id: NodeId, leaf: Uint8Array | null, kids: Uint8Array | null, h: number): void;
300
+ protected abstract _dbGetNode(id: NodeId): NodeRec | null;
301
+ protected abstract _dbFindLeaf(h: number, bytes: Uint8Array): NodeId | null;
302
+ protected abstract _dbFindBranchByLeaf(h: number, bytes: Uint8Array): NodeId | null;
303
+ protected abstract _dbFindBranchByKids(h: number, packed: Uint8Array): NodeId | null;
304
+ protected abstract _dbInsertKid(child: NodeId, parent: NodeId): void;
305
+ protected abstract _dbGetParents(id: NodeId): NodeId[];
306
+ /** LIMITed variant of the parent read — same statement, `LIMIT ?`. Must
307
+ * NOT be implemented by materialising and slicing. */
308
+ protected abstract _dbGetParentsFirst(id: NodeId, limit: number): NodeId[];
309
+ protected abstract _dbGetContainParents(child: NodeId): NodeId[];
310
+ /** Whether a containment row exists for `child` — no blob unpack. */
311
+ protected abstract _dbContainExists(child: NodeId): boolean;
312
+ /** A page of stored containment parents — partial blob unpack. */
313
+ protected abstract _dbGetContainParentsSlice(child: NodeId, offset: number, limit: number): NodeId[];
314
+ /** The stored containment-parent COUNT — blob length / 4, no unpack. */
315
+ protected abstract _dbGetContainCount(child: NodeId): number;
316
+ /** Append containment parents for `child`. MUST NOT re-write the child's
317
+ * whole stored list per call — a hot child's fan-in is corpus-sized, and a
318
+ * full read-modify-write per flush is quadratic over training. Durable
319
+ * dedup may be DEFERRED (e.g. to a geometric merge schedule); readers
320
+ * dedup, so transient duplicates only cost bytes, never correctness. */
321
+ protected abstract _dbAppendContain(child: NodeId, parents: NodeId[]): void;
322
+ protected abstract _dbInsertEdge(src: NodeId, dst: NodeId): void;
323
+ protected abstract _dbGetNextEdges(id: NodeId): NodeId[];
324
+ protected abstract _dbGetPrevEdges(id: NodeId): NodeId[];
325
+ /** LIMITed variants of the two edge reads — same ORDER BY, `LIMIT ?`.
326
+ * These exist so a capped consumer's cost is bounded by the cap, not by
327
+ * the fan-out; an adapter must NOT implement them by materialising and
328
+ * slicing. */
329
+ protected abstract _dbGetNextEdgesFirst(id: NodeId, limit: number): NodeId[];
330
+ protected abstract _dbGetPrevEdgesFirst(id: NodeId, limit: number): NodeId[];
331
+ /** Whether ANY edge already leaves `src` — one indexed point probe, used to
332
+ * maintain the distinct-source count incrementally. */
333
+ protected abstract _dbEdgeSrcExists(src: NodeId): boolean;
334
+ protected abstract _dbEdgeDistinctSrcCount(): number;
335
+ protected abstract _dbGetHalo(id: NodeId): {
336
+ vec: Uint8Array;
337
+ mass: number;
338
+ } | null;
339
+ protected abstract _dbUpsertHalo(id: NodeId, encodedVec: Uint8Array, mass: number): void;
340
+ protected abstract _dbGetMeta(key: string): string | null;
341
+ protected abstract _dbSetMeta(key: string, val: string): void;
342
+ protected abstract _dbDeleteMeta(key: string): void;
343
+ protected abstract _dbSaveSnapshot(bytes: Uint8Array): void;
344
+ protected abstract _dbLoadSnapshot(): Uint8Array | null;
345
+ protected abstract _vecContentUpsert(entries: Array<{
346
+ id: NodeId;
347
+ vector: Float32Array;
348
+ }>): void;
349
+ protected abstract _vecContentQuery(v: Float32Array, k: number, ef: number): Array<{
350
+ id: number;
351
+ distance: number;
352
+ }>;
353
+ /** Whether `id` is already a live entry of the content index — one point
354
+ * query, used to recognise durably-indexed nodes across sessions (the
355
+ * in-memory `_indexedIds` cache starts empty on every open). */
356
+ protected abstract _vecContentHas(id: NodeId): boolean;
357
+ protected abstract _vecContentSize(): number;
358
+ protected abstract _vecContentLastReads(): number;
359
+ protected abstract _vecContentPhysicalSize(): number;
360
+ protected abstract _vecContentClusterCount(): number;
361
+ protected abstract _vecContentCompact(): void;
362
+ /** Live content-index entries whose INTERNAL id is > `after`, as
363
+ * {ext, internal} pairs in internal-id order. Internal ids are monotone
364
+ * at insert and preserved by the index's tombstone-splice compaction, so
365
+ * the largest internal id a scan has seen is a durable watermark for
366
+ * incremental maintenance ({@link compactContentIndex}). */
367
+ protected abstract _vecContentEntriesSince(after: number): IterableIterator<{
368
+ ext: NodeId;
369
+ internal: number;
370
+ }>;
371
+ /** Every node id that carries a continuation edge (as source OR target) or
372
+ * a halo row — the RESONANCE-TARGET id set, sorted ascending and deduped.
373
+ * This is the exact keep/repair criterion of index maintenance; driving
374
+ * the maintenance loops from this (corpus-of-experiences-sized) set
375
+ * instead of probing per node turned repair from an every-node walk into
376
+ * a candidates-only walk. */
377
+ protected abstract _dbEdgeOrHaloIds(): NodeId[];
378
+ /** Remove a batch of entries from the content index by external id, under
379
+ * ONE storage transaction (a tombstone per implicit transaction is one WAL
380
+ * commit per id — the dominant cost of a bulk prune). Idempotent per id —
381
+ * already-deleted or non-existent ids are skipped. */
382
+ protected abstract _vecContentDeleteMany(ids: NodeId[]): void;
383
+ protected abstract _vecHaloUpsert(entries: Array<{
384
+ id: NodeId;
385
+ vector: Float32Array;
386
+ }>): void;
387
+ protected abstract _vecHaloQuery(v: Float32Array, k: number, ef: number): Array<{
388
+ id: number;
389
+ distance: number;
390
+ }>;
391
+ /** Live (non-tombstoned) entry count of the halo index — the denominator
392
+ * the tombstone-ratio compaction trigger compares physical size against. */
393
+ protected abstract _vecHaloSize(): number;
394
+ protected abstract _vecHaloPhysicalSize(): number;
395
+ protected abstract _vecHaloClusterCount(): number;
396
+ protected abstract _vecHaloCompact(): void;
397
+ /** Derived query breadth for a partitioned index of C clusters: probe √C
398
+ * of them (the same √-of-the-population convention as the hub bound √N).
399
+ * The IVF maps ef → nprobe as ceil(ef/4), so ef = 4·⌈√C⌉ probes exactly
400
+ * ⌈√C⌉ clusters. A FIXED efSearch stops scaling the moment the
401
+ * collection outgrows it: at 4,270 clusters the default 64 probed 16
402
+ * clusters (0.4%), and an exact stored match of a query routinely sat in
403
+ * an unprobed cluster — recall silently degraded as the store grew. The
404
+ * configured efSearch remains the floor for small collections. */
405
+ protected efFor(clusterCount: number): number;
406
+ protected _D: number;
407
+ protected _maxGroup: number;
408
+ protected readonly minHaloMass: number;
409
+ protected readonly efSearch: number;
410
+ protected readonly overfetch: number;
411
+ protected readonly batchSize: number;
412
+ protected readonly compactEveryNWrites: number;
413
+ /** Branch node ids are a dense, monotonically-increasing integer sequence
414
+ * (0,1,2,…). Single-byte leaves occupy the implicit negative range −256…−1.
415
+ * They are NEVER deleted, so the count of minted branch ids IS the next id —
416
+ * which doubles as the branch-node count and lets has() be an O(1) check.
417
+ * Set by `_dbOpen()` from the stored node count; incremented by `mintId()`. */
418
+ protected _nextId: number;
419
+ protected _writtenSinceCompact: number;
420
+ protected closed: boolean;
421
+ /** Lifecycle guard — resolved once `_dbOpen()` completes. */
422
+ protected _ready: Promise<void> | null;
423
+ /** Exact-content dedup: content-key → node id. Intrinsic compression. */
424
+ protected readonly _leafKey: BoundedMap<string, NodeId>;
425
+ protected readonly _branchKey: BoundedMap<string, NodeId>;
426
+ /** Reconstructed-bytes read cache (regenerable), keyed by node id. */
427
+ protected readonly _bytesCache: BoundedMap<NodeId, Uint8Array>;
428
+ /** contentLen memo — content is immutable, so entries never invalidate. */
429
+ protected readonly _lenCache: BoundedMap<NodeId, number>;
430
+ /** Node-record cache — avoids repeated persistence queries for shared DAG
431
+ * nodes. Each record is small (a few ints + short leaf buffer). */
432
+ protected readonly _recCache: BoundedMap<NodeId, NodeRec>;
433
+ /** Captured-but-not-yet-indexed gists. Sized in bytes (each is D·4); a deposit
434
+ * links/pours a node right after interning it, so the working set is one
435
+ * deposit's nodes — a small budget captures ~all of it, and an eviction only
436
+ * means that node is reached by the DAG climb instead of by direct
437
+ * resonance. */
438
+ protected _pendingGist: BoundedMap<NodeId, Vec>;
439
+ /** EXACT halo accumulators for the session's live pours: full-precision in
440
+ * memory, 2-bit on disk, so within-session accumulate-then-compare never
441
+ * round-trips through the quantizer. Regenerable — a miss reads the durable
442
+ * 2-bit row. */
443
+ protected _haloExact: BoundedMap<NodeId, Vec>;
444
+ /** NORMALIZED halo read cache — the decoded, normalized vector {@link halo}
445
+ * returns, cached by id so repeat reads skip the per-call 2-bit decode and
446
+ * normalize of a full D-element row (measured on a trained store: ~15K
447
+ * halo() calls per deep query over ~50 distinct ids — all but the first
448
+ * per id pure re-decode). Point-invalidated by {@link pourHalo}, the one
449
+ * halo mutation site. Callers receive a COPY, so the cached vector is
450
+ * never aliased. Regenerable — a miss re-decodes the durable row. */
451
+ protected _haloNorm: BoundedMap<NodeId, Vec>;
452
+ /** Interiors deliberately SKIPPED by indexSubtree (unique nodes with 1 parent
453
+ * that bridge nothing). Remembered so subsequent visits prune the subtree
454
+ * without re-checking parent count. LRU-bounded: an evicted entry is
455
+ * re-checked on next visit — if it gained parents in the meantime, it will
456
+ * be promoted to the index. */
457
+ protected _coveredIds: BoundedMap<NodeId, true>;
458
+ /** Live content-index id set, LRU-bounded so a massive ingest never leaks
459
+ * memory; an evicted entry is still indexed (the row is durable), so the
460
+ * only cost of an eviction is a duplicate index probe on next visit. */
461
+ protected _indexedIds: BoundedMap<NodeId, true>;
462
+ /** ANN read cache for {@link resonate} — keyed by vecKey(v) + ":" + k;
463
+ * lazily initialised, dropped on any index mutation. */
464
+ protected _resonateCache: Map<string, Hit[]> | null;
465
+ /** ANN read cache for {@link resonateHalo} — same scheme. */
466
+ protected _resonateHaloCache: Map<string, Hit[]> | null;
467
+ /** Content (gist) index write buffer. */
468
+ protected _contentBuffer: Array<{
469
+ id: NodeId;
470
+ vector: Float32Array;
471
+ }>;
472
+ /** Halo index write buffer — keyed by id so repeats within a batch coalesce. */
473
+ protected _haloBuffer: Map<number, Float32Array<ArrayBufferLike>>;
474
+ /** Containment write buffer: child → new parents, merged on flush cadence. */
475
+ protected _containBuf: Map<number, Set<number>>;
476
+ /** Dedup-target candidates still in the write buffer (keyed by id). Only
477
+ * roots that have gained an edge/halo are targets; a fresh intermediate
478
+ * branch is never folded onto. */
479
+ protected _nearDedupBuf: Map<number, Float32Array<ArrayBufferLike>>;
480
+ /** Ids currently in `_contentBuffer` (not yet flushed) — O(1) membership. */
481
+ protected _bufferedIds: Set<number>;
482
+ /** {@link Store.chainRun} results, valid for the store's lifetime BETWEEN
483
+ * writes: a chain is a pure function of the kid and edge tables, so any
484
+ * write that could break a node's transparency (a fresh mint inserting kid
485
+ * rows, a link inserting an edge) drops the whole cache — see the two
486
+ * invalidation sites. Regenerable; a miss re-walks. */
487
+ protected _chainMemo: BoundedMap<NodeId, NodeId[]>;
488
+ /** Distinct edge-source count — the store's DOCUMENT COUNT (how many
489
+ * learnt contexts predict a continuation), the N of every
490
+ * inverse-document-frequency read. −1 until first asked for; from then
491
+ * on maintained INCREMENTALLY by {@link link} (edges are never deleted),
492
+ * so a read is O(1) — never a table scan on the recall path. */
493
+ protected _edgeSrcCount: number;
494
+ constructor(config: StoreConfig, D: number, maxGroup: number);
495
+ get D(): number;
496
+ /** Await the async initialisation performed by the concrete constructor. */
497
+ protected _ensureReady(): Promise<void>;
498
+ has(id: NodeId): boolean;
499
+ protected mintId(): NodeId;
500
+ nodeCount(): number;
501
+ size(): Promise<number>;
502
+ get(id: NodeId): NodeRec | null;
503
+ /** Reconstruct the bytes a node spans by traversing the DAG bottom-up.
504
+ * Iterative post-order on an explicit stack — the call stack never sees the
505
+ * tree depth, so even an adversarial chain of nodes stays safe. */
506
+ /** How many reads hit a MISSING node record this session (a dangling edge
507
+ * or kid id). Zero in a healthy store; a growing count means references
508
+ * outlive their records — the read degrades safely to empty bytes, this
509
+ * counter is what keeps that degradation observable. */
510
+ danglingReads: number;
511
+ bytes(id: NodeId): Uint8Array;
512
+ /** First `maxLen` bytes of a node. Walks only the leftmost branch,
513
+ * stopping at `maxLen` — so a 1 MB document root costs the same as a
514
+ * 4-byte leaf. Recursive, but tree depth is logarithmic.
515
+ *
516
+ * IMMUTABILITY CONTRACT (applies to {@link bytes} too): returned arrays
517
+ * may be shared with the byte cache and with other callers — treat them
518
+ * as read-only. Mutating one would corrupt every subsequent read. */
519
+ bytesPrefix(id: NodeId, maxLen: number): Uint8Array;
520
+ contentLen(id: NodeId, cap?: number): number;
521
+ findLeaf(bytes: Uint8Array): NodeId | null;
522
+ findBranch(kids: NodeId[]): NodeId | null;
523
+ parents(id: NodeId): NodeId[];
524
+ parentsFirst(id: NodeId, limit: number): NodeId[];
525
+ hasParents(id: NodeId): boolean;
526
+ chainRun(id: NodeId): readonly NodeId[];
527
+ /** {@link Store.chainRun}'s walk, node at a time through the existing
528
+ * probes. Adapters with a set-based query engine should override with a
529
+ * single server-side descent (the SQLite adapter uses a recursive CTE). */
530
+ protected _chainWalk(id: NodeId, cap: number): NodeId[];
531
+ addContainer(child: NodeId, parent: NodeId): void;
532
+ hasContainers(child: NodeId): boolean;
533
+ containersSlice(child: NodeId, offset: number, limit: number): NodeId[];
534
+ containers(child: NodeId): NodeId[];
535
+ private flatLeafIds;
536
+ /** On a dedup HIT, keep the node's gist available for lazy indexing —
537
+ * EXACTLY when it is not already indexed. Replaces the old id-range
538
+ * "recency" heuristic (id ≥ nextId − cacheWindow), which conflated an LRU
539
+ * entry COUNT with an id RANGE and permanently refused to index any node
540
+ * that first became a resonance target long after it was minted (an early
541
+ * interior later reused as an edge/halo-bearing deposit root was silently
542
+ * unreachable by resonance). The durable index itself is the arbiter:
543
+ * one point query, cached in `_indexedIds` on a hit so repeats are O(1). */
544
+ private captureIfUnindexed;
545
+ /** If `id` structurally bridges ≥2 experiences (the post-hoc compaction
546
+ * criterion), promote its gist into the content index NOW — the exact
547
+ * moment it becomes useful for multi-experience recall. The 1→2 parent
548
+ * transition fires on {@link _dbInsertKid} during mint, and nodes that
549
+ * were already bridges but missed indexing (gist evicted, pre-transition
550
+ * store) are recaptured in {@link captureIfUnindexed}.
551
+ *
552
+ * A no-op when the node is already indexed or its gist is evicted from
553
+ * the pending cache — a future re-encounter will retry. */
554
+ private promoteBridge;
555
+ private intern;
556
+ /** Whether the byte content under `kids` and the byte content of `targetId`
557
+ * are identical except for ONE local span of at most `W` bytes on each side
558
+ * — the near dedup's byte-grain definition of a near-duplicate. A
559
+ * common-prefix / common-suffix trim: whatever remains after both trims is
560
+ * the single differing span (substitution, insertion or deletion), and both
561
+ * remainders must fit the budget. Scattered differences leave a wide
562
+ * middle and are rejected. */
563
+ private differsByOneWindow;
564
+ putLeaf(bytes: Uint8Array, gist: Vec): Promise<NodeId>;
565
+ putBranch(kids: NodeId[], gist: Vec): Promise<NodeId>;
566
+ /** Promote a node's captured gist into the content (resonance) index, once.
567
+ * Called the first time a node becomes a target — i.e. from `link` (it bears
568
+ * or receives a continuation edge) or `pourHalo` (it gains distributional
569
+ * company). Idempotent: a node already indexed, or whose gist has been evicted
570
+ * from the bounded pending map, is a no-op.
571
+ *
572
+ * `dedupTarget` marks the node a candidate the near dedup may fold a fresh
573
+ * near-gist branch ONTO. Only a genuine target — an edge/halo-bearing ROOT —
574
+ * is one; a climb-only interior is reach-indexed but never a dedup sink. */
575
+ protected indexGist(id: NodeId, dedupTarget: boolean): void;
576
+ /** {@link Store.indexTarget} — the public hook for marking a deposit root a
577
+ * resonance target, the one target `link`/`pourHalo` do not cover. A deposit
578
+ * root is a genuine target (a whole experience), so it is a dedup target
579
+ * too. */
580
+ indexTarget(id: NodeId): void;
581
+ /** Index a node and its interior forms as resonance targets. A node that
582
+ * gains an edge is a learnt EXPERIENCE, and the consensus climb
583
+ * ({@link Mind.climbAttention}) answers a query naming only a PORTION of it by
584
+ * resonating its SUB-REGIONS — branch nodes within the experience — and
585
+ * climbing their parents back to it.
586
+ *
587
+ * EVERY interior branch is indexed unconditionally, and this is
588
+ * LOAD-BEARING: indexing only structural bridges (nodes with ≥2 parents,
589
+ * the post-hoc compaction criterion) was tried and REJECTED by the test
590
+ * suite — partial recall of an experience's interior slices, multi-topic
591
+ * attention, and counterfactual anchoring all resonate to SINGLE-parent
592
+ * interiors (13 tests fail without them). Post-hoc structural compaction
593
+ * ({@link compactContentIndex}) may still remove them, but that is a
594
+ * storage/recall trade-off for archived stores, not a free optimisation.
595
+ * The store's hash-cons bounds the index by the number of DISTINCT byte
596
+ * patterns in the corpus — not by the number of deposits.
597
+ *
598
+ * Only the ROOT is a DEDUP TARGET — the whole experience a fresh near-gist
599
+ * branch may legitimately fold onto. Interior nodes are REACH-ONLY: they
600
+ * let a partial query resonate and climb, but a fresh branch must never
601
+ * merge onto an interior node of another experience.
602
+ *
603
+ * Iterative explicit-queue walk: the call stack never sees tree depth. */
604
+ protected indexSubtree(root: NodeId): void;
605
+ resonate(v: Vec, k: number, exhaustive?: boolean): Promise<Hit[]>;
606
+ indexedVectorCount(): number;
607
+ lastResonateReads(): number;
608
+ /** How many physical compaction attempts have failed this session. Zero in
609
+ * a healthy store; a growing count means tombstones are accumulating and
610
+ * index query cost is drifting up (the first failure also warns once). */
611
+ compactFailures: number;
612
+ /** Meta key holding the incremental scan watermark of
613
+ * {@link compactContentIndex}: "minParents:maxInternalIdScanned". KEEP
614
+ * decisions are MONOTONE — parents, edges and halos only ever grow, so an
615
+ * entry once kept can never become removable — and removed entries are
616
+ * gone, so a pass only ever needs to examine entries indexed AFTER the
617
+ * previous pass. Internal ids are monotone and survive the index's
618
+ * splice compaction; the watermark is reset whenever a PHYSICAL index
619
+ * compaction runs (id reuse after a dropped top row would otherwise hide
620
+ * new entries behind it). */
621
+ protected static readonly COMPACT_WATERMARK_KEY = "contentCompact.watermark";
622
+ /** {@link Store.compactContentIndex} */
623
+ compactContentIndex(minParents?: number): Promise<number>;
624
+ /** {@link Store.repairContentIndex} */
625
+ repairContentIndex(regenerateGist: (id: NodeId) => Promise<Vec | null>, minParents?: number): Promise<number>;
626
+ link(from: NodeId, to: NodeId): Promise<void>;
627
+ next(id: NodeId): NodeId[];
628
+ /** {@link Store.hasNext} — one indexed point probe, never a range read. */
629
+ hasNext(id: NodeId): boolean;
630
+ prev(id: NodeId): NodeId[];
631
+ nextFirst(id: NodeId, limit: number): NodeId[];
632
+ prevFirst(id: NodeId, limit: number): NodeId[];
633
+ /** {@link Store.prevCount}. Subclasses with an indexed reverse-edge count
634
+ * should override; this default materialises (correct, not optimal). */
635
+ prevCount(id: NodeId): number;
636
+ edgeSourceCount(): number;
637
+ haloMass(id: NodeId): number;
638
+ halo(id: NodeId): Vec | null;
639
+ /** {@link Store.hasHalo} — MUST mirror {@link halo}'s null condition
640
+ * exactly (row present AND mass ≥ minHaloMass), minus the decode. */
641
+ hasHalo(id: NodeId): boolean;
642
+ pourHalo(id: NodeId, add: Vec): Promise<void>;
643
+ resonateHalo(v: Vec, k: number): Promise<Hit[]>;
644
+ private pending;
645
+ protected flushContent(): number;
646
+ protected flushHalos(): number;
647
+ /** Append the buffered containment pairs, inside the deferred transaction.
648
+ * Pure appends: durable dedup lives in the adapter (the pair PK), so a
649
+ * flush never reads a child's stored list back — the old packed-blob
650
+ * read-merge-rewrite was O(fan-in) per touched child per flush, quadratic
651
+ * over a long training run on a hot window. */
652
+ protected flushContain(): void;
653
+ /** Flush all three buffers; compact vector indices on a write-volume cadence. */
654
+ protected flush(): void;
655
+ protected maybeFlush(): Promise<void>;
656
+ setMeta(key: string, val: string): Promise<void>;
657
+ getMeta(key: string): Promise<string | null>;
658
+ deleteMeta(key: string): Promise<void>;
659
+ saveSnapshot(bytes: Uint8Array): Promise<void>;
660
+ loadSnapshot(): Promise<Uint8Array | null>;
661
+ commit(): void;
662
+ close(): Promise<void>;
663
+ }