@delali/narsil 0.3.1-next.96 → 0.3.1-next.97

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/README.md +2 -1
  2. package/dist/adapters/filesystem.d.ts +1 -1
  3. package/dist/adapters/filesystem.mjs +1 -1
  4. package/dist/adapters/indexeddb.d.ts +1 -1
  5. package/dist/adapters/indexeddb.mjs +1 -1
  6. package/dist/adapters/memory.d.ts +1 -1
  7. package/dist/{adapters-79OIa4xm.d.ts → adapters-BQFQ4PRz.d.ts} +27 -1
  8. package/dist/browser/{chunk-ZGMR46O3.mjs → chunk-CN4I4FZU.mjs} +2 -2
  9. package/dist/browser/chunk-JPTQZWJQ.mjs +10 -0
  10. package/dist/browser/{chunk-WKPJ4E73.mjs → chunk-LD55ZGU3.mjs} +2 -1
  11. package/dist/browser/{chunk-KPMIHLOV.mjs → chunk-NAFT3K6X.mjs} +240 -135
  12. package/dist/browser/{chunk-3MYKLHRO.mjs → chunk-NNG3EEB6.mjs} +5 -4
  13. package/dist/browser/{chunk-HARBSUWP.mjs → chunk-QWES44AW.mjs} +2 -197
  14. package/dist/browser/chunk-RELZRJNR.mjs +203 -0
  15. package/dist/browser/{chunk-FYFQJKFW.mjs → chunk-Z7QH2XHB.mjs} +40 -45
  16. package/dist/browser/{durability-wiring-R7P64REL.mjs → durability-wiring-PY3L7DES.mjs} +7 -5
  17. package/dist/browser/{module-IEOQI5GI.mjs → module-PDXYHT75.mjs} +18 -10
  18. package/dist/browser/{restore-queue-WMYC5ZK6.mjs → restore-queue-DVIYJ7RU.mjs} +1 -1
  19. package/dist/browser/runtime-NYE5TB6O.mjs +557 -0
  20. package/dist/browser/{snapshot-3A3WDNHO.mjs → snapshot-J57MZK6L.mjs} +8 -6
  21. package/dist/browser/{write-JODZHKIF.mjs → write-L7FAQA47.mjs} +6 -4
  22. package/dist/{capabilities-BvxvFzVA.d.ts → capabilities-BTTIs96E.d.ts} +19 -3
  23. package/dist/{chunk-GJZHU4FC.mjs → chunk-2WYMG3OZ.mjs} +4 -4
  24. package/dist/{chunk-H75XXPMY.mjs → chunk-45AVKHMJ.mjs} +2 -2
  25. package/dist/{chunk-QM3VPX4Z.mjs → chunk-ASY5PHYI.mjs} +2 -2
  26. package/dist/{chunk-RDJKYKMQ.mjs → chunk-AY3AQ3UH.mjs} +1 -1
  27. package/dist/{chunk-2BY6K52M.mjs → chunk-BKB3XTMI.mjs} +6 -6
  28. package/dist/{chunk-MWT5WCJ5.mjs → chunk-COVCQ73F.mjs} +5 -5
  29. package/dist/{chunk-FGMGUDHX.mjs → chunk-E74YLAIG.mjs} +4 -1
  30. package/dist/chunk-FMWRCP2C.mjs +57 -0
  31. package/dist/{chunk-ES33L3HO.mjs → chunk-GGSH6KBQ.mjs} +1 -1
  32. package/dist/chunk-HJSN7UYG.mjs +10 -0
  33. package/dist/{chunk-ICL2AELD.mjs → chunk-HXJBSHXF.mjs} +40 -46
  34. package/dist/{chunk-ZHS44YKF.mjs → chunk-JFRNNBOM.mjs} +1 -1
  35. package/dist/{chunk-CHOGQSHK.mjs → chunk-K25LZA54.mjs} +39 -13
  36. package/dist/chunk-K7D4ZTSW.mjs +126 -0
  37. package/dist/{chunk-SYWGORQB.mjs → chunk-KV3AZFT3.mjs} +2 -0
  38. package/dist/chunk-KZ3NX2P7.mjs +21 -0
  39. package/dist/{chunk-GMY7F2VA.mjs → chunk-L3L5YFXC.mjs} +4 -4
  40. package/dist/{chunk-VVFLEGZI.mjs → chunk-LH4NZNJJ.mjs} +10 -10
  41. package/dist/{chunk-7KC56574.mjs → chunk-LU2CE5AE.mjs} +1 -1
  42. package/dist/{chunk-4ZJWRETC.mjs → chunk-LXPIXDUJ.mjs} +2 -2
  43. package/dist/{chunk-Q5DC6WAB.mjs → chunk-LXWDQLTW.mjs} +1 -1
  44. package/dist/{chunk-SBCEHIPL.mjs → chunk-MHOSCQCQ.mjs} +4 -4
  45. package/dist/{chunk-R36MIGBU.mjs → chunk-NKRBEGJZ.mjs} +169 -130
  46. package/dist/{chunk-LJBJQPB5.mjs → chunk-NTRMFARG.mjs} +7 -7
  47. package/dist/chunk-NW4XDSP2.mjs +212 -0
  48. package/dist/{chunk-BB7MASRQ.mjs → chunk-OOEXLUGR.mjs} +1 -1
  49. package/dist/{chunk-3LYY62M6.mjs → chunk-OWNZYMRE.mjs} +10 -10
  50. package/dist/{chunk-HBVLF3HA.mjs → chunk-PPY2GSIB.mjs} +1 -1
  51. package/dist/{chunk-WLOF6HSP.mjs → chunk-R7EEKAJE.mjs} +12 -3
  52. package/dist/{chunk-2GZGBOQI.mjs → chunk-RONEOEON.mjs} +2 -2
  53. package/dist/{chunk-T2QN2FA4.mjs → chunk-UCDF35PU.mjs} +2 -2
  54. package/dist/{chunk-O5WPRAVZ.mjs → chunk-VWULPWRJ.mjs} +60 -21
  55. package/dist/{chunk-F52QGNZ2.mjs → chunk-WCJKUGHB.mjs} +1 -1
  56. package/dist/{chunk-RUIXODYU.mjs → chunk-YA7XLE2R.mjs} +32 -5
  57. package/dist/{chunk-TCYUAUHF.mjs → chunk-ZG477IPV.mjs} +7 -7
  58. package/dist/chunk-ZYNAMIYX.mjs +113 -0
  59. package/dist/{client-DKwterMb.d.ts → client-i9eLJrw5.d.ts} +3 -3
  60. package/dist/client.d.ts +9 -9
  61. package/dist/client.mjs +2 -0
  62. package/dist/{config-6YBtxekG.d.ts → config-BGB_fDtq.d.ts} +2 -2
  63. package/dist/{config-DPphZfuM.d.ts → config-P__Diiy4.d.ts} +25 -3
  64. package/dist/direct-executor-CXZ66ACP.mjs +22 -0
  65. package/dist/distribution/coordinator/etcd.d.ts +3 -3
  66. package/dist/distribution/coordinator/etcd.mjs +1 -1
  67. package/dist/distribution/coordinator/in-memory.d.ts +3 -3
  68. package/dist/distribution/transport/grpc.mjs +1 -1
  69. package/dist/distribution.d.ts +24 -12
  70. package/dist/distribution.mjs +177 -54
  71. package/dist/{durability-wiring-2VBNYYDY.mjs → durability-wiring-QTHOGFMZ.mjs} +26 -25
  72. package/dist/embeddings/openai.d.ts +2 -2
  73. package/dist/embeddings/openai.mjs +22 -133
  74. package/dist/{engine-CbZmXUp6.d.ts → engine-BGCEm9E_.d.ts} +48 -18
  75. package/dist/{index-ONAEaqtx.d.ts → index-lcdGLyJH.d.ts} +1 -1
  76. package/dist/index.browser.mjs +4 -2
  77. package/dist/index.d.ts +8 -8
  78. package/dist/index.mjs +19 -18
  79. package/dist/invalidation/broadcast-channel.d.ts +1 -1
  80. package/dist/invalidation/filesystem.d.ts +1 -1
  81. package/dist/invalidation/noop.d.ts +1 -1
  82. package/dist/{memory-COdoGthn.d.ts → memory-CUEDwr-F.d.ts} +70 -2
  83. package/dist/{module-IUTNXWMV.mjs → module-3NONKBZX.mjs} +25 -18
  84. package/dist/partial-words.mjs +6 -6
  85. package/dist/pattern.mjs +3 -3
  86. package/dist/persistence/durability/checkpoint-worker.d.ts +2 -2
  87. package/dist/persistence/durability/checkpoint-worker.mjs +23 -22
  88. package/dist/react.d.ts +8 -8
  89. package/dist/react.mjs +2 -0
  90. package/dist/rerank-NWTKK636.mjs +60 -0
  91. package/dist/rerankers/http.d.ts +50 -0
  92. package/dist/rerankers/http.mjs +104 -0
  93. package/dist/{restore-queue-UFIQJTSG.mjs → restore-queue-JPRBUYII.mjs} +1 -1
  94. package/dist/runtime-ZKYZFJJC.mjs +177 -0
  95. package/dist/{schema-DttzM-ln.d.ts → schema-4W_7tk1f.d.ts} +2 -2
  96. package/dist/server.d.ts +11 -11
  97. package/dist/server.mjs +63 -22
  98. package/dist/{snapshot-XII3ANGW.mjs → snapshot-HOGXNO5W.mjs} +29 -28
  99. package/dist/synonyms.mjs +3 -3
  100. package/dist/{tasks-BJmamiC4.d.ts → tasks-HG3rlxx6.d.ts} +1 -1
  101. package/dist/{thread-U7XYJWGG.mjs → thread-B657LQXK.mjs} +49 -30
  102. package/dist/vector/search-worker.d.ts +6 -2
  103. package/dist/vector/search-worker.mjs +9 -7
  104. package/dist/workers/entry.mjs +5 -5
  105. package/dist/{write-6M3VG4TU.mjs → write-XLIGTXBU.mjs} +21 -20
  106. package/package.json +11 -7
  107. package/dist/direct-executor-5KJGVQHM.mjs +0 -22
