@delali/narsil 0.2.0 → 0.2.1

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 (151) hide show
  1. package/dist/adapters/filesystem.d.ts +23 -1
  2. package/dist/adapters/filesystem.mjs +1 -1
  3. package/dist/adapters/indexeddb.d.ts +25 -1
  4. package/dist/adapters/indexeddb.mjs +1 -1
  5. package/dist/adapters/memory.d.ts +14 -1
  6. package/dist/adapters-CVqI5NBt.d.ts +149 -0
  7. package/dist/{chunk-S6IAXOBA.mjs → chunk-ASI6AOW2.mjs} +1 -1
  8. package/dist/{chunk-AUMKFYTG.mjs → chunk-FKK76OR7.mjs} +56 -55
  9. package/dist/{chunk-M2EDG55Y.mjs → chunk-UNJZ7ZDB.mjs} +10 -0
  10. package/dist/{chunk-XAKNSWIK.mjs → chunk-WLR5BFL3.mjs} +16 -14
  11. package/dist/config-CAjTHzkH.d.ts +256 -0
  12. package/dist/{direct-executor-2FV3MEDD.mjs → direct-executor-3W4QRA4E.mjs} +2 -2
  13. package/dist/distribution/coordinator/etcd.d.ts +44 -3
  14. package/dist/distribution/coordinator/etcd.mjs +2 -2
  15. package/dist/distribution/coordinator/in-memory.d.ts +14 -3
  16. package/dist/distribution.d.ts +312 -45
  17. package/dist/distribution.mjs +4 -4
  18. package/dist/embeddings/openai.d.ts +28 -1
  19. package/dist/embeddings/openai.mjs +1 -1
  20. package/dist/engine-CCrlfLyq.d.ts +431 -0
  21. package/dist/index.browser.mjs +24 -12
  22. package/dist/index.d.ts +173 -8
  23. package/dist/index.mjs +3 -3
  24. package/dist/invalidation/broadcast-channel.d.ts +20 -1
  25. package/dist/invalidation/filesystem.d.ts +24 -1
  26. package/dist/invalidation/noop.d.ts +14 -1
  27. package/dist/language-DB8KG1z5.d.ts +53 -0
  28. package/dist/languages/albanian.d.ts +11 -1
  29. package/dist/languages/amharic.d.ts +11 -1
  30. package/dist/languages/arabic.d.ts +10 -1
  31. package/dist/languages/armenian.d.ts +10 -1
  32. package/dist/languages/azerbaijani.d.ts +11 -1
  33. package/dist/languages/bambara.d.ts +11 -1
  34. package/dist/languages/basque.d.ts +10 -1
  35. package/dist/languages/belarusian.d.ts +11 -1
  36. package/dist/languages/bengali.d.ts +11 -1
  37. package/dist/languages/bosnian.d.ts +11 -1
  38. package/dist/languages/breton.d.ts +11 -1
  39. package/dist/languages/bulgarian.d.ts +10 -1
  40. package/dist/languages/burmese.d.ts +11 -1
  41. package/dist/languages/catalan.d.ts +10 -1
  42. package/dist/languages/chinese.d.ts +11 -1
  43. package/dist/languages/croatian.d.ts +11 -1
  44. package/dist/languages/czech.d.ts +10 -1
  45. package/dist/languages/dagbani.d.ts +11 -1
  46. package/dist/languages/danish.d.ts +10 -1
  47. package/dist/languages/dutch.d.ts +10 -1
  48. package/dist/languages/english.d.ts +10 -1
  49. package/dist/languages/esperanto.d.ts +10 -1
  50. package/dist/languages/estonian.d.ts +10 -1
  51. package/dist/languages/ewe.d.ts +11 -1
  52. package/dist/languages/faroese.d.ts +11 -1
  53. package/dist/languages/fijian.d.ts +11 -1
  54. package/dist/languages/finnish.d.ts +10 -1
  55. package/dist/languages/french.d.ts +10 -1
  56. package/dist/languages/ga.d.ts +11 -1
  57. package/dist/languages/galician.d.ts +11 -1
  58. package/dist/languages/georgian.d.ts +11 -1
  59. package/dist/languages/german.d.ts +10 -1
  60. package/dist/languages/greek.d.ts +10 -1
  61. package/dist/languages/guarani.d.ts +11 -1
  62. package/dist/languages/gujarati.d.ts +11 -1
  63. package/dist/languages/haitian-creole.d.ts +11 -1
  64. package/dist/languages/hausa.d.ts +11 -1
  65. package/dist/languages/hawaiian.d.ts +11 -1
  66. package/dist/languages/hebrew.d.ts +11 -1
  67. package/dist/languages/hindi.d.ts +10 -1
  68. package/dist/languages/hungarian.d.ts +10 -1
  69. package/dist/languages/icelandic.d.ts +11 -1
  70. package/dist/languages/igbo.d.ts +11 -1
  71. package/dist/languages/indonesian.d.ts +10 -1
  72. package/dist/languages/irish.d.ts +10 -1
  73. package/dist/languages/italian.d.ts +10 -1
  74. package/dist/languages/japanese.d.ts +11 -1
  75. package/dist/languages/kannada.d.ts +11 -1
  76. package/dist/languages/kazakh.d.ts +11 -1
  77. package/dist/languages/khmer.d.ts +11 -1
  78. package/dist/languages/kinyarwanda.d.ts +11 -1
  79. package/dist/languages/kirundi.d.ts +11 -1
  80. package/dist/languages/korean.d.ts +11 -1
  81. package/dist/languages/kurmanji.d.ts +11 -1
  82. package/dist/languages/kyrgyz.d.ts +11 -1
  83. package/dist/languages/lao.d.ts +11 -1
  84. package/dist/languages/latin.d.ts +11 -1
  85. package/dist/languages/latvian.d.ts +11 -1
  86. package/dist/languages/lingala.d.ts +11 -1
  87. package/dist/languages/lithuanian.d.ts +10 -1
  88. package/dist/languages/luxembourgish.d.ts +11 -1
  89. package/dist/languages/macedonian.d.ts +11 -1
  90. package/dist/languages/malagasy.d.ts +11 -1
  91. package/dist/languages/malay.d.ts +11 -1
  92. package/dist/languages/malayalam.d.ts +11 -1
  93. package/dist/languages/maltese.d.ts +11 -1
  94. package/dist/languages/maori.d.ts +11 -1
  95. package/dist/languages/marathi.d.ts +11 -1
  96. package/dist/languages/nepali.d.ts +10 -1
  97. package/dist/languages/norwegian.d.ts +10 -1
  98. package/dist/languages/oromo.d.ts +11 -1
  99. package/dist/languages/persian.d.ts +10 -1
  100. package/dist/languages/polish.d.ts +10 -1
  101. package/dist/languages/portuguese.d.ts +10 -1
  102. package/dist/languages/punjabi.d.ts +11 -1
  103. package/dist/languages/romanian.d.ts +10 -1
  104. package/dist/languages/russian.d.ts +10 -1
  105. package/dist/languages/samoan.d.ts +11 -1
  106. package/dist/languages/sanskrit.d.ts +10 -1
  107. package/dist/languages/scottish-gaelic.d.ts +11 -1
  108. package/dist/languages/serbian.d.ts +10 -1
  109. package/dist/languages/shona.d.ts +11 -1
  110. package/dist/languages/sinhala.d.ts +11 -1
  111. package/dist/languages/slovak.d.ts +11 -1
  112. package/dist/languages/slovenian.d.ts +10 -1
  113. package/dist/languages/sorani.d.ts +11 -1
  114. package/dist/languages/spanish.d.ts +10 -1
  115. package/dist/languages/swahili.d.ts +10 -1
  116. package/dist/languages/swedish.d.ts +10 -1
  117. package/dist/languages/tagalog.d.ts +11 -1
  118. package/dist/languages/tamil.d.ts +10 -1
  119. package/dist/languages/tatar.d.ts +11 -1
  120. package/dist/languages/telugu.d.ts +11 -1
  121. package/dist/languages/thai.d.ts +11 -1
  122. package/dist/languages/tibetan.d.ts +11 -1
  123. package/dist/languages/tigrinya.d.ts +11 -1
  124. package/dist/languages/tongan.d.ts +11 -1
  125. package/dist/languages/turkish.d.ts +10 -1
  126. package/dist/languages/twi.d.ts +11 -1
  127. package/dist/languages/ukrainian.d.ts +10 -1
  128. package/dist/languages/urdu.d.ts +11 -1
  129. package/dist/languages/vietnamese.d.ts +11 -1
  130. package/dist/languages/welsh.d.ts +11 -1
  131. package/dist/languages/wolof.d.ts +11 -1
  132. package/dist/languages/xhosa.d.ts +11 -1
  133. package/dist/languages/yoruba.d.ts +11 -1
  134. package/dist/languages/zulu.d.ts +11 -1
  135. package/dist/persistence/durability/checkpoint-worker.d.ts +2 -2
  136. package/dist/persistence/durability/checkpoint-worker.mjs +3 -3
  137. package/dist/schema-CE6S_aAr.d.ts +208 -0
  138. package/dist/search-CgQQIciB.d.ts +786 -0
  139. package/dist/server.d.ts +213 -12
  140. package/dist/server.mjs +29 -1
  141. package/dist/types-BV3nAKTL.d.ts +302 -0
  142. package/dist/vector/hnsw-build-worker.d.ts +68 -2
  143. package/dist/vector/hnsw-build-worker.mjs +0 -2
  144. package/dist/workers/entry.mjs +1 -1
  145. package/package.json +5 -2
  146. package/dist/adapters-Bo2JQg8b.d.ts +0 -37
  147. package/dist/config-P27AtSn4.d.ts +0 -502
  148. package/dist/language-CmJBHf1j.d.ts +0 -17
  149. package/dist/narsil-CMZRPDlQ.d.ts +0 -159
  150. package/dist/schema-BnvLvjRp.d.ts +0 -67
  151. package/dist/types-BRTcBgAp.d.ts +0 -73
