@delali/narsil 0.3.1-next.113 → 0.3.1-next.116

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 (51) hide show
  1. package/dist/browser/{chunk-DC2SZO4D.mjs → chunk-2TMWIATH.mjs} +107 -67
  2. package/dist/browser/{chunk-YZPOBLAS.mjs → chunk-73U5DWOZ.mjs} +4 -3
  3. package/dist/browser/{chunk-4FVSBSXY.mjs → chunk-FODCC3MK.mjs} +1 -1
  4. package/dist/browser/{chunk-3YPLBK4C.mjs → chunk-I45FAGOF.mjs} +2 -2
  5. package/dist/browser/{durability-wiring-2RG22WQJ.mjs → durability-wiring-CSMTKEYX.mjs} +3 -3
  6. package/dist/browser/{module-5EWHBKHZ.mjs → module-G2PPZV3B.mjs} +27 -24
  7. package/dist/browser/{restore-queue-WCFUB4NS.mjs → restore-queue-N7N42PBS.mjs} +1 -1
  8. package/dist/browser/{runtime-FL5K4JOH.mjs → runtime-BX6XRFYR.mjs} +2 -2
  9. package/dist/browser/{snapshot-BE3F2PNC.mjs → snapshot-EBH6RXQO.mjs} +4 -4
  10. package/dist/browser/{write-MV7K7OCU.mjs → write-5ZKFINX3.mjs} +2 -2
  11. package/dist/{chunk-H2GNWBLB.mjs → chunk-4ZKBKPBV.mjs} +1 -1
  12. package/dist/{chunk-GLZI636G.mjs → chunk-5VVSHCXT.mjs} +27 -12
  13. package/dist/{chunk-LVNBY2TS.mjs → chunk-7EWQZQDT.mjs} +1 -1
  14. package/dist/{chunk-4PFOOQFQ.mjs → chunk-BCNUJVTT.mjs} +1 -1
  15. package/dist/{chunk-PABYSTKO.mjs → chunk-BCSWODXP.mjs} +71 -54
  16. package/dist/{thread-S4SUCV4Y.mjs → chunk-DEXID4ZT.mjs} +300 -202
  17. package/dist/{chunk-4XWIW3F3.mjs → chunk-HC5NURS6.mjs} +4 -3
  18. package/dist/{chunk-AOLD3LPV.mjs → chunk-IE43SRL3.mjs} +4 -1
  19. package/dist/{chunk-27ZEY73B.mjs → chunk-KGVC6KJ3.mjs} +4 -4
  20. package/dist/{chunk-QGVMEMCG.mjs → chunk-KVLX65KD.mjs} +4 -4
  21. package/dist/{chunk-5WEBVYOA.mjs → chunk-N53HN5VA.mjs} +16 -9
  22. package/dist/chunk-N6J6EJW3.mjs +198 -0
  23. package/dist/{chunk-CU4OB64V.mjs → chunk-NX7KU77V.mjs} +1 -1
  24. package/dist/{chunk-QIFOXLWF.mjs → chunk-OGFSUXYY.mjs} +2 -2
  25. package/dist/{chunk-5QIRLJH4.mjs → chunk-Q62NDKEC.mjs} +4 -3
  26. package/dist/{chunk-DZXGNLK5.mjs → chunk-UDZYIWDP.mjs} +3 -3
  27. package/dist/{chunk-HNAP2KTG.mjs → chunk-VFAXPDBH.mjs} +1 -0
  28. package/dist/{chunk-OM5G2J6X.mjs → chunk-VOKEYJHU.mjs} +1 -1
  29. package/dist/{chunk-OABTAUCW.mjs → chunk-YCFQ5754.mjs} +1 -1
  30. package/dist/{chunk-JUAFWJON.mjs → chunk-YCSRB3IN.mjs} +3 -3
  31. package/dist/{chunk-CQUMNIIG.mjs → chunk-Z4DZ4KK2.mjs} +1 -0
  32. package/dist/{chunk-2RAQKITH.mjs → chunk-ZR63OGT2.mjs} +1 -1
  33. package/dist/{direct-executor-R4HOSVPE.mjs → direct-executor-OUY4RPTU.mjs} +4 -4
  34. package/dist/distribution.mjs +17 -17
  35. package/dist/{durability-wiring-XZI6355I.mjs → durability-wiring-5V6DVHFK.mjs} +13 -13
  36. package/dist/index.browser.mjs +1 -1
  37. package/dist/index.mjs +7 -7
  38. package/dist/long-query-thread-HMQM2FWL.mjs +118 -0
  39. package/dist/{module-WVKSJL74.mjs → module-3IMTXNPW.mjs} +30 -27
  40. package/dist/pattern.mjs +1 -1
  41. package/dist/persistence/durability/checkpoint-worker.mjs +10 -10
  42. package/dist/{rerank-3POMPQNX.mjs → rerank-NYX5S7OG.mjs} +3 -3
  43. package/dist/{restore-queue-JAZAB5IQ.mjs → restore-queue-J6PCG4ON.mjs} +1 -1
  44. package/dist/{runtime-C2435MPK.mjs → runtime-XNYW6AWX.mjs} +2 -2
  45. package/dist/server.mjs +93 -199
  46. package/dist/{snapshot-PDUGHQ25.mjs → snapshot-57WF53MK.mjs} +14 -14
  47. package/dist/thread-FDEHU5G3.mjs +31 -0
  48. package/dist/vector/search-worker.mjs +2 -2
  49. package/dist/workers/entry.mjs +17 -5
  50. package/dist/{write-KVJ7YJJ6.mjs → write-YEI7A5OR.mjs} +8 -8
  51. package/package.json +7 -7
