renor-engine 1.1.0 → 1.3.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 (193) hide show
  1. package/README.md +27 -2
  2. package/THIRD-PARTY-NOTICES +2661 -0
  3. package/dist/BUILD.json +3 -3
  4. package/dist/cli.js +1656 -490
  5. package/package.json +16 -80
  6. package/dist/.tsbuildinfo +0 -1
  7. package/dist/api/apiAuth.js +0 -43
  8. package/dist/api/server.js +0 -174
  9. package/dist/buildIdentity.js +0 -149
  10. package/dist/callPhases.js +0 -82
  11. package/dist/cli-extractors.js +0 -46
  12. package/dist/config.js +0 -65
  13. package/dist/context/composer.js +0 -320
  14. package/dist/context/readHonesty.js +0 -478
  15. package/dist/context/rowStore.js +0 -238
  16. package/dist/conversation/formatter.js +0 -81
  17. package/dist/conversation/parser.js +0 -193
  18. package/dist/conversation/types.js +0 -2
  19. package/dist/conversation/writer.js +0 -42
  20. package/dist/db/client.js +0 -149
  21. package/dist/db/handoffTable.js +0 -31
  22. package/dist/db/indexSalvage.js +0 -101
  23. package/dist/db/migrations.js +0 -670
  24. package/dist/db/readCache.js +0 -109
  25. package/dist/db/schema.js +0 -5
  26. package/dist/db/sqlite.js +0 -396
  27. package/dist/db/statements.js +0 -89
  28. package/dist/digests/digestCache.js +0 -146
  29. package/dist/digests/digests.js +0 -597
  30. package/dist/digests/worker.js +0 -350
  31. package/dist/embeddings/caching.js +0 -337
  32. package/dist/embeddings/coalescing.js +0 -177
  33. package/dist/embeddings/interactive.js +0 -103
  34. package/dist/embeddings/local.js +0 -70
  35. package/dist/embeddings/openai.js +0 -106
  36. package/dist/embeddings/rebuild.js +0 -166
  37. package/dist/embeddings/simdScan.js +0 -260
  38. package/dist/embeddings/space.js +0 -21
  39. package/dist/embeddings/types.js +0 -14
  40. package/dist/embeddings/vectorIndex.js +0 -674
  41. package/dist/embeddings/vertex.js +0 -334
  42. package/dist/eval/artifacts.js +0 -42
  43. package/dist/eval/cacheReport.js +0 -146
  44. package/dist/eval/comparison.js +0 -182
  45. package/dist/eval/context700-candidate.js +0 -145
  46. package/dist/eval/evalCache.js +0 -568
  47. package/dist/eval/hashEmbedding.js +0 -35
  48. package/dist/eval/indexSnapshots.js +0 -548
  49. package/dist/eval/longmemeval.js +0 -56
  50. package/dist/eval/metrics.js +0 -181
  51. package/dist/eval/pageDump.js +0 -67
  52. package/dist/eval/renorbenchBaseline.js +0 -486
  53. package/dist/eval/renorbenchDocuments.js +0 -134
  54. package/dist/eval/renorbenchProduct.js +0 -182
  55. package/dist/eval/runLedger.js +0 -279
  56. package/dist/eval/runManifest.js +0 -485
  57. package/dist/eval/scoring.js +0 -197
  58. package/dist/eval/textTokens.js +0 -17
  59. package/dist/evidence/attach.js +0 -264
  60. package/dist/evidence/background.js +0 -147
  61. package/dist/evidence/evidenceCache.js +0 -182
  62. package/dist/evidence/gate.js +0 -37
  63. package/dist/evidence/keyPool.js +0 -85
  64. package/dist/evidence/ollamaChat.js +0 -84
  65. package/dist/evidence/optin.js +0 -165
  66. package/dist/evidence/options.js +0 -151
  67. package/dist/evidence/secondPass.js +0 -294
  68. package/dist/extraction/classifyCapture.js +0 -34
  69. package/dist/extraction/decision-model.js +0 -174
  70. package/dist/extraction/eventExtractor.js +0 -113
  71. package/dist/extraction/extractionClient.js +0 -122
  72. package/dist/extraction/factExtractor.js +0 -46
  73. package/dist/extraction/factsWritePath.js +0 -179
  74. package/dist/extraction/preferenceExtractor.js +0 -150
  75. package/dist/extraction/secretGuard.js +0 -176
  76. package/dist/extraction/secretScanner.js +0 -665
  77. package/dist/extraction/typedFacts.js +0 -224
  78. package/dist/extraction/writePathAdjudication.js +0 -110
  79. package/dist/importing/apply.js +0 -672
  80. package/dist/importing/bundle-write.js +0 -80
  81. package/dist/importing/cli.js +0 -408
  82. package/dist/importing/existing.js +0 -51
  83. package/dist/importing/facts.js +0 -121
  84. package/dist/importing/forgetImported.js +0 -79
  85. package/dist/importing/hosted.js +0 -467
  86. package/dist/importing/journalLog.js +0 -96
  87. package/dist/importing/markdown.js +0 -98
  88. package/dist/importing/plan.js +0 -201
  89. package/dist/importing/secretScreen.js +0 -113
  90. package/dist/importing/serialize.js +0 -188
  91. package/dist/importing/source.js +0 -463
  92. package/dist/importing/types.js +0 -6
  93. package/dist/indexer/chunker.js +0 -319
  94. package/dist/indexer/dailyEntries.js +0 -63
  95. package/dist/indexer/hasher.js +0 -10
  96. package/dist/indexer/laneRuns.js +0 -48
  97. package/dist/indexer/o200k.js +0 -481
  98. package/dist/indexer/outsideRoot.js +0 -77
  99. package/dist/indexer/parser.js +0 -170
  100. package/dist/indexer/pipeline.js +0 -988
  101. package/dist/indexer/staleness.js +0 -201
  102. package/dist/indexer/tokenizer.js +0 -77
  103. package/dist/indexer/walker.js +0 -170
  104. package/dist/mcp/hive.js +0 -88
  105. package/dist/mcp/requestErrors.js +0 -47
  106. package/dist/mcp/server.js +0 -426
  107. package/dist/memory/agentLease.js +0 -43
  108. package/dist/memory/confinedWrite.js +0 -315
  109. package/dist/memory/controls.js +0 -73
  110. package/dist/memory/dailyNote.js +0 -265
  111. package/dist/memory/durableAppend.js +0 -57
  112. package/dist/memory/factConflicts.js +0 -203
  113. package/dist/memory/factTerms.js +0 -321
  114. package/dist/memory/handoff.js +0 -363
  115. package/dist/memory/hiveNameHeader.cjs +0 -10
  116. package/dist/memory/inventory.js +0 -55
  117. package/dist/memory/invisibleText.js +0 -20
  118. package/dist/memory/lifecycle.js +0 -1991
  119. package/dist/memory/limits.js +0 -13
  120. package/dist/memory/requests.js +0 -183
  121. package/dist/memory/sourceName.js +0 -276
  122. package/dist/memory/statusFacts.js +0 -61
  123. package/dist/memory/whatsNew.js +0 -158
  124. package/dist/memory/writer.js +0 -175
  125. package/dist/memory/writerConflicts.js +0 -85
  126. package/dist/memorymap/memoryMap.js +0 -1594
  127. package/dist/memorymap/replacedJournal.js +0 -58
  128. package/dist/memorymap/replacements.js +0 -410
  129. package/dist/mvp/activity.js +0 -86
  130. package/dist/mvp/agentMemory.js +0 -1800
  131. package/dist/mvp/answerCheck.js +0 -211
  132. package/dist/mvp/auth.js +0 -531
  133. package/dist/mvp/cli.js +0 -75
  134. package/dist/mvp/client-store.js +0 -462
  135. package/dist/mvp/compileCache.js +0 -242
  136. package/dist/mvp/compileSeed.js +0 -33
  137. package/dist/mvp/config.js +0 -288
  138. package/dist/mvp/connectionStatus.js +0 -80
  139. package/dist/mvp/contextDistinct.js +0 -53
  140. package/dist/mvp/contextProfile.js +0 -87
  141. package/dist/mvp/contextRelevance.js +0 -413
  142. package/dist/mvp/directorySurface.js +0 -68
  143. package/dist/mvp/engine.js +0 -1078
  144. package/dist/mvp/exportAll.js +0 -374
  145. package/dist/mvp/factLanePack.js +0 -77
  146. package/dist/mvp/factMarkers.js +0 -65
  147. package/dist/mvp/factsLane.js +0 -203
  148. package/dist/mvp/hiddenSpans.js +0 -585
  149. package/dist/mvp/history.js +0 -414
  150. package/dist/mvp/hitDates.js +0 -31
  151. package/dist/mvp/hitFloor.js +0 -36
  152. package/dist/mvp/identity.js +0 -18
  153. package/dist/mvp/idle.js +0 -113
  154. package/dist/mvp/log.js +0 -118
  155. package/dist/mvp/memoryDir.js +0 -98
  156. package/dist/mvp/posthogMcp.js +0 -210
  157. package/dist/mvp/readScope.js +0 -104
  158. package/dist/mvp/readUsefulness.js +0 -222
  159. package/dist/mvp/sanitize.js +0 -48
  160. package/dist/mvp/schemaRejections.js +0 -91
  161. package/dist/mvp/scope.js +0 -127
  162. package/dist/mvp/server.js +0 -2604
  163. package/dist/mvp/serverCard.js +0 -38
  164. package/dist/mvp/storedSize.js +0 -139
  165. package/dist/mvp/telemetry.js +0 -474
  166. package/dist/net/poolFetch.js +0 -174
  167. package/dist/recall/actionRecall.js +0 -282
  168. package/dist/recall/autoRecall.js +0 -447
  169. package/dist/recall/searchRecall.js +0 -189
  170. package/dist/retrieval/adviceLines.js +0 -195
  171. package/dist/retrieval/adviceQuestion.js +0 -44
  172. package/dist/retrieval/conversationShape.js +0 -44
  173. package/dist/retrieval/dailyEntryTime.js +0 -55
  174. package/dist/retrieval/entityLookup.js +0 -162
  175. package/dist/retrieval/factsFirst.js +0 -188
  176. package/dist/retrieval/keyword.js +0 -84
  177. package/dist/retrieval/ledgerEventTime.js +0 -51
  178. package/dist/retrieval/ledgerLiveness.js +0 -83
  179. package/dist/retrieval/ledgerPresentation.js +0 -161
  180. package/dist/retrieval/noteIdentity.js +0 -57
  181. package/dist/retrieval/orchestrator.js +0 -1171
  182. package/dist/retrieval/plainWording.js +0 -236
  183. package/dist/retrieval/queryHelpers.js +0 -142
  184. package/dist/retrieval/questionSpan.js +0 -475
  185. package/dist/retrieval/readerEvents.js +0 -690
  186. package/dist/retrieval/readerLayout.js +0 -422
  187. package/dist/retrieval/relativeTimeHints.js +0 -113
  188. package/dist/retrieval/semantic.js +0 -67
  189. package/dist/router/routerCache.js +0 -106
  190. package/dist/router/sessionRouter.js +0 -726
  191. package/dist/toolRefusal.js +0 -120
  192. package/dist/watcher/watcher.js +0 -77
  193. /package/dist/{indexer/o200k.json → o200k.json} +0 -0
