@delali/narsil 0.3.1-next.112 → 0.3.1-next.115

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 (71) hide show
  1. package/dist/browser/{chunk-UR5MNN53.mjs → chunk-2TMWIATH.mjs} +108 -67
  2. package/dist/browser/{chunk-OVY4RPDS.mjs → chunk-73U5DWOZ.mjs} +39 -4
  3. package/dist/browser/{chunk-O5IKTA27.mjs → chunk-FODCC3MK.mjs} +1 -1
  4. package/dist/browser/{chunk-YRYBTRWB.mjs → chunk-I45FAGOF.mjs} +2 -2
  5. package/dist/browser/{durability-wiring-CPEMDDK7.mjs → durability-wiring-CSMTKEYX.mjs} +3 -3
  6. package/dist/browser/{module-DYKR4INA.mjs → module-G2PPZV3B.mjs} +127 -33
  7. package/dist/browser/{restore-queue-2H4QDQV4.mjs → restore-queue-N7N42PBS.mjs} +1 -1
  8. package/dist/browser/{runtime-FL5K4JOH.mjs → runtime-BX6XRFYR.mjs} +2 -2
  9. package/dist/browser/{snapshot-ISZMBDCN.mjs → snapshot-EBH6RXQO.mjs} +6 -5
  10. package/dist/browser/{write-IABOLE4N.mjs → write-5ZKFINX3.mjs} +2 -2
  11. package/dist/{capabilities-ByaX8Arf.d.ts → capabilities-DOgB3pPf.d.ts} +2 -2
  12. package/dist/{chunk-ZXZ26WSO.mjs → chunk-22YPZVMG.mjs} +5 -1
  13. package/dist/{chunk-R2MRGYU5.mjs → chunk-4ZKBKPBV.mjs} +22 -2
  14. package/dist/{chunk-GLZI636G.mjs → chunk-5VVSHCXT.mjs} +27 -12
  15. package/dist/{chunk-3COL24MT.mjs → chunk-7EWQZQDT.mjs} +1 -1
  16. package/dist/{chunk-QI6JW4PM.mjs → chunk-BCNUJVTT.mjs} +1 -1
  17. package/dist/{chunk-3RRATITJ.mjs → chunk-BCSWODXP.mjs} +75 -55
  18. package/dist/{thread-WGBCVJII.mjs → chunk-DEXID4ZT.mjs} +301 -200
  19. package/dist/chunk-EBIHRL7B.mjs +21 -0
  20. package/dist/{chunk-YIDSHBQS.mjs → chunk-HC5NURS6.mjs} +33 -4
  21. package/dist/{chunk-V7G627TA.mjs → chunk-HFJXEFFV.mjs} +13 -62
  22. package/dist/{chunk-63HFWQEA.mjs → chunk-IE43SRL3.mjs} +276 -102
  23. package/dist/chunk-IWVEG5CX.mjs +67 -0
  24. package/dist/{chunk-2IFU7SXG.mjs → chunk-KGVC6KJ3.mjs} +4 -4
  25. package/dist/{chunk-7CI34JAP.mjs → chunk-KVLX65KD.mjs} +4 -4
  26. package/dist/{chunk-5WEBVYOA.mjs → chunk-N53HN5VA.mjs} +16 -9
  27. package/dist/chunk-N6J6EJW3.mjs +198 -0
  28. package/dist/{chunk-PT7VRWS7.mjs → chunk-NX7KU77V.mjs} +3 -2
  29. package/dist/{chunk-QIFOXLWF.mjs → chunk-OGFSUXYY.mjs} +2 -2
  30. package/dist/chunk-PELHVTO7.mjs +24 -0
  31. package/dist/{chunk-V7ISFBFC.mjs → chunk-Q62NDKEC.mjs} +5 -4
  32. package/dist/{chunk-6OXNHLNZ.mjs → chunk-RIIUZJQ3.mjs} +1 -1
  33. package/dist/{chunk-BVOUSX3U.mjs → chunk-UDZYIWDP.mjs} +3 -3
  34. package/dist/{chunk-HNAP2KTG.mjs → chunk-VFAXPDBH.mjs} +1 -0
  35. package/dist/{chunk-IBTKJIV7.mjs → chunk-VOKEYJHU.mjs} +1 -1
  36. package/dist/{chunk-C7SLA6CM.mjs → chunk-W55X2BYN.mjs} +5 -1
  37. package/dist/{chunk-IM76DLA7.mjs → chunk-YCFQ5754.mjs} +2 -2
  38. package/dist/{chunk-VLRT47GU.mjs → chunk-YCSRB3IN.mjs} +3 -3
  39. package/dist/{chunk-CQUMNIIG.mjs → chunk-Z4DZ4KK2.mjs} +1 -0
  40. package/dist/{chunk-SOADQINJ.mjs → chunk-ZATRDAYU.mjs} +31 -3
  41. package/dist/{chunk-2RAQKITH.mjs → chunk-ZR63OGT2.mjs} +1 -1
  42. package/dist/{client-BdnzDFtO.d.ts → client-BGzLNt78.d.ts} +2 -2
  43. package/dist/client.d.ts +6 -6
  44. package/dist/{config-ujZESkJz.d.ts → config-CS5ADSrx.d.ts} +18 -2
  45. package/dist/{config-CSgvApt0.d.ts → config-CSYMTTm1.d.ts} +1 -1
  46. package/dist/{direct-executor-ZSTKRA6Z.mjs → direct-executor-OUY4RPTU.mjs} +7 -6
  47. package/dist/distribution.d.ts +5 -5
  48. package/dist/distribution.mjs +79 -42
  49. package/dist/{durability-wiring-EQTFL3B4.mjs → durability-wiring-5V6DVHFK.mjs} +17 -16
  50. package/dist/{engine-C_HSy3iz.d.ts → engine-CCBBGmMR.d.ts} +1 -1
  51. package/dist/{events-CJsXF1F9.d.ts → events-D8GPB1-H.d.ts} +5 -0
  52. package/dist/index.browser.mjs +1 -1
  53. package/dist/index.d.ts +5 -5
  54. package/dist/index.mjs +10 -9
  55. package/dist/long-query-thread-HMQM2FWL.mjs +118 -0
  56. package/dist/{module-WP4VVGV2.mjs → module-3IMTXNPW.mjs} +92 -29
  57. package/dist/pattern.mjs +1 -1
  58. package/dist/persistence/durability/checkpoint-worker.mjs +14 -13
  59. package/dist/react.d.ts +6 -6
  60. package/dist/{rerank-3POMPQNX.mjs → rerank-NYX5S7OG.mjs} +3 -3
  61. package/dist/{restore-queue-WZTMTJP2.mjs → restore-queue-J6PCG4ON.mjs} +1 -1
  62. package/dist/{runtime-C2435MPK.mjs → runtime-XNYW6AWX.mjs} +2 -2
  63. package/dist/server.d.ts +8 -8
  64. package/dist/server.mjs +110 -258
  65. package/dist/{snapshot-EU6NNB2P.mjs → snapshot-57WF53MK.mjs} +18 -17
  66. package/dist/{tasks-CI3Fvkxw.d.ts → tasks-5_LCFEzF.d.ts} +1 -1
  67. package/dist/thread-FDEHU5G3.mjs +31 -0
  68. package/dist/vector/search-worker.mjs +2 -2
  69. package/dist/workers/entry.mjs +19 -7
  70. package/dist/{write-CKRWS3P5.mjs → write-YEI7A5OR.mjs} +11 -10
  71. package/package.json +7 -7