package/dist/server.mjs CHANGED
@@ -1,5 +1,6 @@
1
- import { DEFAULT_MAX_RETAINED_TASKS, loadUWebSockets, resolveCors, authorizerFor, createSharedGateBuffer, gateSlotOfWorker, createBodyBudgetBuffer, createRouteRunner, corsHeaderReader, createSharedBodyBudget, MAIN_THREAD_GATE_SLOT, createSharedRequestGate, registerServerRoutes, DEFAULT_MAX_CONCURRENT_TASKS, DEFAULT_MAX_TASK_PAGE_SIZE, DEFAULT_MAX_IMPORT_ERRORS, DEFAULT_MAX_FETCH_DOCUMENTS, DEFAULT_MAX_RESULT_WINDOW, DEFAULT_MAX_CONCURRENT_REQUESTS, DEFAULT_IMPORT_BATCH_SIZE, DEFAULT_MAX_LINE_BYTES, DEFAULT_MAX_RESTORE_BYTES, DEFAULT_MAX_IMPORT_BYTES, DEFAULT_MAX_BODY_BYTES, DEFAULT_MAX_RERANK_WINDOW, DEFAULT_MAX_BODY_BYTES_IN_FLIGHT_FRACTION, RUNNING_TASK_TTL_MS, DEFAULT_TASK_PAGE_SIZE, TERMINAL_TASK_TTL_MS, TASK_PROGRESS_WRITE_INTERVAL_MS, serializeNarsilError, createVersionHandler, acceptorOf, MAX_BODY_BYTES_IN_FLIGHT_FRACTION, createDocumentReadHandlers, sendError, respondError, respondJson, sendText, MAX_INDEX_TOUCH_INTERVAL_MS, INDEX_TOUCH_INTERVALS_PER_IDLE_TIMEOUT, closeEveryThreadAtExit, REQUEST_THREAD_CLOSE_AT_EXIT_MS, clearGateSlot, clearBodyBudgetSlot, createCloseAtExitWords, createDepartureWord, departureConfirmed, parseJson, validateCreateIndex, rejectInvalid, isRemoveOnlyBatch, validateBatch, serializeBatchResult, parseWriteJson, validateDocumentBody, validateSuggest, validateQuery, refuseRegex, withServerRerankWindow, respondAnswer, parseTaskListQuery, parseJsonOptional, validateRebalance, badRequest, sendStream, SNAPSHOT_ARCHIVE_CONTENT_TYPE, DOCUMENT_EXPORT_CONTENT_TYPE, parseRefusalOf, IMPORT_FLUSHES_IN_FLIGHT, confirmDeparture, SERVER_CAPABILITIES, toHttpError, RELAY_STREAM_CHUNKS_IN_FLIGHT, MIN_UNBOUNDED_SERVER_LIMIT, MIN_COUNTED_SERVER_LIMIT } from './chunk-AOLD3LPV.mjs';
2
- export { ASYNC_IMPORT_CAPABILITY, DOCUMENT_EXPORT_CAPABILITY, INDEX_LIFECYCLE_CAPABILITY, REBUILD_ANALYSIS_CAPABILITY, SERVER_CAPABILITIES, SYNONYMS_CAPABILITY, TASK_CANCEL_CAPABILITY, TASK_FILTER_CAPABILITY, httpStatusForNarsilError } from './chunk-AOLD3LPV.mjs';
1
+ import { answerRequest } from './chunk-N6J6EJW3.mjs';
2
+ import { DEFAULT_MAX_RETAINED_TASKS, loadUWebSockets, resolveCors, authorizerFor, createSharedGateBuffer, gateSlotOfWorker, createBodyBudgetBuffer, createRouteRunner, corsHeaderReader, createSharedBodyBudget, MAIN_THREAD_GATE_SLOT, createSharedRequestGate, registerServerRoutes, DEFAULT_MAX_CONCURRENT_TASKS, DEFAULT_MAX_TASK_PAGE_SIZE, DEFAULT_MAX_IMPORT_ERRORS, DEFAULT_MAX_FETCH_DOCUMENTS, DEFAULT_MAX_RESULT_WINDOW, DEFAULT_MAX_CONCURRENT_REQUESTS, DEFAULT_IMPORT_BATCH_SIZE, DEFAULT_MAX_LINE_BYTES, DEFAULT_MAX_RESTORE_BYTES, DEFAULT_MAX_IMPORT_BYTES, DEFAULT_MAX_BODY_BYTES, DEFAULT_MAX_RERANK_WINDOW, DEFAULT_MAX_BODY_BYTES_IN_FLIGHT_FRACTION, RUNNING_TASK_TTL_MS, DEFAULT_TASK_PAGE_SIZE, TERMINAL_TASK_TTL_MS, TASK_PROGRESS_WRITE_INTERVAL_MS, serializeNarsilError, createVersionHandler, acceptorOf, MAX_BODY_BYTES_IN_FLIGHT_FRACTION, createDocumentReadHandlers, sendError, respondError, respondJson, sendText, MAX_INDEX_TOUCH_INTERVAL_MS, INDEX_TOUCH_INTERVALS_PER_IDLE_TIMEOUT, closeEveryThreadAtExit, REQUEST_THREAD_CLOSE_AT_EXIT_MS, clearGateSlot, clearBodyBudgetSlot, createCloseAtExitWords, createDepartureWord, departureConfirmed, parseJson, validateCreateIndex, rejectInvalid, isRemoveOnlyBatch, validateBatch, serializeBatchResult, parseWriteJson, validateDocumentBody, validateSuggest, validateQuery, refuseRegex, withServerRerankWindow, respondAnswer, parseTaskListQuery, parseJsonOptional, validateRebalance, badRequest, sendStream, SNAPSHOT_ARCHIVE_CONTENT_TYPE, DOCUMENT_EXPORT_CONTENT_TYPE, parseRefusalOf, IMPORT_FLUSHES_IN_FLIGHT, confirmDeparture, SERVER_CAPABILITIES, toHttpError, MIN_UNBOUNDED_SERVER_LIMIT, MIN_COUNTED_SERVER_LIMIT } from './chunk-IE43SRL3.mjs';
3
+ export { ASYNC_IMPORT_CAPABILITY, DOCUMENT_EXPORT_CAPABILITY, INDEX_LIFECYCLE_CAPABILITY, REBUILD_ANALYSIS_CAPABILITY, SERVER_CAPABILITIES, SYNONYMS_CAPABILITY, TASK_CANCEL_CAPABILITY, TASK_FILTER_CAPABILITY, httpStatusForNarsilError } from './chunk-IE43SRL3.mjs';
3
4
  import { rerankOnHost } from './chunk-542TD4BL.mjs';
