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

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 (70) hide show
  1. package/README.md +2 -2
  2. package/dist/adapters/filesystem.mjs +1 -1
  3. package/dist/adapters/indexeddb.mjs +1 -1
  4. package/dist/{capabilities-D6gjjQyA.d.ts → capabilities-CAMzmkAg.d.ts} +19 -4
  5. package/dist/{chunk-P2ZZN32C.mjs → chunk-2E35UM3G.mjs} +2 -12
  6. package/dist/chunk-3DDUNI6N.mjs +48 -0
  7. package/dist/{chunk-KZTI25D3.mjs → chunk-4MQ5F4IL.mjs} +1 -1
  8. package/dist/{chunk-HVJYTKK7.mjs → chunk-BVBIQQKG.mjs} +947 -1327
  9. package/dist/{chunk-2X2ZQOAB.mjs → chunk-CTOSGRM7.mjs} +101 -21
  10. package/dist/{chunk-7QMTA7AA.mjs → chunk-CUZOX6CN.mjs} +7784 -4276
  11. package/dist/chunk-I23G3IZC.mjs +593 -0
  12. package/dist/{chunk-RV77FR2F.mjs → chunk-I64LXKO3.mjs} +0 -1
  13. package/dist/chunk-KEHK2O6P.mjs +13 -0
  14. package/dist/{chunk-CVPA5Q7R.mjs → chunk-LX4JERXI.mjs} +9 -6
  15. package/dist/{chunk-EDMCZLSJ.mjs → chunk-NOZUQM7J.mjs} +193 -13
  16. package/dist/{chunk-LCCL6EEH.mjs → chunk-PO53FV4Q.mjs} +93 -94
  17. package/dist/chunk-T5ZWEWVD.mjs +658 -0
  18. package/dist/{chunk-Y52WZWAU.mjs → chunk-TVFLHM7M.mjs} +4 -4
  19. package/dist/{chunk-QR4OKRVY.mjs → chunk-VKX2BPXD.mjs} +147 -642
  20. package/dist/{chunk-3HQPUCCT.mjs → chunk-XW25X6AU.mjs} +66 -237
  21. package/dist/{chunk-M6XF5HDE.mjs → chunk-Z3DQPOJQ.mjs} +127 -30
  22. package/dist/{client-C2TiW29y.d.ts → client-C-I70ArH.d.ts} +77 -26
  23. package/dist/client.d.ts +9 -9
  24. package/dist/client.mjs +44 -22
  25. package/dist/{config-BLguB-om.d.ts → config-C6Iw5rCX.d.ts} +11 -4
  26. package/dist/{config-C7Ip8Ife.d.ts → config-DJPH3IQB.d.ts} +11 -2
  27. package/dist/direct-executor-KFAGILJC.mjs +17 -0
  28. package/dist/distribution/coordinator/etcd.d.ts +29 -16
  29. package/dist/distribution/coordinator/etcd.mjs +162 -75
  30. package/dist/distribution/coordinator/in-memory.d.ts +2 -2
  31. package/dist/distribution/transport/grpc.d.ts +2 -2
  32. package/dist/distribution/transport/grpc.mjs +22 -2
  33. package/dist/distribution/transport/in-memory.d.ts +2 -2
  34. package/dist/distribution/transport/in-memory.mjs +6 -3
  35. package/dist/distribution/transport/tcp.d.ts +2 -2
  36. package/dist/distribution/transport/tcp.mjs +40 -16
  37. package/dist/distribution.d.ts +9 -9
  38. package/dist/distribution.mjs +647 -366
  39. package/dist/embeddings/openai.mjs +1 -1
  40. package/dist/{engine-Dm4446j1.d.ts → engine-B8eRPO7m.d.ts} +97 -188
  41. package/dist/index.browser.mjs +12132 -8592
  42. package/dist/index.d.ts +27 -8
  43. package/dist/index.mjs +15 -14
  44. package/dist/{memory-CKHTU1CL.d.ts → memory-DJEwWoCi.d.ts} +1204 -968
  45. package/dist/partial-words-DTIHO8G4.d.ts +19 -0
  46. package/dist/partial-words.d.ts +22 -0
  47. package/dist/partial-words.mjs +11 -0
  48. package/dist/pattern.mjs +1 -1
  49. package/dist/persistence/durability/checkpoint-worker.d.ts +57 -29
  50. package/dist/persistence/durability/checkpoint-worker.mjs +26 -16
  51. package/dist/react.d.ts +7 -7
  52. package/dist/react.mjs +0 -1
  53. package/dist/{schema-BBOCdhND.d.ts → schema-DgyDijhf.d.ts} +6 -2
  54. package/dist/server.d.ts +11 -11
  55. package/dist/server.mjs +212 -32
  56. package/dist/{tasks-BECd0b__.d.ts → tasks-BVmAKYBh.d.ts} +3 -3
  57. package/dist/{thread-IBSIZZ6W.mjs → thread-W6DPKEF6.mjs} +82 -21
  58. package/dist/{types-BQDlIvfS.d.ts → types-B3b68nfF.d.ts} +1 -1
  59. package/dist/{types-D5OwhtsQ.d.ts → types-Cb9kiY5P.d.ts} +1 -1
  60. package/dist/{types-BiUmaiWT.d.ts → types-ChrVy4lH.d.ts} +1 -1
  61. package/dist/vector/search-worker.d.ts +1 -1
  62. package/dist/vector/search-worker.mjs +4 -3
  63. package/dist/workers/entry.mjs +4 -4
  64. package/package.json +15 -7
  65. package/dist/chunk-3L4U6EJQ.mjs +0 -49
  66. package/dist/chunk-IFBKLBGB.mjs +0 -7
  67. package/dist/chunk-XZ4PAREY.mjs +0 -25
  68. package/dist/direct-executor-SVCHXR74.mjs +0 -14
  69. package/dist/serialization/crc32-worker.d.ts +0 -20
  70. package/dist/serialization/crc32-worker.mjs +0 -62