@@ -1,4 +1,4 @@
1
- import { normalizeSort, requireMatchingCursor, encodePageCursor, decodePageCursor, projectionKeepsField, resolveProjection, clampRowCount, sortSignatureOf, requireSortableFields, fanOutQuery, requireWithinResultWindow, sortModesOf, applySorting, applyPagination, countsWithoutScores, fanOutMatchCount, FNV_OFFSET_BASIS, validatedFilterOf, createPatternWorkMeter, partialWordsToHighlight, partialWordHighlighter, pruneStatsToQueryTerms, everyValueFacetConfig, fulltextMatches, mergeFacets, applyPartitionFiltersBitset, fnv1aContinue, partitionsIn, fnv1aContinueTaggedNumbers, undeclaredFieldOnStrictIndex } from './chunk-5WEBVYOA.mjs';
1
+ import { normalizeSort, requireMatchingCursor, encodePageCursor, decodePageCursor, projectionKeepsField, resolveProjection, clampRowCount, sortSignatureOf, requireSortableFields, fanOutQuery, requireWithinResultWindow, sortModesOf, applySorting, applyPagination, countsWithoutScores, fanOutMatchCount, FNV_OFFSET_BASIS, validatedFilterOf, createPatternWorkMeter, partialWordsToHighlight, partialWordHighlighter, pruneStatsToQueryTerms, everyValueFacetConfig, fulltextMatches, mergeFacets, applyPartitionFiltersBitset, fnv1aContinue, partitionsIn, fnv1aContinueTaggedNumbers, undeclaredFieldOnStrictIndex } from './chunk-N53HN5VA.mjs';
2
2
  import { MAX_INDEX_NAME_LENGTH, INDEX_NAME_PATTERN, MAX_DOC_ID_LENGTH, DEFAULT_LIMIT, DEFAULT_SUGGEST_LIMIT, MAX_SUGGEST_LIMIT, MAX_SUGGEST_SCATTER_LIMIT, ABSOLUTE_WINDOWS_PATH_PATTERN, MODULE_URL_SCHEME_PATTERN, DEFAULT_OFFSET } from './chunk-LXWDQLTW.mjs';
3
3
  import { MIN_OVERSAMPLE, MAX_RENUMBERED_SEARCH_ATTEMPTS } from './chunk-QSK35UC2.mjs';
4
4
  import { flattenSchema, partialFieldsOf } from './chunk-DG62H7OD.mjs';
@@ -63,6 +63,7 @@ function writeEncodedString(stream, value) {
63
63
  stream.length += encoded.length;
64
64
  }
65
65
  function writeString(stream, value) {
66
+ if (stream.clock !== void 0) stream.clock.tick(value.length);
66
67
  ensureCapacity(stream, LENGTH_BYTES + value.length);
67
68
  const start = stream.length + LENGTH_BYTES;
68
69
  const bytes = stream.bytes;
@@ -83,6 +84,7 @@ var NumberList = class {
83
84
  }
84
85
  };