4
5
  import { writeBlockLookupOf, indexReadsOf, isRecord, validateIndexName } from './chunk-LOBYK2FG.mjs';
5
6
  import { readMemoryFigures } from './chunk-HFJXEFFV.mjs';
@@ -32,8 +33,6 @@ import { NarsilError, ErrorCodes, ServerErrorCodes, isNarsilError } from './chun
32
33
  export { ClientErrorCodes, ErrorCodes, NarsilError, ServerErrorCodes, isNarsilError } from './chunk-OBWUWZRA.mjs';
33
34
  import { randomUUID } from 'crypto';
34
35
  import { createReadStream } from 'fs';
35
- import { rm } from 'fs/promises';
36
- import path from 'path';
37
36
  import { MessageChannel } from 'worker_threads';
38
37
 
39
38
  function createAdminHandlers(deps) {
@@ -1097,167 +1096,12 @@ function assertAllowRegex(allowRegex) {
1097
1096
  { field: "allowRegex", value: String(allowRegex) }
1098
1097
  );
1099
1098
  }
1100
-
1101
- // src/server/request-threads/captured-response.ts
1102
- var DEFAULT_STATUS = 200;
1103
- var NO_RESPONSE_STATUS = 500;
1104
- function statusOf(line) {
1105
- const parsed = Number.parseInt(line, 10);
1106
- return Number.isFinite(parsed) ? parsed : DEFAULT_STATUS;
1107
- }
1108
- function bodyBytes(body) {
1109
- if (body === void 0) return new Uint8Array(0);
1110
- if (typeof body === "string") return Buffer.from(body, "utf8");
1111
- return body;
1112
- }
1113
- function createRelayAbort() {
1114
- const listeners = [];
1115
- let aborted = false;
1116
- return {
1117
- get aborted() {
1118
- return aborted;
1119
- },
1120
- onAbort(fn) {
1121
- if (aborted) fn();
1122
- else listeners.push(fn);
1123
- },
1124
- trigger() {
1125
- if (aborted) return;
1126
- aborted = true;
1127
- for (const fn of listeners) fn();
1128
- }
1129
- };
1130
- }
1131
- function createCapturingResponse(remoteAddress, requestId, sendPart) {
1132
- let status = DEFAULT_STATUS;
1133
- const headers = [];
1134
- let finished = false;
1135
- let streaming = false;
1136
- let inFlight = 0;
1137
- let writable = null;
1138
- const abort = createRelayAbort();
1139
- let resolveDone = () => void 0;
1140
- const done = new Promise((resolve) => {
1141
- resolveDone = resolve;
1142
- });
1143
- function finish(body) {
1144
- if (finished) return;
1145
- finished = true;
1146
- if (streaming) {
1147
- sendPart({ type: "stream-end", requestId, failed: false }, []);
1148
- resolveDone(null);
1149
- return;
1150
- }
1151
- resolveDone({ status, headers, body });
1152
- }
1153
- function startStreaming() {
1154
- if (streaming) return;
1155
- streaming = true;
1156
- sendPart({ type: "stream-start", requestId, status, headers }, []);
1157
- }
1158
- const sink = {
1159
- cork(callback) {
1160
- callback();
1161
- return sink;
1162
- },
1163
- writeStatus(line) {
1164
- if (!finished && !streaming) status = statusOf(line);
1165
- return sink;
1166
- },
1167
- writeHeader(key, value) {
1168
- if (!finished && !streaming) headers.push([key, value]);
1169
- return sink;
1170
- },
1171
- end(body) {
1172
- finish(bodyBytes(body));
1173
- return sink;
1174
- },
1175
- write(chunk) {
1176
- if (finished || abort.aborted) return true;
1177
- startStreaming();
1178
- const copy = new Uint8Array(chunk.byteLength);
1179
- copy.set(chunk);
1180
- inFlight += 1;
1181
- sendPart({ type: "stream-chunk", requestId, chunk: copy }, [copy.buffer]);
1182
- return inFlight < RELAY_STREAM_CHUNKS_IN_FLIGHT;
1183
- },
1184
- pause: () => void 0,
1185
- resume: () => void 0,
1186
- close() {
1187
- if (finished) return sink;
1188
- finished = true;
1189
- if (streaming) {
1190
- sendPart({ type: "stream-end", requestId, failed: true }, []);
1191
- resolveDone(null);
1192
- } else {
1193
- status = NO_RESPONSE_STATUS;
1194
- resolveDone({ status, headers, body: new Uint8Array(0) });
1195
- }
1196
- return sink;
1197
- },
1198
- endWithoutBody() {
1199
- finish(new Uint8Array(0));
1200
- return sink;
1201
- },
1202
- tryEnd(body) {
1203
- finish(body);
1204
- return [true, true];
1205
- },
1206
- getWriteOffset: () => 0,
1207
- onWritable(handler) {
1208
- writable = handler;
1209
- return sink;
1210
- },
1211
- onAborted: () => sink,
1212
- onData: () => sink,
1213
- getRemoteAddressAsText: () => new TextEncoder().encode(remoteAddress).buffer
1214
- };
1215
- return {
1216
- sink,
1217
- abort,
1218
- done,
1219
- credit() {
1220
- inFlight = Math.max(0, inFlight - 1);
1221
- if (inFlight >= RELAY_STREAM_CHUNKS_IN_FLIGHT || writable === null) return;
1222
- const handler = writable;
1223
- writable = null;
1224
- handler(0);
1225
- },
1226
- cancel() {
1227
- abort.trigger();
1228
- if (writable !== null) {
1229
- const handler = writable;
1230
- writable = null;
1231
- handler(0);
1232
- }
1233
- if (!finished) {
1234
- finished = true;
1235
- resolveDone(null);
1236
- }
1237
- },
1238
- finishUnanswered() {
1239
- if (finished) return;
1240
- if (streaming) {
1241
- finished = true;
1242
- sendPart({ type: "stream-end", requestId, failed: true }, []);
1243
- resolveDone(null);
1244
- return;
1245
- }
1246
- status = NO_RESPONSE_STATUS;
1247
- finish(new Uint8Array(0));
1248
- }
1249
- };
1250
- }
1251
- function toRelayedResponse(requestId, captured) {
1252
- return { type: "response", requestId, status: captured.status, headers: captured.headers, body: captured.body };
1253
- }
1254
-
1255
- // src/server/request-threads/host.ts
1256
1099
  var RELAYED_TYPES = /* @__PURE__ */ new Set([
1257
1100
  "request",
1258
1101
  "authorize",
1259
1102
  "embed",
1260
1103
  "rerank",
1104
+ "await-writes",
1261
1105
  "stream-credit",
1262
1106
  "stream-cancel"
1263
1107
  ]);
