@hviana/sema 0.2.4 → 0.2.6

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 (142) hide show
  1. package/package.json +1 -1
  2. package/src/geometry.ts +52 -3
  3. package/src/mind/attention.ts +1469 -120
  4. package/src/mind/index.ts +16 -0
  5. package/src/mind/junction.ts +125 -16
  6. package/src/mind/mind.ts +15 -0
  7. package/src/mind/rationale.ts +12 -4
  8. package/src/mind/traverse.ts +75 -7
  9. package/src/mind/types.ts +25 -0
  10. package/test/51-structural-resonance-ladder.test.mjs +552 -0
  11. package/test/52-climb-consensus-instrumentation.test.mjs +324 -0
  12. package/test/53-cross-region-probe-instrumentation.test.mjs +356 -0
  13. package/dist/example/demo.d.ts +0 -1
  14. package/dist/example/demo.js +0 -39
  15. package/dist/example/train_base.d.ts +0 -87
  16. package/dist/example/train_base.js +0 -2252
  17. package/dist/src/alphabet.d.ts +0 -7
  18. package/dist/src/alphabet.js +0 -33
  19. package/dist/src/alu/src/alu.d.ts +0 -185
  20. package/dist/src/alu/src/alu.js +0 -440
  21. package/dist/src/alu/src/expr.d.ts +0 -61
  22. package/dist/src/alu/src/expr.js +0 -318
  23. package/dist/src/alu/src/index.d.ts +0 -11
  24. package/dist/src/alu/src/index.js +0 -19
  25. package/dist/src/alu/src/kernel-arith.d.ts +0 -16
  26. package/dist/src/alu/src/kernel-arith.js +0 -264
  27. package/dist/src/alu/src/kernel-bits.d.ts +0 -19
  28. package/dist/src/alu/src/kernel-bits.js +0 -152
  29. package/dist/src/alu/src/kernel-logic.d.ts +0 -4
  30. package/dist/src/alu/src/kernel-logic.js +0 -60
  31. package/dist/src/alu/src/kernel-nd.d.ts +0 -3
  32. package/dist/src/alu/src/kernel-nd.js +0 -208
  33. package/dist/src/alu/src/kernel-numeric.d.ts +0 -54
  34. package/dist/src/alu/src/kernel-numeric.js +0 -366
  35. package/dist/src/alu/src/operation.d.ts +0 -168
  36. package/dist/src/alu/src/operation.js +0 -189
  37. package/dist/src/alu/src/parser.d.ts +0 -221
  38. package/dist/src/alu/src/parser.js +0 -577
  39. package/dist/src/alu/src/resonance.d.ts +0 -55
  40. package/dist/src/alu/src/resonance.js +0 -126
  41. package/dist/src/alu/src/text.d.ts +0 -31
  42. package/dist/src/alu/src/text.js +0 -73
  43. package/dist/src/alu/src/value.d.ts +0 -109
  44. package/dist/src/alu/src/value.js +0 -300
  45. package/dist/src/alu/test/alu.test.d.ts +0 -1
  46. package/dist/src/alu/test/alu.test.js +0 -764
  47. package/dist/src/bytes.d.ts +0 -14
  48. package/dist/src/bytes.js +0 -59
  49. package/dist/src/canon.d.ts +0 -26
  50. package/dist/src/canon.js +0 -57
  51. package/dist/src/config.d.ts +0 -111
  52. package/dist/src/config.js +0 -91
  53. package/dist/src/derive/src/deduction.d.ts +0 -125
  54. package/dist/src/derive/src/deduction.js +0 -155
  55. package/dist/src/derive/src/index.d.ts +0 -7
  56. package/dist/src/derive/src/index.js +0 -11
  57. package/dist/src/derive/src/priority-queue.d.ts +0 -20
  58. package/dist/src/derive/src/priority-queue.js +0 -73
  59. package/dist/src/derive/src/rewrite.d.ts +0 -56
  60. package/dist/src/derive/src/rewrite.js +0 -100
  61. package/dist/src/derive/src/trie.d.ts +0 -90
  62. package/dist/src/derive/src/trie.js +0 -217
  63. package/dist/src/derive/test/derive.test.d.ts +0 -1
  64. package/dist/src/derive/test/derive.test.js +0 -122
  65. package/dist/src/extension.d.ts +0 -37
  66. package/dist/src/extension.js +0 -7
  67. package/dist/src/geometry.d.ts +0 -176
  68. package/dist/src/geometry.js +0 -546
  69. package/dist/src/index.d.ts +0 -16
  70. package/dist/src/index.js +0 -18
  71. package/dist/src/ingest-cache.d.ts +0 -41
  72. package/dist/src/ingest-cache.js +0 -161
  73. package/dist/src/mind/articulation.d.ts +0 -6
  74. package/dist/src/mind/articulation.js +0 -99
  75. package/dist/src/mind/attention.d.ts +0 -88
  76. package/dist/src/mind/attention.js +0 -997
  77. package/dist/src/mind/bridge.d.ts +0 -30
  78. package/dist/src/mind/bridge.js +0 -569
  79. package/dist/src/mind/canonical.d.ts +0 -29
  80. package/dist/src/mind/canonical.js +0 -88
  81. package/dist/src/mind/graph-search.d.ts +0 -285
  82. package/dist/src/mind/graph-search.js +0 -956
  83. package/dist/src/mind/index.d.ts +0 -5
  84. package/dist/src/mind/index.js +0 -5
  85. package/dist/src/mind/junction.d.ts +0 -95
  86. package/dist/src/mind/junction.js +0 -262
  87. package/dist/src/mind/learning.d.ts +0 -47
  88. package/dist/src/mind/learning.js +0 -248
  89. package/dist/src/mind/match.d.ts +0 -126
  90. package/dist/src/mind/match.js +0 -441
  91. package/dist/src/mind/mechanisms/alu.d.ts +0 -4
  92. package/dist/src/mind/mechanisms/alu.js +0 -36
  93. package/dist/src/mind/mechanisms/cast.d.ts +0 -89
  94. package/dist/src/mind/mechanisms/cast.js +0 -716
  95. package/dist/src/mind/mechanisms/confluence.d.ts +0 -24
  96. package/dist/src/mind/mechanisms/confluence.js +0 -225
  97. package/dist/src/mind/mechanisms/cover.d.ts +0 -6
  98. package/dist/src/mind/mechanisms/cover.js +0 -203
  99. package/dist/src/mind/mechanisms/extraction.d.ts +0 -67
  100. package/dist/src/mind/mechanisms/extraction.js +0 -387
  101. package/dist/src/mind/mechanisms/recall.d.ts +0 -13
  102. package/dist/src/mind/mechanisms/recall.js +0 -325
  103. package/dist/src/mind/mind.d.ts +0 -274
  104. package/dist/src/mind/mind.js +0 -572
  105. package/dist/src/mind/pipeline-mechanism.d.ts +0 -142
  106. package/dist/src/mind/pipeline-mechanism.js +0 -213
  107. package/dist/src/mind/pipeline.d.ts +0 -20
  108. package/dist/src/mind/pipeline.js +0 -217
  109. package/dist/src/mind/primitives.d.ts +0 -70
  110. package/dist/src/mind/primitives.js +0 -287
  111. package/dist/src/mind/rationale.d.ts +0 -134
  112. package/dist/src/mind/rationale.js +0 -162
  113. package/dist/src/mind/reasoning.d.ts +0 -34
  114. package/dist/src/mind/reasoning.js +0 -240
  115. package/dist/src/mind/recognition.d.ts +0 -20
  116. package/dist/src/mind/recognition.js +0 -390
  117. package/dist/src/mind/resonance.d.ts +0 -23
  118. package/dist/src/mind/resonance.js +0 -0
  119. package/dist/src/mind/trace.d.ts +0 -15
  120. package/dist/src/mind/trace.js +0 -73
  121. package/dist/src/mind/traverse.d.ts +0 -113
  122. package/dist/src/mind/traverse.js +0 -504
  123. package/dist/src/mind/types.d.ts +0 -271
  124. package/dist/src/mind/types.js +0 -130
  125. package/dist/src/rabitq-ivf/src/database.d.ts +0 -113
  126. package/dist/src/rabitq-ivf/src/database.js +0 -201
  127. package/dist/src/rabitq-ivf/src/index.d.ts +0 -7
  128. package/dist/src/rabitq-ivf/src/index.js +0 -4
  129. package/dist/src/rabitq-ivf/src/ivf.d.ts +0 -200
  130. package/dist/src/rabitq-ivf/src/ivf.js +0 -1165
  131. package/dist/src/rabitq-ivf/src/prng.d.ts +0 -19
  132. package/dist/src/rabitq-ivf/src/prng.js +0 -36
  133. package/dist/src/rabitq-ivf/src/rabitq.d.ts +0 -95
  134. package/dist/src/rabitq-ivf/src/rabitq.js +0 -283
  135. package/dist/src/sema.d.ts +0 -31
  136. package/dist/src/sema.js +0 -63
  137. package/dist/src/store-sqlite.d.ts +0 -184
  138. package/dist/src/store-sqlite.js +0 -942
  139. package/dist/src/store.d.ts +0 -663
  140. package/dist/src/store.js +0 -1618
  141. package/dist/src/vec.d.ts +0 -31
  142. package/dist/src/vec.js +0 -109
