@delali/narsil 0.3.0 → 0.3.1-next.102
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.
- package/README.md +9 -8
- package/dist/adapters/filesystem.d.ts +1 -1
- package/dist/adapters/filesystem.mjs +1 -1
- package/dist/adapters/indexeddb.d.ts +1 -1
- package/dist/adapters/indexeddb.mjs +1 -1
- package/dist/adapters/memory.d.ts +1 -1
- package/dist/{adapters-79OIa4xm.d.ts → adapters-BQFQ4PRz.d.ts} +27 -1
- package/dist/browser/chunk-BDOSMEEP.mjs +493 -0
- package/dist/browser/chunk-EJDUFWSO.mjs +602 -0
- package/dist/browser/chunk-HOZW3PKP.mjs +9 -0
- package/dist/browser/chunk-JOVZ6HMT.mjs +4358 -0
- package/dist/browser/chunk-JPTQZWJQ.mjs +10 -0
- package/dist/browser/chunk-KPJMDPHG.mjs +24558 -0
- package/dist/browser/chunk-PGIM3HIM.mjs +2743 -0
- package/dist/browser/chunk-RHG4O77A.mjs +206 -0
- package/dist/browser/chunk-RIJSLY2I.mjs +360 -0
- package/dist/browser/durability-wiring-SRUYT3VV.mjs +3875 -0
- package/dist/browser/module-CBB2ETYP.mjs +3111 -0
- package/dist/browser/release-76MXRPGV.mjs +33 -0
- package/dist/browser/replace-RURXTGVG.mjs +57 -0
- package/dist/browser/restore-queue-EEZQO6RF.mjs +35 -0
- package/dist/browser/runtime-7ZAHCHWR.mjs +557 -0
- package/dist/browser/snapshot-OAAA5UJ7.mjs +1210 -0
- package/dist/browser/write-7D6VIK6O.mjs +208 -0
- package/dist/{capabilities-DSsOGz6F.d.ts → capabilities-ByQRMOx-.d.ts} +68 -7
- package/dist/chunk-2RIRGOUL.mjs +113 -0
- package/dist/chunk-37CD3OKS.mjs +87 -0
- package/dist/chunk-44W3CBNG.mjs +7 -0
- package/dist/chunk-46D6JQIG.mjs +426 -0
- package/dist/{chunk-VMRR3DQU.mjs → chunk-5JNA5SKS.mjs} +546 -35
- package/dist/chunk-747OHOUA.mjs +11 -0
- package/dist/chunk-75XIEF6H.mjs +126 -0
- package/dist/chunk-7X5JST5L.mjs +114 -0
- package/dist/chunk-BOFBLJFZ.mjs +209 -0
- package/dist/{chunk-USKFU7J5.mjs → chunk-BWJVNZPR.mjs} +8 -1
- package/dist/chunk-C7SLA6CM.mjs +19 -0
- package/dist/{chunk-POWOTUKJ.mjs → chunk-CQUMNIIG.mjs} +3 -6
- package/dist/chunk-CVXLLEQ3.mjs +1011 -0
- package/dist/chunk-DJHHF2L5.mjs +17 -0
- package/dist/chunk-E74YLAIG.mjs +24 -0
- package/dist/{chunk-UXNWQZST.mjs → chunk-EMRMGYRE.mjs} +236 -18
- package/dist/chunk-EWZLIYHV.mjs +57 -0
- package/dist/chunk-GBEEG5AN.mjs +35 -0
- package/dist/chunk-GES7U2PM.mjs +68 -0
- package/dist/chunk-HJSN7UYG.mjs +10 -0
- package/dist/chunk-HLPRHOSO.mjs +17 -0
- package/dist/chunk-HMFNFVP7.mjs +14 -0
- package/dist/chunk-J5QP52HA.mjs +1751 -0
- package/dist/{chunk-YNVIUGF5.mjs → chunk-JZVARCRZ.mjs} +3 -28
- package/dist/chunk-KOKM4PQN.mjs +52 -0
- package/dist/{chunk-B2TFROFX.mjs → chunk-KWTW6VTG.mjs} +465 -250
- package/dist/chunk-KZ3NX2P7.mjs +21 -0
- package/dist/chunk-L5ORED7V.mjs +25 -0
- package/dist/{chunk-THYRHHO2.mjs → chunk-LGAMKHA2.mjs} +2009 -2351
- package/dist/chunk-LKOB5COA.mjs +117 -0
- package/dist/chunk-LPQOEU5M.mjs +96 -0
- package/dist/{chunk-3LHGNRYE.mjs → chunk-LXWDQLTW.mjs} +7 -2
- package/dist/{chunk-L6TNPLAR.mjs → chunk-OEYI3KRB.mjs} +270 -108
- package/dist/chunk-OM362BRO.mjs +948 -0
- package/dist/chunk-OZDFA4WC.mjs +67 -0
- package/dist/chunk-P36MUFEJ.mjs +10 -0
- package/dist/chunk-PC2G76VW.mjs +2540 -0
- package/dist/{chunk-GCM3JFVA.mjs → chunk-PNEYIHA4.mjs} +11 -2
- package/dist/chunk-PNFKUCG3.mjs +1130 -0
- package/dist/chunk-Q6XWVUZX.mjs +44 -0
- package/dist/chunk-R27EMH5M.mjs +617 -0
- package/dist/{chunk-YMZCMH5M.mjs → chunk-R6A773WK.mjs} +19 -24
- package/dist/chunk-RF7PLG43.mjs +106 -0
- package/dist/chunk-RFBLQLLZ.mjs +16 -0
- package/dist/{chunk-Y3L5MDRV.mjs → chunk-RFVUDM5E.mjs} +17 -2
- package/dist/chunk-S7FL6UAH.mjs +521 -0
- package/dist/chunk-S7GNDRPS.mjs +651 -0
- package/dist/chunk-SP3NM3ZG.mjs +3537 -0
- package/dist/chunk-U476IXKQ.mjs +10 -0
- package/dist/chunk-UA3AUGNV.mjs +462 -0
- package/dist/chunk-UTG5YNXV.mjs +507 -0
- package/dist/chunk-VI4R6W25.mjs +8484 -0
- package/dist/chunk-WQBCBKY3.mjs +8 -0
- package/dist/{chunk-24RXHMEL.mjs → chunk-WVCOCKBU.mjs} +3794 -7570
- package/dist/chunk-X5CV2E2B.mjs +1 -0
- package/dist/chunk-XADZPPZI.mjs +614 -0
- package/dist/chunk-YEEQHT4V.mjs +212 -0
- package/dist/chunk-YTJCGKM4.mjs +56 -0
- package/dist/chunk-YYQIODMF.mjs +275 -0
- package/dist/chunk-ZI34TVOA.mjs +144 -0
- package/dist/{chunk-OOSIDHA3.mjs → chunk-ZKWYWW4Y.mjs} +1 -1
- package/dist/chunk-ZM7KU4YW.mjs +35 -0
- package/dist/{client-BQK6Tf6A.d.ts → client-BOStAkc5.d.ts} +160 -37
- package/dist/client.d.ts +11 -10
- package/dist/client.mjs +209 -45
- package/dist/{config-DmXULPa-.d.ts → config-Cjvzbs_j.d.ts} +51 -3
- package/dist/config-H6SGzbPH.d.ts +421 -0
- package/dist/direct-executor-ZD64PPEZ.mjs +24 -0
- package/dist/distribution/coordinator/etcd.d.ts +79 -18
- package/dist/distribution/coordinator/etcd.mjs +553 -109
- package/dist/distribution/coordinator/in-memory.d.ts +4 -3
- package/dist/distribution/coordinator/in-memory.mjs +22 -3
- package/dist/distribution/transport/grpc.d.ts +2 -2
- package/dist/distribution/transport/grpc.mjs +79 -14
- package/dist/distribution/transport/in-memory.d.ts +2 -2
- package/dist/distribution/transport/in-memory.mjs +12 -7
- package/dist/distribution/transport/tcp.d.ts +2 -2
- package/dist/distribution/transport/tcp.mjs +50 -28
- package/dist/distribution.d.ts +144 -23
- package/dist/distribution.mjs +14479 -8173
- package/dist/durability-wiring-FEUBR5BT.mjs +3330 -0
- package/dist/embeddings/openai.d.ts +2 -2
- package/dist/embeddings/openai.mjs +22 -133
- package/dist/{engine-CIOyFozK.d.ts → engine-rC0vjjY-.d.ts} +165 -141
- package/dist/{memory-yFaVn2xZ.d.ts → events-DqOIg5xa.d.ts} +645 -136
- package/dist/{types-DAK7mnUZ.d.ts → index-Bkdt8nDw.d.ts} +182 -45
- package/dist/index.browser.mjs +4 -32180
- package/dist/index.d.ts +91 -20
- package/dist/index.mjs +33 -16
- package/dist/invalidation/broadcast-channel.d.ts +1 -1
- package/dist/invalidation/filesystem.d.ts +1 -1
- package/dist/invalidation/filesystem.mjs +2 -1
- package/dist/invalidation/noop.d.ts +1 -1
- package/dist/module-3S65MVCM.mjs +2151 -0
- package/dist/partial-words-DTIHO8G4.d.ts +19 -0
- package/dist/partial-words.d.ts +22 -0
- package/dist/partial-words.mjs +17 -0
- package/dist/pattern-Cledccbl.d.ts +18 -0
- package/dist/pattern.d.ts +22 -0
- package/dist/pattern.mjs +12 -0
- package/dist/persistence/durability/checkpoint-worker.d.ts +119 -72
- package/dist/persistence/durability/checkpoint-worker.mjs +51 -18
- package/dist/react.d.ts +279 -183
- package/dist/react.mjs +201 -48
- package/dist/release-BH3DKW3T.mjs +33 -0
- package/dist/replace-CEO5KJJ3.mjs +57 -0
- package/dist/rerank-K7C4WZFG.mjs +60 -0
- package/dist/rerankers/http.d.ts +50 -0
- package/dist/rerankers/http.mjs +104 -0
- package/dist/restore-queue-KQHA7ZV2.mjs +35 -0
- package/dist/runtime-6Y4ZYXOG.mjs +177 -0
- package/dist/{schema-d5Afu03A.d.ts → schema-4W_7tk1f.d.ts} +81 -11
- package/dist/server.d.ts +13 -12
- package/dist/server.mjs +611 -80
- package/dist/snapshot-QGZPODM5.mjs +799 -0
- package/dist/synonyms-CpOAHPa-.d.ts +52 -0
- package/dist/synonyms.d.ts +22 -0
- package/dist/synonyms.mjs +12 -0
- package/dist/{tasks-CH2Dod8w.d.ts → tasks-CwPTz-tP.d.ts} +10 -3
- package/dist/thread-N3IUGUS3.mjs +697 -0
- package/dist/{types-BQDlIvfS.d.ts → types-2qoitTXg.d.ts} +1 -1
- package/dist/{types-D5OwhtsQ.d.ts → types-Cz5okLml.d.ts} +2 -2
- package/dist/vector/search-worker.d.ts +46 -4
- package/dist/vector/search-worker.mjs +21 -11
- package/dist/workers/entry.mjs +9 -6
- package/dist/write-U5RI7MAX.mjs +241 -0
- package/package.json +55 -9
- package/dist/chunk-3L4U6EJQ.mjs +0 -49
- package/dist/chunk-IFBKLBGB.mjs +0 -7
- package/dist/chunk-ORBLD3EL.mjs +0 -6
- package/dist/chunk-U7KYW4BA.mjs +0 -135
- package/dist/chunk-ZJ4CSAB2.mjs +0 -13
- package/dist/chunk-ZNZBXMP5.mjs +0 -2117
- package/dist/chunk-ZZT3EAUC.mjs +0 -11168
- package/dist/config-BhldZgaK.d.ts +0 -194
- package/dist/direct-executor-ALAVE7FC.mjs +0 -12
- package/dist/serialization/crc32-worker.d.ts +0 -20
- package/dist/serialization/crc32-worker.mjs +0 -62
- package/dist/simd-DW5AtJ6B.d.ts +0 -41
- package/dist/thread-DYHEQRVY.mjs +0 -402
package/dist/client.mjs
CHANGED
|
@@ -31,14 +31,18 @@ var ErrorCodes = {
|
|
|
31
31
|
SEARCH_INVALID_MODE: "SEARCH_INVALID_MODE",
|
|
32
32
|
SEARCH_INVALID_CURSOR: "SEARCH_INVALID_CURSOR",
|
|
33
33
|
SEARCH_RESULT_WINDOW_EXCEEDED: "SEARCH_RESULT_WINDOW_EXCEEDED",
|
|
34
|
+
SEARCH_WORK_CAP_EXCEEDED: "SEARCH_WORK_CAP_EXCEEDED",
|
|
34
35
|
LANGUAGE_NOT_SUPPORTED: "LANGUAGE_NOT_SUPPORTED",
|
|
35
36
|
ENVELOPE_VERSION_MISMATCH: "ENVELOPE_VERSION_MISMATCH",
|
|
36
37
|
ENVELOPE_INVALID_MAGIC: "ENVELOPE_INVALID_MAGIC",
|
|
37
38
|
PARTITION_CAPACITY_EXCEEDED: "PARTITION_CAPACITY_EXCEEDED",
|
|
39
|
+
RESTORE_MEMORY_EXCEEDED: "RESTORE_MEMORY_EXCEEDED",
|
|
38
40
|
EMBEDDING_FAILED: "EMBEDDING_FAILED",
|
|
39
41
|
EMBEDDING_DIMENSION_MISMATCH: "EMBEDDING_DIMENSION_MISMATCH",
|
|
40
42
|
EMBEDDING_NO_SOURCE: "EMBEDDING_NO_SOURCE",
|
|
41
43
|
EMBEDDING_CONFIG_INVALID: "EMBEDDING_CONFIG_INVALID",
|
|
44
|
+
RERANK_FAILED: "RERANK_FAILED",
|
|
45
|
+
RERANK_CONFIG_INVALID: "RERANK_CONFIG_INVALID",
|
|
42
46
|
DOC_MISSING_REQUIRED_FIELD: "DOC_MISSING_REQUIRED_FIELD",
|
|
43
47
|
CONFIG_INVALID: "CONFIG_INVALID",
|
|
44
48
|
QUERY_ROUTING_FAILED: "QUERY_ROUTING_FAILED",
|
|
@@ -46,6 +50,7 @@ var ErrorCodes = {
|
|
|
46
50
|
QUERY_NODE_TIMEOUT: "QUERY_NODE_TIMEOUT",
|
|
47
51
|
QUERY_NO_ACTIVE_REPLICA: "QUERY_NO_ACTIVE_REPLICA",
|
|
48
52
|
CLUSTER_OPERATION_UNSUPPORTED: "CLUSTER_OPERATION_UNSUPPORTED",
|
|
53
|
+
CLUSTER_WRITE_BLOCKED: "CLUSTER_WRITE_BLOCKED",
|
|
49
54
|
ALLOCATION_NO_DATA_NODES: "ALLOCATION_NO_DATA_NODES",
|
|
50
55
|
ALLOCATION_INVALID_CONFIG: "ALLOCATION_INVALID_CONFIG",
|
|
51
56
|
ALLOCATION_FAILED: "ALLOCATION_FAILED",
|
|
@@ -55,7 +60,10 @@ var ErrorCodes = {
|
|
|
55
60
|
NODE_NOT_JOINED: "NODE_NOT_JOINED",
|
|
56
61
|
NODE_NOT_READY: "NODE_NOT_READY",
|
|
57
62
|
NODE_NOT_CONTROLLER: "NODE_NOT_CONTROLLER",
|
|
63
|
+
NODE_VERSION_INCOMPATIBLE: "NODE_VERSION_INCOMPATIBLE",
|
|
58
64
|
COORDINATOR_DEPENDENCY_MISSING: "COORDINATOR_DEPENDENCY_MISSING",
|
|
65
|
+
COORDINATOR_AUTH_FAILED: "COORDINATOR_AUTH_FAILED",
|
|
66
|
+
COORDINATOR_UNAVAILABLE: "COORDINATOR_UNAVAILABLE",
|
|
59
67
|
TRANSPORT_DEPENDENCY_MISSING: "TRANSPORT_DEPENDENCY_MISSING",
|
|
60
68
|
REPLICATION_ENTRY_INVALID: "REPLICATION_ENTRY_INVALID",
|
|
61
69
|
REPLICATION_INSYNC_REMOVAL_FAILED: "REPLICATION_INSYNC_REMOVAL_FAILED",
|
|
@@ -71,7 +79,6 @@ var ErrorCodes = {
|
|
|
71
79
|
SNAPSHOT_SYNC_UNAUTHORIZED: "SNAPSHOT_SYNC_UNAUTHORIZED",
|
|
72
80
|
SNAPSHOT_SYNC_REQUEST_INVALID: "SNAPSHOT_SYNC_REQUEST_INVALID",
|
|
73
81
|
SNAPSHOT_SYNC_INDEX_NOT_FOUND: "SNAPSHOT_SYNC_INDEX_NOT_FOUND",
|
|
74
|
-
SNAPSHOT_SYNC_TOO_LARGE: "SNAPSHOT_SYNC_TOO_LARGE",
|
|
75
82
|
SNAPSHOT_SYNC_CAPACITY_EXHAUSTED: "SNAPSHOT_SYNC_CAPACITY_EXHAUSTED",
|
|
76
83
|
SNAPSHOT_SYNC_SNAPSHOT_FAILED: "SNAPSHOT_SYNC_SNAPSHOT_FAILED",
|
|
77
84
|
SNAPSHOT_SYNC_DECODE_FAILED: "SNAPSHOT_SYNC_DECODE_FAILED",
|
|
@@ -154,12 +161,16 @@ var TASK_CANCEL_CAPABILITY = "tasks.cancel";
|
|
|
154
161
|
var TASK_FILTER_CAPABILITY = "tasks.filter";
|
|
155
162
|
var REBUILD_ANALYSIS_CAPABILITY = "indexes.rebuildAnalysis";
|
|
156
163
|
var INDEX_LIFECYCLE_CAPABILITY = "indexes.lifecycle";
|
|
164
|
+
var DOCUMENT_EXPORT_CAPABILITY = "indexes.documentExport";
|
|
165
|
+
var SYNONYMS_CAPABILITY = "indexes.synonyms";
|
|
157
166
|
var SERVER_CAPABILITIES = [
|
|
158
167
|
ASYNC_IMPORT_CAPABILITY,
|
|
159
168
|
TASK_CANCEL_CAPABILITY,
|
|
160
169
|
TASK_FILTER_CAPABILITY,
|
|
161
170
|
REBUILD_ANALYSIS_CAPABILITY,
|
|
162
|
-
INDEX_LIFECYCLE_CAPABILITY
|
|
171
|
+
INDEX_LIFECYCLE_CAPABILITY,
|
|
172
|
+
DOCUMENT_EXPORT_CAPABILITY,
|
|
173
|
+
SYNONYMS_CAPABILITY
|
|
163
174
|
];
|
|
164
175
|
|
|
165
176
|
// src/json-encoding.ts
|
|
@@ -177,6 +188,8 @@ function encodeJson(value) {
|
|
|
177
188
|
var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
|
|
178
189
|
var NO_TIMEOUT = 0;
|
|
179
190
|
var DEFAULT_TASK_POLL_INTERVAL_MS = 250;
|
|
191
|
+
var DEFAULT_URL_SKIP_MS = 1e3;
|
|
192
|
+
var DEFAULT_MAX_URL_SKIP_MS = 3e4;
|
|
180
193
|
|
|
181
194
|
// src/client/paths.ts
|
|
182
195
|
function indexPath(indexName) {
|
|
@@ -240,10 +253,9 @@ function createAdminOperations(transport) {
|
|
|
240
253
|
await transport.json({ method: "POST", path: `${indexPath(indexName)}/_checkpoint`, options });
|
|
241
254
|
},
|
|
242
255
|
snapshot(indexName, options) {
|
|
243
|
-
return transport.
|
|
256
|
+
return transport.stream({
|
|
244
257
|
method: "GET",
|
|
245
258
|
path: `${indexPath(indexName)}/snapshot`,
|
|
246
|
-
binaryAnswer: true,
|
|
247
259
|
defaultTimeoutMs: NO_TIMEOUT,
|
|
248
260
|
options
|
|
249
261
|
});
|
|
@@ -260,6 +272,26 @@ function createAdminOperations(transport) {
|
|
|
260
272
|
});
|
|
261
273
|
return readBody(payload, path);
|
|
262
274
|
},
|
|
275
|
+
exportDocuments(indexName, options) {
|
|
276
|
+
return transport.stream({
|
|
277
|
+
method: "GET",
|
|
278
|
+
path: `${indexPath(indexName)}/export`,
|
|
279
|
+
defaultTimeoutMs: NO_TIMEOUT,
|
|
280
|
+
options
|
|
281
|
+
});
|
|
282
|
+
},
|
|
283
|
+
async importDocumentExport(indexName, data, options) {
|
|
284
|
+
const path = `${indexPath(indexName)}/import`;
|
|
285
|
+
const payload = await transport.json({
|
|
286
|
+
method: "POST",
|
|
287
|
+
path,
|
|
288
|
+
body: data,
|
|
289
|
+
contentType: "application/x-ndjson",
|
|
290
|
+
defaultTimeoutMs: NO_TIMEOUT,
|
|
291
|
+
options
|
|
292
|
+
});
|
|
293
|
+
return readBody(payload, path);
|
|
294
|
+
},
|
|
263
295
|
async vectorMaintenanceStatus(indexName, options) {
|
|
264
296
|
const path = `${indexPath(indexName)}/vector-maintenance`;
|
|
265
297
|
const payload = await transport.json({ method: "GET", path, options });
|
|
@@ -285,6 +317,17 @@ function createAdminOperations(transport) {
|
|
|
285
317
|
async updatePartitionConfig(indexName, partitionConfig, options) {
|
|
286
318
|
await postJson(`${indexPath(indexName)}/partition-config`, partitionConfig, options);
|
|
287
319
|
},
|
|
320
|
+
async updateSynonyms(indexName, synonyms, options) {
|
|
321
|
+
await postJson(`${indexPath(indexName)}/synonyms`, { synonyms }, options);
|
|
322
|
+
},
|
|
323
|
+
async getSynonyms(indexName, options) {
|
|
324
|
+
const path = `${indexPath(indexName)}/synonyms`;
|
|
325
|
+
const body = await readBody(
|
|
326
|
+
await transport.json({ method: "GET", path, options }),
|
|
327
|
+
path
|
|
328
|
+
);
|
|
329
|
+
return body.synonyms;
|
|
330
|
+
},
|
|
288
331
|
async rebuildAnalysis(indexName, options) {
|
|
289
332
|
const path = `${indexPath(indexName)}/_rebuild-analysis`;
|
|
290
333
|
return readBody(await transport.json({ method: "POST", path, options }), path);
|
|
@@ -362,6 +405,7 @@ function createBulkOperations(transport) {
|
|
|
362
405
|
path,
|
|
363
406
|
body: encodeJson({ docIds }),
|
|
364
407
|
contentType: "application/json",
|
|
408
|
+
repeatable: true,
|
|
365
409
|
options
|
|
366
410
|
});
|
|
367
411
|
const documents = readObject(payload, "documents", path);
|
|
@@ -374,6 +418,7 @@ function createBulkOperations(transport) {
|
|
|
374
418
|
path,
|
|
375
419
|
body: encodeJson(params ?? {}),
|
|
376
420
|
contentType: "application/json",
|
|
421
|
+
repeatable: true,
|
|
377
422
|
options
|
|
378
423
|
});
|
|
379
424
|
return readBody(payload, path);
|
|
@@ -455,6 +500,72 @@ function createDocumentOperations(transport) {
|
|
|
455
500
|
};
|
|
456
501
|
}
|
|
457
502
|
|
|
503
|
+
// src/client/failover.ts
|
|
504
|
+
var UNSENT_CONNECTION_CODES = /* @__PURE__ */ new Set(["ECONNREFUSED", "ENOTFOUND", "EAI_AGAIN", "ConnectionRefused"]);
|
|
505
|
+
var MAX_CAUSE_DEPTH = 4;
|
|
506
|
+
var SKIP_DOUBLING_CEILING = 30;
|
|
507
|
+
var RETRIED_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
|
|
508
|
+
function readSkip(value, fallback, field) {
|
|
509
|
+
if (value === void 0) return fallback;
|
|
510
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
511
|
+
throw new NarsilError(ErrorCodes.CONFIG_INVALID, `"${field}" must be a whole number of milliseconds, 0 or more`, {
|
|
512
|
+
[field]: value
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
return value;
|
|
516
|
+
}
|
|
517
|
+
function createUrlPool(bases, options) {
|
|
518
|
+
const skipMs = readSkip(options.urlSkipMs, DEFAULT_URL_SKIP_MS, "urlSkipMs");
|
|
519
|
+
const maxSkipMs = readSkip(options.maxUrlSkipMs, Math.max(DEFAULT_MAX_URL_SKIP_MS, skipMs), "maxUrlSkipMs");
|
|
520
|
+
if (maxSkipMs < skipMs) {
|
|
521
|
+
throw new NarsilError(ErrorCodes.CONFIG_INVALID, '"maxUrlSkipMs" must be at least "urlSkipMs"', {
|
|
522
|
+
urlSkipMs: skipMs,
|
|
523
|
+
maxUrlSkipMs: maxSkipMs
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
const entries = bases.map((base, position) => ({ base, position, refusals: 0, skipUntil: 0 }));
|
|
527
|
+
let nextStart = 0;
|
|
528
|
+
return {
|
|
529
|
+
order(now) {
|
|
530
|
+
const rotation = [...entries.slice(nextStart), ...entries.slice(0, nextStart)];
|
|
531
|
+
const open = rotation.filter((entry) => entry.skipUntil <= now);
|
|
532
|
+
const skipped = rotation.filter((entry) => entry.skipUntil > now).sort((a, b) => a.skipUntil - b.skipUntil);
|
|
533
|
+
return [...open, ...skipped];
|
|
534
|
+
},
|
|
535
|
+
took(entry) {
|
|
536
|
+
nextStart = (entry.position + 1) % entries.length;
|
|
537
|
+
},
|
|
538
|
+
answered(entry) {
|
|
539
|
+
entry.refusals = 0;
|
|
540
|
+
entry.skipUntil = 0;
|
|
541
|
+
},
|
|
542
|
+
refused(entry, now) {
|
|
543
|
+
entry.refusals += 1;
|
|
544
|
+
const doublings = Math.min(entry.refusals - 1, SKIP_DOUBLING_CEILING);
|
|
545
|
+
entry.skipUntil = now + Math.min(skipMs * 2 ** doublings, maxSkipMs);
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
function failedBeforeSending(error, depth = 0) {
|
|
550
|
+
if (depth > MAX_CAUSE_DEPTH || typeof error !== "object" || error === null) return false;
|
|
551
|
+
const { code, cause, errors } = error;
|
|
552
|
+
if (typeof code === "string" && UNSENT_CONNECTION_CODES.has(code)) return true;
|
|
553
|
+
if (failedBeforeSending(cause, depth + 1)) return true;
|
|
554
|
+
return Array.isArray(errors) && errors.length > 0 && errors.every((entry) => failedBeforeSending(entry, depth + 1));
|
|
555
|
+
}
|
|
556
|
+
function answersUnavailable(status) {
|
|
557
|
+
return RETRIED_STATUSES.has(status);
|
|
558
|
+
}
|
|
559
|
+
function movesOnAfterAnswer(status, code, repeatable) {
|
|
560
|
+
if (!answersUnavailable(status)) return false;
|
|
561
|
+
return repeatable || code === ErrorCodes.NODE_NOT_READY;
|
|
562
|
+
}
|
|
563
|
+
function movesOnAfterFailure(failure, sentNothing, repeatable) {
|
|
564
|
+
if (failure.code === ClientErrorCodes.CLIENT_REQUEST_TIMEOUT) return repeatable;
|
|
565
|
+
if (failure.code === ClientErrorCodes.CLIENT_CONNECTION_FAILED) return repeatable || sentNothing;
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
568
|
+
|
|
458
569
|
// src/client/http.ts
|
|
459
570
|
function isRecord2(value) {
|
|
460
571
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -516,20 +627,14 @@ async function readStreamCapped(stream, limitBytes) {
|
|
|
516
627
|
}
|
|
517
628
|
return body;
|
|
518
629
|
}
|
|
519
|
-
async function readAnswer(response, limitBytes
|
|
630
|
+
async function readAnswer(response, limitBytes) {
|
|
520
631
|
const stream = response.body;
|
|
521
632
|
if (limitBytes > 0 && stream !== null && stream !== void 0) {
|
|
522
|
-
|
|
523
|
-
return wantsBytes ? { text: "", bytes: body } : { text: new TextDecoder().decode(body), bytes: null };
|
|
524
|
-
}
|
|
525
|
-
if (wantsBytes) {
|
|
526
|
-
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
527
|
-
if (limitBytes > 0 && bytes.byteLength > limitBytes) throw new ResponseTooLargeError(limitBytes);
|
|
528
|
-
return { text: "", bytes };
|
|
633
|
+
return new TextDecoder().decode(await readStreamCapped(stream, limitBytes));
|
|
529
634
|
}
|
|
530
635
|
const text = await response.text();
|
|
531
636
|
if (limitBytes > 0 && text.length > limitBytes) throw new ResponseTooLargeError(limitBytes);
|
|
532
|
-
return
|
|
637
|
+
return text;
|
|
533
638
|
}
|
|
534
639
|
function invalidResponse(message, details) {
|
|
535
640
|
return new NarsilError(ClientErrorCodes.CLIENT_INVALID_RESPONSE, message, details);
|
|
@@ -564,6 +669,51 @@ function normaliseBase(url) {
|
|
|
564
669
|
}
|
|
565
670
|
return trimmed.replace(/\/+$/, "");
|
|
566
671
|
}
|
|
672
|
+
function normaliseBases(url) {
|
|
673
|
+
if (typeof url === "string") return [normaliseBase(url)];
|
|
674
|
+
if (!Array.isArray(url) || url.length === 0) {
|
|
675
|
+
throw new NarsilError(ErrorCodes.CONFIG_INVALID, 'The client needs a server address, and "url" lists none');
|
|
676
|
+
}
|
|
677
|
+
return url.map((entry) => {
|
|
678
|
+
if (typeof entry !== "string") {
|
|
679
|
+
throw new NarsilError(ErrorCodes.CONFIG_INVALID, 'Every server address in "url" must be a string');
|
|
680
|
+
}
|
|
681
|
+
return normaliseBase(entry);
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
function translateFailure(err, url, timeoutMs, expired, caller) {
|
|
685
|
+
if (err instanceof ResponseTooLargeError) {
|
|
686
|
+
return invalidResponse(`The server at ${url} answered more than this client reads: ${err.message}`, {
|
|
687
|
+
url,
|
|
688
|
+
maxResponseBytes: err.limitBytes
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
if (expired) {
|
|
692
|
+
return new NarsilError(
|
|
693
|
+
ClientErrorCodes.CLIENT_REQUEST_TIMEOUT,
|
|
694
|
+
`The server at ${url} did not answer within ${timeoutMs} ms`,
|
|
695
|
+
{ url, timeoutMs }
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
if (caller?.aborted === true) {
|
|
699
|
+
return new NarsilError(ClientErrorCodes.CLIENT_REQUEST_ABORTED, `The caller cancelled the request to ${url}`, {
|
|
700
|
+
url
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
return new NarsilError(
|
|
704
|
+
ClientErrorCodes.CLIENT_CONNECTION_FAILED,
|
|
705
|
+
`The client could not reach ${url}: ${describeError(err)}`,
|
|
706
|
+
{ url }
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
function envelopeCodeOf(text) {
|
|
710
|
+
try {
|
|
711
|
+
const payload = JSON.parse(text);
|
|
712
|
+
return isRecord2(payload) && isRecord2(payload.error) && typeof payload.error.code === "string" ? payload.error.code : void 0;
|
|
713
|
+
} catch {
|
|
714
|
+
return void 0;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
567
717
|
function withQuery(path, query) {
|
|
568
718
|
if (query === void 0) return path;
|
|
569
719
|
const params = new URLSearchParams();
|
|
@@ -574,7 +724,7 @@ function withQuery(path, query) {
|
|
|
574
724
|
return encoded.length === 0 ? path : `${path}?${encoded}`;
|
|
575
725
|
}
|
|
576
726
|
function createTransport(options) {
|
|
577
|
-
const
|
|
727
|
+
const pool = createUrlPool(normaliseBases(options.url), options);
|
|
578
728
|
const send = options.fetch ?? ((input, init) => fetch(input, init));
|
|
579
729
|
const baseHeaders = { ...options.headers };
|
|
580
730
|
if (options.apiKey !== void 0 && options.apiKey.length > 0) {
|
|
@@ -591,45 +741,58 @@ function createTransport(options) {
|
|
|
591
741
|
if (perCall !== void 0) return perCall;
|
|
592
742
|
return options.maxResponseBytes ?? 0;
|
|
593
743
|
}
|
|
594
|
-
async function exchange(spec) {
|
|
744
|
+
async function exchange(spec, keepsStream = false) {
|
|
745
|
+
const repeatable = spec.repeatable === true || spec.method === "GET";
|
|
746
|
+
const replayable = !(spec.body instanceof ReadableStream);
|
|
747
|
+
let last = null;
|
|
748
|
+
for (const entry of pool.order(Date.now())) {
|
|
749
|
+
pool.took(entry);
|
|
750
|
+
const attempt = await exchangeOnce(entry.base, spec, keepsStream);
|
|
751
|
+
if (attempt.kind === "answer") {
|
|
752
|
+
const unavailable = answersUnavailable(attempt.status);
|
|
753
|
+
const code = unavailable ? envelopeCodeOf(attempt.text) : void 0;
|
|
754
|
+
if (!replayable || !movesOnAfterAnswer(attempt.status, code, repeatable)) {
|
|
755
|
+
if (!unavailable) pool.answered(entry);
|
|
756
|
+
return attempt;
|
|
757
|
+
}
|
|
758
|
+
} else {
|
|
759
|
+
if (attempt.error.code === ClientErrorCodes.CLIENT_CONNECTION_FAILED) pool.refused(entry, Date.now());
|
|
760
|
+
if (!replayable || !movesOnAfterFailure(attempt.error, attempt.sentNothing, repeatable)) throw attempt.error;
|
|
761
|
+
}
|
|
762
|
+
last = attempt;
|
|
763
|
+
}
|
|
764
|
+
if (last === null || last.kind === "failure") {
|
|
765
|
+
throw last?.error ?? new NarsilError(ErrorCodes.CONFIG_INVALID, "The client holds no server address");
|
|
766
|
+
}
|
|
767
|
+
return last;
|
|
768
|
+
}
|
|
769
|
+
async function exchangeOnce(base, spec, keepsStream) {
|
|
595
770
|
const url = `${base}${withQuery(spec.path, spec.query)}`;
|
|
596
771
|
const headers = { ...baseHeaders, ...spec.options?.headers };
|
|
597
772
|
if (spec.contentType !== void 0) headers["content-type"] = spec.contentType;
|
|
598
773
|
const timeoutMs = resolveTimeout(spec);
|
|
599
774
|
const deadline = startDeadline(timeoutMs, spec.options?.signal);
|
|
775
|
+
let handedOver = false;
|
|
600
776
|
try {
|
|
601
777
|
const init = { method: spec.method, headers, signal: deadline.signal };
|
|
602
778
|
if (spec.body !== void 0) init.body = spec.body;
|
|
779
|
+
if (spec.body instanceof ReadableStream) init.duplex = "half";
|
|
603
780
|
const response = await send(url, init);
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
if (err instanceof ResponseTooLargeError) {
|
|
609
|
-
throw invalidResponse(`The server at ${url} answered more than this client reads: ${err.message}`, {
|
|
610
|
-
url,
|
|
611
|
-
maxResponseBytes: err.limitBytes
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
if (deadline.expired()) {
|
|
615
|
-
throw new NarsilError(
|
|
616
|
-
ClientErrorCodes.CLIENT_REQUEST_TIMEOUT,
|
|
617
|
-
`The server at ${url} did not answer within ${timeoutMs} ms`,
|
|
618
|
-
{ url, timeoutMs }
|
|
781
|
+
if (keepsStream && response.ok && response.body !== null) {
|
|
782
|
+
handedOver = true;
|
|
783
|
+
const stream = response.body.pipeThrough(
|
|
784
|
+
new TransformStream({ flush: () => deadline.release() })
|
|
619
785
|
);
|
|
786
|
+
return { kind: "answer", status: response.status, url, text: "", stream };
|
|
620
787
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
ClientErrorCodes.CLIENT_CONNECTION_FAILED,
|
|
628
|
-
`The client could not reach ${url}: ${describeError(err)}`,
|
|
629
|
-
{ url }
|
|
630
|
-
);
|
|
788
|
+
const text = await readAnswer(response, resolveResponseCeiling(spec));
|
|
789
|
+
return { kind: "answer", status: response.status, url, stream: null, text };
|
|
790
|
+
} catch (err) {
|
|
791
|
+
const error = translateFailure(err, url, timeoutMs, deadline.expired(), spec.options?.signal);
|
|
792
|
+
const sentNothing = error.code === ClientErrorCodes.CLIENT_CONNECTION_FAILED && failedBeforeSending(err);
|
|
793
|
+
return { kind: "failure", error, sentNothing };
|
|
631
794
|
} finally {
|
|
632
|
-
deadline.release();
|
|
795
|
+
if (!handedOver) deadline.release();
|
|
633
796
|
}
|
|
634
797
|
}
|
|
635
798
|
function parse(status, text, path) {
|
|
@@ -656,9 +819,9 @@ function createTransport(options) {
|
|
|
656
819
|
throw err;
|
|
657
820
|
}
|
|
658
821
|
},
|
|
659
|
-
async
|
|
660
|
-
const { status, text,
|
|
661
|
-
if (
|
|
822
|
+
async stream(spec) {
|
|
823
|
+
const { status, text, stream, url } = await exchange(spec, true);
|
|
824
|
+
if (stream !== null) return stream;
|
|
662
825
|
throw errorFromBody(status, parse(status, text, url), url);
|
|
663
826
|
},
|
|
664
827
|
async probe(spec) {
|
|
@@ -716,6 +879,7 @@ function createSearchOperations(transport) {
|
|
|
716
879
|
path,
|
|
717
880
|
body: encodeJson(params),
|
|
718
881
|
contentType: "application/json",
|
|
882
|
+
repeatable: true,
|
|
719
883
|
options
|
|
720
884
|
});
|
|
721
885
|
return readBody(payload, path);
|
|
@@ -873,4 +1037,4 @@ function createNarsilClient(options) {
|
|
|
873
1037
|
};
|
|
874
1038
|
}
|
|
875
1039
|
|
|
876
|
-
export { ASYNC_IMPORT_CAPABILITY, ClientErrorCodes, ErrorCodes, INDEX_LIFECYCLE_CAPABILITY, NarsilError, REBUILD_ANALYSIS_CAPABILITY, SERVER_CAPABILITIES, ServerErrorCodes, TASK_CANCEL_CAPABILITY, TASK_FILTER_CAPABILITY, createNarsilClient, isNarsilError };
|
|
1040
|
+
export { ASYNC_IMPORT_CAPABILITY, ClientErrorCodes, DOCUMENT_EXPORT_CAPABILITY, ErrorCodes, INDEX_LIFECYCLE_CAPABILITY, NarsilError, REBUILD_ANALYSIS_CAPABILITY, SERVER_CAPABILITIES, SYNONYMS_CAPABILITY, ServerErrorCodes, TASK_CANCEL_CAPABILITY, TASK_FILTER_CAPABILITY, createNarsilClient, isNarsilError };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { P as PersistenceAdapter, I as InvalidationAdapter, E as EmbeddingAdapter } from './adapters-
|
|
2
|
-
import { Q as QueryParams, e as QueryResult } from './
|
|
3
|
-
import { I as IndexConfig, A as AnyDocument } from './schema-
|
|
1
|
+
import { P as PersistenceAdapter, I as InvalidationAdapter, E as EmbeddingAdapter, R as RerankAdapter } from './adapters-BQFQ4PRz.js';
|
|
2
|
+
import { Q as QueryParams, e as QueryResult, f as NarsilEventHandlers } from './events-DqOIg5xa.js';
|
|
3
|
+
import { I as IndexConfig, A as AnyDocument } from './schema-4W_7tk1f.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Hooks that the engine calls alongside its own work, so that an application
|
|
@@ -191,12 +191,60 @@ interface NarsilConfig {
|
|
|
191
191
|
embedding?: EmbeddingAdapter;
|
|
192
192
|
/** Named adapters; names persist in index metadata so recovery can rebind. */
|
|
193
193
|
embeddingAdapters?: Record<string, EmbeddingAdapter>;
|
|
194
|
+
/**
|
|
195
|
+
* These rerank adapters are registered under their keys, so that a query
|
|
196
|
+
* can give a key in `rerank.adapter`. The engine throws
|
|
197
|
+
* `RERANK_CONFIG_INVALID` for an empty key and for an entry without a
|
|
198
|
+
* `rerank` function.
|
|
199
|
+
*/
|
|
200
|
+
rerankAdapters?: Record<string, RerankAdapter>;
|
|
201
|
+
/**
|
|
202
|
+
* The engine waits this many milliseconds for a rerank adapter to score one
|
|
203
|
+
* query, and 30,000 by default. It then cancels the call through the
|
|
204
|
+
* adapter's abort signal and throws `RERANK_FAILED`. Set a whole number of
|
|
205
|
+
* at least 1; {@link createNarsil} throws `CONFIG_INVALID` for any other
|
|
206
|
+
* value.
|
|
207
|
+
*/
|
|
208
|
+
rerankTimeout?: number;
|
|
209
|
+
/**
|
|
210
|
+
* A query may rerank at most this many of its top hits, which caps the
|
|
211
|
+
* documents that one query sends to a model. Set a whole number from 1 to
|
|
212
|
+
* 1,000, or leave it out for 100; {@link createNarsil} throws
|
|
213
|
+
* `CONFIG_INVALID` for any other value.
|
|
214
|
+
*/
|
|
215
|
+
maxRerankWindow?: number;
|
|
194
216
|
/** These settings recover the writes made since the last snapshot. */
|
|
195
217
|
durability?: DurabilityConfig;
|
|
196
218
|
/** These settings control what the engine does when an index's stored analysis differs from its language module. */
|
|
197
219
|
analysis?: AnalysisConfig;
|
|
198
220
|
/** These limits close indexes while keeping their durable files ready to reopen. */
|
|
199
221
|
lifecycle?: IndexLifecycleConfig;
|
|
222
|
+
/**
|
|
223
|
+
* These listeners receive events from the moment that the engine starts.
|
|
224
|
+
* The engine registers each one before it recovers any index, so a listener
|
|
225
|
+
* here receives the `layoutUpgrade` events of that recovery, which come
|
|
226
|
+
* before {@link createNarsil} returns the engine. For a name outside
|
|
227
|
+
* {@link NarsilEventMap}, or an entry that is not a function,
|
|
228
|
+
* {@link createNarsil} throws `CONFIG_INVALID`.
|
|
229
|
+
*/
|
|
230
|
+
events?: NarsilEventHandlers;
|
|
231
|
+
/**
|
|
232
|
+
* This is the most work that the engine may do on the pattern tests of one
|
|
233
|
+
* search, counted over every partition that it searches. The engine adds one
|
|
234
|
+
* unit for each run of three code points that it looks up in a pattern
|
|
235
|
+
* index, one for each entry that it reads from a pattern index, and one for
|
|
236
|
+
* each step of its matcher. For a text whose case fold is shorter than three
|
|
237
|
+
* code points, it counts each document that it checks as an entry that it
|
|
238
|
+
* reads. It counts an `in` or `nin` test as one `eq` test for each distinct
|
|
239
|
+
* value in its list. For an `eq` test with a `tolerance`, it also adds one
|
|
240
|
+
* unit for each cell that it fills in the table of edit distances between
|
|
241
|
+
* the text and a value. Once the count passes the cap, the engine throws
|
|
242
|
+
* `SEARCH_WORK_CAP_EXCEEDED`. The cap
|
|
243
|
+
* defaults to 25,000,000 units. For any value other than a whole number from
|
|
244
|
+
* 1 to `Number.MAX_SAFE_INTEGER`, {@link createNarsil} throws
|
|
245
|
+
* `CONFIG_INVALID`.
|
|
246
|
+
*/
|
|
247
|
+
patternWorkCap?: number;
|
|
200
248
|
}
|
|
201
249
|
/**
|
|
202
250
|
* Limits on the indexes one engine keeps open in memory.
|