@@ -1267,42 +1111,6 @@ function isRelayRequest(message) {
1267
1111
  if (type === "touch" || type === "leaving") return true;
1268
1112
  return typeof requestId === "number" && typeof type === "string" && RELAYED_TYPES.has(type);
1269
1113
  }
1270
- function spooledBodyOf(relayed) {
1271
- if (relayed === null) return null;
1272
- return {
1273
- path: relayed.path,
1274
- bytes: relayed.bytes,
1275
- remove: () => rm(path.dirname(relayed.path), { recursive: true, force: true })
1276
- };
1277
- }
1278
- async function answerRequest(handlers, request, port, streams) {
1279
- const captured = createCapturingResponse(
1280
- request.hookContext?.remoteAddress ?? "",
1281
- request.requestId,
1282
- (part, moved) => port.postMessage(part, moved)
1283
- );
1284
- streams.set(request.requestId, captured);
1285
- const ctx = {
1286
- res: captured.sink,
1287
- params: request.params,
1288
- query: new URLSearchParams(request.query),
1289
- contentType: request.contentType,
1290
- rawBody: request.rawBody === null ? null : Buffer.from(request.rawBody.buffer, request.rawBody.byteOffset, request.rawBody.byteLength),
1291
- bodyRefusal: request.bodyRefusal,
1292
- spooledBody: spooledBodyOf(request.spooledBody),
1293
- abort: captured.abort,
1294
- hookContext: request.hookContext
1295
- };
1296
- try {
1297
- await handlers[request.route](ctx);
1298
- } catch {
1299
- sendError(ctx.res, 500, ServerErrorCodes.INTERNAL_ERROR, "An unexpected error occurred");
1300
- }
1301
- captured.finishUnanswered();
1302
- const answered = await captured.done;
1303
- streams.delete(request.requestId);
1304
- return answered === null ? null : toRelayedResponse(request.requestId, answered);
1305
- }
1306
1114
  async function answerAuthorize(authorize, request) {
1307
1115
  if (authorize === void 0) {
1308
1116
  return { type: "authorized", requestId: request.requestId, denial: null, hookError: false };
@@ -1348,6 +1156,10 @@ async function answerRerank(core, request) {
1348
1156
  return { type: "reranked", requestId: request.requestId, scores: null, error: toHttpError(err).body };
1349
1157
  }
1350
1158
  }
1159
+ async function answerAwaitWrites(core, request) {
1160
+ await core.orchestrator.awaitWrites(request.indexName).catch(() => void 0);
1161
+ return { type: "writes-applied", requestId: request.requestId };
1162
+ }
1351
1163
  function touchIntervalFor(copyIdleTimeoutMs) {
1352
1164
  return Math.min(MAX_INDEX_TOUCH_INTERVAL_MS, Math.floor(copyIdleTimeoutMs / INDEX_TOUCH_INTERVALS_PER_IDLE_TIMEOUT));
1353
1165
  }
@@ -1359,6 +1171,8 @@ async function startRequestThreads(options) {
1359
1171
  const searchHooks = core.pluginRegistry.hasHooks("beforeSearch") || core.pluginRegistry.hasHooks("afterSearch");
1360
1172
  const touchIntervalMs = touchIntervalFor(core.orchestrator.copyIdleTimeoutMs());
1361
1173
  const threads = /* @__PURE__ */ new Map();
1174
+ const longQueriesInFlight = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT);
1175
+ let longQueryThread = null;
1362
1176
  const closeAtExit = /* @__PURE__ */ new Set();
1363
1177
  let stopped = false;
1364
1178
  function closeThreadsAtExit() {
@@ -1395,12 +1209,23 @@ async function startRequestThreads(options) {
1395
1209
  streams.get(message.requestId)?.cancel();
1396
1210
  return;
1397
1211
  }
1398
- const reply = message.type === "request" ? answerRequest(handlers, message, port, streams) : message.type === "authorize" ? answerAuthorize(authorize, message) : message.type === "embed" ? answerEmbed(core, message) : answerRerank(core, message);
1212
+ const reply = message.type === "request" ? answerRequest(handlers[message.route], message, port, streams) : message.type === "authorize" ? answerAuthorize(authorize, message) : message.type === "embed" ? answerEmbed(core, message) : message.type === "await-writes" ? answerAwaitWrites(core, message) : answerRerank(core, message);
1399
1213
  void reply.then((answer) => {
1400
1214
  if (answer !== null) port.postMessage(answer);
1401
1215
  });
1402
1216
  });
