@delali/narsil 0.3.1-next.70 → 0.3.1-next.72

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 (57) hide show
  1. package/dist/adapters/filesystem.mjs +1 -1
  2. package/dist/adapters/indexeddb.mjs +1 -1
  3. package/dist/{capabilities-Dt-7B4Wz.d.ts → capabilities-D6gjjQyA.d.ts} +2 -2
  4. package/dist/{chunk-P4DSQ6M4.mjs → chunk-2X2ZQOAB.mjs} +69 -28
  5. package/dist/chunk-3HQPUCCT.mjs +785 -0
  6. package/dist/{chunk-VNMTB3KC.mjs → chunk-7QMTA7AA.mjs} +194 -59
  7. package/dist/{chunk-FVLQ63B7.mjs → chunk-CVPA5Q7R.mjs} +24 -3
  8. package/dist/{chunk-2STVUTNA.mjs → chunk-EDMCZLSJ.mjs} +4 -3
  9. package/dist/{chunk-M76V3OGJ.mjs → chunk-HVJYTKK7.mjs} +940 -647
  10. package/dist/{chunk-HWQLTLNG.mjs → chunk-KZTI25D3.mjs} +1 -1
  11. package/dist/{chunk-YJDQ7NLA.mjs → chunk-LCCL6EEH.mjs} +3 -3
  12. package/dist/{chunk-OI42GWLR.mjs → chunk-LJYTW7GT.mjs} +57 -11
  13. package/dist/{chunk-653BNMAF.mjs → chunk-M6XF5HDE.mjs} +57 -17
  14. package/dist/{chunk-YNVIUGF5.mjs → chunk-P2ZZN32C.mjs} +1 -1
  15. package/dist/{chunk-LMO5TJUS.mjs → chunk-QR4OKRVY.mjs} +637 -196
  16. package/dist/{chunk-USKFU7J5.mjs → chunk-RV77FR2F.mjs} +1 -0
  17. package/dist/{chunk-GIVAGD3Q.mjs → chunk-XZ4PAREY.mjs} +1 -1
  18. package/dist/{chunk-3JGWULDF.mjs → chunk-Y52WZWAU.mjs} +5 -5
  19. package/dist/chunk-ZKRV5M2P.mjs +75 -0
  20. package/dist/{client-COek5GXK.d.ts → client-C2TiW29y.d.ts} +3 -3
  21. package/dist/client.d.ts +8 -8
  22. package/dist/client.mjs +1 -0
  23. package/dist/{config-rBpbgTw8.d.ts → config-BLguB-om.d.ts} +2 -2
  24. package/dist/{config-Dfanyqqt.d.ts → config-C7Ip8Ife.d.ts} +17 -2
  25. package/dist/direct-executor-SVCHXR74.mjs +14 -0
  26. package/dist/distribution/coordinator/etcd.d.ts +2 -2
  27. package/dist/distribution/coordinator/etcd.mjs +2 -2
  28. package/dist/distribution/coordinator/in-memory.d.ts +2 -2
  29. package/dist/distribution/coordinator/in-memory.mjs +1 -1
  30. package/dist/distribution/transport/grpc.mjs +1 -1
  31. package/dist/distribution.d.ts +8 -8
  32. package/dist/distribution.mjs +58 -35
  33. package/dist/embeddings/openai.mjs +1 -1
  34. package/dist/{engine-CXKfmK7I.d.ts → engine-Dm4446j1.d.ts} +104 -62
  35. package/dist/index.browser.mjs +2222 -1100
  36. package/dist/index.d.ts +27 -8
  37. package/dist/index.mjs +14 -12
  38. package/dist/invalidation/filesystem.mjs +1 -1
  39. package/dist/{memory-C7UMCMH3.d.ts → memory-CKHTU1CL.d.ts} +66 -25
  40. package/dist/pattern-Cledccbl.d.ts +18 -0
  41. package/dist/pattern.d.ts +22 -0
  42. package/dist/pattern.mjs +7 -0
  43. package/dist/persistence/durability/checkpoint-worker.d.ts +17 -1
  44. package/dist/persistence/durability/checkpoint-worker.mjs +14 -12
  45. package/dist/react.d.ts +277 -182
  46. package/dist/react.mjs +190 -45
  47. package/dist/{schema-Bgzr4g7b.d.ts → schema-BBOCdhND.d.ts} +9 -7
  48. package/dist/server.d.ts +10 -10
  49. package/dist/server.mjs +13 -12
  50. package/dist/{tasks-BZt_zes6.d.ts → tasks-BECd0b__.d.ts} +1 -1
  51. package/dist/{thread-JEVAYETR.mjs → thread-IBSIZZ6W.mjs} +22 -13
  52. package/dist/{types-gOUqhs2F.d.ts → types-BiUmaiWT.d.ts} +1 -1
  53. package/dist/vector/search-worker.d.ts +1 -1
  54. package/dist/vector/search-worker.mjs +4 -4
  55. package/dist/workers/entry.mjs +4 -4
  56. package/package.json +15 -7
  57. package/dist/direct-executor-GYJEKNV5.mjs +0 -12
