renor-engine 0.0.0-stage → 1.0.0

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 (176) hide show
  1. package/LICENSE +661 -0
  2. package/NOTICE +73 -0
  3. package/README.md +105 -2
  4. package/dist/BUILD.json +6 -0
  5. package/dist/api/apiAuth.js +43 -0
  6. package/dist/api/server.js +172 -0
  7. package/dist/buildIdentity.js +132 -0
  8. package/dist/cli-extractors.js +46 -0
  9. package/dist/cli.js +491 -0
  10. package/dist/config.js +65 -0
  11. package/dist/context/composer.js +320 -0
  12. package/dist/context/readHonesty.js +478 -0
  13. package/dist/context/rowStore.js +238 -0
  14. package/dist/conversation/formatter.js +81 -0
  15. package/dist/conversation/parser.js +189 -0
  16. package/dist/conversation/types.js +2 -0
  17. package/dist/conversation/writer.js +42 -0
  18. package/dist/db/client.js +147 -0
  19. package/dist/db/indexSalvage.js +81 -0
  20. package/dist/db/migrations.js +642 -0
  21. package/dist/db/readCache.js +109 -0
  22. package/dist/db/schema.js +5 -0
  23. package/dist/db/statements.js +89 -0
  24. package/dist/digests/digestCache.js +142 -0
  25. package/dist/digests/digests.js +597 -0
  26. package/dist/digests/worker.js +348 -0
  27. package/dist/embeddings/caching.js +337 -0
  28. package/dist/embeddings/coalescing.js +177 -0
  29. package/dist/embeddings/interactive.js +103 -0
  30. package/dist/embeddings/local.js +68 -0
  31. package/dist/embeddings/openai.js +105 -0
  32. package/dist/embeddings/rebuild.js +166 -0
  33. package/dist/embeddings/simdScan.js +258 -0
  34. package/dist/embeddings/space.js +21 -0
  35. package/dist/embeddings/types.js +14 -0
  36. package/dist/embeddings/vectorIndex.js +675 -0
  37. package/dist/embeddings/vertex.js +224 -0
  38. package/dist/eval/artifacts.js +42 -0
  39. package/dist/eval/cacheReport.js +139 -0
  40. package/dist/eval/comparison.js +182 -0
  41. package/dist/eval/context700-candidate.js +145 -0
  42. package/dist/eval/evalCache.js +525 -0
  43. package/dist/eval/hashEmbedding.js +35 -0
  44. package/dist/eval/longmemeval.js +56 -0
  45. package/dist/eval/metrics.js +181 -0
  46. package/dist/eval/renorbenchBaseline.js +486 -0
  47. package/dist/eval/renorbenchDocuments.js +134 -0
  48. package/dist/eval/renorbenchProduct.js +182 -0
  49. package/dist/eval/runLedger.js +279 -0
  50. package/dist/eval/runManifest.js +479 -0
  51. package/dist/eval/scoring.js +197 -0
  52. package/dist/evidence/attach.js +267 -0
  53. package/dist/evidence/background.js +147 -0
  54. package/dist/evidence/evidenceCache.js +182 -0
  55. package/dist/evidence/gate.js +37 -0
  56. package/dist/evidence/keyPool.js +85 -0
  57. package/dist/evidence/ollamaChat.js +84 -0
  58. package/dist/evidence/optin.js +165 -0
  59. package/dist/evidence/options.js +130 -0
  60. package/dist/evidence/secondPass.js +456 -0
  61. package/dist/extraction/classifyCapture.js +34 -0
  62. package/dist/extraction/decision-model.js +174 -0
  63. package/dist/extraction/eventExtractor.js +113 -0
  64. package/dist/extraction/extractionClient.js +122 -0
  65. package/dist/extraction/factExtractor.js +46 -0
  66. package/dist/extraction/factsWritePath.js +179 -0
  67. package/dist/extraction/preferenceExtractor.js +153 -0
  68. package/dist/extraction/secretGuard.js +176 -0
  69. package/dist/extraction/secretScanner.js +665 -0
  70. package/dist/extraction/typedFacts.js +224 -0
  71. package/dist/extraction/writePathAdjudication.js +110 -0
  72. package/dist/importing/apply.js +644 -0
  73. package/dist/importing/bundle-write.js +80 -0
  74. package/dist/importing/cli.js +407 -0
  75. package/dist/importing/existing.js +49 -0
  76. package/dist/importing/facts.js +123 -0
  77. package/dist/importing/forgetImported.js +79 -0
  78. package/dist/importing/hosted.js +467 -0
  79. package/dist/importing/index.js +29 -0
  80. package/dist/importing/journalLog.js +96 -0
  81. package/dist/importing/markdown.js +98 -0
  82. package/dist/importing/plan.js +206 -0
  83. package/dist/importing/secretScreen.js +113 -0
  84. package/dist/importing/serialize.js +188 -0
  85. package/dist/importing/source.js +463 -0
  86. package/dist/importing/types.js +6 -0
  87. package/dist/indexer/chunker.js +319 -0
  88. package/dist/indexer/dailyEntries.js +63 -0
  89. package/dist/indexer/hasher.js +10 -0
  90. package/dist/indexer/laneRuns.js +48 -0
  91. package/dist/indexer/o200k.js +481 -0
  92. package/dist/indexer/o200k.json +8 -0
  93. package/dist/indexer/outsideRoot.js +77 -0
  94. package/dist/indexer/parser.js +167 -0
  95. package/dist/indexer/pipeline.js +1168 -0
  96. package/dist/indexer/staleness.js +201 -0
  97. package/dist/indexer/tokenizer.js +77 -0
  98. package/dist/indexer/walker.js +184 -0
  99. package/dist/mcp/hive.js +88 -0
  100. package/dist/mcp/requestErrors.js +47 -0
  101. package/dist/mcp/server.js +396 -0
  102. package/dist/memory/agentLease.js +43 -0
  103. package/dist/memory/confinedWrite.js +315 -0
  104. package/dist/memory/controls.js +73 -0
  105. package/dist/memory/dailyNote.js +265 -0
  106. package/dist/memory/durableAppend.js +57 -0
  107. package/dist/memory/factConflicts.js +203 -0
  108. package/dist/memory/factTerms.js +321 -0
  109. package/dist/memory/hiveNameHeader.cjs +10 -0
  110. package/dist/memory/inventory.js +55 -0
  111. package/dist/memory/invisibleText.js +20 -0
  112. package/dist/memory/lifecycle.js +1756 -0
  113. package/dist/memory/limits.js +13 -0
  114. package/dist/memory/requests.js +183 -0
  115. package/dist/memory/sourceName.js +200 -0
  116. package/dist/memory/whatsNew.js +158 -0
  117. package/dist/memory/writer.js +175 -0
  118. package/dist/memory/writerConflicts.js +85 -0
  119. package/dist/memorymap/memoryMap.js +1568 -0
  120. package/dist/memorymap/replacedJournal.js +58 -0
  121. package/dist/memorymap/replacements.js +405 -0
  122. package/dist/mvp/activity.js +86 -0
  123. package/dist/mvp/agentMemory.js +1744 -0
  124. package/dist/mvp/auth.js +531 -0
  125. package/dist/mvp/cli.js +73 -0
  126. package/dist/mvp/client-store.js +462 -0
  127. package/dist/mvp/compileCache.js +249 -0
  128. package/dist/mvp/compileSeed.js +27 -0
  129. package/dist/mvp/config.js +288 -0
  130. package/dist/mvp/connectionStatus.js +80 -0
  131. package/dist/mvp/contextRelevance.js +413 -0
  132. package/dist/mvp/engine.js +1065 -0
  133. package/dist/mvp/exportAll.js +359 -0
  134. package/dist/mvp/factLanePack.js +77 -0
  135. package/dist/mvp/factMarkers.js +49 -0
  136. package/dist/mvp/factsLane.js +203 -0
  137. package/dist/mvp/hiddenSpans.js +585 -0
  138. package/dist/mvp/history.js +413 -0
  139. package/dist/mvp/hitDates.js +31 -0
  140. package/dist/mvp/hitFloor.js +36 -0
  141. package/dist/mvp/identity.js +18 -0
  142. package/dist/mvp/idle.js +113 -0
  143. package/dist/mvp/memoryDir.js +98 -0
  144. package/dist/mvp/posthogMcp.js +210 -0
  145. package/dist/mvp/readScope.js +104 -0
  146. package/dist/mvp/readUsefulness.js +222 -0
  147. package/dist/mvp/sanitize.js +48 -0
  148. package/dist/mvp/schemaRejections.js +91 -0
  149. package/dist/mvp/scope.js +127 -0
  150. package/dist/mvp/server.js +2089 -0
  151. package/dist/mvp/serverCard.js +29 -0
  152. package/dist/mvp/storedSize.js +139 -0
  153. package/dist/mvp/telemetry.js +441 -0
  154. package/dist/retrieval/adviceLines.js +195 -0
  155. package/dist/retrieval/adviceQuestion.js +44 -0
  156. package/dist/retrieval/conversationShape.js +44 -0
  157. package/dist/retrieval/dailyEntryTime.js +55 -0
  158. package/dist/retrieval/entityLookup.js +113 -0
  159. package/dist/retrieval/factsFirst.js +188 -0
  160. package/dist/retrieval/keyword.js +84 -0
  161. package/dist/retrieval/ledgerEventTime.js +51 -0
  162. package/dist/retrieval/ledgerLiveness.js +83 -0
  163. package/dist/retrieval/ledgerPresentation.js +161 -0
  164. package/dist/retrieval/noteIdentity.js +57 -0
  165. package/dist/retrieval/orchestrator.js +1086 -0
  166. package/dist/retrieval/queryHelpers.js +142 -0
  167. package/dist/retrieval/questionSpan.js +475 -0
  168. package/dist/retrieval/readerEvents.js +690 -0
  169. package/dist/retrieval/readerLayout.js +503 -0
  170. package/dist/retrieval/relativeTimeHints.js +113 -0
  171. package/dist/retrieval/semantic.js +67 -0
  172. package/dist/router/routerCache.js +106 -0
  173. package/dist/router/sessionRouter.js +726 -0
  174. package/dist/toolRefusal.js +120 -0
  175. package/dist/watcher/watcher.js +75 -0
  176. package/package.json +120 -4
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ /**
3
+ * The distance scan of the in-process vector mirror (vectorIndex.ts), on 128-bit SIMD.
4
+ *
5
+ * A hosted workspace stores dense vectors (768 floats each). A JavaScript scan over them costs about 0.8 microseconds a
6
+ * vector whether the rows are in cache or not (9,661 vectors: 7.5 ms), so it is the arithmetic that is slow, not the
7
+ * memory. The same scan in WebAssembly SIMD (f32x4, four independent partial sums) takes 1.1 ms. The module is a few
8
+ * hundred bytes, assembled below from named instructions, with no import but its memory.
9
+ *
10
+ * It only measures squared distances, in f32, for vectorIndex.ts to choose candidates from. That choice is a band around
11
+ * the k-th nearest, wider than the gap between this arithmetic and `vec_distance_l2` (8e-8 measured over 71 queries and
12
+ * 9,661 real Vertex vectors, against a band of 1e-3); every candidate is then scored by `vec_distance_l2` itself, and a
13
+ * candidate that disagrees with the scan by more than half the band sends that query to the exact KNN path. Nothing a
14
+ * caller reads comes from this module.
15
+ *
16
+ * The rows live in the module's own linear memory and `data` is a view of it, so there is still one copy of the
17
+ * vectors. A linear memory reserves address space and starts the WebAssembly runtime, so a mirror too small to matter does
18
+ * not get one (`SIMD_MIN_BYTES`), and an allocation that fails means no SIMD (the JavaScript scan), never an error.
19
+ *
20
+ * RENOR_VECTOR_SIMD=0 turns it off.
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.SimdRows = exports.SIMD_MIN_BYTES = exports.SIMD_MAX_DIMS = void 0;
24
+ exports.simdScanEnabled = simdScanEnabled;
25
+ /** Rows one call writes distances for; the output area below holds this many f32. */
26
+ const CHUNK_ROWS = 8192;
27
+ /** The most floats in a row this module scans (the query area below). */
28
+ exports.SIMD_MAX_DIMS = 8192;
29
+ /** Layout of the linear memory: the query, then the distances of one chunk, then the rows. */
30
+ const QUERY_AT = 0;
31
+ const OUT_AT = exports.SIMD_MAX_DIMS * 4;
32
+ const DATA_AT = OUT_AT + CHUNK_ROWS * 4;
33
+ const PAGE = 65536;
34
+ /**
35
+ * Below this many bytes of vectors (2,731 of them at 768 dimensions) a mirror is scanned in JavaScript: that scan costs under
36
+ * 2.2 ms, about a tenth of a `get_context`, and a WebAssembly memory brings the runtime with it (about 3 MiB resident for
37
+ * the whole engine, 10 GiB of address space). From here the scan is a fifth of a call and the saving pays for both. The
38
+ * bytes counted are the vectors the mirror holds, never the room it keeps for more (vectorIndex.ts wantsRows).
39
+ */
40
+ exports.SIMD_MIN_BYTES = 8 * 1024 * 1024;
41
+ // ---- the module: a few instructions, named as in the WebAssembly text format --------------------------------------
42
+ const uleb = (n) => {
43
+ const out = [];
44
+ do {
45
+ let b = n & 0x7f;
46
+ n >>>= 7;
47
+ if (n)
48
+ b |= 0x80;
49
+ out.push(b);
50
+ } while (n);
51
+ return out;
52
+ };
53
+ const sleb = (n) => {
54
+ const out = [];
55
+ for (;;) {
56
+ const b = n & 0x7f;
57
+ n >>= 7;
58
+ if ((n === 0 && !(b & 0x40)) || (n === -1 && (b & 0x40))) {
59
+ out.push(b);
60
+ return out;
61
+ }
62
+ out.push(b | 0x80);
63
+ }
64
+ };
65
+ const section = (id, body) => [id, ...uleb(body.length), ...body];
66
+ const vec = (items) => [...uleb(items.length), ...items.flat()];
67
+ const text = (s) => [...uleb(s.length), ...Buffer.from(s)];
68
+ const I32 = 0x7f;
69
+ const V128 = 0x7b;
70
+ const get = (i) => [0x20, ...uleb(i)];
71
+ const set = (i) => [0x21, ...uleb(i)];
72
+ const tee = (i) => [0x22, ...uleb(i)];
73
+ const i32 = (n) => [0x41, ...sleb(n)];
74
+ const I32_ADD = [0x6a];
75
+ const I32_AND = [0x71];
76
+ const I32_SHL = [0x74];
77
+ const I32_GE_U = [0x4f];
78
+ const BLOCK = [0x02, 0x40];
79
+ const LOOP = [0x03, 0x40];
80
+ const END = [0x0b];
81
+ const br = (depth) => [0x0c, ...uleb(depth)];
82
+ const brIf = (depth) => [0x0d, ...uleb(depth)];
83
+ /** v128.load at `p + offset`, byte aligned: a row of a mirror is not 16-byte aligned. */
84
+ const v128Load = (offset) => [0xfd, 0x00, 0x00, ...uleb(offset)];
85
+ const V128_ZERO = [0xfd, 0x0c, ...new Array(16).fill(0)];
86
+ const F32X4_ADD = [0xfd, ...uleb(0xe4)];
87
+ const F32X4_SUB = [0xfd, ...uleb(0xe5)];
88
+ const F32X4_MUL = [0xfd, ...uleb(0xe6)];
89
+ const f32x4Lane = (lane) => [0xfd, 0x1f, lane];
90
+ const F32_ADD = [0x92];
91
+ const F32_STORE = [0x38, 0x02, 0x00];
92
+ // parameters: rows (byte address of the first row), count, dims, query (byte address), out (byte address)
93
+ const [ROWS, COUNT, DIMS, QUERY, OUT] = [0, 1, 2, 3, 4];
94
+ // locals: i (the row), p (the next float of the row), q (the next float of the query), end16, end4, then the sums
95
+ const [I, P, Q, END16, END4, A0, A1, A2, A3, X] = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
96
+ /** sum += (row[at..at+4) - query[at..at+4))^2, four lanes at once. */
97
+ const step = (sum, at) => [
98
+ ...get(sum),
99
+ ...get(P), ...v128Load(at), ...get(Q), ...v128Load(at), ...F32X4_SUB, ...tee(X), ...get(X), ...F32X4_MUL,
100
+ ...F32X4_ADD, ...set(sum),
101
+ ];
102
+ /**
103
+ * (func (export "s") (param $rows i32) (param $count i32) (param $dims i32) (param $query i32) (param $out i32)
104
+ * for each of $count rows, which follow one another $dims floats apart (dims is a multiple of 4):
105
+ * four sums of four lanes, 16 floats a turn, so no add waits for the one before it; the left over groups of 4 go to the first
106
+ * out[i] = sum of the sixteen lanes (f32)
107
+ */
108
+ const SCAN_BODY = [
109
+ ...get(ROWS), ...set(P),
110
+ ...BLOCK, ...LOOP,
111
+ ...get(I), ...get(COUNT), ...I32_GE_U, ...brIf(1),
112
+ ...V128_ZERO, ...set(A0), ...V128_ZERO, ...set(A1), ...V128_ZERO, ...set(A2), ...V128_ZERO, ...set(A3),
113
+ ...get(QUERY), ...set(Q),
114
+ ...get(P), ...get(DIMS), ...i32(-16), ...I32_AND, ...i32(2), ...I32_SHL, ...I32_ADD, ...set(END16),
115
+ ...get(P), ...get(DIMS), ...i32(2), ...I32_SHL, ...I32_ADD, ...set(END4),
116
+ ...BLOCK, ...LOOP,
117
+ ...get(P), ...get(END16), ...I32_GE_U, ...brIf(1),
118
+ ...step(A0, 0), ...step(A1, 16), ...step(A2, 32), ...step(A3, 48),
119
+ ...get(P), ...i32(64), ...I32_ADD, ...set(P),
120
+ ...get(Q), ...i32(64), ...I32_ADD, ...set(Q),
121
+ ...br(0), ...END, ...END,
122
+ ...BLOCK, ...LOOP,
123
+ ...get(P), ...get(END4), ...I32_GE_U, ...brIf(1),
124
+ ...step(A0, 0),
125
+ ...get(P), ...i32(16), ...I32_ADD, ...set(P),
126
+ ...get(Q), ...i32(16), ...I32_ADD, ...set(Q),
127
+ ...br(0), ...END, ...END,
128
+ ...get(OUT), ...get(I), ...i32(2), ...I32_SHL, ...I32_ADD,
129
+ ...get(A0), ...get(A1), ...F32X4_ADD, ...get(A2), ...get(A3), ...F32X4_ADD, ...F32X4_ADD, ...set(X),
130
+ ...get(X), ...f32x4Lane(0), ...get(X), ...f32x4Lane(1), ...F32_ADD,
131
+ ...get(X), ...f32x4Lane(2), ...get(X), ...f32x4Lane(3), ...F32_ADD,
132
+ ...F32_ADD, ...F32_STORE,
133
+ ...get(I), ...i32(1), ...I32_ADD, ...set(I),
134
+ ...br(0), ...END, ...END,
135
+ ...END,
136
+ ];
137
+ const SCAN_MODULE = new Uint8Array([
138
+ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, // "\0asm", version 1
139
+ ...section(1, vec([[0x60, ...vec([[I32], [I32], [I32], [I32], [I32]]), 0x00]])), // (i32 x5) -> ()
140
+ ...section(2, vec([[...text('e'), ...text('m'), 0x02, 0x00, 0x01]])), // import e.m: a memory of at least one page
141
+ ...section(3, vec([[0x00]])), // one function, of that type
142
+ ...section(7, vec([[...text('s'), 0x00, 0x00]])), // export it as "s"
143
+ ...section(10, vec([(() => {
144
+ const code = [...vec([[...uleb(5), I32], [...uleb(5), V128]]), ...SCAN_BODY];
145
+ return [...uleb(code.length), ...code];
146
+ })()])),
147
+ ]);
148
+ let warned = false;
149
+ let compiled;
150
+ /** The compiled module, or null where SIMD (or WebAssembly) is not there. Compiled once per process. */
151
+ function scanModule() {
152
+ if (compiled === undefined) {
153
+ try {
154
+ compiled = typeof WebAssembly === 'object' && WebAssembly.validate(SCAN_MODULE) ? new WebAssembly.Module(SCAN_MODULE) : null;
155
+ }
156
+ catch {
157
+ compiled = null;
158
+ }
159
+ }
160
+ return compiled;
161
+ }
162
+ /** RENOR_VECTOR_SIMD: 0/false/no/off turns the SIMD scan off; anything else (or nothing) leaves it on where it can run. */
163
+ function simdScanEnabled(env = process.env) {
164
+ return !['0', 'false', 'no', 'off'].includes((env.RENOR_VECTOR_SIMD ?? '').trim().toLowerCase());
165
+ }
166
+ const pagesFor = (dims, rows) => Math.ceil((DATA_AT + rows * dims * 4) / PAGE);
167
+ /**
168
+ * `capRows` rows of `dims` floats in a linear memory of their own, and the SIMD scan over them. `data` is a view of the
169
+ * rows (row-major, as vectorIndex.ts stores them) and is a new object after `grow`: take it from here each time.
170
+ */
171
+ class SimdRows {
172
+ memory;
173
+ scan;
174
+ dims;
175
+ data;
176
+ capRows;
177
+ outView;
178
+ queryView;
179
+ constructor(memory, scan, dims, capRows) {
180
+ this.memory = memory;
181
+ this.scan = scan;
182
+ this.dims = dims;
183
+ this.capRows = capRows;
184
+ const views = this.views();
185
+ this.data = views.data;
186
+ this.outView = views.outView;
187
+ this.queryView = views.queryView;
188
+ }
189
+ /** Null when the scan cannot run here: switched off, no SIMD, a row it does not take, or no address space for another memory. */
190
+ static create(dims, capRows, env = process.env) {
191
+ if (!simdScanEnabled(env) || !Number.isInteger(dims) || dims < 4 || dims % 4 !== 0 || dims > exports.SIMD_MAX_DIMS || capRows < 1)
192
+ return null;
193
+ const module = scanModule();
194
+ if (!module)
195
+ return null;
196
+ try {
197
+ const memory = new WebAssembly.Memory({ initial: pagesFor(dims, capRows) });
198
+ const { s } = new WebAssembly.Instance(module, { e: { m: memory } }).exports;
199
+ return new SimdRows(memory, s, dims, capRows);
200
+ }
201
+ catch (err) {
202
+ if (!warned) {
203
+ warned = true;
204
+ console.warn(`[vectors] no memory for the SIMD scan (${err instanceof Error ? err.message : String(err)}): scanning in JavaScript`);
205
+ }
206
+ return null;
207
+ }
208
+ }
209
+ views() {
210
+ const buffer = this.memory.buffer;
211
+ return {
212
+ data: new Float32Array(buffer, DATA_AT, this.capRows * this.dims),
213
+ outView: new Float32Array(buffer, OUT_AT, CHUNK_ROWS),
214
+ queryView: new Float32Array(buffer, QUERY_AT, this.dims),
215
+ };
216
+ }
217
+ /** Room for `capRows` rows, the rows kept. False when the memory cannot grow: the caller drops the mirror. */
218
+ grow(capRows) {
219
+ if (capRows <= this.capRows)
220
+ return true;
221
+ try {
222
+ const have = this.memory.buffer.byteLength / PAGE;
223
+ const need = pagesFor(this.dims, capRows);
224
+ if (need > have)
225
+ this.memory.grow(need - have);
226
+ }
227
+ catch {
228
+ return false;
229
+ }
230
+ this.capRows = capRows;
231
+ const views = this.views();
232
+ this.data = views.data;
233
+ this.outView = views.outView;
234
+ this.queryView = views.queryView;
235
+ return true;
236
+ }
237
+ /** The query every `distances` and `distance` that follows measures from. */
238
+ stage(query) {
239
+ this.queryView.set(query);
240
+ }
241
+ /** Distances (not squared) from the staged query to rows `from..from+count-1`, written to `out[at..at+count)`. */
242
+ distances(from, count, out, at) {
243
+ const rowBytes = this.dims * 4;
244
+ for (let done = 0; done < count; done += CHUNK_ROWS) {
245
+ const chunk = Math.min(CHUNK_ROWS, count - done);
246
+ this.scan(DATA_AT + (from + done) * rowBytes, chunk, this.dims, QUERY_AT, OUT_AT);
247
+ const squared = this.outView;
248
+ for (let i = 0; i < chunk; i++)
249
+ out[at + done + i] = Math.sqrt(squared[i]);
250
+ }
251
+ }
252
+ /** Distance from the staged query to one row. */
253
+ distance(row) {
254
+ this.scan(DATA_AT + row * this.dims * 4, 1, this.dims, QUERY_AT, OUT_AT);
255
+ return Math.sqrt(this.outView[0]);
256
+ }
257
+ }
258
+ exports.SimdRows = SimdRows;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EMBEDDING_SPACE_VERSION = void 0;
4
+ exports.embeddingSpace = embeddingSpace;
5
+ /**
6
+ * Bump when the engine changes how it asks a model for the vectors it stores (the task type, a prefix,
7
+ * normalization, truncation), so an index built the old way is not mixed with vectors written the new way.
8
+ */
9
+ exports.EMBEDDING_SPACE_VERSION = 1;
10
+ /**
11
+ * The embedding space a provider's stored vectors live in: how the engine embeds documents, which provider
12
+ * and model, and how many dimensions. A stored vector can stand in for a freshly embedded one only if the
13
+ * two spaces are equal; mixing spaces in one index makes search compare numbers that mean different things.
14
+ * A provider that declares no identity has no space, so nothing stored is ever reused for it.
15
+ */
16
+ function embeddingSpace(provider) {
17
+ const identity = provider.identity;
18
+ if (!identity)
19
+ return null;
20
+ return `v${exports.EMBEDDING_SPACE_VERSION}|document|${identity.kind}|${identity.model}|${provider.dimensions}`;
21
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EmbeddingUnavailableError = void 0;
4
+ /**
5
+ * The embedding service is slow, refusing (429, 500, 503) or silent, as opposed to refusing one text. What a caller
6
+ * does about it is the same whatever the cause: keep what was saved, answer without the service, and ask again later.
7
+ */
8
+ class EmbeddingUnavailableError extends Error {
9
+ constructor(message, options) {
10
+ super(message, options);
11
+ this.name = 'EmbeddingUnavailableError';
12
+ }
13
+ }
14
+ exports.EmbeddingUnavailableError = EmbeddingUnavailableError;