1403
1217
  }
1218
+ function connectToLongQueries(thread) {
1219
+ if (longQueryThread === null) return;
1220
+ const channel = new MessageChannel();
1221
+ thread.port.postMessage({ type: "long-query-port", port: channel.port1 }, [channel.port1]);
1222
+ longQueryThread.port.postMessage({ type: "long-query-port", port: channel.port2 }, [channel.port2]);
1223
+ }
1224
+ function dropLongQueryThread() {
1225
+ if (longQueryThread === null) return;
1226
+ longQueryThread.port.close();
1227
+ longQueryThread = null;
1228
+ }
1404
1229
  async function stopThread(workerId, thread) {
1405
1230
  releaseDescriptor(thread);
1406
1231
  thread.port.close();
@@ -1409,6 +1234,46 @@ async function startRequestThreads(options) {
1409
1234
  await thread.executor.execute({ type: "stopServing", requestId: `stop-serving-${workerId}` }).catch(() => void 0);
1410
1235
  }
1411
1236
  const listener = {
1237
+ async onLongQueryWorkerReady(workerId, executor) {
1238
+ if (stopped) return;
1239
+ dropLongQueryThread();
1240
+ const channel = new MessageChannel();
1241
+ const relaying = {
1242
+ descriptor: null,
1243
+ port: channel.port2,
1244
+ executor,
1245
+ departure: createDepartureWord(),
1246
+ closeAtExit: createCloseAtExitWords()
1247
+ };
1248
+ relayFrom(relaying);
1249
+ try {
1250
+ await executor.execute(
1251
+ {
1252
+ type: "serveLongQueries",
1253
+ requestId: `serve-long-queries-${workerId}`,
1254
+ settings: {
1255
+ port: channel.port1,
1256
+ touchIntervalMs,
1257
+ limits: options.limits,
1258
+ patternWorkCap: options.core.patternWorkCap,
1259
+ maxRerankWindow: options.core.rerankSettings.maxWindow,
1260
+ allowRegex: options.allowRegex
1261
+ }
1262
+ },
1263
+ [channel.port1]
1264
+ );
1265
+ } catch (err) {
1266
+ channel.port2.close();
1267
+ console.warn(`Worker ${workerId} could not start answering long queries:`, err);
1268
+ return;
1269
+ }
1270
+ if (stopped) {
1271
+ channel.port2.close();
1272
+ return;
1273
+ }
1274
+ longQueryThread = { workerId, port: channel.port2, executor };
1275
+ for (const thread of threads.values()) connectToLongQueries(thread);
1276
+ },
1412
1277
  async onWorkerReady(workerId, executor) {
1413
1278
  if (stopped) return;
1414
1279
  const channel = new MessageChannel();
@@ -1421,6 +1286,9 @@ async function startRequestThreads(options) {
1421
1286
  };
1422
1287
  relayFrom(thread);
1423
1288
  closeAtExit.add(thread.closeAtExit);
1289
+ const longQueries = longQueryThread;
1290
+ const longQueryChannel = longQueries === null ? null : new MessageChannel();
1291
+ const transfer = longQueryChannel === null ? [channel.port1] : [channel.port1, longQueryChannel.port1];
1424
1292
  let result;
1425
1293
  try {
1426
1294
  result = await executor.execute(
@@ -1443,26 +1311,42 @@ async function startRequestThreads(options) {
1443
1311
  searchHooks,
1444
1312
  patternWorkCap: options.core.patternWorkCap,
1445
1313
  maxRerankWindow: options.core.rerankSettings.maxWindow,
1446
- allowRegex: options.allowRegex
1314
+ allowRegex: options.allowRegex,
1315
+ longQueriesInFlight,
1316
+ longQueryPort: longQueryChannel?.port1 ?? null
1447
1317
  }
1448
1318
  },
1449
- [channel.port1]
1319
+ transfer
1450
1320
  );
1451
1321
  } catch (err) {
1452
1322
  closeAtExit.delete(thread.closeAtExit);
1453
1323
  channel.port2.close();
1324
+ longQueryChannel?.port2.close();
1454
1325
  console.warn(`Worker ${workerId} could not start taking requests:`, err);
1455
1326
  return;
1456
1327
  }
1457
1328
  thread.descriptor = result.descriptor;
1458
1329
  if (stopped || departureConfirmed(thread.departure)) {
1330
+ longQueryChannel?.port2.close();
1459
1331
  await stopThread(workerId, thread);
1460
1332
  return;
1461
1333
  }
1334
+ if (longQueryChannel !== null && longQueries !== null && longQueryThread === longQueries) {
1335
+ longQueries.port.postMessage({ type: "long-query-port", port: longQueryChannel.port2 }, [
1336
+ longQueryChannel.port2
1337
+ ]);
1338
+ } else {
1339
+ longQueryChannel?.port2.close();
1340
+ connectToLongQueries(thread);
1341
+ }
1462
1342
  acceptor.addChildAppDescriptor(result.descriptor);
1463
1343
  threads.set(workerId, thread);
1464
1344
  },
1465
1345
  onWorkerGone(workerId) {
1346
+ if (longQueryThread?.workerId === workerId) {
1347
+ dropLongQueryThread();
1348
+ return;
1349
+ }
1466
1350
  const thread = threads.get(workerId);
1467
1351
  if (thread === void 0) return;
1468
1352
  threads.delete(workerId);
@@ -1486,6 +1370,16 @@ async function startRequestThreads(options) {
1486
1370
  threads.delete(workerId);
1487
1371
  return stopThread(workerId, thread);
1488
1372
  });
1373
+ const longQueries = longQueryThread;
1374
+ dropLongQueryThread();
1375
+ if (longQueries !== null) {
1376
+ stopping.push(
1377
+ longQueries.executor.execute({ type: "stopServing", requestId: `stop-long-queries-${longQueries.workerId}` }).then(
1378
+ () => void 0,
1379
+ () => void 0
1380
+ )
1381
+ );
1382
+ }
1489
1383
  await Promise.all(stopping);
1490
1384
  }