@@ -1,4 +1,4 @@
1
- import { NarsilError, ErrorCodes } from '../chunk-RV77FR2F.mjs';
1
+ import { NarsilError, ErrorCodes } from '../chunk-I64LXKO3.mjs';
2
2
 
3
3
  // src/embeddings/constants.ts
4
4
  var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
@@ -1,171 +1,6 @@
1
1
  import { E as EmbeddingAdapter } from './adapters-79OIa4xm.js';
2
- import { B as BatchResult, I as IndexInfo, f as IndexStats, P as PartitionStatsResult, L as ListParams, g as ListResult, Q as QueryParams, e as QueryResult, h as PreflightResult, j as SuggestParams, k as SuggestResult, M as MemoryStats, V as VectorMaintenanceResult } from './memory-CKHTU1CL.js';
3
- import { A as AnyDocument, a as InsertOptions, W as WriteOptions, I as IndexConfig, P as PartitionConfig } from './schema-BBOCdhND.js';
4
-
5
- /**
6
- * This map lists every event that the engine emits, with the payload of each
7
- * one.
8
- *
9
- * {@link Narsil.on} registers a listener under a key from this map, so that the
10
- * engine can pass the matching payload to that listener. Most of these events
11
- * report work that the engine does in the background, away from the call that
12
- * started it, so a failure that such an event reports never rejects a promise
13
- * that you are holding.
14
- *
15
- * @public
16
- */
17
- type NarsilEventMap = {
18
- /**
19
- * The engine emits this event after a call changes what a read returns from
20
- * an index. The calls are the inserts, updates, and removals, singly or in a
21
- * batch, together with `clear`, `restore`, `rebalance`, `rebuildAnalysis`,
22
- * `compactVectors`, `optimizeVectors`, `createIndex`, and `dropIndex`. The
23
- * engine emits the event after a call that throws as well, because a call can
24
- * change the index before it throws. It also emits the event after it reloads
25
- * an index, once a shared invalidation adapter reports that another instance
26
- * saved that index. The engine emits one event per batch, however many
27
- * documents the batch holds.
28
- *
29
- * The engine emits the event once a query can see the change, which means
30
- * after every worker copy applies the change and after any rebalance in
31
- * progress replays it. A query that a listener sends from its handler
32
- * therefore returns results that include the change. The engine waits for the
33
- * change to become visible only while a listener is registered for the event.
34
- */
35
- write: {
36
- /** This is the name of the index that changed. */
37
- indexName: string;
38
- };
39
- /**
40
- * A worker thread exited unexpectedly. The pool removes the thread and fails
41
- * the requests that the thread was serving with `WORKER_CRASHED`. The engine
42
- * then sends each of those queries again on the main thread, so the caller
43
- * receives a result with no error. The remaining workers keep serving
44
- * queries, because each of them holds a full worker copy of every promoted
45
- * index.
46
- *
47
- * After a delay, the engine spawns a replacement and loads every copy onto
48
- * it before it sends queries to the replacement. Once no worker is left, the
49
- * main thread serves every query, because it holds every document. The first
50
- * request after the delay then starts a new pool. The delay starts at one
51
- * second and doubles up to a minute while replacements keep failing.
52
- */
53
- workerCrash: {
54
- /** This is the id of the worker that exited. */
55
- workerId: number;
56
- /** These are the indexes that the worker held. */
57
- indexNames: string[];
58
- /** This is the error that ended the worker. */
59
- error: Error;
60
- };
61
- /** An index gained worker copies, either because it reached the copy
62
- * threshold or because a request loaded its copies again after an idle
63
- * spell. */
64
- workerPromote: {
65
- /** This is the number of workers in the pool. */
66
- workerCount: number;
67
- /** This is the reason that the index gained its copies, such as the copy
68
- * threshold that it reached. */
69
- reason: string;
70
- };
71
- /** An index could not gain worker copies, so the main thread keeps serving
72
- * its queries. */
73
- workerPromoteFailure: {
74
- /** This is the reason that the engine tried to load the copies. */
75
- reason: string;
76
- /** This is the error that stopped the load. */
77
- error: Error;
78
- /** This is true when the engine will try again at a later threshold. */
79
- retryable: boolean;
80
- };
81
- /** An index finished spreading its documents across a new number of
82
- * partitions. */
83
- partitionRebalance: {
84
- /** This is the name of the index that the engine rebalanced. */
85
- indexName: string;
86
- /** This is the number of partitions before the rebalance. */
87
- oldCount: number;
88
- /** This is the number of partitions after the rebalance. */
89
- newCount: number;
90
- };
91
- /**
92
- * An index passed its watermark, so its partitions are close to their
93
- * capacity. On a cluster node, the engine reports the document count and the
94
- * capacity of the one partition that `partitionId` identifies, which this
95
- * node leads.
96
- */
97
- partitionWatermark: {
98
- /** This is the name of the index that crossed the mark. */
99
- indexName: string;
100
- /** This is the number of documents in the index, or in the partition on a
101
- * cluster node. */
102
- documentCount: number;
103
- /** This is the number of documents that the current partitions of the
104
- * index can hold, or that the partition can hold on a cluster node. */
105
- capacity: number;
106
- /** This is the number of partitions in the index. */
107
- partitionCount: number;
108
- /** On a cluster node, this is the partition that crossed the mark, while
109
- * outside a cluster the field is absent. */
110
- partitionId?: number;
111
- };
112
- /**
113
- * The process uses nine tenths of its heap, as measured during a write or a
114
- * load, so the next large index can end the process with an out-of-memory
115
- * error.
116
- *
117
- * Where `--max-old-space-size` or `--max-old-space-size-percentage` sets a
118
- * limit, on the command line or in `NODE_OPTIONS`, the engine measures the
119
- * used bytes against that limit, which `heapLimit` then reports. Where
120
- * neither flag sets a limit, the engine measures the share of the heap that
121
- * V8 reports as no longer available. V8 reports a limit about 192 MB above
122
- * the true ceiling, so a process on a default heap below about 2 GB can end before
123
- * this event fires.
124
- *
125
- * The engine emits the event once per crossing, then arms it again once the
126
- * free share of the heap recovers to two tenths. Raise the limit with
127
- * `--max-old-space-size-percentage` or `--max-old-space-size`, or close an
128
- * idle index; see {@link ProcessMemoryReport.heapLimit}.
129
- */
130
- heapPressure: {
131
- /** This is the index that a write or a load was touching when the heap
132
- * reached that point. */
133
- indexName: string;
134
- /** This is the heap that the process uses, in bytes. */
135
- heapUsed: number;
136
- /** This is the size in bytes that the heap can grow to. */
137
- heapLimit: number;
138
- /** This is the estimate of the bytes that the index holds. */
139
- estimatedMemoryBytes: number;
140
- };
141
- /** The engine started, completed, or failed a rebuild that brings the terms
142
- * of an index up to the current analysis of its language module. */
143
- analysisRebuild: {
144
- /** This is the name of the index under rebuild. */
145
- indexName: string;
146
- /** This is the stage that the rebuild has reached. */
147
- status: 'started' | 'completed' | 'failed';
148
- /** This is the number of partitions that the rebuild has covered so far. */
149
- partitionsRebuilt: number;
150
- /** This is the number of partitions that the rebuild covers in total. */
151
- partitionCount: number;
152
- /** This is the error that stopped the rebuild, which only a `failed`
153
- * status includes. */
154
- error?: Error;
155
- };
156
- /** A write to the write-ahead log or a checkpoint failed, so the writes since
157
- * the last checkpoint are at risk. */
158
- durabilityError: {
159
- /** This is the error that the durability layer threw. */
160
- error: Error;
161
- };
162
- /** The invalidation channel failed, so this instance can serve partitions
163
- * that another instance has since changed. */
164
- invalidationError: {
165
- /** This is the error that the adapter threw. */
166
- error: Error;
167
- };
168
- };
2
+ import { B as BatchResult, I as IndexInfo, g as IndexStats, P as PartitionStatsResult, L as ListParams, h as ListResult, Q as QueryParams, e as QueryResult, j as PreflightResult, k as SuggestParams, l as SuggestResult, D as DocumentImportResult, M as MemoryStats, V as VectorMaintenanceResult, m as NarsilEventMap } from './memory-DJEwWoCi.js';
3
+ import { A as AnyDocument, a as InsertOptions, W as WriteOptions, I as IndexConfig, P as PartitionConfig } from './schema-DgyDijhf.js';
169
4
 
