@delali/narsil 0.3.1-next.129 → 0.3.1-next.131

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 (107) hide show
  1. package/dist/adapters/filesystem.mjs +1 -1
  2. package/dist/adapters/indexeddb.mjs +1 -1
  3. package/dist/browser/chunk-26A5JFT2.mjs +89 -0
  4. package/dist/browser/{chunk-5D6NJD6C.mjs → chunk-2Y3CO4EQ.mjs} +342 -201
  5. package/dist/browser/{chunk-WLD6DDIX.mjs → chunk-AIIJDWMG.mjs} +1 -1
  6. package/dist/browser/{chunk-YAGXZU4W.mjs → chunk-D7WQF6DV.mjs} +2 -2
  7. package/dist/browser/{chunk-WZBTVTSU.mjs → chunk-M5UAAXGU.mjs} +2 -2
  8. package/dist/browser/{chunk-XTFJZHQP.mjs → chunk-NSCSR6MA.mjs} +15 -5
  9. package/dist/browser/{chunk-3NVZD52E.mjs → chunk-UDGB2MWT.mjs} +5 -28
  10. package/dist/browser/{chunk-II5POT55.mjs → chunk-VBBLTD7O.mjs} +4 -3
  11. package/dist/browser/chunk-VEGHFP2P.mjs +30 -0
  12. package/dist/browser/{durability-wiring-HCCC6BJB.mjs → durability-wiring-FNZSRH4N.mjs} +8 -6
  13. package/dist/browser/{module-S2VDU2JE.mjs → module-4HIMOQM5.mjs} +6 -5
  14. package/dist/browser/phrase-module-WESYVU7K.mjs +327 -0
  15. package/dist/browser/{restore-queue-BZ7WWEC4.mjs → restore-queue-GEZ54CA5.mjs} +1 -1
  16. package/dist/browser/{runtime-PL4TTFJE.mjs → runtime-3X7ZJ5T3.mjs} +2 -1
  17. package/dist/browser/{snapshot-RTUCHI2L.mjs → snapshot-V7VF6BN6.mjs} +25 -10
  18. package/dist/browser/{write-IMU7G5NU.mjs → write-YIC2MKRY.mjs} +7 -5
  19. package/dist/{capabilities-BTjv-tK8.d.ts → capabilities-B6WxrWxt.d.ts} +3 -10
  20. package/dist/{chunk-3XHFVYIQ.mjs → chunk-2C3WXBQS.mjs} +1 -1
  21. package/dist/{chunk-37RTD6KD.mjs → chunk-2JWNJSNE.mjs} +8 -8
  22. package/dist/{chunk-K76F5YYX.mjs → chunk-2MKX2SCO.mjs} +219 -58
  23. package/dist/{chunk-AN3CUMPZ.mjs → chunk-2SEL6SBS.mjs} +4 -95
  24. package/dist/{chunk-OPO5SE4J.mjs → chunk-2WBY4Y4M.mjs} +1 -1
  25. package/dist/{chunk-PTIJAZWL.mjs → chunk-4GDLFDPZ.mjs} +1 -1
  26. package/dist/chunk-4UMZ7KQL.mjs +17 -0
  27. package/dist/{chunk-TY64A3ZW.mjs → chunk-5LX6MOIB.mjs} +2 -2
  28. package/dist/{chunk-3LJVM6XM.mjs → chunk-5W7AEVTH.mjs} +2 -2
  29. package/dist/{chunk-PCRWCOZC.mjs → chunk-6M6SDH3S.mjs} +43 -23
  30. package/dist/{chunk-MGD7XETB.mjs → chunk-6SSVIW7Y.mjs} +19 -3
  31. package/dist/{chunk-5LC5VMDQ.mjs → chunk-7OIQ2SIO.mjs} +4 -4
  32. package/dist/{chunk-4XEVROSP.mjs → chunk-7XY6VD7B.mjs} +1 -1
  33. package/dist/{chunk-WI5Q3L43.mjs → chunk-CZ7ISLXA.mjs} +2 -0
  34. package/dist/{chunk-RC27KF7F.mjs → chunk-D5TFRB5G.mjs} +3 -15
  35. package/dist/{chunk-F4UKMTKM.mjs → chunk-EUCX5K74.mjs} +4 -4
  36. package/dist/{chunk-CTF6WFTX.mjs → chunk-F6AAXI7T.mjs} +3 -3
  37. package/dist/{chunk-DX2FI4LU.mjs → chunk-FQBFZAWG.mjs} +3 -1
  38. package/dist/{chunk-XTER67YM.mjs → chunk-HCGJKDZV.mjs} +1 -1
  39. package/dist/{chunk-WQYB4TNR.mjs → chunk-JJ6EUMXB.mjs} +2 -2
  40. package/dist/{chunk-2HQQ7Y5D.mjs → chunk-JT3YZGCE.mjs} +2 -2
  41. package/dist/chunk-JUKYYXSP.mjs +93 -0
  42. package/dist/{chunk-WUIDPBSY.mjs → chunk-K77FJXKS.mjs} +17 -7
  43. package/dist/{chunk-CSSCLRGY.mjs → chunk-NMXRXFGZ.mjs} +2 -2
  44. package/dist/{chunk-44TB6AIZ.mjs → chunk-NNO7CO3A.mjs} +1 -1
  45. package/dist/{chunk-EZIGAOUJ.mjs → chunk-OGLV4I3L.mjs} +6 -5
  46. package/dist/{chunk-FRSWYMXH.mjs → chunk-PATMDIMN.mjs} +1 -1
  47. package/dist/{chunk-AFOZR4ZQ.mjs → chunk-PU6SKH7O.mjs} +2 -2
  48. package/dist/{chunk-TB7YMDD5.mjs → chunk-RCMNL7RI.mjs} +650 -100
  49. package/dist/{chunk-Y4NOHICF.mjs → chunk-RNSC4NFI.mjs} +1 -1
  50. package/dist/{chunk-RYH3PASD.mjs → chunk-RWESFSJI.mjs} +21 -11
  51. package/dist/{chunk-QQS4QZQA.mjs → chunk-SOHMMNCH.mjs} +4 -4
  52. package/dist/{chunk-K73PZTBR.mjs → chunk-SZGRYEIC.mjs} +4 -4
  53. package/dist/{chunk-43Q7HAI2.mjs → chunk-T4OFG4IQ.mjs} +4 -4
  54. package/dist/{chunk-2YOAGAGF.mjs → chunk-TGHNXN7W.mjs} +59 -30
  55. package/dist/{chunk-J4LRE5Q7.mjs → chunk-WVRDRLIC.mjs} +6 -6
  56. package/dist/{chunk-XRXBCOA4.mjs → chunk-X5CNUKD5.mjs} +2 -2
  57. package/dist/{chunk-Y4US5EGH.mjs → chunk-Y2U5VVWX.mjs} +1 -1
  58. package/dist/{chunk-5VSTAJET.mjs → chunk-Y4BVTQ53.mjs} +2 -2
  59. package/dist/{chunk-M6MBSVIJ.mjs → chunk-ZR4VM4A6.mjs} +1 -1
  60. package/dist/{client-BOcveV7A.d.ts → client-gNAfaHcE.d.ts} +3 -3
  61. package/dist/client.d.ts +7 -8
  62. package/dist/client.mjs +2 -0
  63. package/dist/{config-CPmIY3aH.d.ts → config-CmYJO34X.d.ts} +3 -3
  64. package/dist/{events-pM0lna7M.d.ts → config-D1cDv3sE.d.ts} +431 -3
  65. package/dist/direct-executor-HQ4QVDX7.mjs +28 -0
  66. package/dist/distribution/coordinator/etcd.d.ts +2 -2
  67. package/dist/distribution/coordinator/etcd.mjs +1 -1
  68. package/dist/distribution/coordinator/in-memory.d.ts +2 -2
  69. package/dist/distribution/transport/grpc.mjs +1 -1
  70. package/dist/distribution.d.ts +7 -8
  71. package/dist/distribution.mjs +85 -45
  72. package/dist/{durability-wiring-6R26AJDI.mjs → durability-wiring-S7OX2MAI.mjs} +27 -25
  73. package/dist/embeddings/openai.mjs +2 -2
  74. package/dist/{engine-JjRAXpT3.d.ts → engine-m_Ddr1bz.d.ts} +2 -2
  75. package/dist/{index-DkQ2DlgR.d.ts → index-HYnqS1SE.d.ts} +2 -2
  76. package/dist/index.browser.mjs +5 -3
  77. package/dist/index.d.ts +6 -7
  78. package/dist/index.mjs +20 -18
  79. package/dist/{long-query-thread-6VLA6YJI.mjs → long-query-thread-BSL25PD6.mjs} +17 -15
  80. package/dist/{module-S4WGMFNW.mjs → module-2E4XYSGT.mjs} +11 -11
  81. package/dist/partial-words.mjs +7 -6
  82. package/dist/pattern.mjs +4 -3
  83. package/dist/persistence/durability/checkpoint-worker.d.ts +2 -1
  84. package/dist/persistence/durability/checkpoint-worker.mjs +23 -21
  85. package/dist/phrase-module-JERF2IDG.mjs +329 -0
  86. package/dist/react.d.ts +11 -8
  87. package/dist/react.mjs +2 -0
  88. package/dist/{rerank-V4J4MIWR.mjs → rerank-DMMT4FZA.mjs} +6 -6
  89. package/dist/rerankers/http.mjs +2 -2
  90. package/dist/{restore-queue-PUGWCPCX.mjs → restore-queue-JAMNRC6T.mjs} +1 -1
  91. package/dist/{runtime-TBFBQQQO.mjs → runtime-7MLQ7J64.mjs} +7 -7
  92. package/dist/{schema-DGAP_8HJ.d.ts → schema-BTXbHCqA.d.ts} +8 -5
  93. package/dist/server.d.ts +198 -11
  94. package/dist/server.mjs +30 -19
  95. package/dist/{snapshot-PUVSMV7E.mjs → snapshot-DOQLGGEX.mjs} +44 -29
  96. package/dist/synonyms.mjs +4 -3
  97. package/dist/tasks-Co8HfRD7.d.ts +704 -0
  98. package/dist/{thread-TA7QQBWP.mjs → thread-SKO7CN3R.mjs} +16 -14
  99. package/dist/vector/search-worker.d.ts +1 -1
  100. package/dist/vector/search-worker.mjs +4 -4
  101. package/dist/workers/entry.mjs +7 -7
  102. package/dist/{write-TGKYT3C4.mjs → write-ZKR7SNRT.mjs} +22 -20
  103. package/openapi.json +5215 -0
  104. package/package.json +16 -8
  105. package/dist/config-C3YXk5Rn.d.ts +0 -412
  106. package/dist/direct-executor-ULA6V5HC.mjs +0 -26
  107. package/dist/tasks-txGvNz6h.d.ts +0 -302