1491
1385
  };
@@ -1,22 +1,22 @@
1
- import { documentsOfPayloadV2 } from './chunk-OM5G2J6X.mjs';
2
- import { buildArchiveFromMemory, archiveStream, memoryCheckpointStore, readSnapshotArchive } from './chunk-QGVMEMCG.mjs';
3
- import './chunk-CU4OB64V.mjs';
4
- import { indexMetadataOf, unpackIndexSnapshotEnvelope, loadSegmentedCheckpoint, writeMetadataEnvelope, readVectorFile, readGraphParts, deserializePayloadV1, SINGLE_NODE_PRIMARY_TERM } from './chunk-JUAFWJON.mjs';
1
+ import { documentsOfPayloadV2 } from './chunk-VOKEYJHU.mjs';
2
+ import { buildArchiveFromMemory, archiveStream, memoryCheckpointStore, readSnapshotArchive } from './chunk-KVLX65KD.mjs';
3
+ import './chunk-NX7KU77V.mjs';
4
+ import { indexMetadataOf, unpackIndexSnapshotEnvelope, loadSegmentedCheckpoint, writeMetadataEnvelope, readVectorFile, readGraphParts, deserializePayloadV1, SINGLE_NODE_PRIMARY_TERM } from './chunk-YCSRB3IN.mjs';
5
5
  import { decodeVectorIndexParts, bytesToVectors } from './chunk-OCB7TMUQ.mjs';
6
- import './chunk-4XWIW3F3.mjs';
6
+ import './chunk-HC5NURS6.mjs';
7
7
  import './chunk-DJHHF2L5.mjs';
8
8
  import './chunk-37CD3OKS.mjs';
9
- import { manifestKey, encodeSegmentManifest, manifestFileRefs, readSegmentFile } from './chunk-27ZEY73B.mjs';
10
- import './chunk-LVNBY2TS.mjs';
9
+ import { manifestKey, encodeSegmentManifest, manifestFileRefs, readSegmentFile } from './chunk-KGVC6KJ3.mjs';
10
+ import './chunk-7EWQZQDT.mjs';
11
11
  import './chunk-P36MUFEJ.mjs';
12
12
  import './chunk-YH5OIL7B.mjs';
13
- import { encodeIndexConfiguration, createByteReader, hasNrslMagic, HEADER_SIZE, readHeader, validateRequiredFieldsInSchema, validateEmbeddingConfig, decodeIndexConfiguration, prepareStoredSynonyms, insertDocumentVectors } from './chunk-PABYSTKO.mjs';
14
- import { validatePatternValueLimit, requireSurfaceFormsForPartialFields } from './chunk-GLZI636G.mjs';
13
+ import { encodeIndexConfiguration, createByteReader, hasNrslMagic, HEADER_SIZE, readHeader, validateRequiredFieldsInSchema, validateEmbeddingConfig, decodeIndexConfiguration, prepareStoredSynonyms, insertDocumentVectors } from './chunk-BCSWODXP.mjs';
14
+ import { validatePatternValueLimit, requireSurfaceFormsForPartialFields } from './chunk-5VVSHCXT.mjs';
15
15
  import { restoredConfigFields, restoredEmbedding, rejectSnapshot } from './chunk-N57XXGPG.mjs';
16
16
  import './chunk-6PN3U6XW.mjs';
17
17
  import './chunk-AV4IJKD2.mjs';
18
- import { decodeEveryStoredDocument } from './chunk-5QIRLJH4.mjs';
19
- import './chunk-5WEBVYOA.mjs';
18
+ import { decodeEveryStoredDocument } from './chunk-Q62NDKEC.mjs';
19
+ import './chunk-N53HN5VA.mjs';
20
20
  import { getLanguage } from './chunk-FUUP45IS.mjs';
21
21
  import { readHeapStatistics, readResidentMemory } from './chunk-ZATRDAYU.mjs';
22
22
  import './chunk-EBIHRL7B.mjs';
@@ -27,7 +27,7 @@ import './chunk-U2BKYEC7.mjs';
27
27
  import './chunk-KOKM4PQN.mjs';
28
28
  import './chunk-QSK35UC2.mjs';
29
29
  import './chunk-VK45J47R.mjs';
30
- import './chunk-HNAP2KTG.mjs';
30
+ import './chunk-VFAXPDBH.mjs';
31
31
  import './chunk-WQBCBKY3.mjs';
32
32
  import { parseVectorDimension } from './chunk-KCQG2PJT.mjs';
33
33
  import { raiseEarlierReleaseGraphSetting, validateSchema, validateVectorPromotion, validateVectorStorage, extractVectorFieldsFromSchema, flattenSchema } from './chunk-DG62H7OD.mjs';
@@ -43,8 +43,8 @@ import './chunk-OFYKBKKV.mjs';
43
43
  import './chunk-R6A773WK.mjs';
44
44
  import './chunk-YTJCGKM4.mjs';
45
45
  import { collectAndReturnPages } from './chunk-RIIUZJQ3.mjs';