@@ -1,14 +1,14 @@
1
- import { partialWordSearchModule } from './chunk-SBCEHIPL.mjs';
2
- import './chunk-4ZJWRETC.mjs';
3
- import './chunk-FGMGUDHX.mjs';
1
+ import { partialWordSearchModule } from './chunk-MHOSCQCQ.mjs';
2
+ import './chunk-LXPIXDUJ.mjs';
3
+ import './chunk-E74YLAIG.mjs';
4
4
  import './chunk-KEHK2O6P.mjs';
5
5
  import './chunk-GES7U2PM.mjs';
6
- import './chunk-BB7MASRQ.mjs';
7
- import './chunk-7KC56574.mjs';
6
+ import './chunk-OOEXLUGR.mjs';
7
+ import './chunk-LU2CE5AE.mjs';
8
8
  import './chunk-R6A773WK.mjs';
9
9
  import './chunk-YTJCGKM4.mjs';
10
10
  import './chunk-L5ORED7V.mjs';
11
- import './chunk-SYWGORQB.mjs';
11
+ import './chunk-KV3AZFT3.mjs';
12
12
 
13
13
  // src/partial-words/index.ts
14
14
  var partialWordSearch = partialWordSearchModule;
package/dist/pattern.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { patternSearchModule } from './chunk-QM3VPX4Z.mjs';
1
+ import { patternSearchModule } from './chunk-ASY5PHYI.mjs';
2
2
  import './chunk-WQBCBKY3.mjs';
3
3
  import './chunk-GES7U2PM.mjs';
4
- import './chunk-BB7MASRQ.mjs';
4
+ import './chunk-OOEXLUGR.mjs';
5
5
  import './chunk-YTJCGKM4.mjs';