@@ -1,4 +1,5 @@
1
- import { A as AnyDocument, S as SchemaDefinition, B as BM25Params, e as ScoringMode } from './schema-DGAP_8HJ.js';
1
+ import { P as PersistenceAdapter, I as InvalidationAdapter, E as EmbeddingAdapter, R as RerankAdapter } from './adapters-BQFQ4PRz.js';
2
+ import { A as AnyDocument, S as SchemaDefinition, B as BM25Params, e as ScoringMode, a as IndexConfig } from './schema-BTXbHCqA.js';
2
3
 
3
4
  /**
4
5
  * Every code a {@link NarsilError} carries, grouped by the part of the engine
@@ -42,6 +43,8 @@ declare const ErrorCodes: {
42
43
  readonly SEARCH_INVALID_CURSOR: "SEARCH_INVALID_CURSOR";
43
44
  readonly SEARCH_RESULT_WINDOW_EXCEEDED: "SEARCH_RESULT_WINDOW_EXCEEDED";
44
45
  readonly SEARCH_WORK_CAP_EXCEEDED: "SEARCH_WORK_CAP_EXCEEDED";
46
+ readonly SEARCH_INVALID_PHRASE: "SEARCH_INVALID_PHRASE";
47
+ readonly SEARCH_PHRASE_NOT_READY: "SEARCH_PHRASE_NOT_READY";
45
48
  readonly BM25_NOT_READY: "BM25_NOT_READY";
46
49
  readonly LANGUAGE_NOT_SUPPORTED: "LANGUAGE_NOT_SUPPORTED";
47
50
  readonly ENVELOPE_VERSION_MISMATCH: "ENVELOPE_VERSION_MISMATCH";
@@ -362,7 +365,9 @@ interface HighlightMatch {
362
365
  * field, whatever the snippet contains.
363
366
  */