@@ -1,260 +0,0 @@
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
- const log_1 = require("../mvp/log");
26
- const log = (0, log_1.createLogger)('engine');
27
- /** Rows one call writes distances for; the output area below holds this many f32. */
28
- const CHUNK_ROWS = 8192;
29
- /** The most floats in a row this module scans (the query area below). */
30
- exports.SIMD_MAX_DIMS = 8192;
31
- /** Layout of the linear memory: the query, then the distances of one chunk, then the rows. */
32
- const QUERY_AT = 0;
33
- const OUT_AT = exports.SIMD_MAX_DIMS * 4;
34
- const DATA_AT = OUT_AT + CHUNK_ROWS * 4;
35
- const PAGE = 65536;
36
- /**
37
- * Below this many bytes of vectors (2,731 of them at 768 dimensions) a mirror is scanned in JavaScript: that scan costs under
38
- * 2.2 ms, about a tenth of a `get_context`, and a WebAssembly memory brings the runtime with it (about 3 MiB resident for
39
- * 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
40
- * bytes counted are the vectors the mirror holds, never the room it keeps for more (vectorIndex.ts wantsRows).
41
- */
42
- exports.SIMD_MIN_BYTES = 8 * 1024 * 1024;
43
- // ---- the module: a few instructions, named as in the WebAssembly text format --------------------------------------
44
- const uleb = (n) => {
45
- const out = [];
46
- do {
47
- let b = n & 0x7f;
48
- n >>>= 7;
49
- if (n)
50
- b |= 0x80;
51
- out.push(b);
52
- } while (n);
53
- return out;
54
- };
55
- const sleb = (n) => {
56
- const out = [];
57
- for (;;) {
58
- const b = n & 0x7f;
59
- n >>= 7;
60
- if ((n === 0 && !(b & 0x40)) || (n === -1 && (b & 0x40))) {
61
- out.push(b);
62
- return out;
63
- }
64
- out.push(b | 0x80);
65
- }
66
- };
67
- const section = (id, body) => [id, ...uleb(body.length), ...body];
68
- const vec = (items) => [...uleb(items.length), ...items.flat()];
69
- const text = (s) => [...uleb(s.length), ...Buffer.from(s)];
70
- const I32 = 0x7f;
71
- const V128 = 0x7b;
72
- const get = (i) => [0x20, ...uleb(i)];
73
- const set = (i) => [0x21, ...uleb(i)];
74
- const tee = (i) => [0x22, ...uleb(i)];
75
- const i32 = (n) => [0x41, ...sleb(n)];
76
- const I32_ADD = [0x6a];
77
- const I32_AND = [0x71];
78
- const I32_SHL = [0x74];
79
- const I32_GE_U = [0x4f];
80
- const BLOCK = [0x02, 0x40];
81
- const LOOP = [0x03, 0x40];
82
- const END = [0x0b];
83
- const br = (depth) => [0x0c, ...uleb(depth)];
84
- const brIf = (depth) => [0x0d, ...uleb(depth)];
85
- /** v128.load at `p + offset`, byte aligned: a row of a mirror is not 16-byte aligned. */
86
- const v128Load = (offset) => [0xfd, 0x00, 0x00, ...uleb(offset)];
87
- const V128_ZERO = [0xfd, 0x0c, ...new Array(16).fill(0)];
88
- const F32X4_ADD = [0xfd, ...uleb(0xe4)];
89
- const F32X4_SUB = [0xfd, ...uleb(0xe5)];
90
- const F32X4_MUL = [0xfd, ...uleb(0xe6)];
91
- const f32x4Lane = (lane) => [0xfd, 0x1f, lane];
92
- const F32_ADD = [0x92];
93
- const F32_STORE = [0x38, 0x02, 0x00];
94
- // parameters: rows (byte address of the first row), count, dims, query (byte address), out (byte address)
95
- const [ROWS, COUNT, DIMS, QUERY, OUT] = [0, 1, 2, 3, 4];
96
- // locals: i (the row), p (the next float of the row), q (the next float of the query), end16, end4, then the sums
97
- const [I, P, Q, END16, END4, A0, A1, A2, A3, X] = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
98
- /** sum += (row[at..at+4) - query[at..at+4))^2, four lanes at once. */
99
- const step = (sum, at) => [
100
- ...get(sum),
101
- ...get(P), ...v128Load(at), ...get(Q), ...v128Load(at), ...F32X4_SUB, ...tee(X), ...get(X), ...F32X4_MUL,
102
- ...F32X4_ADD, ...set(sum),
103
- ];
104
- /**
105
- * (func (export "s") (param $rows i32) (param $count i32) (param $dims i32) (param $query i32) (param $out i32)
106
- * for each of $count rows, which follow one another $dims floats apart (dims is a multiple of 4):
107
- * 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
108
- * out[i] = sum of the sixteen lanes (f32)
109
- */
110
- const SCAN_BODY = [
111
- ...get(ROWS), ...set(P),
112
- ...BLOCK, ...LOOP,
113
- ...get(I), ...get(COUNT), ...I32_GE_U, ...brIf(1),
114
- ...V128_ZERO, ...set(A0), ...V128_ZERO, ...set(A1), ...V128_ZERO, ...set(A2), ...V128_ZERO, ...set(A3),
115
- ...get(QUERY), ...set(Q),
116
- ...get(P), ...get(DIMS), ...i32(-16), ...I32_AND, ...i32(2), ...I32_SHL, ...I32_ADD, ...set(END16),
117
- ...get(P), ...get(DIMS), ...i32(2), ...I32_SHL, ...I32_ADD, ...set(END4),
118
- ...BLOCK, ...LOOP,
119
- ...get(P), ...get(END16), ...I32_GE_U, ...brIf(1),
120
- ...step(A0, 0), ...step(A1, 16), ...step(A2, 32), ...step(A3, 48),
121
- ...get(P), ...i32(64), ...I32_ADD, ...set(P),
122
- ...get(Q), ...i32(64), ...I32_ADD, ...set(Q),
123
- ...br(0), ...END, ...END,
124
- ...BLOCK, ...LOOP,
125
- ...get(P), ...get(END4), ...I32_GE_U, ...brIf(1),
126
- ...step(A0, 0),
127
- ...get(P), ...i32(16), ...I32_ADD, ...set(P),
128
- ...get(Q), ...i32(16), ...I32_ADD, ...set(Q),
129
- ...br(0), ...END, ...END,
130
- ...get(OUT), ...get(I), ...i32(2), ...I32_SHL, ...I32_ADD,
131
- ...get(A0), ...get(A1), ...F32X4_ADD, ...get(A2), ...get(A3), ...F32X4_ADD, ...F32X4_ADD, ...set(X),
132
- ...get(X), ...f32x4Lane(0), ...get(X), ...f32x4Lane(1), ...F32_ADD,
133
- ...get(X), ...f32x4Lane(2), ...get(X), ...f32x4Lane(3), ...F32_ADD,
134
- ...F32_ADD, ...F32_STORE,
135
- ...get(I), ...i32(1), ...I32_ADD, ...set(I),
136
- ...br(0), ...END, ...END,
137
- ...END,
138
- ];
139
- const SCAN_MODULE = new Uint8Array([
140
- 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, // "\0asm", version 1
141
- ...section(1, vec([[0x60, ...vec([[I32], [I32], [I32], [I32], [I32]]), 0x00]])), // (i32 x5) -> ()
142
- ...section(2, vec([[...text('e'), ...text('m'), 0x02, 0x00, 0x01]])), // import e.m: a memory of at least one page
143
- ...section(3, vec([[0x00]])), // one function, of that type
144
- ...section(7, vec([[...text('s'), 0x00, 0x00]])), // export it as "s"
145
- ...section(10, vec([(() => {
146
- const code = [...vec([[...uleb(5), I32], [...uleb(5), V128]]), ...SCAN_BODY];
147
- return [...uleb(code.length), ...code];
148
- })()])),
149
- ]);
150
- let warned = false;
151
- let compiled;
152
- /** The compiled module, or null where SIMD (or WebAssembly) is not there. Compiled once per process. */
153
- function scanModule() {
154
- if (compiled === undefined) {
155
- try {
156
- compiled = typeof WebAssembly === 'object' && WebAssembly.validate(SCAN_MODULE) ? new WebAssembly.Module(SCAN_MODULE) : null;
157
- }
158
- catch {
159
- compiled = null;
160
- }
161
- }
162
- return compiled;
163
- }
164
- /** RENOR_VECTOR_SIMD: 0/false/no/off turns the SIMD scan off; anything else (or nothing) leaves it on where it can run. */
165
- function simdScanEnabled(env = process.env) {
166
- return !['0', 'false', 'no', 'off'].includes((env.RENOR_VECTOR_SIMD ?? '').trim().toLowerCase());
167
- }
168
- const pagesFor = (dims, rows) => Math.ceil((DATA_AT + rows * dims * 4) / PAGE);
169
- /**
170
- * `capRows` rows of `dims` floats in a linear memory of their own, and the SIMD scan over them. `data` is a view of the
171
- * rows (row-major, as vectorIndex.ts stores them) and is a new object after `grow`: take it from here each time.
172
- */
173
- class SimdRows {
174
- memory;
175
- scan;
176
- dims;
177
- data;
178
- capRows;
179
- outView;
180
- queryView;
181
- constructor(memory, scan, dims, capRows) {
182
- this.memory = memory;
183
- this.scan = scan;
184
- this.dims = dims;
185
- this.capRows = capRows;
186
- const views = this.views();
187
- this.data = views.data;
188
- this.outView = views.outView;
189
- this.queryView = views.queryView;
190
- }
191
- /** Null when the scan cannot run here: switched off, no SIMD, a row it does not take, or no address space for another memory. */
192
- static create(dims, capRows, env = process.env) {
193
- if (!simdScanEnabled(env) || !Number.isInteger(dims) || dims < 4 || dims % 4 !== 0 || dims > exports.SIMD_MAX_DIMS || capRows < 1)
194
- return null;
195
- const module = scanModule();
196
- if (!module)
197
- return null;
198
- try {
199
- const memory = new WebAssembly.Memory({ initial: pagesFor(dims, capRows) });
200
- const { s } = new WebAssembly.Instance(module, { e: { m: memory } }).exports;
201
- return new SimdRows(memory, s, dims, capRows);
202
- }
203
- catch (err) {
204
- if (!warned) {
205
- warned = true;
206
- log.warn('simd_scan_unavailable', { detail: 'scanning in JavaScript' }, err);
207
- }
208
- return null;
209
- }
210
- }
211
- views() {
212
- const buffer = this.memory.buffer;
213
- return {
214
- data: new Float32Array(buffer, DATA_AT, this.capRows * this.dims),
215
- outView: new Float32Array(buffer, OUT_AT, CHUNK_ROWS),
216
- queryView: new Float32Array(buffer, QUERY_AT, this.dims),
217
- };
218
- }
219
- /** Room for `capRows` rows, the rows kept. False when the memory cannot grow: the caller drops the mirror. */
220
- grow(capRows) {
221
- if (capRows <= this.capRows)
222
- return true;
223
- try {
224
- const have = this.memory.buffer.byteLength / PAGE;
225
- const need = pagesFor(this.dims, capRows);
226
- if (need > have)
227
- this.memory.grow(need - have);
228
- }
229
- catch {
230
- return false;
231
- }
232
- this.capRows = capRows;
233
- const views = this.views();
234
- this.data = views.data;
235
- this.outView = views.outView;
236
- this.queryView = views.queryView;
237
- return true;
238
- }
239
- /** The query every `distances` and `distance` that follows measures from. */
240
- stage(query) {
241
- this.queryView.set(query);
242
- }
243
- /** Distances (not squared) from the staged query to rows `from..from+count-1`, written to `out[at..at+count)`. */
244
- distances(from, count, out, at) {
245
- const rowBytes = this.dims * 4;
246
- for (let done = 0; done < count; done += CHUNK_ROWS) {
247
- const chunk = Math.min(CHUNK_ROWS, count - done);
248
- this.scan(DATA_AT + (from + done) * rowBytes, chunk, this.dims, QUERY_AT, OUT_AT);
249
- const squared = this.outView;
250
- for (let i = 0; i < chunk; i++)
251
- out[at + done + i] = Math.sqrt(squared[i]);
252
- }
253
- }
254
- /** Distance from the staged query to one row. */
255
- distance(row) {
256
- this.scan(DATA_AT + row * this.dims * 4, 1, this.dims, QUERY_AT, OUT_AT);
257
- return Math.sqrt(this.outView[0]);
258
- }
259
- }
260
- exports.SimdRows = SimdRows;
@@ -1,21 +0,0 @@
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
- }
@@ -1,14 +0,0 @@
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;