@@ -0,0 +1,431 @@
1
+ import { E as EmbeddingAdapter } from './adapters-CVqI5NBt.js';
2
+ import { I as IndexInfo, m as IndexStats, P as PartitionStatsResult, B as BatchResult, Q as QueryParams, q as QueryResult, n as PreflightResult, t as SuggestParams, u as SuggestResult, M as MemoryStats, V as VectorMaintenanceResult } from './search-CgQQIciB.js';
3
+ import { I as IndexConfig, A as AnyDocument, a as InsertOptions, P as PartitionConfig } from './schema-CE6S_aAr.js';
4
+
5
+ /**
6
+ * Every event the engine emits, with the payload each one carries.
7
+ *
8
+ * {@link Narsil.on} takes a key from this map and hands your listener the
9
+ * matching payload. These events report work the engine does on its own, away
10
+ * from the call that triggered it, so a failure here never rejects a promise
11
+ * you are holding.
12
+ *
13
+ * @public
14
+ */
15
+ type NarsilEventMap = {
16
+ /** A partition failed to reach the persistence adapter. */
17
+ persistenceError: {
18
+ /** The partition belongs to this index. */
19
+ indexName: string;
20
+ /** This partition failed to save. */
21
+ partitionId: number;
22
+ /** The adapter threw this. */
23
+ error: Error;
24
+ /** This turns true once the engine has given up retrying, which means the partition stays unsaved. */
25
+ retriesExhausted: boolean;
26
+ };
27
+ /** A worker thread died, and the engine has rebuilt the indexes it held. */
28
+ workerCrash: {
29
+ /** This worker died. */
30
+ workerId: number;
31
+ /** That worker was holding these indexes. */
32
+ indexNames: string[];
33
+ /** This ended the worker. */
34
+ error: Error;
35
+ };
36
+ /** The engine moved its indexes onto worker threads. */
37
+ workerPromote: {
38
+ /** The pool started with this many workers. */
39
+ workerCount: number;
40
+ /** The engine promoted for this reason, such as the threshold the index passed. */
41
+ reason: string;
42
+ };
43
+ /** The engine tried to move onto worker threads and could not. Indexes keep answering on the main thread. */
44
+ workerPromoteFailure: {
45
+ /** The engine tried to promote for this reason. */
46
+ reason: string;
47
+ /** This stopped it. */
48
+ error: Error;
49
+ /** This turns true when the engine will try again on a later threshold. */
50
+ retryable: boolean;
51
+ };
52
+ /** An index finished spreading its documents across a new partition count. */
53
+ partitionRebalance: {
54
+ /** This index was rebalanced. */
55
+ indexName: string;
56
+ /** The index held this many partitions before. */
57
+ oldCount: number;
58
+ /** The index holds this many partitions now. */
59
+ newCount: number;
60
+ };
61
+ /** A partition passed its watermark, so the index is close to needing another one. */
62
+ partitionWatermark: {
63
+ /** This index crossed the mark. */
64
+ indexName: string;
65
+ /** The index holds this many documents. */
66
+ documentCount: number;
67
+ /** The index can hold this many across its current partitions. */
68
+ capacity: number;
69
+ /** The index holds this many partitions. */
70
+ partitionCount: number;
71
+ };
72
+ /** A rebuild is bringing an index's terms up to its language module's current analysis. */
73
+ analysisRebuild: {
74
+ /** This index is being rebuilt. */
75
+ indexName: string;
76
+ /** The rebuild stands here. */
77
+ status: 'started' | 'completed' | 'failed';
78
+ /** The rebuild has covered this many partitions so far. */
79
+ partitionsRebuilt: number;
80
+ /** The rebuild covers this many partitions in total. */
81
+ partitionCount: number;
82
+ /** This stopped the rebuild, and only a `failed` status carries it. */
83
+ error?: Error;
84
+ };
85
+ /** The write-ahead log or a checkpoint failed, so writes since the last checkpoint are at risk. */
86
+ durabilityError: {
87
+ /** The durability layer threw this. */
88
+ error: Error;
89
+ };
90
+ /** The invalidation channel failed, so this instance may be reading partitions another instance has changed. */
91
+ invalidationError: {
92
+ /** The adapter threw this. */
93
+ error: Error;
94
+ };
95
+ };
96
+
97
+ /**
98
+ * The search engine, and everything you do with it.
99
+ *
100
+ * One instance holds every index you create, so an application usually keeps a
101
+ * single engine for its lifetime and reaches each index by name. Build one
102
+ * with {@link createNarsil}.
103
+ *
104
+ * @public
105
+ */
106
+ interface Narsil {
107
+ /**
108
+ * Creates an index you can insert documents into and query.
109
+ *
110
+ * The schema sets the type of each field, marks which fields you can
111
+ * filter and sort on, and controls how the engine tokenises text. The
112
+ * `language` option picks the analyser that stems those text fields.
113
+ *
114
+ * @param name - Every later call uses this name to reach the index.
115
+ * @param config - This carries the schema, and the language, partitioning,
116
+ * and scoring settings.
117
+ */
118
+ createIndex(name: string, config: IndexConfig): Promise<void>;
119
+ /** Registers an adapter under a name that index configs can reference and
120
+ * durability metadata can persist; re-registering rebinds referencing indexes. */
121
+ registerEmbeddingAdapter(name: string, adapter: EmbeddingAdapter): void;
122
+ /**
123
+ * Removes an index and everything it holds, including whatever persistence
124
+ * wrote for it. The documents do not come back.
125
+ *
126
+ * @param name - The index to drop.
127
+ */
128
+ dropIndex(name: string): Promise<void>;
129
+ /**
130
+ * Lists every index this engine holds, with its size and its language.
131
+ *
132
+ * @returns One entry per index, in creation order.
133
+ */
134
+ listIndexes(): IndexInfo[];
135
+ /**
136
+ * Returns one index's document count, partition count, memory estimate,
137
+ * language, and schema.
138
+ *
139
+ * @param indexName - The index to describe.
140
+ * @returns The index's current figures.
141
+ * @throws A `NarsilError` with `INDEX_NOT_FOUND` for an unknown name.
142
+ */
143
+ getStats(indexName: string): IndexStats;
144
+ /**
145
+ * Returns per-partition figures for one index, which is where you look when
146
+ * an index grows unevenly or a rebalance is worth running.
147
+ *
148
+ * @param indexName - The index to describe.
149
+ * @returns One entry per partition, in partition order.
150
+ */
151
+ getPartitionStats(indexName: string): PartitionStatsResult[];
152
+ /**
153
+ * Adds one document to an index and returns the id it is stored under.
154
+ *
155
+ * The id comes from the `docId` argument when you pass one, otherwise from
156
+ * the document's own `id` field, and otherwise the engine generates it. Use
157
+ * {@link Narsil.insertBatch} for a large load, so that one bad document
158
+ * cannot abandon the rest.
159
+ *
160
+ * @param indexName - The index that receives the document.
161
+ * @param document - Its fields must match the types the schema declares.
162
+ * @param docId - Pass an id to control it yourself, or omit it and read the
163
+ * returned value.
164
+ * @param options - Per-write settings, such as skipping the defensive copy.
165
+ * @returns The id the document is stored under.
166
+ */
167
+ insert(indexName: string, document: AnyDocument, docId?: string, options?: InsertOptions): Promise<string>;
168
+ /**
169
+ * Adds many documents in one pass and reports each one's outcome.
170
+ *
171
+ * A document the engine rejects appears in `failed` with the error that
172
+ * rejected it, and every other document is still written, which is what
173
+ * makes this the call to load a corpus with.
174
+ *
175
+ * @param indexName - The index that receives the documents.
176
+ * @param documents - The documents to write, each carrying its own id or
177
+ * leaving the engine to generate one.
178
+ * @param options - Per-write settings applied to every document.
179
+ * @returns The ids written, and each rejection with its error.
180
+ */
181
+ insertBatch(indexName: string, documents: AnyDocument[], options?: InsertOptions): Promise<BatchResult>;
182
+ /**
183
+ * Removes one document.
184
+ *
185
+ * @param indexName - The index holding the document.
186
+ * @param docId - The document to remove.
187
+ * @throws A `NarsilError` with `DOC_NOT_FOUND` when the index holds no such
188
+ * document.
189
+ */
190
+ remove(indexName: string, docId: string): Promise<void>;
191
+ /**
192
+ * Removes many documents in one pass and reports each one's outcome.
193
+ *
194
+ * @param indexName - The index holding the documents.
195
+ * @param docIds - The documents to remove.
196
+ * @returns The ids removed, and each failure with its error.
197
+ */
198
+ removeBatch(indexName: string, docIds: string[]): Promise<BatchResult>;
199
+ /**
200
+ * Replaces a stored document with the one you pass.
201
+ *
202
+ * The engine removes the old document and indexes the new one, so the
203
+ * document you supply has to be complete rather than a set of changed
204
+ * fields.
205
+ *
206
+ * @param indexName - The index holding the document.
207
+ * @param docId - The document to replace.
208
+ * @param document - The complete replacement.
209
+ */
210
+ update(indexName: string, docId: string, document: AnyDocument): Promise<void>;
211
+ /**
212
+ * Replaces many documents in one pass and reports each one's outcome.
213
+ *
214
+ * @param indexName - The index holding the documents.
215
+ * @param updates - Each id with the complete document that replaces it.
216
+ * @returns The ids replaced, and each failure with its error.
217
+ */
218
+ updateBatch(indexName: string, updates: Array<{
219
+ docId: string;
220
+ document: AnyDocument;
221
+ }>): Promise<BatchResult>;
222
+ /**
223
+ * Fetches one stored document by id, without searching.
224
+ *
225
+ * @param indexName - The index holding the document.
226
+ * @param docId - The document to fetch.
227
+ * @returns The document, or `undefined` when the index holds no such id.
228
+ */
229
+ get(indexName: string, docId: string): Promise<AnyDocument | undefined>;
230
+ /**
231
+ * Fetches many stored documents by id in one pass.
232
+ *
233
+ * @param indexName - The index holding the documents.
234
+ * @param docIds - The documents to fetch.
235
+ * @returns A map from id to document, holding an entry for each id that
236
+ * exists and nothing for the rest.
237
+ */
238
+ getMultiple(indexName: string, docIds: string[]): Promise<Map<string, AnyDocument>>;
239
+ /**
240
+ * Reports whether an index holds a document, without reading it.
241
+ *
242
+ * @param indexName - The index to check.
243
+ * @param docId - The document to look for.
244
+ * @returns True when the index holds that id.
245
+ */
246
+ has(indexName: string, docId: string): Promise<boolean>;
247
+ /**
248
+ * Counts the documents an index holds.
249
+ *
250
+ * @param indexName - The index to count.
251
+ * @returns The document count across every partition.
252
+ */
253
+ countDocuments(indexName: string): Promise<number>;
254
+ /**
255
+ * Runs a search against an index and returns the ranked hits.
256
+ *
257
+ * One call covers keyword search, vector search, and a hybrid of the two,
258
+ * chosen by the `mode` parameter. BM25 ranks keyword results by default.
259
+ * Every hit carries its score and its document, along with highlights when
260
+ * you ask for them.
261
+ *
262
+ * @typeParam T - Shape of the stored documents, which flows through to each
263
+ * hit's `document`.
264
+ * @param indexName - The index the search runs against.
265
+ * @param params - These set the search term, filters, field boosts, sorting,
266
+ * facets, highlighting, and the result limit.
267
+ * @returns The hits, the total count, the elapsed time, and any facets or
268
+ * groups the query asked for.
269
+ */
270
+ query<T = AnyDocument>(indexName: string, params: QueryParams): Promise<QueryResult<T>>;
271
+ /**
272
+ * Counts what a query would match without building or ranking a single hit,
273
+ * which is how a result-count badge stays cheap.
274
+ *
275
+ * @param indexName - The index the query would run against.
276
+ * @param params - The same parameters {@link Narsil.query} takes. Anything
277
+ * that shapes the output alone, such as `limit` or `highlight`, is ignored.
278
+ * @returns The match count and the time the count took.
279
+ */
280
+ preflight(indexName: string, params: QueryParams): Promise<PreflightResult>;
281
+ /**
282
+ * Returns the indexed terms that complete a prefix, ready to offer as
283
+ * you-type suggestions.
284
+ *
285
+ * The terms come back as the index holds them, which means stems unless the
286
+ * index was created with `surfaceForms`.
287
+ *
288
+ * @param indexName - The index to draw completions from.
289
+ * @param params - The prefix typed so far, and how many completions to
290
+ * return.
291
+ * @returns The completions, most widely used first.
292
+ */
293
+ suggest(indexName: string, params: SuggestParams): Promise<SuggestResult>;
294
+ /**
295
+ * Rebuilds an index's terms from the documents it already stores, and
296
+ * resolves once every partition carries terms the current language module
297
+ * produced.
298
+ *
299
+ * An index whose stored analysis revision differs from the one its language
300
+ * module carries answers text queries from terms an earlier analysis wrote,
301
+ * and every such result reports `analysisStale`. Call this after the engine
302
+ * reports a stale index to configuration that declined an automatic rebuild.
303
+ * Calling it for an index whose terms are current does nothing.
304
+ *
305
+ * @param indexName - The index whose terms are rebuilt.
306
+ */
307
+ rebuildAnalysis(indexName: string): Promise<void>;
308
+ /**
309
+ * Serialises a whole index into the portable `.nrsl` format, which any
310
+ * Narsil implementation reads.
311
+ *
312
+ * @param indexName - The index to serialise.
313
+ * @returns The file's bytes, ready to store or send.
314
+ */
315
+ snapshot(indexName: string): Promise<Uint8Array>;
316
+ /**
317
+ * Loads an index from `.nrsl` bytes, replacing whatever the name held.
318
+ *
319
+ * @param indexName - The name the restored index takes.
320
+ * @param data - Bytes a {@link Narsil.snapshot} produced.
321
+ * @throws A `NarsilError` with `ENVELOPE_INVALID_MAGIC` or
322
+ * `ENVELOPE_VERSION_MISMATCH` when the bytes are not a file this engine
323
+ * reads.
324
+ */
325
+ restore(indexName: string, data: Uint8Array): Promise<void>;
326
+ /**
327
+ * Writes an index's current state to the durability directory, so a restart
328
+ * replays less of the log.
329
+ *
330
+ * @param indexName - The index to checkpoint.
331
+ */
332
+ checkpoint(indexName: string): Promise<void>;
333
+ /**
334
+ * Removes every document from an index and keeps the index itself, along
335
+ * with its schema and settings.
336
+ *
337
+ * @param indexName - The index to empty.
338
+ */
339
+ clear(indexName: string): Promise<void>;
340
+ /**
341
+ * Spreads an index's documents across a different number of partitions.
342
+ *
343
+ * The engine keeps answering queries throughout, and it queues the writes
344
+ * that arrive while the work runs, replaying them in order once it finishes.
345
+ *
346
+ * @param indexName - The index to rebalance.
347
+ * @param targetPartitionCount - Partitions the index ends up with.
348
+ */
349
+ rebalance(indexName: string, targetPartitionCount: number): Promise<void>;
350
+ /**
351
+ * Changes how an index grows into new partitions, without moving the
352
+ * documents it already holds.
353
+ *
354
+ * @param indexName - The index to reconfigure.
355
+ * @param config - The partitioning fields to change. Anything you leave out
356
+ * keeps its current value.
357
+ */
358
+ updatePartitionConfig(indexName: string, config: Partial<PartitionConfig>): Promise<void>;
359
+ /**
360
+ * Reports what this engine and its host process are using, which is what you
361
+ * size a host from.
362
+ *
363
+ * @returns Process heap figures, the engine's own estimate, and one entry
364
+ * per worker once the engine has promoted.
365
+ */
366
+ getMemoryStats(): Promise<MemoryStats>;
367
+ /**
368
+ * Rebuilds a vector field's graph without the tombstones removed documents
369
+ * left behind, which returns the memory they held and speeds searches up.
370
+ *
371
+ * Read {@link Narsil.vectorMaintenanceStatus} first to see whether the work
372
+ * is worth its cost.
373
+ *
374
+ * @param indexName - The index holding the field.
375
+ * @param fieldName - The vector field to compact. Omit it to compact every
376
+ * vector field in the index.
377
+ */
378
+ compactVectors(indexName: string, fieldName?: string): Promise<void>;
379
+ /**
380
+ * Rebuilds a vector field's graph from scratch, which recovers the recall a
381
+ * long run of inserts and removals costs.
382
+ *
383
+ * This is heavier than {@link Narsil.compactVectors} and gives a better
384
+ * graph, so run it once a search starts missing documents it should find,
385
+ * rather than on a schedule.
386
+ *
387
+ * @param indexName - The index holding the field.
388
+ * @param fieldName - The vector field to rebuild. Omit it to rebuild every
389
+ * vector field in the index.
390
+ */
391
+ optimizeVectors(indexName: string, fieldName?: string): Promise<void>;
392
+ /**
393
+ * Reports the state of each vector field in an index, and what compaction or
394
+ * optimisation would cost.
395
+ *
396
+ * @param indexName - The index to describe.
397
+ * @returns One entry per vector field.
398
+ */
399
+ vectorMaintenanceStatus(indexName: string): VectorMaintenanceResult[];
400
+ /**
401
+ * Starts delivering one kind of engine event to your listener.
402
+ *
403
+ * These events report work the engine does on its own, away from the call
404
+ * that triggered it, so this is where a failed background save or a worker
405
+ * crash reaches you.
406
+ *
407
+ * @typeParam K - The event name, which fixes the payload the listener gets.
408
+ * @param event - Which event to listen for.
409
+ * @param handler - Called once per event.
410
+ */
411
+ on<K extends keyof NarsilEventMap>(event: K, handler: (payload: NarsilEventMap[K]) => void): void;
412
+ /**
413
+ * Removes a listener {@link Narsil.on} registered, so it receives no
414
+ * further events.
415
+ *
416
+ * @typeParam K - The event name.
417
+ * @param event - The event the listener was registered for.
418
+ * @param handler - The same function reference that was registered.
419
+ */
420
+ off<K extends keyof NarsilEventMap>(event: K, handler: (payload: NarsilEventMap[K]) => void): void;
421
+ /**
422
+ * Closes the engine: it flushes pending writes, ends its workers, and
423
+ * releases every adapter it opened.
424
+ *
425
+ * Call it before the process exits, because writes still in flight are lost
426
+ * otherwise. The engine rejects new work once this starts.
427
+ */
428
+ shutdown(): Promise<void>;
429
+ }
430
+
431
+ export type { Narsil as N, NarsilEventMap as a };
@@ -92,8 +92,18 @@ var ErrorCodes = {
92
92
  SNAPSHOT_SYNC_ABORTED: "SNAPSHOT_SYNC_ABORTED"
93
93
  };