6
6
  import './chunk-L5ORED7V.mjs';
7
- import './chunk-SYWGORQB.mjs';
7
+ import './chunk-KV3AZFT3.mjs';
8
8
 
9
9
  // src/pattern/index.ts
10
10
  var patternSearch = patternSearchModule;
@@ -1,5 +1,5 @@
1
- import { P as PartitionConfig, b as ScoringMode, V as VectorIndexConfig } from '../../schema-DttzM-ln.js';
2
- import '../../adapters-79OIa4xm.js';
1
+ import { P as PartitionConfig, d as ScoringMode, V as VectorIndexConfig } from '../../schema-4W_7tk1f.js';
2
+ import '../../adapters-BQFQ4PRz.js';
3
3
  import '../../synonyms-CpOAHPa-.js';
4
4
 
5
5
  interface PatternIndexArrays {
@@ -1,41 +1,42 @@
1
- import { createDurableDirectory } from '../../chunk-H75XXPMY.mjs';
1
+ import { createDurableDirectory } from '../../chunk-45AVKHMJ.mjs';
2
2
  import '../../chunk-C7SLA6CM.mjs';
3
- import { CHECKPOINT_WORKER_HEARTBEAT_MS, writeCheckpointSegments, directoryCheckpointStore } from '../../chunk-VVFLEGZI.mjs';
4
- import '../../chunk-GMY7F2VA.mjs';
5
- import '../../chunk-OHP7QR33.mjs';
3
+ import { CHECKPOINT_WORKER_HEARTBEAT_MS, writeCheckpointSegments, directoryCheckpointStore } from '../../chunk-LH4NZNJJ.mjs';
4
+ import '../../chunk-L3L5YFXC.mjs';
6
5
  import '../../chunk-P36MUFEJ.mjs';
7
- import '../../chunk-O5WPRAVZ.mjs';
8
- import '../../chunk-R36MIGBU.mjs';
9
- import '../../chunk-RDJKYKMQ.mjs';
10
- import '../../chunk-3LYY62M6.mjs';
11
- import '../../chunk-CHOGQSHK.mjs';
12
- import '../../chunk-WLOF6HSP.mjs';
6
+ import '../../chunk-OHP7QR33.mjs';
7
+ import '../../chunk-VWULPWRJ.mjs';
8
+ import '../../chunk-NKRBEGJZ.mjs';
9
+ import '../../chunk-R7EEKAJE.mjs';
10
+ import '../../chunk-AY3AQ3UH.mjs';
13
11
  import '../../chunk-AV4IJKD2.mjs';
14
- import '../../chunk-Q5DC6WAB.mjs';
15
- import '../../chunk-ZHS44YKF.mjs';
12
+ import '../../chunk-OWNZYMRE.mjs';
13
+ import '../../chunk-K25LZA54.mjs';
14
+ import '../../chunk-JFRNNBOM.mjs';
15
+ import '../../chunk-HJSN7UYG.mjs';
16
+ import '../../chunk-LXWDQLTW.mjs';
16
17
  import '../../chunk-TGP5M5R7.mjs';
17
18
  import '../../chunk-U2BKYEC7.mjs';
18
19
  import '../../chunk-KOKM4PQN.mjs';
19
20
  import '../../chunk-QY7GC2MW.mjs';
20
- import '../../chunk-ES33L3HO.mjs';
21
- import '../../chunk-QM3VPX4Z.mjs';
21
+ import '../../chunk-GGSH6KBQ.mjs';
22
+ import '../../chunk-ASY5PHYI.mjs';
22
23
  import '../../chunk-WQBCBKY3.mjs';
23
- import '../../chunk-SBCEHIPL.mjs';
24
- import '../../chunk-4ZJWRETC.mjs';
25
- import '../../chunk-FGMGUDHX.mjs';
24
+ import '../../chunk-MHOSCQCQ.mjs';
25
+ import '../../chunk-LXPIXDUJ.mjs';
26
+ import '../../chunk-E74YLAIG.mjs';
26
27
  import '../../chunk-KEHK2O6P.mjs';
27
28
  import '../../chunk-GES7U2PM.mjs';
28
- import '../../chunk-BB7MASRQ.mjs';
29
- import '../../chunk-2GZGBOQI.mjs';
29
+ import '../../chunk-OOEXLUGR.mjs';
30
+ import '../../chunk-RONEOEON.mjs';
30
31
  import '../../chunk-X5CV2E2B.mjs';
31
32
  import '../../chunk-7X5JST5L.mjs';
32
- import '../../chunk-7KC56574.mjs';
33
+ import '../../chunk-LU2CE5AE.mjs';
33
34
  import '../../chunk-R6A773WK.mjs';
34
35
  import '../../chunk-YTJCGKM4.mjs';
35
36
  import '../../chunk-R6PR4WYZ.mjs';
36
- import '../../chunk-HBVLF3HA.mjs';
37
+ import '../../chunk-PPY2GSIB.mjs';
37
38
  import '../../chunk-L5ORED7V.mjs';
38
- import '../../chunk-SYWGORQB.mjs';
39
+ import '../../chunk-KV3AZFT3.mjs';
39
40
 
40
41
  // src/persistence/durability/rebuild.ts
41
42
  async function rebuildSegmentsFromDurable(root, metadata, targets, compactionThreshold, prior, capturedPartitions = []) {
package/dist/react.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { N as NarsilError, L as ListParams, h as ListResult, I as IndexInfo, g as IndexStats, Q as QueryParams, j as PreflightResult, e as QueryResult, k as SuggestParams, l as SuggestResult } from './memory-COdoGthn.js';
2
- export { C as ClientErrorCode, a as ClientErrorCodes, E as ErrorCode, b as ErrorCodes, c as NarsilErrorCode, S as ServerErrorCode, d as ServerErrorCodes, i as isNarsilError } from './memory-COdoGthn.js';
3
- import { e as TaskRecord, d as TaskProgress, b as ImportResult, c as TaskListQuery, T as TaskListPage } from './tasks-BJmamiC4.js';
4
- export { I as ImportError, f as TaskStatus, g as TaskType } from './tasks-BJmamiC4.js';
1
+ import { N as NarsilError, L as ListParams, g as ListResult, m as IndexInfo, I as IndexStats, Q as QueryParams, P as PreflightResult, e as QueryResult, h as SuggestParams, j as SuggestResult } from './memory-CUEDwr-F.js';
2
+ export { C as ClientErrorCode, a as ClientErrorCodes, E as ErrorCode, b as ErrorCodes, c as NarsilErrorCode, S as ServerErrorCode, d as ServerErrorCodes, i as isNarsilError } from './memory-CUEDwr-F.js';
3
+ import { e as TaskRecord, d as TaskProgress, b as ImportResult, c as TaskListQuery, T as TaskListPage } from './tasks-HG3rlxx6.js';
4
+ export { I as ImportError, f as TaskStatus, g as TaskType } from './tasks-HG3rlxx6.js';
5
5
  import { ReactNode, ReactElement } from 'react';
6
- import { N as Narsil } from './engine-CbZmXUp6.js';
7
- import { N as NarsilClient, I as ImportSource } from './client-DKwterMb.js';
8
- import { A as AnyDocument } from './schema-DttzM-ln.js';
6
+ import { N as Narsil } from './engine-BGCEm9E_.js';
7
+ import { N as NarsilClient, I as ImportSource } from './client-i9eLJrw5.js';
8
+ import { A as AnyDocument } from './schema-4W_7tk1f.js';
9
9
  import './synonyms-CpOAHPa-.js';
10
- import './adapters-79OIa4xm.js';
10
+ import './adapters-BQFQ4PRz.js';
11
11
 
12
12
  /**
13
13
  * These settings apply to {@link NarsilProvider} whether it holds a client or
package/dist/react.mjs CHANGED
@@ -43,6 +43,8 @@ var ErrorCodes = {
43
43
  EMBEDDING_DIMENSION_MISMATCH: "EMBEDDING_DIMENSION_MISMATCH",
44
44
  EMBEDDING_NO_SOURCE: "EMBEDDING_NO_SOURCE",
45
45
  EMBEDDING_CONFIG_INVALID: "EMBEDDING_CONFIG_INVALID",
46
+ RERANK_FAILED: "RERANK_FAILED",
47
+ RERANK_CONFIG_INVALID: "RERANK_CONFIG_INVALID",
46
48
  DOC_MISSING_REQUIRED_FIELD: "DOC_MISSING_REQUIRED_FIELD",
47
49
  CONFIG_INVALID: "CONFIG_INVALID",
48
50
  QUERY_ROUTING_FAILED: "QUERY_ROUTING_FAILED",
@@ -0,0 +1,60 @@
1
+ import { runRerankedQuery, rerankTextOf } from './chunk-NW4XDSP2.mjs';
2
+ import './chunk-KZ3NX2P7.mjs';
3
+ import { rerankOnHost } from './chunk-ZYNAMIYX.mjs';
4
+ import './chunk-FMWRCP2C.mjs';
5
+ import './chunk-HJSN7UYG.mjs';
6
+ import './chunk-LXWDQLTW.mjs';
7
+ import './chunk-E74YLAIG.mjs';
8
+ import { NarsilError, ErrorCodes } from './chunk-KV3AZFT3.mjs';
9
+
10
+ // src/distribution/cluster-node/reads/rerank.ts
11
+ async function rerankClusterQuery(deps, indexName, params, firstStage, readDocuments, host) {
12
+ const startTime = host.now();
13
+ const core = host.engineCoreOf(deps.engine);
14
+ if (core === void 0) {
15
+ throw new NarsilError(ErrorCodes.RERANK_CONFIG_INVALID, "This cluster node holds no rerank adapters");
16
+ }
17
+ const schema = await deps.config.coordinator.getSchema(indexName);
18
+ if (schema === null) {
19
+ throw new NarsilError(ErrorCodes.INDEX_NOT_FOUND, `Index "${indexName}" does not exist`, { indexName });
20
+ }
21
+ const result = await runRerankedQuery(params, {
22
+ host,
23
+ schema,
24
+ maxWindow: core.rerankSettings.maxWindow,
25
+ binding: host.queryBindingOf(params),
26
+ clampsPins: false,
27
+ fusesRankings: (request) => request.vector !== void 0 && (request.term !== void 0 || request.mode === "hybrid"),
28
+ firstStage,
29
+ async texts(docIds, fields) {
30
+ const documents = await readDocuments(docIds);
31
+ return docIds.map((docId) => {
32
+ const document = documents.get(docId);
33
+ return document === void 0 ? "" : rerankTextOf(fields.map((field) => host.getNestedValue(document, field)));
34
+ });
35
+ },
36
+ async storedPins(docIds) {
37
+ return new Set((await readDocuments(docIds)).keys());
38
+ },
39
+ score: (adapter, query, documents) => rerankOnHost(core, adapter, query, documents),
40
+ async fillDocuments(hits, groups, projection) {
41
+ const grouped = (groups ?? []).flatMap((group) => group.hits);
42
+ if (projection.kind === "none") {
43
+ for (const hit of hits) hit.document = {};
44
+ for (const hit of grouped) hit.document = {};
45
+ return;
46
+ }
47
+ const documents = await readDocuments([...hits.map((hit) => hit.id), ...grouped.map((hit) => hit.id)]);
48
+ const read = (docId) => {
49
+ const document = documents.get(docId);
50
+ return document === void 0 ? {} : host.applyProjection(document, projection);
51
+ };
52
+ for (const hit of hits) hit.document = read(hit.id);
53
+ for (const hit of grouped) hit.document = read(hit.id);
54
+ }
55
+ });
56
+ result.elapsed = host.now() - startTime;
57
+ return result;
58
+ }
59
+
60
+ export { rerankClusterQuery };
@@ -0,0 +1,50 @@
1
+ import { R as RerankAdapter } from '../adapters-BQFQ4PRz.js';
2
+
3
+ /**
4
+ * How {@link createHttpReranker} reaches a rerank endpoint.
5
+ *
6
+ * @public
7
+ */
8
+ interface HttpRerankerConfig {
9
+ /**
10
+ * The adapter sends each request to this address with `/rerank` added.
11
+ * Give the versioned API address of Cohere or Jina, or the address of a
12
+ * vLLM or Infinity server that you host.
13
+ */
14
+ baseUrl: string;
15
+ /** The service scores the documents with this model. */
16
+ model: string;
17
+ /**
18
+ * The adapter sends this key as a bearer token. Pass a function to fetch a
19
+ * fresh or short-lived key for every request, and leave the key out for a
20
+ * server that you host without one.
21
+ */
22
+ apiKey?: string | (() => string | Promise<string>);
23
+ /** The adapter aborts a request that takes longer than this many milliseconds, and waits 30,000 by default. */
24
+ timeout?: number;
25
+ /** The adapter retries a request this many times, and 3 times by default, when the service answers with status 429, 500, 502, 503, or 504 or the network fails. */
26
+ maxRetries?: number;
27
+ /** The adapter sends at most this many documents in one request, and 1,000 by default, splitting a larger list across several requests. */
28
+ maxDocumentsPerRequest?: number;
29
+ }
30
+ /**
31
+ * Builds a rerank adapter that calls a Cohere-compatible `/rerank` endpoint,
32
+ * which Cohere, Jina, vLLM, and Infinity serve.
33
+ *
34
+ * The adapter posts the model, the query, and the documents, and reads one
35
+ * `relevance_score` per document from the `results` list. It retries a
36
+ * request on a rate limit, a server error, or a network failure, with an
37
+ * exponential wait and jitter, and it keeps the API key out of every error
38
+ * message.
39
+ *
40
+ * @param config - The endpoint, model, key, and limits.
41
+ * @returns An adapter that you pass in `rerankAdapters` or register with
42
+ * {@link AdapterRegistrationOperations.registerRerankAdapter}.
43
+ * @throws A `NarsilError` with `RERANK_CONFIG_INVALID` when the base URL, the
44
+ * model, the key, or a limit is missing or out of range.
45
+ *
46
+ * @public
47
+ */
48
+ declare function createHttpReranker(config: HttpRerankerConfig): RerankAdapter;
49
+
50
+ export { type HttpRerankerConfig, createHttpReranker };
@@ -0,0 +1,104 @@
1
+ import { resolveApiKey, buildSignal, postJsonWithRetry } from '../chunk-K7D4ZTSW.mjs';
2
+ import { ErrorCodes, NarsilError } from '../chunk-KV3AZFT3.mjs';
3
+
4
+ // src/rerankers/constants.ts
5
+ var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
6
+ var DEFAULT_MAX_RETRIES = 3;
7
+ var DEFAULT_MAX_DOCUMENTS_PER_REQUEST = 1e3;
8
+
9
+ // src/rerankers/http.ts
10
+ var SERVICE = "Rerank service";
11
+ function invalid(message) {
12
+ return new NarsilError(ErrorCodes.RERANK_CONFIG_INVALID, `HTTP rerank adapter ${message}`);
13
+ }
14
+ function requireConfig(config) {
15
+ if (typeof config?.baseUrl !== "string" || config.baseUrl.trim().length === 0) {
16
+ throw invalid("requires a non-empty baseUrl");
17
+ }
18
+ let protocol;
19
+ try {
20
+ protocol = new URL(config.baseUrl).protocol;
21
+ } catch {
22
+ throw invalid("requires baseUrl to be an absolute URL");
23
+ }
24
+ if (protocol !== "https:" && protocol !== "http:") throw invalid("requires an http or https baseUrl");
25
+ if (typeof config.model !== "string" || config.model.trim().length === 0) throw invalid("requires a non-empty model");
26
+ if (config.timeout !== void 0 && (!Number.isFinite(config.timeout) || config.timeout <= 0)) {
27
+ throw invalid("timeout must be a positive number");
28
+ }
29
+ if (config.maxRetries !== void 0 && (!Number.isInteger(config.maxRetries) || config.maxRetries < 0)) {
30
+ throw invalid("maxRetries must be a non-negative integer");
31
+ }
32
+ const perRequest = config.maxDocumentsPerRequest;
33
+ if (perRequest !== void 0 && (!Number.isInteger(perRequest) || perRequest < 1)) {
34
+ throw invalid("maxDocumentsPerRequest must be a positive integer");
35
+ }
36
+ const apiKey = config.apiKey;
37
+ if (apiKey !== void 0 && typeof apiKey !== "string" && typeof apiKey !== "function") {
38
+ throw invalid("apiKey must be a string or a function returning a string");
39
+ }
40
+ if (typeof apiKey === "string" && apiKey.trim().length === 0) throw invalid("requires a non-empty apiKey");
41
+ }
42
+ function failed(message, details) {
43
+ return new NarsilError(ErrorCodes.RERANK_FAILED, `${SERVICE} ${message}`, details);
44
+ }
45
+ function scoresFromResults(results, count) {
46
+ if (!Array.isArray(results)) throw failed('response is missing a "results" array');
47
+ if (results.length !== count) {
48
+ throw failed(`returned ${results.length} results for ${count} documents`, {
49
+ expected: count,
50
+ actual: results.length
51
+ });
52
+ }
53
+ const scores = new Array(count);
54
+ const seen = new Uint8Array(count);
55
+ for (let i = 0; i < results.length; i++) {
56
+ const item = results[i];
57
+ const index = typeof item === "object" && item !== null ? item.index : void 0;
58
+ const score = typeof item === "object" && item !== null ? item.relevance_score : void 0;
59
+ if (typeof index !== "number" || !Number.isInteger(index) || index < 0 || index >= count || seen[index] === 1) {
60
+ throw failed(`result at position ${i} carries no index of a document it was sent, or repeats one`);
61
+ }
62
+ if (typeof score !== "number" || !Number.isFinite(score)) {
63
+ throw failed(`result at position ${i} carries no finite "relevance_score"`);
64
+ }
65
+ seen[index] = 1;
66
+ scores[index] = score;
67
+ }
68
+ return scores;
69
+ }
70
+ function createHttpReranker(config) {
71
+ requireConfig(config);
72
+ const url = `${config.baseUrl.replace(/\/+$/, "")}/rerank`;
73
+ const model = config.model;
74
+ const apiKeySource = config.apiKey;
75
+ const timeoutMs = config.timeout ?? DEFAULT_REQUEST_TIMEOUT_MS;
76
+ const maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
77
+ const perRequest = config.maxDocumentsPerRequest ?? DEFAULT_MAX_DOCUMENTS_PER_REQUEST;
78
+ return {
79
+ async rerank(query, documents, signal) {
80
+ if (documents.length === 0) return [];
81
+ const apiKey = apiKeySource === void 0 ? null : await resolveApiKey(apiKeySource, "HTTP rerank adapter", ErrorCodes.RERANK_CONFIG_INVALID);
82
+ const combinedSignal = buildSignal(signal, timeoutMs);
83
+ const scores = [];
84
+ for (let start = 0; start < documents.length; start += perRequest) {
85
+ const chunk = documents.slice(start, start + perRequest);
86
+ const response = await postJsonWithRetry({
87
+ url,
88
+ body: JSON.stringify({ model, query, documents: chunk, top_n: chunk.length }),
89
+ apiKey,
90
+ maxRetries,
91
+ signal: combinedSignal,
92
+ service: SERVICE,
93
+ failureCode: ErrorCodes.RERANK_FAILED
94
+ });
95
+ for (const score of scoresFromResults(response.results, chunk.length)) scores.push(score);
96
+ }
97
+ return scores;
98
+ },
99
+ async shutdown() {
100
+ }
101
+ };
102
+ }
103
+
104
+ export { createHttpReranker };
@@ -18,7 +18,7 @@ function restoreDepsOf(core, host) {
18
18
  function queueRestore(core, host, restoresInFlight, indexName, data) {
19
19
  const previous = restoresInFlight.get(indexName) ?? Promise.resolve();
20
20
  const restored = previous.then(async () => {
21
- const { restoreFromSnapshot } = await import('./snapshot-XII3ANGW.mjs');
21
+ const { restoreFromSnapshot } = await import('./snapshot-HOGXNO5W.mjs');
22
22
  await restoreFromSnapshot(indexName, data, restoreDepsOf(core, host));
23
23
  });
24
24
  const settled = restored.then(
@@ -0,0 +1,177 @@
1
+ import { runRerankedQuery, rerankTextOf } from './chunk-NW4XDSP2.mjs';
2
+ export { withRerankQueryText } from './chunk-KZ3NX2P7.mjs';
3
+ import { rerankOnHost } from './chunk-ZYNAMIYX.mjs';
4
+ export { rerankOnHost } from './chunk-ZYNAMIYX.mjs';
5
+ import { fixedHybridDepthOf, requireWithinHybridDepth, pageByPosition } from './chunk-FMWRCP2C.mjs';
6
+ import { MIN_RERANK_TIMEOUT_MS, MAX_RERANK_TIMEOUT_MS, MIN_RERANK_WINDOW, MAX_RERANK_WINDOW, DEFAULT_MAX_RERANK_WINDOW, DEFAULT_RERANK_TIMEOUT_MS } from './chunk-HJSN7UYG.mjs';
7
+ import './chunk-LXWDQLTW.mjs';
8
+ import { HYBRID_RESCORE_WINDOW } from './chunk-E74YLAIG.mjs';
9
+ import { NarsilError, ErrorCodes } from './chunk-KV3AZFT3.mjs';
10
+
11
+ // src/engine/query/hybrid-depth.ts
12
+ function countOfUnion(text, vectorScored) {
13
+ const textIds = /* @__PURE__ */ new Set();
14
+ for (const doc of text.scored) textIds.add(doc.docId);
15
+ let vectorOnly = 0;
16
+ for (const doc of vectorScored) if (!textIds.has(doc.docId)) vectorOnly++;
17
+ if (text.scored.length === text.totalMatched) return text.totalMatched + vectorOnly;
18
+ return Math.max(text.totalMatched, text.scored.length + vectorOnly);
19
+ }
20
+ async function fusedAtDepth(params, context, depth, legs) {
21
+ const { textLeg, vectorLeg } = legs;
22
+ const { vector: vectorConfig, mode: _mode, hybrid: _hybrid, searchAfter: _after, pinned: _pinned, ...rest } = params;
23
+ const fusion = legs.resolveHybridFusion(params.hybrid);
24
+ const textOnlyParams = { ...rest, limit: depth, offset: 0 };
25
+ const filtered = legs.filteredSearchOf(params, context);
26
+ if (filtered !== void 0 && legs.filterSubsetsMatchNothing(filtered.first)) {
27
+ return { scored: [], totalMatched: 0 };
28
+ }
29
+ if (!vectorConfig || !vectorConfig.value) {
30
+ const textOnly = await textLeg(textOnlyParams, context);
31
+ return { scored: textOnly.scored, totalMatched: textOnly.totalMatched, facets: textOnly.facets };
32
+ }
33
+ const vectorPending = vectorLeg(
34
+ vectorConfig,
35
+ new Float32Array(vectorConfig.value),
36
+ context,
37
+ filtered,
38
+ depth,
39
+ HYBRID_RESCORE_WINDOW
40
+ );
41
+ const [textFanOutResult, vectorOutcome] = await Promise.all([textLeg(textOnlyParams, context), vectorPending]);
42
+ const vectorScored = vectorOutcome.scored;
43
+ const textScored = textFanOutResult.scored.slice(0, depth);
44
+ let fusedScored;
45
+ if (fusion.strategy === "rrf") {
46
+ fusedScored = legs.reciprocalRankFusion([textScored, vectorScored], { k: fusion.k });
47
+ } else {
48
+ fusedScored = legs.linearCombination(textScored, vectorScored, { alpha: fusion.alpha });
49
+ }
50
+ const textHoldsEveryMatch = textFanOutResult.scored.length === textFanOutResult.totalMatched;
51
+ const threshold = params.minScore ?? 0;
52
+ const filtersByScore = threshold > 0;
53
+ if (filtersByScore) fusedScored = fusedScored.filter((doc) => doc.score >= threshold);
54
+ return {
55
+ scored: fusedScored.length > depth ? fusedScored.slice(0, depth) : fusedScored,
56
+ totalMatched: filtersByScore ? fusedScored.length : countOfUnion(textFanOutResult, vectorScored),
57
+ matchedExact: vectorOutcome.holdsEveryMatch && textHoldsEveryMatch && (!filtersByScore || textScored.length === textFanOutResult.totalMatched),
58
+ facets: textFanOutResult.facets
59
+ };
60
+ }
61
+ async function searchFixedDepthHybrid(params, context, { cursorDepth, offset, limit }, host) {
62
+ const depth = fixedHybridDepthOf(params.hybrid) ?? 0;
63
+ requireWithinHybridDepth(cursorDepth, offset, depth);
64
+ const result = await fusedAtDepth(params, context, depth, host);
65
+ const placesPins = context.partitionIds === void 0;
66
+ const paginate = (placed, _limit, _offset, _binding, _cursor, _sort, pinnedIds) => {
67
+ const pins = placesPins ? pinnedIds : void 0;
68
+ const organic = pins === void 0 ? placed : result.scored.map((doc) => ({ id: doc.docId }));
69
+ const { page, cursor } = pageByPosition(placed, organic, {
70
+ start: cursorDepth + offset,
71
+ limit,
72
+ pinnedIds: pins,
73
+ binding: context.cursorBinding,
74
+ encodeCursor: host.encodePageCursor
75
+ });
76
+ return { paginated: page, nextCursor: cursor };
77
+ };
78
+ return { ...result, paginate };
79
+ }
80
+
81
+ // src/engine/query/rerank.ts
82
+ async function executeRerankedQuery(request, context, firstStage, host) {
83
+ const startTime = host.now();
84
+ const runner = context.rerank;
85
+ if (runner === void 0) {
86
+ throw new NarsilError(ErrorCodes.RERANK_CONFIG_INVALID, "This search path holds no rerank adapters");
87
+ }
88
+ const { manager } = context;
89
+ const result = await runRerankedQuery(request, {
90
+ host,
91
+ schema: context.config.schema,
92
+ maxWindow: runner.maxWindow,
93
+ binding: context.cursorBinding,
94
+ clampsPins: true,
95
+ fusesRankings: (params) => params.vector !== void 0 && (params.mode === "hybrid" || params.term !== void 0 && params.term.trim().length > 0),
96
+ firstStage: (params) => firstStage(params, context),
97
+ async texts(docIds, fields) {
98
+ return docIds.map((docId) => rerankTextOf(manager.fieldValues(docId, fields)));
99
+ },
100
+ async storedPins(docIds) {
101
+ return new Set(docIds.filter((docId) => manager.getRef(docId) !== void 0));
102
+ },
103
+ score: (adapter, query, documents) => runner.score(adapter, query, documents),
104
+ async fillDocuments(hits, groups, projection) {
105
+ const read = (docId) => projection.kind === "none" ? {} : manager.get(docId, projection) ?? {};
106
+ for (const hit of hits) hit.document = read(hit.id);
107
+ for (const group of groups ?? []) {
108
+ for (const hit of group.hits) hit.document = read(hit.id);
109
+ }
110
+ },
111
+ highlight(page, projection) {
112
+ const fields = request.highlight?.fields ?? [];
113
+ const dropped = fields.some((field) => !host.projectionKeepsField(projection, field));
114
+ const readStoredDocument = dropped ? (docId) => manager.get(docId, { kind: "full" }) : void 0;
115
+ host.applyHighlights(
116
+ page,
117
+ request,
118
+ context.language,
119
+ manager.analysis,
120
+ manager.schema,
121
+ readStoredDocument,
122
+ manager.synonyms
123
+ );
124
+ }
125
+ });
126
+ result.elapsed = host.now() - startTime;
127
+ return result;
128
+ }
129
+
130
+ // src/rerank/runner.ts
131
+ function rerankRunnerFor(core) {
132
+ return {
133
+ maxWindow: core.rerankSettings.maxWindow,
134
+ score: (adapter, query, documents) => rerankOnHost(core, adapter, query, documents)
135
+ };
136
+ }
137
+
138
+ // src/rerank/settings.ts
139
+ function wholeNumberIn(value, low, high) {
140
+ return typeof value === "number" && Number.isInteger(value) && value >= low && value <= high;
141
+ }
142
+ function resolveRerankSettings(config) {
143
+ const timeout = config?.rerankTimeout;
144
+ const maxWindow = config?.maxRerankWindow;
145
+ if (timeout !== void 0 && !wholeNumberIn(timeout, MIN_RERANK_TIMEOUT_MS, MAX_RERANK_TIMEOUT_MS)) {
146
+ throw new NarsilError(
147
+ ErrorCodes.CONFIG_INVALID,
148
+ `rerankTimeout must be a whole number of milliseconds from ${MIN_RERANK_TIMEOUT_MS} to ${MAX_RERANK_TIMEOUT_MS}`,
149
+ { rerankTimeout: timeout }
150
+ );
151
+ }
152
+ if (maxWindow !== void 0 && !wholeNumberIn(maxWindow, MIN_RERANK_WINDOW, MAX_RERANK_WINDOW)) {
153
+ throw new NarsilError(
154
+ ErrorCodes.CONFIG_INVALID,
155
+ `maxRerankWindow must be a whole number from ${MIN_RERANK_WINDOW} to ${MAX_RERANK_WINDOW}`,
156
+ {
157
+ maxRerankWindow: maxWindow
158
+ }
159
+ );
160
+ }
161
+ return {
162
+ timeoutMs: timeout ?? DEFAULT_RERANK_TIMEOUT_MS,
163
+ maxWindow: maxWindow ?? DEFAULT_MAX_RERANK_WINDOW
164
+ };
165
+ }
166
+ async function shutdownRerankAdapters(adapters) {
167
+ const distinct = new Set(adapters.values());
168
+ adapters.clear();
169
+ for (const adapter of distinct) {
170
+ try {
171
+ await adapter.shutdown?.();
172
+ } catch {
173
+ }
174
+ }
175
+ }
176
+
177
+ export { executeRerankedQuery, rerankRunnerFor, resolveRerankSettings, searchFixedDepthHybrid, shutdownRerankAdapters };
@@ -1,4 +1,4 @@
1
- import { E as EmbeddingAdapter } from './adapters-79OIa4xm.js';
1
+ import { E as EmbeddingAdapter } from './adapters-BQFQ4PRz.js';
2
2
  import { a as SynonymRule } from './synonyms-CpOAHPa-.js';
3
3
 
4
4
  /**
@@ -356,4 +356,4 @@ interface InsertOptions extends WriteOptions {
356
356
  skipClone?: boolean;
357
357
  }
358
358
 
359
- export type { AnyDocument as A, BM25Params as B, CustomTokenizer as C, EmbeddingFieldConfig as E, FieldOptionChain as F, IndexConfig as I, PartitionConfig as P, SchemaDefinition as S, TextFieldOption as T, VectorIndexConfig as V, WriteOptions as W, InsertOptions as a, ScoringMode as b, StopWordOverride as c, FieldType as d, VectorQuantizationMode as e, VectorStorageMode as f };
359
+ export type { AnyDocument as A, BM25Params as B, CustomTokenizer as C, EmbeddingFieldConfig as E, FieldOptionChain as F, IndexConfig as I, PartitionConfig as P, SchemaDefinition as S, TextFieldOption as T, VectorIndexConfig as V, WriteOptions as W, InsertOptions as a, StopWordOverride as b, FieldType as c, ScoringMode as d, VectorQuantizationMode as e, VectorStorageMode as f };
package/dist/server.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- export { C as ClientErrorCode, a as ClientErrorCodes, E as ErrorCode, b as ErrorCodes, N as NarsilError, c as NarsilErrorCode, S as ServerErrorCode, d as ServerErrorCodes, i as isNarsilError } from './memory-COdoGthn.js';
2
- import { c as ServerOptions, N as NarsilServer } from './capabilities-BvxvFzVA.js';
3
- export { A as ASYNC_IMPORT_CAPABILITY, C as CorsOptions, D as DOCUMENT_EXPORT_CAPABILITY, E as ErrorEnvelope, I as INDEX_LIFECYCLE_CAPABILITY, O as OnRequestHook, R as REBUILD_ANALYSIS_CAPABILITY, d as RequestContext, e as RequestDenial, S as SERVER_CAPABILITIES, a as SYNONYMS_CAPABILITY, f as ServerLimits, T as TASK_CANCEL_CAPABILITY, b as TASK_FILTER_CAPABILITY } from './capabilities-BvxvFzVA.js';
4
- import { N as Narsil } from './engine-CbZmXUp6.js';
5
- import { d as TaskProgress, b as ImportResult, h as TaskStore, e as TaskRecord } from './tasks-BJmamiC4.js';
6
- export { C as CapabilitiesResponse, a as CreateIndexEmbedding, i as CreateIndexRequest, H as HttpIndexConfig, I as ImportError, M as MemoryStatsResponse, T as TaskListPage, c as TaskListQuery, f as TaskStatus, g as TaskType } from './tasks-BJmamiC4.js';
7
- import './schema-DttzM-ln.js';
8
- import './adapters-79OIa4xm.js';
1
+ export { C as ClientErrorCode, a as ClientErrorCodes, E as ErrorCode, b as ErrorCodes, N as NarsilError, c as NarsilErrorCode, S as ServerErrorCode, d as ServerErrorCodes, i as isNarsilError } from './memory-CUEDwr-F.js';
2
+ import { c as ServerOptions, N as NarsilServer } from './capabilities-BTTIs96E.js';
3
+ export { A as ASYNC_IMPORT_CAPABILITY, C as CorsOptions, D as DOCUMENT_EXPORT_CAPABILITY, E as ErrorEnvelope, I as INDEX_LIFECYCLE_CAPABILITY, O as OnRequestHook, R as REBUILD_ANALYSIS_CAPABILITY, d as RequestContext, e as RequestDenial, S as SERVER_CAPABILITIES, a as SYNONYMS_CAPABILITY, f as ServerLimits, T as TASK_CANCEL_CAPABILITY, b as TASK_FILTER_CAPABILITY } from './capabilities-BTTIs96E.js';
4
+ import { N as Narsil } from './engine-BGCEm9E_.js';
5
+ import { d as TaskProgress, b as ImportResult, h as TaskStore, e as TaskRecord } from './tasks-HG3rlxx6.js';
6
+ export { C as CapabilitiesResponse, a as CreateIndexEmbedding, i as CreateIndexRequest, H as HttpIndexConfig, I as ImportError, M as MemoryStatsResponse, T as TaskListPage, c as TaskListQuery, f as TaskStatus, g as TaskType } from './tasks-HG3rlxx6.js';
7
+ import './schema-4W_7tk1f.js';
8
+ import './adapters-BQFQ4PRz.js';
9
9
  import './synonyms-CpOAHPa-.js';
10
- import './config-6YBtxekG.js';
11
- import './config-DPphZfuM.js';
12
- import './index-ONAEaqtx.js';
10
+ import './config-BGB_fDtq.js';
11
+ import './config-P__Diiy4.js';
12
+ import './index-lcdGLyJH.js';
13
13
  import './types-Cb9kiY5P.js';
14
14
 
15
15
  /**