364
367
  positions: Array<{
368
+ /** The match starts at this offset. */
365
369
  start: number;
370
+ /** The match ends at this offset. */
366
371
  end: number;
367
372
  }>;
368
373
  }
@@ -860,7 +865,9 @@ type GeoPolygonFilter = {
860
865
  * antimeridian or span more than half the globe.
861
866
  */
862
867
  points: Array<{
868
+ /** The corner has this latitude, in degrees. */
863
869
  lat: number;
870
+ /** The corner has this longitude, in degrees. */
864
871
  lon: number;
865
872
  }>;
866
873
  /** The engine matches the points inside the polygon while this is true, which is the default, and the points outside it while this is false. */
@@ -1166,7 +1173,15 @@ type SortSpec = Record<string, 'asc' | 'desc'> | readonly SortField[];
1166
1173
  * @public
1167
1174
  */
1168
1175
  interface QueryParams {
1169
- /** The engine analyses this text with the index's language module and searches for the terms that result. */
1176
+ /**
1177
+ * The engine analyses this text with the index's language module and searches
1178
+ * for the terms that result. Words inside double quotes form a phrase, which
1179
+ * a document has to hold side by side and in that order inside one field. The
1180
+ * engine throws `SEARCH_INVALID_PHRASE` for a phrase of more than 32 words, for
1181
+ * more than 32 phrases, and for a phrase on an index with `trackPositions` off.
1182
+ * It throws `SEARCH_PHRASE_NOT_READY` while an index with a `string[]` field
1183
+ * waits for a rebuild.
1184
+ */
1170
1185
  term?: string;
1171
1186
  /** The engine searches the term in these fields, and in every text field in the schema by default. */
1172
1187
  fields?: string[];
@@ -1303,7 +1318,9 @@ interface QueryParams {
1303
1318
  highlight?: HighlightConfig;
1304
1319
  /** These documents take fixed positions, ahead of the ranking. */
1305
1320
  pinned?: Array<{
1321
+ /** The engine places the document with this id. */
1306
1322
  docId: string;
1323
+ /** The document takes this place in the results, counting from zero. */
1307
1324
  position: number;
1308
1325
  }>;
1309
1326
  /** This picks which engine answers the query. Keyword search runs by default. */
@@ -1370,7 +1387,9 @@ interface FacetConfig {
1370
1387
  sort?: 'asc' | 'desc';
1371
1388
  /** The engine counts a numeric field's matches into these ranges, with one count for each range. A cluster search counts up to 1,000 ranges on a field and throws `CONFIG_INVALID` for more. */
1372
1389
  ranges?: Array<{
1390
+ /** The range starts at this value. */
1373
1391
  from: number;
1392
+ /** The range ends at this value. */
1374
1393
  to: number;
1375
1394
  }>;
1376
1395
  };
@@ -1442,6 +1461,170 @@ interface HighlightConfig {
1442
1461
  maxSnippetLength?: number;
1443
1462
  }
1444
1463
 
1464
+ /**
1465
+ * Hooks that the engine calls alongside its own work, so that an application
1466
+ * can add validation, auditing, enrichment, or metrics without forking the
1467
+ * engine.
1468
+ *
1469
+ * Every hook is optional. A `before` hook fires first and rejects the
1470
+ * operation by throwing, while an `after` hook fires once the operation
1471
+ * succeeds. Where a `before` hook on a write throws a {@link NarsilError}, the
1472
+ * engine passes that error to the caller unchanged. It turns any other error
1473
+ * into `DOC_VALIDATION_FAILED` with the same message, for a single write and
1474
+ * for each entry of a batch alike. The engine awaits a hook that returns a
1475
+ * promise, so slow work in one hook slows every write or search that it
1476
+ * covers.
1477
+ *
1478
+ * @public
1479
+ */
1480
+ interface NarsilPlugin {
1481
+ /** This name identifies the plugin in errors and in event payloads. */
1482
+ name: string;
1483
+ /** Fires before the engine indexes a document. Throw to reject the write. */
1484
+ beforeInsert?(ctx: InsertContext): void | Promise<void>;
1485
+ /** Fires once the engine has indexed a document. */
1486
+ afterInsert?(ctx: InsertContext): void | Promise<void>;
1487
+ /** Fires before the engine removes a document. Throw to reject the removal. */
1488
+ beforeRemove?(ctx: RemoveContext): void | Promise<void>;
1489
+ /** Fires once the engine has removed a document. */
1490
+ afterRemove?(ctx: RemoveContext): void | Promise<void>;
1491
+ /** Fires before the engine replaces a document. Throw to reject the update. */
1492
+ beforeUpdate?(ctx: UpdateContext): void | Promise<void>;
1493
+ /** Fires once the engine has replaced a document. */
1494
+ afterUpdate?(ctx: UpdateContext): void | Promise<void>;
1495
+ /**
1496
+ * Fires before every search, and before every preflight. Throw to reject the
1497
+ * query. It fires before the engine embeds a `vector.text` query, so a hook
1498
+ * that counts or refuses work stops the call to the embedding provider, and
1499
+ * `ctx.params.vector` still holds the text that the caller passed.
1500
+ * {@link Narsil.suggest} scans the term dictionary and searches no document,
1501
+ * so it fires no hook.
1502
+ */
1503
+ beforeSearch?(ctx: SearchContext): void | Promise<void>;
1504
+ /**
1505
+ * Fires once a search returns. The context holds a copy of the results, so a
1506
+ * change that you make here leaves the caller's own result untouched. Where
1507
+ * this hook throws, the engine logs a warning and answers the query all the
1508
+ * same, because the search is already over.
1509
+ */
1510
+ afterSearch?(ctx: SearchContext): void | Promise<void>;
1511
+ /**
1512
+ * Fires once the engine creates an index, and a `restore` fires it too,
1513
+ * because a restore recreates the index that it replaces. Where this hook
1514
+ * throws, the engine logs a warning and keeps the index, because the hook
1515
+ * fires after the index exists.
1516
+ */
1517
+ onIndexCreate?(ctx: IndexContext): void | Promise<void>;
1518
+ /**
1519
+ * Fires once the engine drops an index, and a `restore` fires it too,
1520
+ * because a restore drops the index that it replaces. Where this hook
1521
+ * throws, the engine logs a warning, because the hook fires after the index
1522
+ * is gone.
1523
+ */
1524
+ onIndexDrop?(ctx: IndexContext): void | Promise<void>;
1525
+ /**
1526
+ * Fires once {@link Narsil.rebalance} moves an index onto a new partition
1527
+ * count, which is the only way that the count changes. An index opens with
1528
+ * the count that `partitions.maxPartitions` sets, because the engine adds no
1529
+ * partition on its own. Subscribe to the `partitionWatermark` event to learn
1530
+ * when an index fills its capacity.
1531
+ */
1532
+ onPartitionSplit?(ctx: PartitionContext): void | Promise<void>;
1533
+ /** Fires once the engine loads worker copies of its indexes. */
1534
+ onWorkerPromote?(ctx: WorkerContext): void | Promise<void>;
1535
+ }
1536
+ /**
1537
+ * What a plugin receives around an insert.
1538
+ *
1539
+ * @public
1540
+ */
1541
+ interface InsertContext {
1542
+ /** The engine writes the document to this index. */
1543
+ indexName: string;
1544
+ /** The document is stored under this id, which the engine resolves before the `before` hook runs. */
1545
+ docId: string;
1546
+ /** This is the document itself, and the engine indexes whatever a `before` hook leaves here. */
1547
+ document: AnyDocument;
1548
+ }
1549
+ /**
1550
+ * What a plugin receives around a removal.
1551
+ *
1552
+ * @public
1553
+ */
1554
+ interface RemoveContext {
1555
+ /** The engine removes the document from this index. */
1556
+ indexName: string;
1557
+ /** The engine removes this document. */
1558
+ docId: string;
1559
+ }
1560
+ /**
1561
+ * What a plugin receives around an update.
1562
+ *
1563
+ * @public
1564
+ */
1565
+ interface UpdateContext {
1566
+ /** The document belongs to this index. */
1567
+ indexName: string;
1568
+ /** The engine replaces this document. */
1569
+ docId: string;
1570
+ /** The index holds this document before the update. */
1571
+ oldDocument: AnyDocument;
1572
+ /** This document replaces it, and the engine indexes whatever a `before` hook leaves here. */
1573
+ newDocument: AnyDocument;
1574
+ }
1575
+ /**
1576
+ * What a plugin receives around a search.
1577
+ *
1578
+ * @public
1579
+ */
1580
+ interface SearchContext {
1581
+ /** The search runs against this index. */
1582
+ indexName: string;
1583
+ /** These are the parameters the query runs with, and a `before` hook that changes them rewrites the search. */
1584
+ params: QueryParams;
1585
+ /**
1586
+ * These are the results, which an `after` hook alone receives. A preflight
1587
+ * fires `beforeSearch` and stops there, because it answers with a count and
1588
+ * no hits. Read this field inside an `afterSearch` hook alone.
1589
+ */
1590
+ results?: QueryResult;
1591
+ }
1592
+ /**
1593
+ * What a plugin receives when the engine creates or drops an index.
1594
+ *
1595
+ * @public
1596
+ */
1597
+ interface IndexContext {
1598
+ /** The engine creates or drops this index. */
1599
+ indexName: string;
1600
+ /** The index holds this configuration. */
1601
+ config: IndexConfig;
1602
+ }
1603
+ /**
1604
+ * What a plugin receives when a rebalance changes an index's partition count.
1605
+ *
1606
+ * @public
1607
+ */
1608
+ interface PartitionContext {
1609
+ /** The rebalance moved this index. */
1610
+ indexName: string;
1611
+ /** The index held this many partitions before the rebalance. */
1612
+ oldPartitionCount: number;
1613
+ /** The index holds this many partitions now. */
1614
+ newPartitionCount: number;
1615
+ }
1616
+ /**
1617
+ * What a plugin receives when the engine moves onto worker threads.
1618
+ *
1619
+ * @public
1620
+ */
1621
+ interface WorkerContext {
1622
+ /** The pool holds this many workers. */
1623
+ workerCount: number;
1624
+ /** The engine promoted for this reason, such as the threshold that the index crossed. */
1625
+ reason: string;
1626
+ }
1627
+
1445
1628
  /**
1446
1629
  * Snapshot of V8 heap usage as reported by `process.memoryUsage()`, with the
1447
1630
  * limit the heap may grow to. All values are bytes. `null` in environments
@@ -1749,4 +1932,249 @@ type NarsilEventHandlers = {
1749
1932
  [K in keyof NarsilEventMap]?: (payload: NarsilEventMap[K]) => void;
1750
1933
  };
1751
1934
 
1752
- export { type TermMatchPolicy as $, type ArrayFilter as A, type BatchResult as B, type ClientErrorCode as C, type DocumentImportResult as D, type ErrorCode as E, type FacetConfig as F, type GeoFilter as G, type HeldCheckpointReport as H, type IndexInfo as I, type HybridConfig as J, type ListedDocument as K, type ListParams as L, type MemoryStats as M, NarsilError as N, type PresenceFilter as O, type PreflightResult as P, type QueryParams as Q, type ProcessMemoryReport as R, type ServerErrorCode as S, type QueryCoverage as T, type RerankConfig as U, type VectorMaintenanceResult as V, type ScoreComponents as W, type SearchMode as X, type SortField as Y, type SortSpec as Z, type StringFilter as _, ClientErrorCodes as a, type VectorQueryConfig as a0, type WorkerCopyReport as a1, ErrorCodes as b, type NarsilErrorCode as c, ServerErrorCodes as d, type QueryResult as e, type NarsilEventHandlers as f, type ListResult as g, type SuggestParams as h, isNarsilError as i, type SuggestResult as j, type IndexStats as k, type PartitionStatsResult as l, type NarsilEventMap as m, type ComparisonFilter as n, type DocumentProjection as o, type FacetResult as p, type FieldFilter as q, type FilterExpression as r, type GeoPolygonFilter as s, type GeoRadiusFilter as t, type GroupConfig as u, type GroupReducer as v, type GroupResult as w, type HighlightConfig as x, type HighlightMatch as y, type Hit as z };
1935
+ /**
1936
+ * Everything {@link createNarsil} accepts when it builds an engine.
1937
+ *
1938
+ * Every field is optional, and an engine created without any of them keeps
1939
+ * its indexes in memory alone. Add persistence to survive a restart, add
1940
+ * invalidation to share a store with another process, and add durability to
1941
+ * recover the writes made since the last snapshot.
1942
+ *
1943
+ * @public
1944
+ */
1945
+ interface NarsilConfig {
1946
+ /** This adapter writes partitions somewhere they outlive the process. */
1947
+ persistence?: PersistenceAdapter;
1948
+ /** This channel carries partition changes to other instances sharing the store. */
1949
+ invalidation?: InvalidationAdapter;
1950
+ /** These hooks observe or reject writes, searches, and lifecycle changes. */
1951
+ plugins?: NarsilPlugin[];
1952
+ /** This supplies the id for a document inserted without one. The engine generates a UUID v7 by default. */
1953
+ idGenerator?: () => string;
1954
+ /** These settings control when an index gains worker copies, how many threads they share, and when an idle index gives them up. */
1955
+ workers?: WorkerConfig;
1956
+ /** Every index uses this adapter unless its own config names another. */
1957
+ embedding?: EmbeddingAdapter;
1958
+ /** Named adapters; names persist in index metadata so recovery can rebind. */
1959
+ embeddingAdapters?: Record<string, EmbeddingAdapter>;
1960
+ /**
1961
+ * These rerank adapters are registered under their keys, so that a query
1962
+ * can give a key in `rerank.adapter`. The engine throws
1963
+ * `RERANK_CONFIG_INVALID` for an empty key and for an entry without a
1964
+ * `rerank` function.
1965
+ */
1966
+ rerankAdapters?: Record<string, RerankAdapter>;
1967
+ /**
1968
+ * The engine waits this many milliseconds for a rerank adapter to score one
1969
+ * query, and 30,000 by default. It then cancels the call through the
1970
+ * adapter's abort signal and throws `RERANK_FAILED`. Set a whole number of
1971
+ * at least 1; {@link createNarsil} throws `CONFIG_INVALID` for any other
1972
+ * value.
1973
+ */
1974
+ rerankTimeout?: number;
1975
+ /**
1976
+ * A query may rerank at most this many of its top hits, which caps the
1977
+ * documents that one query sends to a model. Set a whole number from 1 to
1978
+ * 1,000, or leave it out for 100; {@link createNarsil} throws
1979
+ * `CONFIG_INVALID` for any other value.
1980
+ */
1981
+ maxRerankWindow?: number;
1982
+ /** These settings recover the writes made since the last snapshot. */
1983
+ durability?: DurabilityConfig;
1984
+ /** These settings control what the engine does when an index's stored analysis differs from its language module. */
1985
+ analysis?: AnalysisConfig;
1986
+ /** These limits close indexes while keeping their durable files ready to reopen. */
1987
+ lifecycle?: IndexLifecycleConfig;
1988
+ /**
1989
+ * These listeners receive events from the moment that the engine starts.
1990
+ * The engine registers each one before it recovers any index, so a listener
1991
+ * here receives the `layoutUpgrade` events of that recovery, which come
1992
+ * before {@link createNarsil} returns the engine. For a name outside
1993
+ * {@link NarsilEventMap}, or an entry that is not a function,
1994
+ * {@link createNarsil} throws `CONFIG_INVALID`.
1995
+ */
1996
+ events?: NarsilEventHandlers;
1997
+ /**
1998
+ * This is the most work that the engine may do on the pattern tests and
1999
+ * phrases of one search, counted over every partition that it searches. For
2000
+ * a phrase, the engine adds one unit for each posting of its starting word
2001
+ * that it visits, and one for each position that it compares. For a pattern
2002
+ * test, it adds one unit for each run of three code points that it looks up in a pattern
2003
+ * index, one for each entry that it reads from a pattern index, and one for
2004
+ * each step of its matcher. For a text whose case fold is shorter than three
2005
+ * code points, it counts each document that it checks as an entry that it
2006
+ * reads. It counts an `in` or `nin` test as one `eq` test for each distinct
2007
+ * value in its list. For an `eq` test with a `tolerance`, it also adds one
2008
+ * unit for each cell that it fills in the table of edit distances between
2009
+ * the text and a value. It also counts the preparation of that test once for
2010
+ * a search, however many worker copies prepare it. Once the count passes the
2011
+ * cap, the engine throws `SEARCH_WORK_CAP_EXCEEDED`. The cap
2012
+ * defaults to 25,000,000 units. For any value other than a whole number from
2013
+ * 1 to `Number.MAX_SAFE_INTEGER`, {@link createNarsil} throws
2014
+ * `CONFIG_INVALID`.
2015
+ */
2016
+ patternWorkCap?: number;
2017
+ }
2018
+ /**
2019
+ * Limits on the indexes one engine keeps open in memory.
2020
+ *
2021
+ * @public
2022
+ */
2023
+ interface IndexLifecycleConfig {
2024
+ /** An index closes after this many milliseconds without activity. */
2025
+ idleTimeoutMs?: number;
2026
+ /** The engine keeps at most this many indexes open at once. */
2027
+ maxOpenIndexes?: number;
2028
+ /** Open indexes may use at most this many estimated bytes in total. */
2029
+ maxOpenBytes?: number;
2030
+ /** At most this many callers may wait behind one index reopen. */
2031
+ maxReopenWaiters?: number;
2032
+ }
2033
+ /**
2034
+ * Describes an index whose stored terms came from an older analysis than the
2035
+ * one its language module carries today.
2036
+ *
2037
+ * The engine hands this to {@link AnalysisConfig.onStaleAnalysis} together
2038
+ * with the rebuild that fixes it, so you decide when the work runs.
2039
+ *
2040
+ * @public
2041
+ */
2042
+ interface StaleAnalysis {
2043
+ /** This index holds terms that are out of date. */
2044
+ indexName: string;
2045
+ /** The index was built with this language module. */
2046
+ language: string;
2047
+ /** The index recorded this revision when it was written, and `null` for an index written before revisions existed. */
2048
+ storedRevision: string | null;
2049
+ /** The language module carries this revision now. */
2050
+ currentRevision: string;
2051
+ /** The rebuild reindexes this many documents. */
2052
+ documentCount: number;
2053
+ }
2054
+ /**
2055
+ * What the engine does when an index's stored terms no longer match the
2056
+ * analysis its language module produces.
2057
+ *
2058
+ * A stale index answers text queries from terms an older analysis wrote, and
2059
+ * every such result reports `analysisStale`. Rebuilding fixes it, and this
2060
+ * setting controls whether the engine starts that work itself.
2061
+ *
2062
+ * @public
2063
+ */
2064
+ interface AnalysisConfig {
2065
+ /** `auto` rebuilds a stale index in the background, and `manual` leaves it to you. The engine rebuilds automatically by default. */
2066
+ rebuild?: 'auto' | 'manual';
2067
+ /**
2068
+ * Called once for each stale index the engine finds.
2069
+ *
2070
+ * @param index - The index that is stale, and how far behind it is.
2071
+ * @param rebuild - Starts the rebuild and resolves once every partition
2072
+ * carries current terms. Under `manual` nothing rebuilds until you call it.
2073
+ */
2074
+ onStaleAnalysis?(index: StaleAnalysis, rebuild: () => Promise<void>): void | Promise<void>;
2075
+ }
2076
+ /**
2077
+ * Write-ahead logging and checkpointing, which recover the writes made since
2078
+ * the last snapshot.
2079
+ *
2080
+ * The `wal` tier logs every mutation before applying it, so a crash costs
2081
+ * nothing once the log replays. The `snapshot` tier writes whole partitions on
2082
+ * an interval, which is cheaper to run and loses whatever arrived after the
2083
+ * last write.
2084
+ *
2085
+ * @public
2086
+ */
2087
+ interface DurabilityConfig {
2088
+ /** `wal` logs every mutation, and `snapshot` writes whole partitions on an interval. */
2089
+ tier?: 'wal' | 'snapshot';
2090
+ /** The engine writes the log and its checkpoints into this directory. */
2091
+ directory?: string;
2092
+ /** `sync` flushes before a write resolves, and `async` flushes on the interval below. */
2093
+ mode?: 'sync' | 'async';
2094
+ /** In `async` mode the engine flushes this many milliseconds apart. */
2095
+ flushIntervalMs?: number;
2096
+ /** The log rolls over to a new segment once it reaches this size. */
2097
+ segmentMaxBytes?: number;
2098
+ /** The engine checkpoints this many milliseconds apart, which shortens the replay a restart has to do. */
2099
+ checkpointIntervalMs?: number;
2100
+ /** This many mutations trigger a checkpoint before the interval elapses. */
2101
+ checkpointMutationThreshold?: number;
2102
+ /**
2103
+ * The engine merges a partition's checkpoint segments once that partition
2104
+ * holds more than this many of them, 12 by default. The value is a whole
2105
+ * number of segments.
2106
+ */
2107
+ compactionThreshold?: number;
2108
+ }
2109
+ /**
2110
+ * Which queries the main copy of an index answers once the index holds worker
2111
+ * copies. Under `lone`, the main copy answers a query the engine receives
2112
+ * while no copy holds one, on an index of at most 50,000 documents. Once
2113
+ * every copy is busy, it also answers one query per turn of the event loop.
2114
+ * Under `none`, every query on an index that holds copies goes to one of
2115
+ * them, while the main copy still answers a query on an index whose copies
2116
+ * are loading.
2117
+ *
2118
+ * @public
2119
+ */
2120
+ type MainCopyQueries = 'lone' | 'none';
2121
+ /**
2122
+ * How the engine holds worker copies of its indexes, and how many threads
2123
+ * they may use.
2124
+ *
2125
+ * A small index answers fastest on the main thread. Once an index holds as
2126
+ * many documents as the copy threshold, the engine loads a copy of it onto
2127
+ * every worker thread, and each query then runs whole on the copy with the
2128
+ * fewest queries in flight. The same switch governs the vector search pool.
2129
+ *
2130
+ * @public
2131
+ */
2132
+ interface WorkerConfig {
2133
+ /**
2134
+ * Whether the engine may hold worker copies and a vector search pool. It is
2135
+ * on everywhere but a browser page. Set it to false to hold the process to
2136
+ * one thread, which leaves both pools absent. Where a bundler folds
2137
+ * `@delali/narsil` into an application bundle, the engine finds no worker
2138
+ * entry: left unset, it answers on one thread and prints one warning, and
2139
+ * set to true, `createNarsil` throws `CONFIG_INVALID`.
2140
+ */
2141
+ enabled?: boolean;
2142
+ /**
2143
+ * The keyword copies and the vector search pool share this many threads
2144
+ * between them, half each, in an embedded engine, so a budget of 4 gives 2
2145
+ * keyword copies and 2 vector search workers. The HTTP server holds a copy
2146
+ * on every one of them and receives requests there. The engine takes the
2147
+ * host's cores minus one by default, between 2 and 8. It caps a value that
2148
+ * you set at 31, which is how many scratch slots the shared vector arena
2149
+ * reserves.
2150
+ */
2151
+ count?: number;
2152
+ /** An index gains worker copies once it holds this many documents, 1,000 by default. */
2153
+ promotionThreshold?: number;
2154
+ /**
2155
+ * The engine drops an index's copies after this many milliseconds without a
2156
+ * read or a write, five minutes by default, and loads them again on the
2157
+ * next request while the main copy answers it. It may not exceed
2158
+ * `lifecycle.idleTimeoutMs`, and where it is unset the copies take the
2159
+ * smaller of five minutes and that interval.
2160
+ */
2161
+ idleTimeoutMs?: number;
2162
+ /**
2163
+ * Which queries the main copy answers, `lone` by default. Set `none` where
2164
+ * the main thread also serves the host's own work, such as HTTP requests,
2165
+ * because a query answered on the main copy then delays every other request
2166
+ * waiting on that thread. A server created with `createServer` sets `none` on
2167
+ * an engine that leaves this unset.
2168
+ */
2169
+ mainCopyQueries?: MainCopyQueries;
2170
+ /**
2171
+ * Each worker imports this module on start-up, which is how a worker reaches
2172
+ * a custom tokeniser or language. Give an absolute path or a URL, such as
2173
+ * `new URL('./bootstrap.js', import.meta.url).href`, because a worker
2174
+ * resolves a relative specifier against Narsil's own directory. A relative
2175
+ * value raises `CONFIG_INVALID`.
2176
+ */
2177
+ bootstrapModule?: string;
2178
+ }
2179
+
2180
+ export { type PresenceFilter as $, type AnalysisConfig as A, type BatchResult as B, type ClientErrorCode as C, type DocumentImportResult as D, type ErrorCode as E, type FacetConfig as F, type GroupResult as G, type HeldCheckpointReport as H, type IndexInfo as I, type HighlightMatch as J, type Hit as K, type ListParams as L, type MemoryStats as M, NarsilError as N, type HybridConfig as O, type PartitionStatsResult as P, type QueryParams as Q, type IndexContext as R, type ServerErrorCode as S, type IndexLifecycleConfig as T, type InsertContext as U, type VectorMaintenanceResult as V, type ListedDocument as W, type MainCopyQueries as X, type NarsilEventHandlers as Y, type NarsilPlugin as Z, type PartitionContext as _, ClientErrorCodes as a, type ProcessMemoryReport as a0, type QueryCoverage as a1, type RemoveContext as a2, type RerankConfig as a3, type ScoreComponents as a4, type SearchContext as a5, type SearchMode as a6, type SortField as a7, type SortSpec as a8, type StaleAnalysis as a9, type StringFilter as aa, type TermMatchPolicy as ab, type UpdateContext as ac, type VectorQueryConfig as ad, type WorkerConfig as ae, type WorkerContext as af, type WorkerCopyReport as ag, ErrorCodes as b, type NarsilErrorCode as c, ServerErrorCodes as d, type NarsilConfig as e, type ListResult as f, type SuggestParams as g, type SuggestResult as h, isNarsilError as i, type PreflightResult as j, type IndexStats as k, type NarsilEventMap as l, type QueryResult as m, type GroupConfig as n, type ArrayFilter as o, type ComparisonFilter as p, type DocumentProjection as q, type DurabilityConfig as r, type FacetResult as s, type FieldFilter as t, type FilterExpression as u, type GeoFilter as v, type GeoPolygonFilter as w, type GeoRadiusFilter as x, type GroupReducer as y, type HighlightConfig as z };
@@ -0,0 +1,28 @@
1
+ export { createDirectExecutor } from './chunk-RWESFSJI.mjs';
2
+ import './chunk-2MKX2SCO.mjs';
3
+ import './chunk-ZR4VM4A6.mjs';
4
+ import './chunk-ZATRDAYU.mjs';
5
+ import './chunk-EBIHRL7B.mjs';
6
+ import './chunk-TGP5M5R7.mjs';
7
+ import './chunk-U2BKYEC7.mjs';
8
+ import './chunk-2SEL6SBS.mjs';
9
+ import './chunk-WQBCBKY3.mjs';
10
+ import './chunk-JUKYYXSP.mjs';
11
+ import './chunk-EUCX5K74.mjs';
12
+ import './chunk-PU6SKH7O.mjs';
13
+ import './chunk-U476IXKQ.mjs';
14
+ import './chunk-FQBFZAWG.mjs';
15
+ import './chunk-VJS4JFBQ.mjs';
16
+ import './chunk-GES7U2PM.mjs';
17
+ import './chunk-7XY6VD7B.mjs';
18
+ import './chunk-6SSVIW7Y.mjs';
19
+ import './chunk-X5CV2E2B.mjs';
20
+ import './chunk-7X5JST5L.mjs';
21
+ import './chunk-D5TFRB5G.mjs';
22
+ import './chunk-4UMZ7KQL.mjs';
23
+ import './chunk-R6A773WK.mjs';
24
+ import './chunk-YTJCGKM4.mjs';
25
+ import './chunk-HCGJKDZV.mjs';
26
+ import './chunk-22YPZVMG.mjs';
27
+ import './chunk-L5ORED7V.mjs';
28
+ import './chunk-CZ7ISLXA.mjs';
@@ -1,5 +1,5 @@
1
- import { C as ClusterCoordinator } from '../../index-DkQ2DlgR.js';
2
- import '../../schema-DGAP_8HJ.js';
1
+ import { C as ClusterCoordinator } from '../../index-HYnqS1SE.js';
2
+ import '../../schema-BTXbHCqA.js';
3
3
  import '../../adapters-BQFQ4PRz.js';
4
4
  import '../../synonyms-CpOAHPa-.js';
5
5
 
@@ -2,7 +2,7 @@ import { INDEX_METADATA_KEY_PREFIX, indexNameOfMetadataSuffix } from '../../chun
2
2
  import { MAX_NODE_ID_LENGTH, CONTROLLER_LEASE_KEY, MAX_WATCHERS } from '../../chunk-44W3CBNG.mjs';
3
3
  import '../../chunk-R6A773WK.mjs';
4
4
  import { compareCodePoints } from '../../chunk-YTJCGKM4.mjs';
5
- import { NarsilError, ErrorCodes, describeError } from '../../chunk-WI5Q3L43.mjs';
5
+ import { NarsilError, ErrorCodes, describeError } from '../../chunk-CZ7ISLXA.mjs';
6
6
  import { encode, decode } from '@msgpack/msgpack';
7
7
 
8
8
  // src/distribution/coordinator/etcd/constants.ts
@@ -1,5 +1,5 @@
1
- import { C as ClusterCoordinator } from '../../index-DkQ2DlgR.js';
2
- import '../../schema-DGAP_8HJ.js';
1
+ import { C as ClusterCoordinator } from '../../index-HYnqS1SE.js';
2
+ import '../../schema-BTXbHCqA.js';
3
3
  import '../../adapters-BQFQ4PRz.js';
4
4
  import '../../synonyms-CpOAHPa-.js';
5
5
 
@@ -2,7 +2,7 @@ import { decodeTransportMessage, encodeTransportMessage } from '../../chunk-J6YV
2
2
  import { timeoutsOf, replyDeadlineMs } from '../../chunk-PWIWSUCX.mjs';
3
3
  import { MAX_MESSAGE_SIZE_BYTES, GRPC_KEEPALIVE_TIMEOUT_MS, GRPC_KEEPALIVE_TIME_MS, GRPC_ENVELOPE_OVERHEAD_BYTES } from '../../chunk-UNEEFTEU.mjs';
4
4
  import { TransportError, TransportErrorCodes } from '../../chunk-YH5OIL7B.mjs';
5
- import { NarsilError, ErrorCodes } from '../../chunk-WI5Q3L43.mjs';
5
+ import { NarsilError, ErrorCodes } from '../../chunk-CZ7ISLXA.mjs';
6
6
 
7
7
  // src/distribution/transport/grpc/codec.ts
8
8
  var FIELD_ONE_LENGTH_DELIMITED_KEY = 10;
@@ -1,14 +1,13 @@
1
- import { a as CreateIndexOptions, C as ClusterNamespace, b as ClusterNodeConfig } from './config-CPmIY3aH.js';
2
- export { c as ClusterControllerConfig, d as ClusterHealth, e as ClusterHealthStatus, f as ClusterMemoryConfig, g as ClusterMetrics, h as ClusterNodeInfo, i as ClusterQueryConfig, j as CommitPointFigure, k as CoordinatorRequestFigure, I as IndexHealth, N as NodeReadiness, P as PartitionReplicationFigure, R as ReplicaLagFigure, l as ReplicationConfig, V as VectorRebuildWaitFigure } from './config-CPmIY3aH.js';
1
+ import { b as CreateIndexOptions, C as ClusterNamespace, c as ClusterNodeConfig } from './config-CmYJO34X.js';
2
+ export { d as ClusterControllerConfig, e as ClusterHealth, f as ClusterHealthStatus, g as ClusterMemoryConfig, h as ClusterMetrics, a as ClusterNodeInfo, i as ClusterQueryConfig, j as CommitPointFigure, k as CoordinatorRequestFigure, I as IndexHealth, N as NodeReadiness, P as PartitionReplicationFigure, R as ReplicaLagFigure, l as ReplicationConfig, V as VectorRebuildWaitFigure } from './config-CmYJO34X.js';
3
3
  import { R as RerankAdapter } from './adapters-BQFQ4PRz.js';
4
- import { B as BatchResult, L as ListParams, g as ListResult, h as SuggestParams, j as SuggestResult, Q as QueryParams, P as PreflightResult, I as IndexInfo, k as IndexStats, l as PartitionStatsResult, M as MemoryStats, m as NarsilEventMap, e as QueryResult } from './events-pM0lna7M.js';
5
- import { B as BM25Params, I as IndexConfig, A as AnyDocument, a as InsertOptions } from './schema-DGAP_8HJ.js';
6
- import { b as NodeCapacity, N as NodeRole } from './index-DkQ2DlgR.js';
7
- export { c as AllocationConstraints, d as AllocationEvent, A as AllocationTable, C as ClusterCoordinator, I as IndexMetadataEvent, e as IndexMetadataWatch, f as IndexPartitionBytes, g as NodeEvent, h as NodeMemoryReport, a as NodeRegistration, P as PartitionAssignment, i as PartitionState, R as RegistrationLease, S as SchemaEvent, U as UnassignedReason } from './index-DkQ2DlgR.js';
4
+ import { B as BatchResult, L as ListParams, f as ListResult, g as SuggestParams, h as SuggestResult, Q as QueryParams, j as PreflightResult, I as IndexInfo, k as IndexStats, P as PartitionStatsResult, M as MemoryStats, l as NarsilEventMap, m as QueryResult } from './config-D1cDv3sE.js';
5
+ import { B as BM25Params, a as IndexConfig, A as AnyDocument, I as InsertOptions } from './schema-BTXbHCqA.js';
6
+ import { b as NodeCapacity, N as NodeRole } from './index-HYnqS1SE.js';
7
+ export { d as AllocationConstraints, e as AllocationEvent, A as AllocationTable, C as ClusterCoordinator, I as IndexMetadataEvent, f as IndexMetadataWatch, g as IndexPartitionBytes, h as NodeEvent, c as NodeMemoryReport, a as NodeRegistration, P as PartitionAssignment, i as PartitionState, R as RegistrationLease, S as SchemaEvent, U as UnassignedReason } from './index-HYnqS1SE.js';
8
8
  import { a as SynonymRule } from './synonyms-CpOAHPa-.js';
9
- import { N as Narsil } from './engine-JjRAXpT3.js';
9
+ import { N as Narsil } from './engine-m_Ddr1bz.js';
10
10
  export { L as ListenHandler, N as NodeTransport, R as RespondFn, T as TransportConfig, a as TransportMessage } from './types-DvncmvuQ.js';
11
- import './config-C3YXk5Rn.js';
12
11
 
13
12
  /**
14
13
  * The cluster splits an index into this many partitions when