94
94
  var NarsilError = class extends Error {
95
+ /** This says which failure it is. */
95
96
  code;
97
+ /** This carries the values behind the failure, such as the field, index, or limit involved. It is empty when the code says everything. */
96
98
  details;
99
+ /**
100
+ * Builds an error carrying a code the caller can branch on.
101
+ *
102
+ * @param code - The failure this error reports.
103
+ * @param message - Plain description, for a log or a person.
104
+ * @param details - Values behind the failure, which reach
105
+ * {@link NarsilError.details}.
106
+ */
97
107
  constructor(code, message, details) {
98
108
  super(message);
99
109
  this.name = "NarsilError";
@@ -16689,18 +16699,7 @@ function readProcessMemory() {
16689
16699
  }
16690
16700
  }
16691
16701
 
16692
- // src/narsil.ts
16693
- async function createNarsil(config) {
16694
- const core = createEngineCore(config);
16695
- if (core.durability) {
16696
- await core.durability.manager.recover();
16697
- }
16698
- if (core.invalidation) {
16699
- await core.invalidation.start();
16700
- }
16701
- await core.analysisRebuild.reviewStaleIndexes();
16702
- return createNarsilFromCore(core, config);
16703
- }
16702
+ // src/narsil/operations.ts
16704
16703
  function createNarsilFromCore(core, config) {
16705
16704
  const {
16706
16705
  executor,
@@ -17002,6 +17001,19 @@ function createNarsilFromCore(core, config) {
17002
17001
  return narsil;
17003
17002
  }
17004
17003
 
17004
+ // src/narsil/index.ts
17005
+ async function createNarsil(config) {
17006
+ const core = createEngineCore(config);
17007
+ if (core.durability) {
17008
+ await core.durability.manager.recover();
17009
+ }
17010
+ if (core.invalidation) {
17011
+ await core.invalidation.start();
17012
+ }
17013
+ await core.analysisRebuild.reviewStaleIndexes();
17014
+ return createNarsilFromCore(core, config);
17015
+ }
17016
+
17005
17017
  // src/index.ts
17006
17018
  var VERSION = "0.1.0";
17007
17019