@@ -1,201 +0,0 @@
1
- import { IvfIndex } from "./ivf.js";
2
- /**
3
- * A persistent vector database: an adaptive PARTITIONED (IVF) index over
4
- * 1-bit RaBitQ codes (cosine), stored entirely in SQLite at `dbPath`. See
5
- * ivf.ts for the index design. The original float vectors are never
6
- * retained — only the sign codes — so a 1024-d vector costs 128 bytes.
7
- *
8
- * Inserting is route-and-append: cost is essentially FLAT in collection size
9
- * (one RAM scan of the pivot table + one chunk append — no per-insert graph
10
- * walk). Query cost is bounded by nprobe × cluster size — constant in N
11
- * once the collection is past its first splits.
12
- */
13
- export class VectorDatabase {
14
- index;
15
- constructor(options) {
16
- if (!options || typeof options.dbPath !== "string" ||
17
- options.dbPath.length === 0) {
18
- throw new Error("DatabaseOptions.dbPath (string) is required");
19
- }
20
- this.index = new IvfIndex(options.dbPath, options);
21
- }
22
- get dim() {
23
- return this.index.dim;
24
- }
25
- /** Number of live (non-deleted) vectors. */
26
- get size() {
27
- return this.index.size;
28
- }
29
- /** Physical slot count including tombstones from deletes/updates. */
30
- get physicalSize() {
31
- return this.index.physicalSize;
32
- }
33
- /** Number of clusters (partitions) currently in the index. */
34
- get clusterCount() {
35
- return this.index.clusterCount;
36
- }
37
- get efSearch() {
38
- return this.index.efSearch;
39
- }
40
- set efSearch(value) {
41
- this.index.efSearch = value;
42
- }
43
- /** Distance computations performed during the most recent query. */
44
- get lastQueryDistanceComputations() {
45
- return this.index.lastQueryDistComps;
46
- }
47
- /** Storage row reads issued by the most recent query — the honest,
48
- * cache-independent scalability metric. */
49
- get lastQueryStorageReads() {
50
- return this.index.lastQueryStorageReads;
51
- }
52
- get storage() {
53
- const f32 = this.dim * 4;
54
- const bpv = this.index.bytesPerVector;
55
- return {
56
- float32BytesPerVector: f32,
57
- codeBytesPerVector: bpv,
58
- bytesPerVector: bpv,
59
- compressionRatio: f32 / bpv,
60
- };
61
- }
62
- checkId(id) {
63
- // 32-bit signed range: chunk blobs store exts as int32 — a wider id
64
- // would silently truncate, so it is rejected at the door instead.
65
- if (!Number.isInteger(id) || id > 0x7fffffff || id < -0x80000000) {
66
- throw new Error(`External id must be a 32-bit integer, got ${id}`);
67
- }
68
- return id;
69
- }
70
- /** Convert a value to code bytes, selecting by length: `codeWords`
71
- * elements → an existing 1-bit code; otherwise a raw `dim`-vector. */
72
- toCodeBytes(value) {
73
- if (value.length === this.index.codeWords) {
74
- return this.index.codeToBytes(value);
75
- }
76
- if (value.length !== this.dim) {
77
- throw new Error(`Vector dimension mismatch: expected ${this.dim}, got ${value.length}`);
78
- }
79
- return this.index.encodeToBytes(value);
80
- }
81
- has(id) {
82
- return this.index.has(this.checkId(id));
83
- }
84
- /** Stream every live external id (bounded memory). */
85
- *keys() {
86
- yield* this.index.keys();
87
- }
88
- /** Stream live entries whose INTERNAL id is > `after` — a durable
89
- * incremental watermark (internal ids are monotone at insert and preserved
90
- * by update and compact). */
91
- *keysSince(after) {
92
- yield* this.index.keysSince(after);
93
- }
94
- /** Read the stored 1-bit code for an id (a copy as a Uint32Array), or null. */
95
- get(id) {
96
- const bytes = this.index.codeOf(this.checkId(id));
97
- return bytes ? this.index.bytesToCode(bytes) : null;
98
- }
99
- insert(id, value) {
100
- this.index.begin();
101
- try {
102
- this.index.insert(this.checkId(id), this.toCodeBytes(value));
103
- this.index.commit();
104
- }
105
- catch (e) {
106
- this.index.rollback();
107
- throw e;
108
- }
109
- }
110
- update(id, value) {
111
- this.index.begin();
112
- try {
113
- this.index.update(this.checkId(id), this.toCodeBytes(value));
114
- this.index.commit();
115
- }
116
- catch (e) {
117
- this.index.rollback();
118
- throw e;
119
- }
120
- }
121
- upsert(id, value) {
122
- this.upsertMany([{ id, vector: value }]);
123
- }
124
- /**
125
- * Upsert many vectors under ONE transaction — one WAL commit for the whole
126
- * batch instead of one per vector, with chunk appends to the same cluster
127
- * coalesced in the index's write-back buffer.
128
- */
129
- upsertMany(entries) {
130
- if (entries.length === 0)
131
- return;
132
- this.index.begin();
133
- try {
134
- for (const e of entries) {
135
- // One shared vmap probe decides insert vs update — the per-row point
136
- // query is the dominant bulk-load cost, so it is never duplicated.
137
- this.index.upsert(this.checkId(e.id), this.toCodeBytes(e.vector));
138
- }
139
- this.index.commit();
140
- }
141
- catch (e) {
142
- this.index.rollback();
143
- throw e;
144
- }
145
- }
146
- /** Delete many ids under ONE transaction. Absent ids are skipped.
147
- * Returns the number of vectors actually removed. */
148
- deleteMany(ids) {
149
- if (ids.length === 0)
150
- return 0;
151
- let removed = 0;
152
- this.index.begin();
153
- try {
154
- for (const id of ids) {
155
- if (this.index.remove(this.checkId(id)))
156
- removed++;
157
- }
158
- this.index.commit();
159
- }
160
- catch (e) {
161
- this.index.rollback();
162
- throw e;
163
- }
164
- return removed;
165
- }
166
- /** Delete the vector bound to an id. Returns false if absent. */
167
- delete(id) {
168
- return this.deleteMany([id]) === 1;
169
- }
170
- /** Heat the SQLite page cache with sequential scans (latency only). */
171
- warmCache() {
172
- return this.index.warmCache();
173
- }
174
- /** Reclaim tombstoned slots by rewriting the clusters that carry any, then
175
- * VACUUM. Internal ids and cluster assignment are preserved. */
176
- compact() {
177
- this.index.compact();
178
- }
179
- /**
180
- * k-NN search. The argument's length selects the mode:
181
- * - `dim` elements → a raw vector (accurate estimator)
182
- * - `codeWords` elements → a 1-bit code, by sign-bit Hamming
183
- */
184
- query(query, k = 10, opts) {
185
- let hits;
186
- if (query.length === this.index.codeWords) {
187
- hits = this.index.searchKnnByCode(this.index.codeToBytes(query), k, opts?.ef);
188
- }
189
- else {
190
- if (query.length !== this.dim) {
191
- throw new Error(`Vector dimension mismatch: expected ${this.dim}, got ${query.length}`);
192
- }
193
- hits = this.index.searchKnn(query, k, opts?.ef);
194
- }
195
- return hits;
196
- }
197
- /** Close the underlying database. The instance must not be used afterwards. */
198
- close() {
199
- this.index.close();
200
- }
201
- }
@@ -1,7 +0,0 @@
1
- export { VectorDatabase } from "./database.js";
2
- export type { DatabaseOptions, ExternalId, QueryResult, StorageStats, } from "./database.js";
3
- export { IvfIndex } from "./ivf.js";
4
- export type { IvfConfig, IvfHit } from "./ivf.js";
5
- export { RaBitQuantizer } from "./rabitq.js";
6
- export type { QueryContext, RaBitQOptions } from "./rabitq.js";
7
- export { Prng } from "./prng.js";
@@ -1,4 +0,0 @@
1
- export { VectorDatabase } from "./database.js";
2
- export { IvfIndex } from "./ivf.js";
3
- export { RaBitQuantizer } from "./rabitq.js";
4
- export { Prng } from "./prng.js";
@@ -1,200 +0,0 @@
1
- import { DatabaseSync } from "node:sqlite";
2
- export interface IvfConfig {
3
- dim: number;
4
- efSearch: number;
5
- queryBits: number;
6
- rotationRounds: number;
7
- seed: number;
8
- centroid: Float64Array | null;
9
- codeWords: number;
10
- paddedDim: number;
11
- }
12
- export interface IvfHit {
13
- /** external (user) id */
14
- id: number;
15
- /** estimated cosine distance (1 - cosine) */
16
- distance: number;
17
- }
18
- export declare class IvfIndex {
19
- readonly db: DatabaseSync;
20
- private readonly quantizer;
21
- private readonly codeBytes;
22
- private readonly chunkBytes;
23
- private _efSearch;
24
- /** Pivot codes, K × codeBytes, contiguous — the insert/query routing scan
25
- * is one linear pass over this array. */
26
- private centCodes;
27
- /** Aligned 32-bit word view of {@link centCodes} — the routing scan's
28
- * operand (4 bytes per XOR+popcount instead of byte re-composition). */
29
- private centWords;
30
- /** Per-cluster entry count (live + dead) — the split trigger. */
31
- private centEntries;
32
- /** Per-cluster chunk count (tail seq = count − 1). */
33
- private centChunks;
34
- private K;
35
- private live;
36
- private totalSlots;
37
- private nextId;
38
- /** Storage row reads (chunk blob fetches) — the cache-independent
39
- * scalability witness, same discipline as the graph index it replaces. */
40
- reads: number;
41
- lastQueryDistComps: number;
42
- lastQueryStorageReads: number;
43
- private readonly chunkCache;
44
- private readonly dirtyChunks;
45
- private readonly dirtyCents;
46
- private metaDirty;
47
- private readonly cacheEnabled;
48
- private readonly chunkCacheMax;
49
- private sSelChunk;
50
- private sUpsChunk;
51
- private sDelChunk;
52
- private sSelVmap;
53
- private sInsVmap;
54
- private sUpdVmap;
55
- private sDelVmap;
56
- private sUpsCent;
57
- private sMeta;
58
- constructor(dbPath: string, options: {
59
- dim?: number;
60
- efSearch?: number;
61
- queryBits?: number;
62
- rotationRounds?: number;
63
- seed?: number;
64
- centroid?: ArrayLike<number>;
65
- cacheSizeMb?: number;
66
- });
67
- readonly dim: number;
68
- private prepareAll;
69
- /** Load the pivot table into RAM — K rows, ~(codeBytes + 8) bytes each. */
70
- private loadCents;
71
- private growCents;
72
- get size(): number;
73
- get physicalSize(): number;
74
- get clusterCount(): number;
75
- get bytesPerVector(): number;
76
- get efSearch(): number;
77
- set efSearch(v: number);
78
- resetReads(): void;
79
- /** Fetch a chunk, serving dirty/cached copies first. `retain` controls
80
- * whether a clean fetch enters the cache — read-only consumers pass the
81
- * cacheEnabled flag so the `cacheSizeMb: 0` mode stays honestly uncached;
82
- * writers always retain (the copy is about to become dirty). */
83
- private chunkAt;
84
- private cacheChunk;
85
- private markDirty;
86
- /** Write every dirty chunk row; drop the clean cache only when retention
87
- * is off (no budget) — under a budget the warm set survives the flush.
88
- * Runs inside the caller's transaction. */
89
- private flushChunks;
90
- private flushCents;
91
- /** Persist all buffered state. MUST be called before the enclosing
92
- * transaction commits (upsertMany/deleteMany do; single-op paths too). */
93
- private flushAll;
94
- private static readonly SUPER_G;
95
- private static readonly SUPER_TOP;
96
- /** Majority super-pivot codes, one per group of SUPER_G clusters. */
97
- private superWords;
98
- /** Group ids whose super-pivot is stale (member pivot changed). */
99
- private readonly superStale;
100
- /** Scratch word view of the code being routed (avoids per-call copies). */
101
- private routeScratch;
102
- private markSuperStale;
103
- /** Recompute stale super-pivots (majority bit over member pivots). */
104
- private freshenSupers;
105
- /** Word-popcount Hamming between the routing scratch and a words-row. */
106
- private hamAt;
107
- /** Nearest cluster to a code — exact over member pivots of the SUPER_TOP
108
- * nearest super-groups (or over everything while K is small). Pure RAM,
109
- * no allocation, no storage reads. */
110
- private nearestCid;
111
- /** The nprobe nearest clusters to a QUERY (accurate estimator on pivots),
112
- * as cids ordered nearest-first. */
113
- private probeOrder;
114
- private probeOrderByCode;
115
- /** Whether an external id is present (live). */
116
- has(ext: number): boolean;
117
- /** The stored code for an ext (a copy), or null. */
118
- codeOf(ext: number): Uint8Array | null;
119
- /** Insert a code under `ext`. Caller owns the transaction; buffered rows
120
- * are flushed by {@link commitFlush}. Throws if ext is already live. */
121
- insert(ext: number, code: Uint8Array): void;
122
- /** Insert-or-update with ONE vmap probe. The point probe is a real cost
123
- * at bulk-load rates (statement dispatch + a B-tree descent per row —
124
- * profiled as the single largest insert-path term), so the presence check
125
- * and the update lookup share it. */
126
- upsert(ext: number, code: Uint8Array): void;
127
- /** The insert core — presence already established by the caller. */
128
- private insertNew;
129
- private newCluster;
130
- private appendToCluster;
131
- /** Tombstone a live ext. Returns false when absent. */
132
- remove(ext: number): boolean;
133
- /** Update the code bound to a live ext. A byte-identical code is a no-op
134
- * (content-addressed callers re-upsert unchanged vectors wholesale after a
135
- * restart; each no-op otherwise costs a tombstone + reinsert). */
136
- update(ext: number, code: Uint8Array): void;
137
- private updateAt;
138
- /** Flush buffered chunk/cent/meta rows. Call before COMMIT. */
139
- commitFlush(): void;
140
- /** Split a full cluster in two, deterministically. Dead slots are dropped
141
- * (splits double as incremental compaction). Both halves get fresh
142
- * majority-bit pivots, so routing sharpens as the corpus grows. */
143
- private split;
144
- /** Bit-majority sample size per split side. A pivot is a routing aid, not
145
- * a stored value: the majority bit of a 512-member deterministic sample
146
- * agrees with the full-population majority except on near-tied bits,
147
- * where either choice routes equally well — and counting every member of
148
- * a 4096-entry cluster was 25% of bulk-load CPU (profiled). */
149
- private static readonly MAJORITY_SAMPLE;
150
- /** Majority-bit code of the side's members (the binary centroid), or null
151
- * when the side is empty. Members are sampled on a deterministic stride
152
- * when the side exceeds {@link MAJORITY_SAMPLE}. */
153
- private majorityCode;
154
- /** Rewrite a cluster's chunks from a member list (one side of a split or a
155
- * compaction survivor set), updating vmap rows. `dropFrom` deletes any
156
- * leftover chunk rows beyond the new count. */
157
- private rebuildCluster;
158
- /** Multi-row vmap statements, prepared per row count (powers of a fixed
159
- * batch width) — REPLACE semantics on the ext primary key. */
160
- private readonly vmapBatchStmts;
161
- private static readonly VMAP_BATCH;
162
- private vmapBatchStmt;
163
- /** Write flat (ext, id, cid, seq, slot) tuples in wide batches. */
164
- private flushVmapRows;
165
- /** ef → clusters probed. ef is the familiar "candidate breadth" knob; a
166
- * probe scans one whole cluster, so nprobe = ef/4 keeps the default
167
- * (ef 64 → 16 probes) both accurate on trained stores and bounded. */
168
- private nprobeOf;
169
- /** k-NN with a full-precision query (accurate RaBitQ estimator). */
170
- searchKnn(vec: ArrayLike<number>, k: number, ef?: number): IvfHit[];
171
- /** k-NN with an already-quantized code (sign-bit Hamming distance). */
172
- searchKnnByCode(code: Uint8Array, k: number, ef?: number): IvfHit[];
173
- private scanClusters;
174
- /** Stream live entries whose internal id is > `after`, in id order.
175
- * Internal ids are monotone at insert and PRESERVED by update/compact, so
176
- * the largest id a caller has seen is a durable incremental watermark. */
177
- keysSince(after: number, batch?: number): IterableIterator<{
178
- ext: number;
179
- internal: number;
180
- }>;
181
- /** Stream every live external id. */
182
- keys(): IterableIterator<number>;
183
- /** Drop tombstoned slots by rewriting each cluster that carries any, then
184
- * VACUUM. Internal ids and cluster assignment are preserved — routing
185
- * quality is untouched, only dead space is reclaimed. */
186
- compact(): void;
187
- /** Heat SQLite's page cache with sequential scans of the chunk and vmap
188
- * tables — a cold session otherwise warms it through random point reads.
189
- * Purely a latency optimisation; returns rows touched. */
190
- warmCache(): number;
191
- begin(): void;
192
- commit(): void;
193
- rollback(): void;
194
- /** Encode a raw vector to its 1-bit code bytes. */
195
- encodeToBytes(vec: ArrayLike<number>): Uint8Array;
196
- codeToBytes(code: ArrayLike<number>): Uint8Array;
197
- bytesToCode(bytes: Uint8Array): Uint32Array;
198
- get codeWords(): number;
199
- close(): void;
200
- }