85
86
  function writeNumberList(stream, list) {
87
+ if (stream.clock !== void 0) stream.clock.tick(list.members.length);
86
88
  writeByte(stream, LIST_TAG);
87
89
  writeUint32(stream, list.members.length);
88
90
  flush(stream);
@@ -154,15 +156,15 @@ function boundRerankOf(rerank) {
154
156
  }
155
157
  var FILTERS_SLOT = 2;
156
158
  var BOUND_SLOT_COUNT = 16;
157
- function bindingOf(values) {
158
- const stream = { bytes: new Uint8Array(256), length: 0, hash: FNV_OFFSET_BASIS };
159
+ function bindingOf(values, clock) {
160
+ const stream = { bytes: new Uint8Array(256), length: 0, hash: FNV_OFFSET_BASIS, clock };
159
161
  for (const value of values) {
160
162
  writeValue(stream, value);
161
163
  }
162
164
  flush(stream);
163
165
  return (stream.hash >>> 0).toString(16).padStart(8, "0");
164
166
  }
165
- function queryBindingOf(params) {
167
+ function queryBindingOf(params, clock) {
166
168
  const values = [
167
169
  params.term,
168
170
  params.fields,
@@ -182,7 +184,14 @@ function queryBindingOf(params) {
182
184
  params.scoring ?? "local"
183
185
  ];
184
186
  if (params.rerank !== void 0) values.push(boundRerankOf(params.rerank));
185
- return bindingOf(values);
187
+ return bindingOf(values, clock);
188
+ }
189
+ function lazyQueryBinding(params, clock) {
190
+ let binding;
191
+ return () => {
192
+ binding ??= queryBindingOf(params, clock);
193
+ return binding;
194
+ };
186
195
  }
187
196
  function listBindingOf(filters) {
188
197
  const values = new Array(BOUND_SLOT_COUNT).fill(void 0);
@@ -262,7 +271,7 @@ function requireValidTypoTolerance(params) {
262
271
 
263
272
  // src/engine/query/shared.ts
264
273
  function withPatternWork(context) {
265
- return { ...context, patternWork: createPatternWorkMeter(context.patternWorkCap) };
274
+ return { ...context, patternWork: createPatternWorkMeter(context.patternWorkCap, context.clock) };
266
275
  }
267
276
  function partitionsFor(manager, partitionIds) {
268
277
  return partitionsIn(manager, partitionIds);
@@ -1181,6 +1190,7 @@ function filteredSearchOf(params, context) {
1181
1190
  }
1182
1191
  function searchField(vecIndex, vectorConfig, queryVector, k, context, filtered, rescoreWindow) {
1183
1192
  const options = {
1193
+ clock: context.patternWork.clock,
1184
1194
  metric: vectorConfig.metric ?? "cosine",
1185
1195
  minSimilarity: vectorConfig.similarity ?? -Infinity,
1186
1196
  efSearch: vectorConfig.efSearch,
@@ -1328,7 +1338,7 @@ function executeSortedQueryPage(params, context, limit, offset, sortSignature) {
1328
1338
  let anchorId = null;
1329
1339
  if (params.searchAfter !== void 0) {
1330
1340
  const decoded = decodePageCursor(params.searchAfter);
1331
- requireMatchingCursor(decoded, params.searchAfter, sortSignature, true, context.cursorBinding);
1341
+ requireMatchingCursor(decoded, params.searchAfter, sortSignature, true, context.cursorBinding());
1332
1342
  anchorKey = decoded.sortKey;
1333
1343
  anchorId = decoded.anchor;
1334
1344
  }
@@ -1345,8 +1355,11 @@ function executeSortedQueryPage(params, context, limit, offset, sortSignature) {
1345
1355
  const partitionFacets = [];
1346
1356
  const partitionFacetConfig = params.facets !== void 0 && partitions.length > 1 ? everyValueFacetConfig(params.facets) : params.facets;
1347
1357
  let count = 0;
1358
+ const clock = context.patternWork.clock;
1348
1359
  for (const partition of partitions) {
1360
+ clock?.check();
1349
1361
  const matches = fulltextMatches(partition, params, language, schema, options);
1362
+ clock?.check();
1350
1363
  if (partitionFacetConfig !== void 0) {
1351
1364
  partitionFacets.push(
1352
1365
  partition.computeFacets(
@@ -1358,6 +1371,7 @@ function executeSortedQueryPage(params, context, limit, offset, sortSignature) {
1358
1371
  }
1359
1372
  if (matches === null || matches.count === 0) continue;
1360
1373
  count += matches.count;
1374
+ clock?.check();
1361
1375
  const page2 = partition.sortedPage({
1362
1376
  fields,
1363
1377
  directions,
@@ -1370,6 +1384,7 @@ function executeSortedQueryPage(params, context, limit, offset, sortSignature) {
1370
1384
  });
1371
1385
  for (const entry of page2) merged.push(entry);
1372
1386
  }
1387
+ clock?.check();
1373
1388
  merged.sort((a, b) => compareComparableKeys(a.key, b.key, directions) || compareCodePoints(a.id, b.id));
1374
1389
  const hasMore = merged.length > offset + limit;
1375
1390
  const page = merged.slice(offset, offset + limit);
@@ -1381,7 +1396,7 @@ function executeSortedQueryPage(params, context, limit, offset, sortSignature) {
1381
1396
  score: null,
1382
1397
  sortKey: last.key,
1383
1398
  sortSignature,
1384
- binding: context.cursorBinding
1399
+ binding: context.cursorBinding()
1385
1400
  });
1386
1401
  }
1387
1402
  return {
@@ -1396,18 +1411,18 @@ function executeSortedQueryPage(params, context, limit, offset, sortSignature) {
1396
1411
  function requireCursorDepth(cursor, signature, binding) {
1397
1412
  if (cursor === void 0) return 0;
1398
1413
  const decoded = decodePageCursor(cursor);
1399
- requireMatchingCursor(decoded, cursor, signature, true, binding);
1414
+ requireMatchingCursor(decoded, cursor, signature, true, binding());
1400
1415
  return decoded.depth ?? 0;
1401
1416
  }
1402
1417
  function hybridSearchOf(params, context, limit, offset, cursorDepth) {
1403
1418
  if ((params.hybrid?.depth ?? null) === null) return executeHybridSearch(params, context, limit, offset, cursorDepth);
1404
- return import('./runtime-C2435MPK.mjs').then(
1419
+ return import('./runtime-XNYW6AWX.mjs').then(
1405
1420
  (runtime) => runtime.searchFixedDepthHybrid(params, context, { cursorDepth: cursorDepth ?? 0, offset, limit }, runtimeHost)
1406
1421
  );
1407
1422
  }
1408
1423
  function executeQuery(request, callerContext) {
1409
1424
  if (request.rerank === void 0) return runQuery(request, callerContext);
1410
- return import('./runtime-C2435MPK.mjs').then(
1425
+ return import('./runtime-XNYW6AWX.mjs').then(
1411
1426
  (runtime) => runtime.executeRerankedQuery(request, callerContext, executeQuery, runtimeHost)
1412
1427
  );
1413
1428
  }
@@ -1702,4 +1717,4 @@ function pickDisplaySurface(surfaceOccurrences) {
1702
1717
  return best;
1703
1718
  }
1704
1719
 
1705
- export { clampLimit, dedupePinnedEntries, executeListDocuments, executePreflight, executeQuery, executeSuggest, foldGroupReducer, hitsKeptPerGroup, listBindingOf, now, queryBindingOf, requireSurfaceFormsForPartialFields, resolveHybridFusion, runtimeHost, validateBM25Params, validateDocId, validateIndexName, validatePartitionConfig, validatePatternValueLimit, validateWorkerConfig };
1720
+ export { clampLimit, dedupePinnedEntries, executeListDocuments, executePreflight, executeQuery, executeSuggest, foldGroupReducer, hitsKeptPerGroup, lazyQueryBinding, listBindingOf, now, queryBindingOf, requireSurfaceFormsForPartialFields, resolveHybridFusion, runtimeHost, validateBM25Params, validateDocId, validateIndexName, validatePartitionConfig, validatePatternValueLimit, validateWorkerConfig };
@@ -1,4 +1,4 @@
1
- import { removeDocumentVectors, prepareDocumentVectors, insertDocumentVectors } from './chunk-3RRATITJ.mjs';
1
+ import { removeDocumentVectors, prepareDocumentVectors, insertDocumentVectors } from './chunk-BCSWODXP.mjs';
2
2
  import { getNestedValue } from './chunk-KCQG2PJT.mjs';
3
3
  import { requireValidFieldTypes } from './chunk-DG62H7OD.mjs';
4
4
  import { VECTOR_PATTERN } from './chunk-L5ORED7V.mjs';
@@ -14,7 +14,7 @@ function requireLoadedVectorCode() {
14
14
  function loadVectorCode() {
15
15
  if (loaded !== null) return Promise.resolve(loaded);
16
16
  if (loading === null) {
17
- loading = import('./module-WP4VVGV2.mjs').then(
17
+ loading = import('./module-3IMTXNPW.mjs').then(
18
18
  (code) => {
19
19
  loaded = code;
20
20
  return code;
@@ -1,22 +1,23 @@
1
- import { validateWorkerConfig, validateIndexName, validatePatternValueLimit, requireSurfaceFormsForPartialFields, validateBM25Params, validatePartitionConfig, queryBindingOf, executeQuery, executePreflight, executeSuggest, executeListDocuments, validateDocId } from './chunk-GLZI636G.mjs';
1
+ import { validateWorkerConfig, validateIndexName, validatePatternValueLimit, requireSurfaceFormsForPartialFields, validateBM25Params, validatePartitionConfig, lazyQueryBinding, executeQuery, executePreflight, executeSuggest, executeListDocuments, validateDocId } from './chunk-5VVSHCXT.mjs';
2
2
  import { resolveVectorText, bindEngineCore, restoredConfigFields, restoredEmbedding, collectRequiredFieldFailures, embedChunkDocuments, providedDocId, requireDocumentObject, admitInsert, asBatchInsertError, requireMatchingDocId, embedDocumentFields, assertDocumentCarriesMappedVectors, admitBufferedUpsert, createPendingAdmissions, recordPendingAdmission } from './chunk-N57XXGPG.mjs';
3
3
  import { splitWorkerBudget, resolveWorkerCount, resolveWorkerEntry, missingWorkerEntry, DEFAULT_REQUEST_TIMEOUT_MS, resolveRequestThreadCount, workerResourceLimits, DEFAULT_BACKPRESSURE_LIMIT, SHUTDOWN_TIMEOUT_MS, CONSECUTIVE_TIMEOUTS_BEFORE_DEATH } from './chunk-6PN3U6XW.mjs';
4
4
  import { detectRuntime } from './chunk-AV4IJKD2.mjs';
5
- import { isEmptySynonymSet, synonymModule, createDirectExecutor, createPartitionRouter, availableSynonymModule, mergeFrozenSegments, createSharedFrozenSegment, freezeSegmentShared, resolvePartitionInsertOptions, createFrozenSegment } from './chunk-V7ISFBFC.mjs';
6
- import { requirePatternSearchFor, requirePartialWordSearchFor, collectQueryTermStats, mergePartitionStats, createPartitionIndex, oversampledFacetConfig, availablePatternSearch, PATTERN_HOST, kWayMerge, mergeFacets, isCompositePartition, fnv1a, encodeSegmentState } from './chunk-5WEBVYOA.mjs';
5
+ import { isEmptySynonymSet, synonymModule, createDirectExecutor, createPartitionRouter, availableSynonymModule, mergeFrozenSegments, createSharedFrozenSegment, freezeSegmentShared, resolvePartitionInsertOptions, createFrozenSegment } from './chunk-Q62NDKEC.mjs';
6
+ import { requirePatternSearchFor, requirePartialWordSearchFor, collectQueryTermStats, mergePartitionStats, createPartitionIndex, oversampledFacetConfig, availablePatternSearch, PATTERN_HOST, kWayMerge, mergeFacets, isCompositePartition, fnv1a, encodeSegmentState } from './chunk-N53HN5VA.mjs';
7
7
  import { generateId, getLanguage } from './chunk-FUUP45IS.mjs';
8
- import { readHeapStatistics } from './chunk-SOADQINJ.mjs';
8
+ import { readHeapStatistics } from './chunk-ZATRDAYU.mjs';
9
+ import { countEngineThread } from './chunk-EBIHRL7B.mjs';
9
10
  import { DEFAULT_MAX_RERANK_WINDOW, DEFAULT_RERANK_TIMEOUT_MS } from './chunk-HJSN7UYG.mjs';
10
11
  import { MAX_INDEX_CONFIGURATION_BYTES, MAX_SWEEP_INTERVAL_MS, MIN_SWEEP_INTERVAL_MS, STATISTICS_BROADCAST_INTERVAL_MS, MAX_EXPORT_LINE_BYTES, IMPORT_BATCH_DOCUMENTS, HEAP_PRESSURE_WARNING_FRACTION, FOREIGN_STATS_TTL_MS, MAX_IMPORT_REFUSALS_REPORTED, MIN_DOCUMENTS_FOR_SEGMENTS, HEAP_PRESSURE_REARM_FRACTION, BATCH_CHUNK_SIZE } from './chunk-LXWDQLTW.mjs';
11
12
  import { requireSearchBackendSettings } from './chunk-VK45J47R.mjs';
12
- import { DEFAULT_PATTERN_WORK_CAP, MATCHER_STATE_BUDGET_BYTES } from './chunk-HNAP2KTG.mjs';
13
+ import { DEFAULT_PATTERN_WORK_CAP, MATCHER_STATE_BUDGET_BYTES } from './chunk-VFAXPDBH.mjs';
13
14
  import { getNestedValue } from './chunk-KCQG2PJT.mjs';
14
15
  import { flattenSchema, raiseEarlierReleaseGraphSetting, messagePackUpperBoundBytes, validateSchema, requireCreatableSchema, validateVectorPromotion, validateVectorStorage, extractVectorFieldsFromSchema, schemaFieldsOf, validateRequiredFields, requireDocumentWithinSizeLimit, validateDocument, validateDocumentStrict } from './chunk-DG62H7OD.mjs';
15
16
  import { NATIVE_CRC32_MIN_BYTES, MAX_FILE_BYTES, CHECKSUM_YIELD_CHUNK_BYTES } from './chunk-U476IXKQ.mjs';
16
17
  import { isSingleStringFieldType } from './chunk-6ODIY6ZB.mjs';
17
18
  import { compareCodePoints } from './chunk-YTJCGKM4.mjs';
18
- import { createRequestId, isValidWorkerResponse } from './chunk-CQUMNIIG.mjs';
19
- import { loadVectorCodeFor, requireLoadedVectorCode } from './chunk-QI6JW4PM.mjs';
19
+ import { createRequestId, isValidWorkerResponse } from './chunk-Z4DZ4KK2.mjs';
20
+ import { loadVectorCodeFor, requireLoadedVectorCode } from './chunk-BCNUJVTT.mjs';
20
21
  import { noteThreadSlotLive, threadSlotOfWorker, noteThreadSlotGone } from './chunk-RFBLQLLZ.mjs';
21
22
  import { MAX_DOCUMENT_NESTING_DEPTH } from './chunk-L5ORED7V.mjs';
22
23
  import { ErrorCodes, NarsilError } from './chunk-OBWUWZRA.mjs';
@@ -1892,6 +1893,7 @@ var MAX_PENDING_REPLICATION_DOCUMENTS = 2e4;
1892
1893
  var REPLICATION_WINDOW = 32;
1893
1894
  var LOAD_BUFFER_YIELD_INTERVAL = 1e3;
1894
1895
  var MAIN_COPY_LONE_QUERY_DOCUMENTS = 5e4;
1896
+ var LONG_QUERY_THREADS = 1;
1895
1897
  var POOL_RESTART_DELAY_MS = 1e3;
1896
1898
  var POOL_RESTART_DELAY_MAX_MS = 6e4;
1897
1899
  var RETIRED_THREADS_EXIT_WAIT_MS = 1e4;
@@ -2761,6 +2763,7 @@ async function createWorkerFactory(entryPoint) {
2761
2763
  resourceLimits: workerResourceLimits(),
2762
2764
  workerData: { workerId }
2763
2765
  });
2766
+ countEngineThread(instance, workerResourceLimits().maxYoungGenerationSizeMb);
2764
2767
  return createWorkerExecutor(instance, { onDeath, onGone });
2765
2768
  };
2766
2769
  }
@@ -2773,15 +2776,41 @@ async function createWorkerFactory(entryPoint) {
2773
2776
  throw new NarsilError(ErrorCodes.WORKER_CRASHED, `No worker support available on runtime "${runtime.runtime}"`);
2774
2777
  }
2775
2778
 
2776
- // src/workers/pool.ts
2779
+ // src/workers/pool-memory.ts
2777
2780
  function toFinite(value) {
2778
2781
  return typeof value === "number" && Number.isFinite(value) ? value : 0;
2779
2782
  }
2780
2783
  function toHeapLimit(value) {
2781
2784
  return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : null;
2782
2785
  }
2786
+ async function memoryStatsOf(slots) {
2787
+ const indices = [];
2788
+ const pending = [];
2789
+ for (const [slotIndex, slot] of slots) {
2790
+ indices.push(slotIndex);
2791
+ pending.push(
2792
+ slot.executor.execute({ type: "memoryReport", requestId: createRequestId() }).catch(() => null)
2793
+ );
2794
+ }
2795
+ const reports = await Promise.all(pending);
2796
+ const stats = [];
2797
+ for (let n = 0; n < indices.length; n++) {
2798
+ const report = reports[n];
2799
+ stats.push({
2800
+ workerId: indices[n],
2801
+ heapUsed: toFinite(report?.heapUsed),
2802
+ heapTotal: toFinite(report?.heapTotal),
2803
+ heapLimit: toHeapLimit(report?.heapLimit),
2804
+ external: toFinite(report?.external)
2805
+ });
2806
+ }
2807
+ return stats;
2808
+ }
2809
+
2810
+ // src/workers/pool.ts
2783
2811
  function createWorkerPool(config) {
2784
2812
  const workerCount = resolveWorkerCount(config.count);
2813
+ const queryWorkerCount = workerCount - Math.min(config.longQueryWorkers ?? 0, workerCount - 1);
2785
2814
  const workers = /* @__PURE__ */ new Map();
2786
2815
  const deadSlots = /* @__PURE__ */ new Set();
2787
2816
  const goneSlots = /* @__PURE__ */ new Set();
@@ -2876,10 +2905,13 @@ function createWorkerPool(config) {
2876
2905
  }
2877
2906
  };
2878
2907
  }
2908
+ function isLongQueryWorker(workerId) {
2909
+ return workerId >= queryWorkerCount;
2910
+ }
2879
2911
  function assignSlot(indexName) {
2880
- const preferred = fnv1a(indexName) % workerCount;
2881
- for (let probe = 0; probe < workerCount; probe++) {
2882
- const candidate2 = (preferred + probe) % workerCount;
2912
+ const preferred = fnv1a(indexName) % queryWorkerCount;
2913
+ for (let probe = 0; probe < queryWorkerCount; probe++) {
2914
+ const candidate2 = (preferred + probe) % queryWorkerCount;
2883
2915
  if (!deadSlots.has(candidate2)) {
2884
2916
  return candidate2;
2885
2917
  }
@@ -2924,29 +2956,6 @@ function createWorkerPool(config) {
2924
2956
  }
2925
2957
  throw new NarsilError(ErrorCodes.WORKER_CRASHED, `Every worker holding index "${indexName}" has crashed`);
2926
2958
  }
2927
- async function getMemoryStats() {
2928
- const indices = [];
2929
- const pending = [];
2930
- for (const [slotIndex, slot] of workers) {
2931
- indices.push(slotIndex);
2932
- pending.push(
2933
- slot.executor.execute({ type: "memoryReport", requestId: createRequestId() }).catch(() => null)
2934
- );
2935
- }
2936
- const reports = await Promise.all(pending);
2937
- const stats = [];
2938
- for (let n = 0; n < indices.length; n++) {
2939
- const report = reports[n];
2940
- stats.push({
2941
- workerId: indices[n],
2942
- heapUsed: toFinite(report?.heapUsed),
2943
- heapTotal: toFinite(report?.heapTotal),
2944
- heapLimit: toHeapLimit(report?.heapLimit),
2945
- external: toFinite(report?.external)
2946
- });
2947
- }
2948
- return stats;
2949
- }
2950
2959
  async function shutdown() {
2951
2960
  if (isShutdown) {
2952
2961
  return;
@@ -2994,7 +3003,7 @@ function createWorkerPool(config) {
2994
3003
  let chosenId = -1;
2995
3004
  let chosen = null;
2996
3005
  for (const [workerId, slot] of workers) {
2997
- if (!slot.serving) continue;
3006
+ if (!slot.serving || isLongQueryWorker(workerId)) continue;
2998
3007
  if (indexName !== void 0 && !slot.indexes.has(indexName)) continue;
2999
3008
  if (chosen === null || slot.inFlight < chosen.inFlight) {
3000
3009
  chosenId = workerId;
@@ -3006,8 +3015,8 @@ function createWorkerPool(config) {
3006
3015
  }
3007
3016
  function queriesInFlight() {
3008
3017
  let total = 0;
3009
- for (const slot of workers.values()) {
3010
- if (slot.serving) total += slot.inFlight;
3018
+ for (const [workerId, slot] of workers) {
3019
+ if (slot.serving && !isLongQueryWorker(workerId)) total += slot.inFlight;
3011
3020
  }
3012
3021
  return total;
3013
3022
  }
@@ -3015,7 +3024,7 @@ function createWorkerPool(config) {
3015
3024
  const leases = [];
3016
3025
  for (const [workerId, slot] of workers) {
3017
3026
  if (leases.length >= limit) break;
3018
- if (slot.serving && slot.inFlight === 0) leases.push(lease(workerId, slot));
3027
+ if (slot.serving && slot.inFlight === 0 && !isLongQueryWorker(workerId)) leases.push(lease(workerId, slot));
3019
3028
  }
3020
3029
  return leases;
3021
3030
  }
@@ -3041,6 +3050,7 @@ function createWorkerPool(config) {
3041
3050
  executorsHolding,
3042
3051
  leaseLeastBusy,
3043
3052
  leaseIdle,
3053
+ isLongQueryWorker,
3044
3054
  queriesInFlight,
3045
3055
  spawnAll,
3046
3056
  deadWorkerIds,
@@ -3051,7 +3061,7 @@ function createWorkerPool(config) {
3051
3061
  addIndex,
3052
3062
  addIndexToAll,
3053
3063
  removeIndex,
3054
- getMemoryStats,
3064
+ getMemoryStats: () => memoryStatsOf(workers.entries()),
3055
3065
  shutdown,
3056
3066
  whenEveryThreadIsGone
3057
3067
  };
@@ -3081,7 +3091,7 @@ async function insertOnLease(lease, indexName, fieldName, handle, ordinals) {
3081
3091
  function sharedCopyHostOf(state) {
3082
3092
  return {
3083
3093
  get workerCount() {
3084
- return state.workerPool?.workerCount ?? state.keywordWorkerCount;
3094
+ return state.workerPool?.workerCount ?? state.keywordWorkerCount + state.longQueryWorkerCount;
3085
3095
  },
3086
3096
  holdsIndex: (indexName) => holdsIndex(state, indexName),
3087
3097
  resolvePartition: (indexName, docId) => state.executor.getManager(indexName)?.partitionIdOf(docId),
@@ -3143,8 +3153,12 @@ function refreshVectorCopies(state, indexName) {
3143
3153
  async function announceRequestThreads(state, pool) {
3144
3154
  const listener = state.requestThreads;
3145
3155
  if (listener === null) return;
3146
- for (const { workerId, executor } of pool.executorEntries()) {
3147
- await listener.onWorkerReady(workerId, executor);
3156
+ const entries = pool.executorEntries();
3157
+ for (const { workerId, executor } of entries) {
3158
+ if (pool.isLongQueryWorker(workerId)) await listener.onLongQueryWorkerReady(workerId, executor);
3159
+ }
3160
+ for (const { workerId, executor } of entries) {
3161
+ if (!pool.isLongQueryWorker(workerId)) await listener.onWorkerReady(workerId, executor);
3148
3162
  }
3149
3163
  }
3150
3164
  function scheduleRequestThreadPoolRestart(state) {
@@ -3165,13 +3179,14 @@ async function serveRequestsOnWorkers(state, listener) {
3165
3179
  if (!state.workersEnabled) return 0;
3166
3180
  state.requestThreads = listener;
3167
3181
  state.keywordWorkerCount = resolveRequestThreadCount(state.config?.workers?.count);
3182
+ state.longQueryWorkerCount = LONG_QUERY_THREADS;
3168
3183
  if (state.vectorCopyPolicy !== void 0) {
3169
3184
  state.vectorCopyPolicy.host = sharedCopyHostOf(state);
3170
3185
  state.vectorCopyPolicy.enabled = state.workersEnabled;
3171
3186
  }
3172
3187
  if (state.poolStart !== null) await state.poolStart.catch(() => void 0);
3173
3188
  const running = state.workerPool;
3174
- if (running !== null && running.workerCount !== state.keywordWorkerCount) {
3189
+ if (running !== null && running.workerCount !== resolveWorkerCount(state.keywordWorkerCount + LONG_QUERY_THREADS)) {
3175
3190
  retirePool(state, running);
3176
3191
  state.poolRetryAt = 0;
3177
3192
  }
@@ -3283,7 +3298,9 @@ async function replaceWorker(state, pool, workerId) {
3283
3298
  await loadOntoReplacement(state, replacement, indexName);
3284
3299
  }
3285
3300
  replacement.admit();
3286
- await state.requestThreads?.onWorkerReady(workerId, replacement.executor);
3301
+ if (pool.isLongQueryWorker(workerId))
3302
+ await state.requestThreads?.onLongQueryWorkerReady(workerId, replacement.executor);
3303
+ else await state.requestThreads?.onWorkerReady(workerId, replacement.executor);
3287
3304
  } catch (err) {
3288
3305
  replacement.abandon();
3289
3306
  throw err;
@@ -3342,7 +3359,8 @@ async function startPool(state) {
3342
3359
  const factory = await createWorkerFactory();
3343
3360
  let started = null;
3344
3361
  const pool = createWorkerPool({
3345
- count: state.keywordWorkerCount,
3362
+ count: state.keywordWorkerCount + state.longQueryWorkerCount,
3363
+ longQueryWorkers: state.longQueryWorkerCount,
3346
3364
  workerFactory: factory,
3347
3365
  onWorkerCrash(workerId, indexNames, error) {
3348
3366
  if (started !== null) handleWorkerCrash(state, started, workerId, indexNames, error);
@@ -3767,6 +3785,7 @@ function createWorkerOrchestrator(config, executor, indexRegistry, callbacks, ve
3767
3785
  vectorCopyPolicy,
3768
3786
  workersEnabled: config?.workers?.enabled ?? workersEnabledByDefault(),
3769
3787
  keywordWorkerCount: splitWorkerBudget(resolveWorkerCount(config?.workers?.count)).keyword,
3788
+ longQueryWorkerCount: 0,
3770
3789
  requestThreads: null,
3771
3790
  copyThreshold: config?.workers?.promotionThreshold ?? DEFAULT_COPY_THRESHOLD,
3772
3791
  copyIdleTimeoutMs: config?.workers?.idleTimeoutMs ?? copyIdleTimeoutBeforeClose(config?.lifecycle?.idleTimeoutMs),
@@ -4026,7 +4045,7 @@ async function emitWriteEventAfter(source, indexName, write) {
4026
4045
  // src/engine/core.ts
4027
4046
  async function createEngineCore(config, hooks, capacityScope = "index") {
4028
4047
  validateWorkerConfig(config?.workers, config?.lifecycle);
4029
- const rerankSettings = config?.rerankTimeout === void 0 && config?.maxRerankWindow === void 0 ? { timeoutMs: DEFAULT_RERANK_TIMEOUT_MS, maxWindow: DEFAULT_MAX_RERANK_WINDOW } : (await import('./runtime-C2435MPK.mjs')).resolveRerankSettings(config);
4048
+ const rerankSettings = config?.rerankTimeout === void 0 && config?.maxRerankWindow === void 0 ? { timeoutMs: DEFAULT_RERANK_TIMEOUT_MS, maxWindow: DEFAULT_MAX_RERANK_WINDOW } : (await import('./runtime-XNYW6AWX.mjs')).resolveRerankSettings(config);
4030
4049
  const eventHandlers = eventHandlersOf(config?.events);
4031
4050
  const vectorWorkerCount = splitWorkerBudget(resolveWorkerCount(config?.workers?.count)).vector;
4032
4051
  const vectorCopyPolicy = {
@@ -4037,7 +4056,7 @@ async function createEngineCore(config, hooks, capacityScope = "index") {
4037
4056
  if (config?.lifecycle !== void 0 && durabilityTier === null) {
4038
4057
  throw new NarsilError(ErrorCodes.CONFIG_INVALID, "Index lifecycle settings require durability");
4039
4058
  }
4040
- const durabilityWiring = durabilityTier === null ? null : await import('./durability-wiring-EQTFL3B4.mjs');
4059
+ const durabilityWiring = durabilityTier === null ? null : await import('./durability-wiring-5V6DVHFK.mjs');
4041
4060
  const filesystemDurability = durabilityTier?.kind === "wal";
4042
4061
  const executor = createDirectExecutor({
4043
4062
  vectorWorkerCopies: vectorCopyPolicy,
@@ -4334,7 +4353,7 @@ async function shutdownEngine(core) {
4334
4353
  }
4335
4354
  }
4336
4355
  if (core.rerankAdapters.size > 0) {
4337
- await (await import('./runtime-C2435MPK.mjs')).shutdownRerankAdapters(core.rerankAdapters);
4356
+ await (await import('./runtime-XNYW6AWX.mjs')).shutdownRerankAdapters(core.rerankAdapters);
4338
4357
  }
4339
4358
  await orchestrator.shutdown();
4340
4359
  await executor.shutdown();
@@ -6434,6 +6453,7 @@ function getVectorMaintenanceStatus(manager) {
6434
6453
  graphCount: status.graphCount,
6435
6454
  bufferSize: status.bufferSize,
6436
6455
  building: status.building,
6456
+ waitingForMemory: status.waitingForMemory,
6437
6457
  estimatedCompactMs: status.estimatedCompactMs,
6438
6458
  estimatedOptimizeMs: status.estimatedOptimizeMs
6439
6459
  });
@@ -6951,14 +6971,14 @@ function portabilityOperations(core, config, engine) {
6951
6971
  return {
6952
6972
  snapshot(indexName) {
6953
6973
  return withOpenIndex(indexName, async () => {
6954
- const { createSnapshot } = await import('./snapshot-EU6NNB2P.mjs');
6974
+ const { createSnapshot } = await import('./snapshot-57WF53MK.mjs');
6955
6975
  return createSnapshot(snapshotDepsOf(indexName));
6956
6976
  });
6957
6977
  },
6958
6978
  async restore(indexName, data) {
6959
6979
  core.guardShutdown();
6960
6980
  validateIndexName(indexName);
6961
- const restored = import('./restore-queue-WZTMTJP2.mjs').then(
6981
+ const restored = import('./restore-queue-J6PCG4ON.mjs').then(
6962
6982
  ({ queueRestore }) => queueRestore(core, restoreHost, restoresInFlight, indexName, data)
6963
6983
  );
6964
6984
  await emitWriteEventAfter(core, indexName, restored);
@@ -6967,8 +6987,8 @@ function portabilityOperations(core, config, engine) {
6967
6987
  exportDocuments(indexName) {
6968
6988
  return withOpenIndex(indexName, async () => {
6969
6989
  const [{ checkpointForArchive }, { documentExportStream }] = await Promise.all([
6970
- import('./snapshot-EU6NNB2P.mjs'),
6971
- import('./write-CKRWS3P5.mjs')
6990
+ import('./snapshot-57WF53MK.mjs'),
6991
+ import('./write-YEI7A5OR.mjs')
6972
6992
  ]);
6973
6993
  const header = indexConfigurationOf(core.requireIndex(indexName));
6974
6994
  return documentExportStream(header, await checkpointForArchive(snapshotDepsOf(indexName)));
@@ -7020,7 +7040,7 @@ async function runEngineQuery(core, indexName, params, options) {
7020
7040
  const manager = core.requireManager(indexName);
7021
7041
  const scoped = scopedParams(params, options);
7022
7042
  await core.pluginRegistry.runHook("beforeSearch", { indexName, params: scoped });
7023
- const rerank = scoped.rerank === void 0 ? void 0 : await import('./runtime-C2435MPK.mjs');
7043
+ const rerank = scoped.rerank === void 0 ? void 0 : await import('./runtime-XNYW6AWX.mjs');
7024
7044
  const resolvedParams = await resolveVectorText(
7025
7045
  rerank === void 0 ? scoped : rerank.withRerankQueryText(scoped),
7026
7046
  entry.embeddingAdapter,
@@ -7037,7 +7057,7 @@ async function runEngineQuery(core, indexName, params, options) {
7037
7057
  broadcastStats: broadcastStatsFor(core, options),
7038
7058
  partitionIds: options?.partitionIds,
7039
7059
  rescoreWindow: options?.rescoreWindow,
7040
- cursorBinding: queryBindingOf(params),
7060
+ cursorBinding: lazyQueryBinding(params),
7041
7061
  patternWorkCap: core.patternWorkCap,
7042
7062
  rerank: rerank?.rerankRunnerFor(core)
7043
7063
  };
@@ -7086,7 +7106,7 @@ async function runEnginePreflight(core, indexName, params, options) {
7086
7106
  indexName,
7087
7107
  broadcastStats: broadcastStatsFor(core, options),
7088
7108
  partitionIds: options?.partitionIds,
7089
- cursorBinding: queryBindingOf(params),
7109
+ cursorBinding: lazyQueryBinding(params),
7090
7110
  patternWorkCap: core.patternWorkCap
7091
7111
  };
7092
7112
  const { result, analysisStale } = await readUnderOneAnalysis(