46
- import './chunk-CQUMNIIG.mjs';
47
- import { loadVectorCodeFor } from './chunk-4PFOOQFQ.mjs';
46
+ import './chunk-Z4DZ4KK2.mjs';
47
+ import { loadVectorCodeFor } from './chunk-BCNUJVTT.mjs';
48
48
  import './chunk-22YPZVMG.mjs';
49
49
  import './chunk-RFBLQLLZ.mjs';
50
50
  import './chunk-L5ORED7V.mjs';
@@ -0,0 +1,31 @@
1
+ export { closeRequestThread, searchHandler, serveRequests } from './chunk-DEXID4ZT.mjs';
2
+ import './chunk-IE43SRL3.mjs';
3
+ import './chunk-KZ3NX2P7.mjs';
4
+ import './chunk-HFJXEFFV.mjs';
5
+ import './chunk-IWVEG5CX.mjs';
6
+ import './chunk-DJHHF2L5.mjs';
7
+ import './chunk-5VVSHCXT.mjs';
8
+ import './chunk-N53HN5VA.mjs';
9
+ import './chunk-ZATRDAYU.mjs';
10
+ import './chunk-EBIHRL7B.mjs';
11
+ import './chunk-HJSN7UYG.mjs';
12
+ import './chunk-LXWDQLTW.mjs';
13
+ import './chunk-QSK35UC2.mjs';
14
+ import './chunk-VK45J47R.mjs';
15
+ import './chunk-VFAXPDBH.mjs';
16
+ import './chunk-WQBCBKY3.mjs';
17
+ import './chunk-KCQG2PJT.mjs';
18
+ import './chunk-DG62H7OD.mjs';
19
+ import './chunk-U476IXKQ.mjs';
20
+ import './chunk-E74YLAIG.mjs';
21
+ import './chunk-VJS4JFBQ.mjs';
22
+ import './chunk-GES7U2PM.mjs';
23
+ import './chunk-6ODIY6ZB.mjs';
24
+ import './chunk-X5CV2E2B.mjs';
25
+ import './chunk-OFYKBKKV.mjs';
26
+ import './chunk-R6A773WK.mjs';
27
+ import './chunk-YTJCGKM4.mjs';
28
+ import './chunk-RIIUZJQ3.mjs';
29
+ import './chunk-22YPZVMG.mjs';
30
+ import './chunk-L5ORED7V.mjs';
31
+ import './chunk-OBWUWZRA.mjs';
@@ -1,5 +1,5 @@
1
- import { openSharedVectorField, createVectorStore } from '../chunk-H2GNWBLB.mjs';
2
- import { osqBitsOf, createHNSWIndex, createOsqQuantizer } from '../chunk-4XWIW3F3.mjs';
1
+ import { openSharedVectorField, createVectorStore } from '../chunk-4ZKBKPBV.mjs';
2
+ import { osqBitsOf, createHNSWIndex, createOsqQuantizer } from '../chunk-HC5NURS6.mjs';
3
3
  import '../chunk-DJHHF2L5.mjs';
4
4
  import { osqRecordBytes } from '../chunk-37CD3OKS.mjs';
5
5
  import '../chunk-KOKM4PQN.mjs';
@@ -1,6 +1,6 @@
1
1
  import { startIdleHeapCleanup } from '../chunk-RIIUZJQ3.mjs';
2
- import { isValidWorkerAction } from '../chunk-CQUMNIIG.mjs';
3
- import { loadVectorCode } from '../chunk-4PFOOQFQ.mjs';
2
+ import { isValidWorkerAction } from '../chunk-Z4DZ4KK2.mjs';
3
+ import { loadVectorCode } from '../chunk-BCNUJVTT.mjs';
4
4
  import '../chunk-22YPZVMG.mjs';
5
5
  import { threadSlotOfWorker } from '../chunk-RFBLQLLZ.mjs';
6
6
  import '../chunk-L5ORED7V.mjs';
@@ -22,8 +22,10 @@ async function importBootstrapModule(moduleUrl) {
22
22
  await import(moduleUrl);
23
23
  }
24
24
  async function stopServingRequests() {
25
- const { closeRequestThread } = await import('../thread-S4SUCV4Y.mjs');
25
+ const { closeRequestThread } = await import('../thread-FDEHU5G3.mjs');
26
26
  closeRequestThread();
27
+ const { closeLongQueryThread } = await import('../long-query-thread-HMQM2FWL.mjs');
28
+ closeLongQueryThread();
27
29
  }