170
5
  /**
171
6
  * Opens and closes durable indexes without deleting them.
@@ -293,6 +128,14 @@ interface DocumentWriteOperations {
293
128
  waitForWrites(indexName: string): Promise<void>;
294
129
  }
295
130
 
131
+ /**
132
+ * The bytes that {@link Narsil.restore} and {@link Narsil.importDocumentExport}
133
+ * accept, as one array, a stream of chunks, or an async iterable of chunks,
134
+ * such as a Node.js file stream.
135
+ *
136
+ * @public
137
+ */
138
+ type ByteSource = Uint8Array | ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;
296
139
  /**
297
140
  * The search engine, and everything you do with it.
298
141
  *
@@ -472,28 +315,94 @@ interface Narsil extends IndexLifecycleOperations, DocumentWriteOperations {
472
315
  */
473
316
  rebuildAnalysis(indexName: string): Promise<void>;
474
317
  /**
475
- * Serialises a whole index into the portable `.nrsl` format, which any
476
- * Narsil implementation reads.
318
+ * Returns a stream of the index's snapshot archive. The archive is a pax
319
+ * file containing the index's configuration and the files of one
320
+ * checkpoint, and any implementation of the Narsil format can restore it.
321
+ *
322
+ * With write-ahead log durability, the engine takes a checkpoint before it
323
+ * starts the stream, so the archive contains every write that the engine
324
+ * acknowledged before the call. The engine keeps that checkpoint's files on
325
+ * disk until the stream ends or you cancel it. Without write-ahead log
326
+ * durability, the engine builds the archive's files from the index in
327
+ * memory.
328
+ *
329
+ * @param indexName - The index to stream.
330
+ * @returns A stream of the archive's bytes, which you can write to a file or
331
+ * send over a network.
332
+ */
333
+ snapshot(indexName: string): Promise<ReadableStream<Uint8Array>>;
334
+ /**
335
+ * Creates an index from a snapshot under the name that you pass, replacing
336
+ * any index of that name.
337
+ *
338
+ * The engine accepts the archive that {@link Narsil.snapshot} streams. It
339
+ * also accepts the single `.nrsl` file that `snapshot` returned in release
340
+ * 0.3, and it inserts that file's documents and vectors as new writes. The
341
+ * engine reads an archive one file at a time. Before it replaces an existing
342
+ * index, it checks each file against the archive's manifest and decodes
343
+ * every document, so a failed check leaves the existing index unchanged.
344
+ *
345
+ * @param indexName - The name that the restored index takes.
346
+ * @param data - The snapshot's bytes, as one array, a stream, or an async
347
+ * iterable of chunks.
348
+ * @throws A `NarsilError` with `PERSISTENCE_LOAD_FAILED` when the archive is
349
+ * malformed or a file's length differs from the manifest. The engine raises
350
+ * `PERSISTENCE_CRC_MISMATCH` when a file's checksum differs from its
351
+ * contents, and `ENVELOPE_VERSION_MISMATCH` when a file has a format version
352
+ * other than the ones that this release implements. It raises
353
+ * `CONFIG_INVALID` when the archive's configuration is invalid, and
354
+ * `DOC_VALIDATION_FAILED` when the data is empty or the release 0.3 file is
355
+ * invalid.
356
+ */
357
+ restore(indexName: string, data: ByteSource): Promise<void>;
358
+ /**
359
+ * Returns a stream of the index's document export. The export is JSON Lines
360
+ * text whose format stays the same in every release, so you can use it to
361
+ * move an index across releases or between implementations.
362
+ *
363
+ * The first line is a header containing the format name, the format
364
+ * version, and the index configuration. Each later line contains one
365
+ * document, with its ID under `id` and the value of each vector field as an
366
+ * array of numbers. With write-ahead log durability, the engine exports every
367
+ * document from one checkpoint; otherwise, it exports them from the index in
368
+ * memory at one moment.
369
+ *
370
+ * JSON has no type for a date, for raw bytes, or for an infinite number or
371
+ * `NaN`, so the engine writes each such value as a tag. Each tag is an
372
+ * object with one key that begins with `$`, such as
373
+ * `{"$date":[1700000000,123000000]}`. The engine also wraps a stored object
374
+ * whose only key begins with `$` in an `$object` tag, because the import
375
+ * decodes every other object of that shape as a tag.
376
+ *
377
+ * @param indexName - The index to export.
378
+ * @returns A stream of the export's UTF-8 bytes.
379
+ */
380
+ exportDocuments(indexName: string): Promise<ReadableStream<Uint8Array>>;
381
+ /**
382
+ * Imports a document export into the named index. Where the name is free,
383
+ * the engine creates the index from the export's configuration.
384
+ *
385
+ * The engine writes the documents in batches and replaces any document
386
+ * whose ID the index already contains. Because it replaces existing
387
+ * documents, you can run an interrupted import again to make the index equal
388
+ * to the export. When a line is invalid or the engine rejects its document,
389
+ * the engine records the refusal and continues with the next line.
390
+ *
391
+ * The engine converts each tag that {@link Narsil.exportDocuments} writes
392
+ * into the value that the tag stands for. When an object has one key that
393
+ * begins with `$` and that key names no tag, or when a tag holds an invalid
394
+ * value, the engine refuses the line.
477
395
  *
478
- * @param indexName - The index to serialise.
479
- * @returns The file's bytes, ready to store or send.
480
- */
481
- snapshot(indexName: string): Promise<Uint8Array>;
482
- /**
483
- * Loads an index from snapshot bytes, replacing whatever the name held.
484
- *
485
- * The engine reads the `.nrsl` envelope that {@link Narsil.snapshot} writes.
486
- *
487
- * @param indexName - The name the restored index takes.
488
- * @param data - Bytes that {@link Narsil.snapshot} produced.
489
- * @throws A `NarsilError` with `ENVELOPE_INVALID_MAGIC` when the bytes are
490
- * shorter than an envelope header or open with anything other than the
491
- * `NRSL` magic bytes, `ENVELOPE_VERSION_MISMATCH` when the envelope carries a
492
- * format version other than the index snapshot format,
493
- * `PERSISTENCE_CRC_MISMATCH` when the payload fails its checksum, and
494
- * `DOC_VALIDATION_FAILED` when the envelope holds no valid index snapshot.
396
+ * @param indexName - The index that receives the documents.
397
+ * @param data - The export's bytes, as one array, a stream, or an async
398
+ * iterable of chunks.
399
+ * @returns The number of imported documents, the number of refused lines,
400
+ * and the 1,000 refusals with the lowest line numbers.
401
+ * @throws A `NarsilError` with `CONFIG_INVALID` when the first line is
402
+ * anything other than a version 1 header, or when the named index exists
403
+ * with a different schema.
495
404
  */
496
- restore(indexName: string, data: Uint8Array): Promise<void>;
405
+ importDocumentExport(indexName: string, data: ByteSource): Promise<DocumentImportResult>;
497
406
  /**
498
407
  * Writes an index's current state to the durability directory, so a restart
499
408
  * replays less of the log.
@@ -599,4 +508,4 @@ interface Narsil extends IndexLifecycleOperations, DocumentWriteOperations {
599
508
  shutdown(): Promise<void>;
600
509
  }
601
510
 
602
- export type { DocumentWriteOperations as D, IndexLifecycleOperations as I, NarsilEventMap as N, Narsil as a };
511
+ export type { ByteSource as B, DocumentWriteOperations as D, IndexLifecycleOperations as I, Narsil as N };