@@ -1,4 +1,4 @@
1
- import { NarsilError, ErrorCodes } from '../chunk-USKFU7J5.mjs';
1
+ import { NarsilError, ErrorCodes } from '../chunk-RV77FR2F.mjs';
2
2
 
3
3
  // src/persistence/filesystem.ts
4
4
  var cachedFs = null;
@@ -1,4 +1,4 @@
1
- import { NarsilError, ErrorCodes } from '../chunk-USKFU7J5.mjs';
1
+ import { NarsilError, ErrorCodes } from '../chunk-RV77FR2F.mjs';
2
2
 
3
3
  // src/persistence/constants.ts
4
4
  var DEFAULT_INDEXEDDB_NAME = "narsil";
@@ -1,6 +1,6 @@
1
1
  import { E as EmbeddingAdapter } from './adapters-79OIa4xm.js';
2
- import { C as ClusterNamespace } from './config-rBpbgTw8.js';
3
- import { h as TaskStore } from './tasks-BZt_zes6.js';
2
+ import { C as ClusterNamespace } from './config-BLguB-om.js';
3
+ import { h as TaskStore } from './tasks-BECd0b__.js';
4
4
 
5
5
  /**
6
6
  * Context handed to {@link OnRequestHook} for every inbound request, captured
@@ -1,9 +1,9 @@
1
- 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-GIVAGD3Q.mjs';
2
- import { clampRowCount, sortSignatureOf, requireSortableFields, decodePageCursor, requireMatchingCursor, resolveProjection, encodePageCursor, requireWithinResultWindow, normalizeSort, fanOutQuery, sortModesOf, applySorting, applyPagination, projectionKeepsField, countsWithoutScores, fanOutMatchCount, tokenize, fnv1aBytes, requireValidFilter, everyValueFacetConfig, fulltextMatches, mergeFacets, pruneStatsToQueryTerms, partitionsIn, undeclaredFieldOnStrictIndex, fuzzyTermMatches } from './chunk-LMO5TJUS.mjs';
3
- import { MIN_PATTERN_VALUE_LIMIT, MAX_PATTERN_VALUE_LIMIT, DEFAULT_MAX_PER_GROUP, flattenSchema, DEFAULT_LINEAR_ALPHA, MIN_LINEAR_ALPHA, MAX_LINEAR_ALPHA, DEFAULT_RANK_CONSTANT, MIN_RANK_CONSTANT, DEFAULT_FUZZY_PREFIX_LENGTH, RESULT_WINDOW, isWordIndexedFieldType, isGeopointOrVectorType, MAX_TOLERANCE, MAX_PREFIX_LENGTH } from './chunk-653BNMAF.mjs';
1
+ 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-XZ4PAREY.mjs';
2
+ import { clampRowCount, sortSignatureOf, requireSortableFields, decodePageCursor, requireMatchingCursor, resolveProjection, encodePageCursor, requireWithinResultWindow, normalizeSort, fanOutQuery, sortModesOf, applySorting, applyPagination, projectionKeepsField, countsWithoutScores, fanOutMatchCount, tokenize, fnv1aBytes, requireValidFilter, createPatternWorkMeter, everyValueFacetConfig, fulltextMatches, mergeFacets, pruneStatsToQueryTerms, partitionsIn, undeclaredFieldOnStrictIndex, fuzzyTermMatches } from './chunk-QR4OKRVY.mjs';
3
+ import { MIN_PATTERN_VALUE_LIMIT, MAX_PATTERN_VALUE_LIMIT, DEFAULT_MAX_PER_GROUP, flattenSchema, DEFAULT_LINEAR_ALPHA, MIN_LINEAR_ALPHA, MAX_LINEAR_ALPHA, DEFAULT_RANK_CONSTANT, MIN_RANK_CONSTANT, DEFAULT_FUZZY_PREFIX_LENGTH, RESULT_WINDOW, isWordIndexedFieldType, isGeopointOrVectorType, MAX_TOLERANCE, MAX_PREFIX_LENGTH } from './chunk-M6XF5HDE.mjs';
4
4
  import { MIN_OVERSAMPLE } from './chunk-ZJ4CSAB2.mjs';
5
- import { compareCodePoints, compareComparableKeys } from './chunk-OI42GWLR.mjs';
6
- import { NarsilError, ErrorCodes } from './chunk-USKFU7J5.mjs';
5
+ import { holdsUnpairedSurrogate, compareCodePoints, compareComparableKeys } from './chunk-LJYTW7GT.mjs';
6
+ import { NarsilError, ErrorCodes } from './chunk-RV77FR2F.mjs';
7
7
 
8
8
  // src/search/cursor-binding.ts
9
9
  var ABSENT_TAG = 0;
@@ -225,6 +225,9 @@ function requireValidTypoTolerance(params) {
225
225
  }
226
226
 
227
227
  // src/engine/query/shared.ts
228
+ function withPatternWork(context) {
229
+ return { ...context, patternWork: createPatternWorkMeter(context.patternWorkCap) };
230
+ }
228
231
  function partitionsFor(manager, partitionIds) {
229
232
  return partitionsIn(manager, partitionIds);
230
233
  }
@@ -271,18 +274,19 @@ function broadcastStatsForWorker(params, context, scoring) {
271
274
  }
272
275
  return pruneStatsToQueryTerms(scoring.globalStats, term, context.language, context.manager.analysis);
273
276
  }
274
- function searchOptionsFor(manager) {
277
+ function searchOptionsFor(manager, patternWork) {
275
278
  return {
276
279
  bm25Params: manager.config.bm25,
277
280
  stopWords: manager.analysis.stopWords,
278
- customTokenizer: manager.analysis.customTokenizer
281
+ customTokenizer: manager.analysis.customTokenizer,
282
+ patternWork
279
283
  };
280
284
  }
281
- function collectFilterDocIds(manager, params, schema, partitionIds) {
285
+ function collectFilterDocIds(manager, params, schema, partitionIds, patternWork) {
282
286
  const filterDocIds = /* @__PURE__ */ new Set();