28
30
  function holdsCopies(executor) {
29
31
  return typeof executor.queryContextOf === "function";
@@ -53,7 +55,7 @@ function createActionHandler(executor) {
53
55
  if (!holdsCopies(executor)) {
54
56
  throw new NarsilError(ErrorCodes.CONFIG_INVALID, "This executor holds no copies to answer requests from");
55
57
  }
56
- const starting = import('../thread-S4SUCV4Y.mjs').then(
58
+ const starting = import('../thread-FDEHU5G3.mjs').then(
57
59
  ({ serveRequests }) => serveRequests(executor, action.settings)
58
60
  );
59
61
  serving.start = starting.then(
@@ -66,6 +68,16 @@ function createActionHandler(executor) {
66
68
  post(buildSuccessResponse(action.requestId, result2));
67
69
  return false;
68
70
  }
71
+ if (action.type === "serveLongQueries") {
72
+ if (!holdsCopies(executor)) {
73
+ throw new NarsilError(ErrorCodes.CONFIG_INVALID, "This executor holds no copies to answer long queries from");
74
+ }
75
+ const { serveLongQueries } = await import('../long-query-thread-HMQM2FWL.mjs');
76
+ serveLongQueries(executor, action.settings);
77
+ servingRequests = true;
78
+ post(buildSuccessResponse(action.requestId, void 0));
79
+ return false;
80
+ }
69
81
  if (action.type === "stopServing") {
70
82
  await stopServingOnceStarted();
71
83
  post(buildSuccessResponse(action.requestId, void 0));
@@ -106,7 +118,7 @@ async function setup() {
106
118
  } catch {
107
119
  parentPort = null;
108
120
  }
109
- const [{ createDirectExecutor }] = await Promise.all([import('../direct-executor-R4HOSVPE.mjs'), loadVectorCode()]);
121
+ const [{ createDirectExecutor }] = await Promise.all([import('../direct-executor-OUY4RPTU.mjs'), loadVectorCode()]);
110
122
  const handleAction = createActionHandler(createDirectExecutor({ threadSlot }));
111
123
  if (parentPort) {
112
124
  const port = parentPort;
@@ -1,13 +1,13 @@
1
1
  import { decodeVectorFilePayload, isDead, bytesToVectors } from './chunk-OCB7TMUQ.mjs';
2
2
  import './chunk-37CD3OKS.mjs';
3
- import { setNestedValue, KEYWORD_SEGMENT_ENVELOPE_VERSION, decodeKeywordSegment } from './chunk-LVNBY2TS.mjs';
4
- import { openChecksummedEnvelope, NUMBER_TAG, DATE_TAG, BYTES_TAG, encodeBase64, startsWithTagPrefix, OBJECT_TAG, MILLISECONDS_PER_SECOND, NANOSECONDS_PER_MILLISECOND, DOCUMENT_EXPORT_VERSION, DOCUMENT_EXPORT_FORMAT } from './chunk-PABYSTKO.mjs';
5
- import './chunk-GLZI636G.mjs';
3
+ import { setNestedValue, KEYWORD_SEGMENT_ENVELOPE_VERSION, decodeKeywordSegment } from './chunk-7EWQZQDT.mjs';
4
+ import { openChecksummedEnvelope, NUMBER_TAG, DATE_TAG, BYTES_TAG, encodeBase64, startsWithTagPrefix, OBJECT_TAG, MILLISECONDS_PER_SECOND, NANOSECONDS_PER_MILLISECOND, DOCUMENT_EXPORT_VERSION, DOCUMENT_EXPORT_FORMAT } from './chunk-BCSWODXP.mjs';
5
+ import './chunk-5VVSHCXT.mjs';
6
6
  import './chunk-N57XXGPG.mjs';
7
7
  import './chunk-6PN3U6XW.mjs';
8
8
  import './chunk-AV4IJKD2.mjs';
9
- import { decodeStoredDocument } from './chunk-5QIRLJH4.mjs';
10
- import './chunk-5WEBVYOA.mjs';
9
+ import { decodeStoredDocument } from './chunk-Q62NDKEC.mjs';
10
+ import './chunk-N53HN5VA.mjs';
11
11
  import './chunk-FUUP45IS.mjs';
12
12
  import './chunk-ZATRDAYU.mjs';
13
13
  import './chunk-EBIHRL7B.mjs';
@@ -18,7 +18,7 @@ import './chunk-U2BKYEC7.mjs';
18
18
  import './chunk-KOKM4PQN.mjs';
19
19
  import './chunk-QSK35UC2.mjs';
20
20
  import './chunk-VK45J47R.mjs';
21
- import './chunk-HNAP2KTG.mjs';
21
+ import './chunk-VFAXPDBH.mjs';
22
22
  import './chunk-WQBCBKY3.mjs';
23
23
  import './chunk-KCQG2PJT.mjs';
24
24
  import './chunk-DG62H7OD.mjs';
@@ -33,8 +33,8 @@ import './chunk-7X5JST5L.mjs';
33
33
  import './chunk-OFYKBKKV.mjs';
34
34
  import './chunk-R6A773WK.mjs';
35
35
  import './chunk-YTJCGKM4.mjs';
36
- import './chunk-CQUMNIIG.mjs';
37
- import './chunk-4PFOOQFQ.mjs';
36
+ import './chunk-Z4DZ4KK2.mjs';
37
+ import './chunk-BCNUJVTT.mjs';
38
38
  import './chunk-22YPZVMG.mjs';
39
39
  import './chunk-RFBLQLLZ.mjs';
40
40
  import './chunk-L5ORED7V.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delali/narsil",
3
- "version": "0.3.1-next.113",
3
+ "version": "0.3.1-next.116",
4
4
  "type": "module",
5
5
  "description": "Distributed search engine with full-text, vector, hybrid, and geosearch. One engine, embedded or on a server, with a cross-language .nrsl format.",
6
6
  "author": "Delali (https://sondelali.com)",
@@ -269,11 +269,11 @@
269
269
  }
270
270
  },
271
271
  "optionalDependencies": {
272
- "@delali/narsil-native-darwin-arm64": "0.3.1-next.113",
273
- "@delali/narsil-native-darwin-x64": "0.3.1-next.113",
274
- "@delali/narsil-native-linux-arm64": "0.3.1-next.113",
275
- "@delali/narsil-native-linux-x64": "0.3.1-next.113",
276
- "@delali/narsil-native-win32-arm64": "0.3.1-next.113",
277
- "@delali/narsil-native-win32-x64": "0.3.1-next.113"
272
+ "@delali/narsil-native-darwin-arm64": "0.3.1-next.116",
273
+ "@delali/narsil-native-darwin-x64": "0.3.1-next.116",
274
+ "@delali/narsil-native-linux-arm64": "0.3.1-next.116",
275
+ "@delali/narsil-native-linux-x64": "0.3.1-next.116",
276
+ "@delali/narsil-native-win32-arm64": "0.3.1-next.116",
277
+ "@delali/narsil-native-win32-x64": "0.3.1-next.116"
278
278
  }
279
279
  }