283
287
  if (!params.filters) return filterDocIds;
284
288
  for (const partition of partitionsFor(manager, partitionIds)) {
285
- const partitionFiltered = partition.applyFilters(params.filters, schema);
289
+ const partitionFiltered = partition.applyFilters(params.filters, schema, patternWork);
286
290
  for (const docId of partitionFiltered) {
287
291
  filterDocIds.add(docId);
288
292
  }
@@ -317,11 +321,11 @@ function requireValidQueryOptions(params, config) {
317
321
  const strict = config.strict === true;
318
322
  requireValidTypoTolerance(params);
319
323
  requireSortableFields(params.sort, config.schema, strict);
320
- requireValidQueryFilter(params.filters, config.schema, strict);
324
+ requireValidQueryFilter(params.filters, config.schema);
321
325
  requireUsableQueryFields(params, config.schema, strict);
322
326
  }
323
- function requireValidQueryFilter(filters, schema, strict = false) {
324
- if (filters !== void 0) requireValidFilter(filters, flattenSchema(schema), strict);
327
+ function requireValidQueryFilter(filters, schema) {
328
+ if (filters !== void 0) requireValidFilter(filters, flattenSchema(schema));
325
329
  }
326
330
  function requireVectorSearchable(params, context, needsVector) {
327
331
  if (!needsVector) return;
@@ -395,6 +399,13 @@ function validateDocId(docId) {
395
399
  if (docId.includes("\0")) {
396
400
  throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, "Document ID must not contain null bytes", { docId });
397
401
  }
402
+ if (holdsUnpairedSurrogate(docId)) {
403
+ throw new NarsilError(
404
+ ErrorCodes.DOC_VALIDATION_FAILED,
405
+ "Document ID holds an unpaired surrogate, the half of a character such as an emoji whose other half is missing, so the engine cannot store it as UTF-8",
406
+ { docId }
407
+ );
408
+ }
398
409
  }
399
410
  function validatePartitionConfig(partitions) {
400
411
  const { maxDocsPerPartition, maxPartitions, watermark } = partitions;
@@ -493,8 +504,9 @@ function firstIdAfter(sorted, anchor) {
493
504
  }
494
505
  return low;
495
506
  }
496
- function collectFilterMatches(partitions, filters, schema) {
497
- const perPartition = partitions.map((partition) => partition.filterMatches(filters, schema));
507
+ function collectFilterMatches(partitions, filters, schema, patternWorkCap) {
508
+ const meter = createPatternWorkMeter(patternWorkCap);
509
+ const perPartition = partitions.map((partition) => partition.filterMatches(filters, schema, meter));
498
510
  let total = 0;
499
511
  for (const matches of perPartition) total += matches.count;
500
512
  return { matchesFor: (partitionIndex) => perPartition[partitionIndex] ?? null, total };
@@ -572,7 +584,7 @@ function executeListDocuments(params, context) {
572
584
  const limit = clampListLimit(params.limit);
573
585
  const signature = sortSignatureOf(params.sort);
574
586
  requireSortableFields(params.sort, schema, context.strict === true);
575
- requireValidQueryFilter(params.filters, schema, context.strict === true);
587
+ requireValidQueryFilter(params.filters, schema);
576
588
  const binding = listBindingOf(params.filters);
577
589
  let cursor = null;
578
590
  if (params.cursor !== void 0) {
@@ -580,7 +592,7 @@ function executeListDocuments(params, context) {
580
592
  requireMatchingCursor(cursor, params.cursor, signature, false, binding);
581
593
  }
582
594
  const partitions = context.partitionIds === void 0 ? manager.getAllPartitions() : context.partitionIds.map((partitionId) => manager.partitionAt(partitionId)).filter((partition) => partition !== void 0);
583
- const filtered = params.filters === void 0 ? null : collectFilterMatches(partitions, params.filters, schema);
595
+ const filtered = params.filters === void 0 ? null : collectFilterMatches(partitions, params.filters, schema, context.patternWorkCap);
584
596
  const total = filtered === null ? countAcrossPartitions(manager, context.partitionIds, partitions) : filtered.total;
585
597
  const page = params.sort === void 0 || signature === null ? pageInIdOrder(partitions, cursor, filtered, limit, binding) : pageInSortOrder(partitions, cursor, filtered, limit, params.sort, signature, schema, binding);
586
598
  const projection = resolveProjection(params.document);
@@ -947,7 +959,7 @@ function executeSortedQueryPage(params, context, limit, offset, sortSignature) {
947
959
  const flatSchema = flattenSchema(schema);
948
960
  const fieldTypes = fields.map((field) => flatSchema[field]);
949
961
  const modes = sortModesOf(normalized);
950
- const options = searchOptionsFor(manager);
962
+ const options = searchOptionsFor(manager, context.patternWork);
951
963
  const partitions = partitionsFor(manager, context.partitionIds);
952
964
  const partitionLimit = offset + limit + 1;
953
965
  const merged = [];
@@ -1148,7 +1160,7 @@ async function executeVectorSearch(params, context, limit, offset, cursorDepth =
1148
1160
  let filterDocIds;
1149
1161
  let filterPartitions;
1150
1162
  if (params.filters) {
1151
- filterDocIds = collectFilterDocIds(manager, params, config.schema, partitionIds);
1163
+ filterDocIds = collectFilterDocIds(manager, params, config.schema, partitionIds, context.patternWork);
1152
1164
  if (filterDocIds.size === 0) {
1153
1165
  return { scored: [], totalMatched: 0 };
1154
1166
  }
@@ -1176,11 +1188,19 @@ async function textLeg(textOnlyParams, context) {
1176
1188
  indexName,
1177
1189
  textOnlyParams,
1178
1190
  broadcastStatsForWorker(textOnlyParams, context, scoring),
1179
- context.partitionIds
1191
+ context.partitionIds,
1192
+ context.patternWork
1180
1193
  );
1181
1194
  if (viaWorker) return viaWorker;
1182
1195
  }
1183
- return fanOutQuery(manager, textOnlyParams, language, config.schema, scoring, searchOptionsFor(manager));
1196
+ return fanOutQuery(
1197
+ manager,
1198
+ textOnlyParams,
1199
+ language,
1200
+ config.schema,
1201
+ scoring,
1202
+ searchOptionsFor(manager, context.patternWork)
1203
+ );
1184
1204
  }
1185
1205
  async function vectorLeg(vectorConfig, queryVector, context, filterDocIds, k) {
1186
1206
  const { manager } = context;
@@ -1206,7 +1226,7 @@ async function executeHybridSearch(params, context, limit, offset, cursorDepth =
1206
1226
  const fusion = resolveHybridFusion(params.hybrid);
1207
1227
  let filterDocIds;
1208
1228
  if (params.filters) {
1209
- filterDocIds = collectFilterDocIds(manager, params, config.schema, context.partitionIds);
1229
+ filterDocIds = collectFilterDocIds(manager, params, config.schema, context.partitionIds, context.patternWork);
1210
1230
  if (filterDocIds.size === 0) {
1211
1231
  return { scored: [], totalMatched: 0 };
1212
1232
  }
@@ -1250,7 +1270,8 @@ function requireCursorDepth(cursor, signature, binding) {
1250
1270
  requireMatchingCursor(decoded, cursor, signature, true, binding);
1251
1271
  return decoded.depth ?? 0;
1252
1272
  }
1253
- async function executeQuery(params, context) {
1273
+ async function executeQuery(params, callerContext) {
1274
+ const context = withPatternWork(callerContext);
1254
1275
  const { manager, language, config, workerSearch, indexName } = context;
1255
1276
  const startTime = now();
1256
1277
  const limit = clampLimit(params.limit);
@@ -1296,11 +1317,24 @@ async function executeQuery(params, context) {
1296
1317
  fanOutResult = await executeHybridSearch(params, context, limit, offset, depth);
1297
1318
  } else {
1298
1319
  const scoring = scoringConfigFor(params, context);
1299
- const workerResult = workerSearch ? await workerSearch(indexName, params, broadcastStatsForWorker(params, context, scoring), context.partitionIds) : null;
1320
+ const workerResult = workerSearch ? await workerSearch(
1321
+ indexName,
1322
+ params,
1323
+ broadcastStatsForWorker(params, context, scoring),
1324
+ context.partitionIds,
1325
+ context.patternWork
1326
+ ) : null;
1300
1327
  if (workerResult) {
1301
1328
  fanOutResult = workerResult;
1302
1329
  } else {
1303
- fanOutResult = await fanOutQuery(manager, params, language, config.schema, scoring, searchOptionsFor(manager));
1330
+ fanOutResult = await fanOutQuery(
1331
+ manager,
1332
+ params,
1333
+ language,
1334
+ config.schema,
1335
+ scoring,
1336
+ searchOptionsFor(manager, context.patternWork)
1337
+ );
1304
1338
  }
1305
1339
  }
1306
1340
  const needsFullHits = params.sort !== void 0 || params.group !== void 0 || params.pinned !== void 0 || params.searchAfter !== void 0;
@@ -1420,7 +1454,8 @@ async function executeQuery(params, context) {
1420
1454
  coverage: coverageFor(manager, context.partitionIds)
1421
1455
  };
1422
1456
  }
1423
- async function executePreflight(params, context) {
1457
+ async function executePreflight(params, callerContext) {
1458
+ const context = withPatternWork(callerContext);
1424
1459
  const { manager, language, config, workerSearch, indexName } = context;
1425
1460
  const startTime = now();
1426
1461
  requireKnownMode(params);
@@ -1446,12 +1481,18 @@ async function executePreflight(params, context) {
1446
1481
  countExact = result.matchedExact !== false;
1447
1482
  } else if (countsWithoutScores(params)) {
1448
1483
  totalMatched = fanOutMatchCount(manager, params, language, config.schema, {
1449
- searchOptions: searchOptionsFor(manager),
1484
+ searchOptions: searchOptionsFor(manager, context.patternWork),
1450
1485
  partitionIds: context.partitionIds
1451
1486
  });
1452
1487
  } else {
1453
1488
  const scoring = scoringConfigFor(params, context);
1454
- const workerResult = workerSearch ? await workerSearch(indexName, params, broadcastStatsForWorker(params, context, scoring), context.partitionIds) : null;
1489
+ const workerResult = workerSearch ? await workerSearch(
1490
+ indexName,
1491
+ params,
1492
+ broadcastStatsForWorker(params, context, scoring),
1493
+ context.partitionIds,
1494
+ context.patternWork
1495
+ ) : null;
1455
1496
  if (workerResult) {
1456
1497
  totalMatched = workerResult.totalMatched;
1457
1498
  } else {
@@ -1461,7 +1502,7 @@ async function executePreflight(params, context) {
1461
1502
  language,
1462
1503
  config.schema,
1463
1504
  scoring,
1464
- searchOptionsFor(manager)
1505
+ searchOptionsFor(manager, context.patternWork)
1465
1506
  );
1466
1507
  totalMatched = fanOutResult.totalMatched;
1467
1508
  }