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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/adapters/filesystem.mjs +1 -1
  2. package/dist/adapters/indexeddb.mjs +1 -1
  3. package/dist/browser/chunk-26A5JFT2.mjs +89 -0
  4. package/dist/browser/{chunk-5D6NJD6C.mjs → chunk-2Y3CO4EQ.mjs} +342 -201
  5. package/dist/browser/{chunk-WLD6DDIX.mjs → chunk-AIIJDWMG.mjs} +1 -1
  6. package/dist/browser/{chunk-YAGXZU4W.mjs → chunk-D7WQF6DV.mjs} +2 -2
  7. package/dist/browser/{chunk-WZBTVTSU.mjs → chunk-M5UAAXGU.mjs} +2 -2
  8. package/dist/browser/{chunk-XTFJZHQP.mjs → chunk-NSCSR6MA.mjs} +15 -5
  9. package/dist/browser/{chunk-3NVZD52E.mjs → chunk-UDGB2MWT.mjs} +5 -28
  10. package/dist/browser/{chunk-II5POT55.mjs → chunk-VBBLTD7O.mjs} +4 -3
  11. package/dist/browser/chunk-VEGHFP2P.mjs +30 -0
  12. package/dist/browser/{durability-wiring-HCCC6BJB.mjs → durability-wiring-FNZSRH4N.mjs} +8 -6
  13. package/dist/browser/{module-S2VDU2JE.mjs → module-4HIMOQM5.mjs} +6 -5
  14. package/dist/browser/phrase-module-WESYVU7K.mjs +327 -0
  15. package/dist/browser/{restore-queue-BZ7WWEC4.mjs → restore-queue-GEZ54CA5.mjs} +1 -1
  16. package/dist/browser/{runtime-PL4TTFJE.mjs → runtime-3X7ZJ5T3.mjs} +2 -1
  17. package/dist/browser/{snapshot-RTUCHI2L.mjs → snapshot-V7VF6BN6.mjs} +25 -10
  18. package/dist/browser/{write-IMU7G5NU.mjs → write-YIC2MKRY.mjs} +7 -5
  19. package/dist/{capabilities-BTjv-tK8.d.ts → capabilities-B6WxrWxt.d.ts} +3 -10
  20. package/dist/{chunk-3XHFVYIQ.mjs → chunk-2C3WXBQS.mjs} +1 -1
  21. package/dist/{chunk-37RTD6KD.mjs → chunk-2JWNJSNE.mjs} +8 -8
  22. package/dist/{chunk-K76F5YYX.mjs → chunk-2MKX2SCO.mjs} +219 -58
  23. package/dist/{chunk-AN3CUMPZ.mjs → chunk-2SEL6SBS.mjs} +4 -95
  24. package/dist/{chunk-OPO5SE4J.mjs → chunk-2WBY4Y4M.mjs} +1 -1
  25. package/dist/{chunk-PTIJAZWL.mjs → chunk-4GDLFDPZ.mjs} +1 -1
  26. package/dist/chunk-4UMZ7KQL.mjs +17 -0
  27. package/dist/{chunk-TY64A3ZW.mjs → chunk-5LX6MOIB.mjs} +2 -2
  28. package/dist/{chunk-3LJVM6XM.mjs → chunk-5W7AEVTH.mjs} +2 -2
  29. package/dist/{chunk-PCRWCOZC.mjs → chunk-6M6SDH3S.mjs} +43 -23
  30. package/dist/{chunk-MGD7XETB.mjs → chunk-6SSVIW7Y.mjs} +19 -3
  31. package/dist/{chunk-5LC5VMDQ.mjs → chunk-7OIQ2SIO.mjs} +4 -4
  32. package/dist/{chunk-4XEVROSP.mjs → chunk-7XY6VD7B.mjs} +1 -1
  33. package/dist/{chunk-WI5Q3L43.mjs → chunk-CZ7ISLXA.mjs} +2 -0
  34. package/dist/{chunk-RC27KF7F.mjs → chunk-D5TFRB5G.mjs} +3 -15
  35. package/dist/{chunk-F4UKMTKM.mjs → chunk-EUCX5K74.mjs} +4 -4
  36. package/dist/{chunk-CTF6WFTX.mjs → chunk-F6AAXI7T.mjs} +3 -3
  37. package/dist/{chunk-DX2FI4LU.mjs → chunk-FQBFZAWG.mjs} +3 -1
  38. package/dist/{chunk-XTER67YM.mjs → chunk-HCGJKDZV.mjs} +1 -1
  39. package/dist/{chunk-WQYB4TNR.mjs → chunk-JJ6EUMXB.mjs} +2 -2
  40. package/dist/{chunk-2HQQ7Y5D.mjs → chunk-JT3YZGCE.mjs} +2 -2
  41. package/dist/chunk-JUKYYXSP.mjs +93 -0
  42. package/dist/{chunk-WUIDPBSY.mjs → chunk-K77FJXKS.mjs} +17 -7
  43. package/dist/{chunk-CSSCLRGY.mjs → chunk-NMXRXFGZ.mjs} +2 -2
  44. package/dist/{chunk-44TB6AIZ.mjs → chunk-NNO7CO3A.mjs} +1 -1
  45. package/dist/{chunk-EZIGAOUJ.mjs → chunk-OGLV4I3L.mjs} +6 -5
  46. package/dist/{chunk-FRSWYMXH.mjs → chunk-PATMDIMN.mjs} +1 -1
  47. package/dist/{chunk-AFOZR4ZQ.mjs → chunk-PU6SKH7O.mjs} +2 -2
  48. package/dist/{chunk-TB7YMDD5.mjs → chunk-RCMNL7RI.mjs} +650 -100
  49. package/dist/{chunk-Y4NOHICF.mjs → chunk-RNSC4NFI.mjs} +1 -1
  50. package/dist/{chunk-RYH3PASD.mjs → chunk-RWESFSJI.mjs} +21 -11
  51. package/dist/{chunk-QQS4QZQA.mjs → chunk-SOHMMNCH.mjs} +4 -4
  52. package/dist/{chunk-K73PZTBR.mjs → chunk-SZGRYEIC.mjs} +4 -4
  53. package/dist/{chunk-43Q7HAI2.mjs → chunk-T4OFG4IQ.mjs} +4 -4
  54. package/dist/{chunk-2YOAGAGF.mjs → chunk-TGHNXN7W.mjs} +59 -30
  55. package/dist/{chunk-J4LRE5Q7.mjs → chunk-WVRDRLIC.mjs} +6 -6
  56. package/dist/{chunk-XRXBCOA4.mjs → chunk-X5CNUKD5.mjs} +2 -2
  57. package/dist/{chunk-Y4US5EGH.mjs → chunk-Y2U5VVWX.mjs} +1 -1
  58. package/dist/{chunk-5VSTAJET.mjs → chunk-Y4BVTQ53.mjs} +2 -2
  59. package/dist/{chunk-M6MBSVIJ.mjs → chunk-ZR4VM4A6.mjs} +1 -1
  60. package/dist/{client-BOcveV7A.d.ts → client-gNAfaHcE.d.ts} +3 -3
  61. package/dist/client.d.ts +7 -8
  62. package/dist/client.mjs +2 -0
  63. package/dist/{config-CPmIY3aH.d.ts → config-CmYJO34X.d.ts} +3 -3
  64. package/dist/{events-pM0lna7M.d.ts → config-D1cDv3sE.d.ts} +431 -3
  65. package/dist/direct-executor-HQ4QVDX7.mjs +28 -0
  66. package/dist/distribution/coordinator/etcd.d.ts +2 -2
  67. package/dist/distribution/coordinator/etcd.mjs +1 -1
  68. package/dist/distribution/coordinator/in-memory.d.ts +2 -2
  69. package/dist/distribution/transport/grpc.mjs +1 -1
  70. package/dist/distribution.d.ts +7 -8
  71. package/dist/distribution.mjs +85 -45
  72. package/dist/{durability-wiring-6R26AJDI.mjs → durability-wiring-S7OX2MAI.mjs} +27 -25
  73. package/dist/embeddings/openai.mjs +2 -2
  74. package/dist/{engine-JjRAXpT3.d.ts → engine-m_Ddr1bz.d.ts} +2 -2
  75. package/dist/{index-DkQ2DlgR.d.ts → index-HYnqS1SE.d.ts} +2 -2
  76. package/dist/index.browser.mjs +5 -3
  77. package/dist/index.d.ts +6 -7
  78. package/dist/index.mjs +20 -18
  79. package/dist/{long-query-thread-6VLA6YJI.mjs → long-query-thread-BSL25PD6.mjs} +17 -15
  80. package/dist/{module-S4WGMFNW.mjs → module-2E4XYSGT.mjs} +11 -11
  81. package/dist/partial-words.mjs +7 -6
  82. package/dist/pattern.mjs +4 -3
  83. package/dist/persistence/durability/checkpoint-worker.d.ts +2 -1
  84. package/dist/persistence/durability/checkpoint-worker.mjs +23 -21
  85. package/dist/phrase-module-JERF2IDG.mjs +329 -0
  86. package/dist/react.d.ts +11 -8
  87. package/dist/react.mjs +2 -0
  88. package/dist/{rerank-V4J4MIWR.mjs → rerank-DMMT4FZA.mjs} +6 -6
  89. package/dist/rerankers/http.mjs +2 -2
  90. package/dist/{restore-queue-PUGWCPCX.mjs → restore-queue-JAMNRC6T.mjs} +1 -1
  91. package/dist/{runtime-TBFBQQQO.mjs → runtime-7MLQ7J64.mjs} +7 -7
  92. package/dist/{schema-DGAP_8HJ.d.ts → schema-BTXbHCqA.d.ts} +8 -5
  93. package/dist/server.d.ts +198 -11
  94. package/dist/server.mjs +30 -19
  95. package/dist/{snapshot-PUVSMV7E.mjs → snapshot-DOQLGGEX.mjs} +44 -29
  96. package/dist/synonyms.mjs +4 -3
  97. package/dist/tasks-Co8HfRD7.d.ts +704 -0
  98. package/dist/{thread-TA7QQBWP.mjs → thread-SKO7CN3R.mjs} +16 -14
  99. package/dist/vector/search-worker.d.ts +1 -1
  100. package/dist/vector/search-worker.mjs +4 -4
  101. package/dist/workers/entry.mjs +7 -7
  102. package/dist/{write-TGKYT3C4.mjs → write-ZKR7SNRT.mjs} +22 -20
  103. package/openapi.json +5215 -0
  104. package/package.json +16 -8
  105. package/dist/config-C3YXk5Rn.d.ts +0 -412
  106. package/dist/direct-executor-ULA6V5HC.mjs +0 -26
  107. package/dist/tasks-txGvNz6h.d.ts +0 -302
@@ -1,15 +1,16 @@
1
- import { partialWordSearchModule } from './chunk-F4UKMTKM.mjs';
2
- import './chunk-AFOZR4ZQ.mjs';
1
+ import { partialWordSearchModule } from './chunk-EUCX5K74.mjs';
2
+ import './chunk-PU6SKH7O.mjs';
3
3
  import './chunk-U476IXKQ.mjs';
4
- import './chunk-DX2FI4LU.mjs';
4
+ import './chunk-FQBFZAWG.mjs';
5
5
  import './chunk-VJS4JFBQ.mjs';
6
6
  import './chunk-GES7U2PM.mjs';
7
- import './chunk-4XEVROSP.mjs';
8
- import './chunk-RC27KF7F.mjs';
7
+ import './chunk-7XY6VD7B.mjs';
8
+ import './chunk-D5TFRB5G.mjs';
9
+ import './chunk-4UMZ7KQL.mjs';
9
10
  import './chunk-R6A773WK.mjs';
10
11
  import './chunk-YTJCGKM4.mjs';
11
12
  import './chunk-L5ORED7V.mjs';
12
- import './chunk-WI5Q3L43.mjs';
13
+ import './chunk-CZ7ISLXA.mjs';
13
14
 
14
15
  // src/partial-words/index.ts
15
16
  var partialWordSearch = partialWordSearchModule;
package/dist/pattern.mjs CHANGED
@@ -1,10 +1,11 @@
1
- import { patternSearchModule } from './chunk-AN3CUMPZ.mjs';
1
+ import { patternSearchModule } from './chunk-2SEL6SBS.mjs';
2
2
  import './chunk-WQBCBKY3.mjs';
3
+ import './chunk-JUKYYXSP.mjs';
3
4
  import './chunk-GES7U2PM.mjs';
4
- import './chunk-4XEVROSP.mjs';
5
+ import './chunk-7XY6VD7B.mjs';
5
6
  import './chunk-YTJCGKM4.mjs';
6
7
  import './chunk-L5ORED7V.mjs';
7
- import './chunk-WI5Q3L43.mjs';
8
+ import './chunk-CZ7ISLXA.mjs';
8
9
 
9
10
  // src/pattern/index.ts
10
11
  var patternSearch = patternSearchModule;
@@ -1,4 +1,4 @@
1
- import { c as BM25FieldParams, P as PartitionConfig, e as ScoringMode, V as VectorIndexConfig } from '../../schema-DGAP_8HJ.js';
1
+ import { c as BM25FieldParams, P as PartitionConfig, e as ScoringMode, V as VectorIndexConfig } from '../../schema-BTXbHCqA.js';
2
2
  import '../../adapters-BQFQ4PRz.js';
3
3
  import '../../synonyms-CpOAHPa-.js';
4
4
 
@@ -192,6 +192,7 @@ interface IndexMetadata {
192
192
  /** Persisted so recovered indexes keep collecting surface forms. */
193
193
  surfaceForms?: boolean;
194
194
  analysisRevision?: string;
195
+ arrayPositionGap?: number;
195
196
  tokenizer?: string;
196
197
  stopWords?: string;
197
198
  stopWordList?: string[];
@@ -1,48 +1,50 @@
1
- import { createDurableDirectory } from '../../chunk-CSSCLRGY.mjs';
1
+ import { createDurableDirectory } from '../../chunk-NMXRXFGZ.mjs';
2
2
  import '../../chunk-W55X2BYN.mjs';
3
3
  import '../../chunk-HLPRHOSO.mjs';
4
- import { CHECKPOINT_WORKER_HEARTBEAT_MS, writeCheckpointSegments, directoryCheckpointStore } from '../../chunk-37RTD6KD.mjs';
5
- import '../../chunk-5LC5VMDQ.mjs';
4
+ import { CHECKPOINT_WORKER_HEARTBEAT_MS, writeCheckpointSegments, directoryCheckpointStore } from '../../chunk-2JWNJSNE.mjs';
5
+ import '../../chunk-7OIQ2SIO.mjs';
6
6
  import '../../chunk-P36MUFEJ.mjs';
7
7
  import '../../chunk-YH5OIL7B.mjs';
8
- import '../../chunk-2YOAGAGF.mjs';
9
- import '../../chunk-PCRWCOZC.mjs';
10
- import '../../chunk-2HQQ7Y5D.mjs';
11
- import '../../chunk-44TB6AIZ.mjs';
8
+ import '../../chunk-TGHNXN7W.mjs';
9
+ import '../../chunk-6M6SDH3S.mjs';
10
+ import '../../chunk-JT3YZGCE.mjs';
11
+ import '../../chunk-NNO7CO3A.mjs';
12
12
  import '../../chunk-AV4IJKD2.mjs';
13
- import '../../chunk-RYH3PASD.mjs';
14
- import '../../chunk-K76F5YYX.mjs';
15
- import '../../chunk-M6MBSVIJ.mjs';
13
+ import '../../chunk-RWESFSJI.mjs';
14
+ import '../../chunk-2MKX2SCO.mjs';
15
+ import '../../chunk-ZR4VM4A6.mjs';
16
16
  import '../../chunk-ZATRDAYU.mjs';
17
17
  import '../../chunk-EBIHRL7B.mjs';
18
18
  import '../../chunk-HJSN7UYG.mjs';
19
- import '../../chunk-Y4NOHICF.mjs';
19
+ import '../../chunk-RNSC4NFI.mjs';
20
20
  import '../../chunk-TGP5M5R7.mjs';
21
21
  import '../../chunk-U2BKYEC7.mjs';
22
22
  import '../../chunk-KOKM4PQN.mjs';
23
23
  import '../../chunk-QSK35UC2.mjs';
24
- import '../../chunk-3XHFVYIQ.mjs';
25
- import '../../chunk-AN3CUMPZ.mjs';
24
+ import '../../chunk-2C3WXBQS.mjs';
25
+ import '../../chunk-2SEL6SBS.mjs';
26
26
  import '../../chunk-WQBCBKY3.mjs';
27
- import '../../chunk-F4UKMTKM.mjs';
28
- import '../../chunk-AFOZR4ZQ.mjs';
27
+ import '../../chunk-JUKYYXSP.mjs';
28
+ import '../../chunk-EUCX5K74.mjs';
29
+ import '../../chunk-PU6SKH7O.mjs';
29
30
  import '../../chunk-U476IXKQ.mjs';
30
- import '../../chunk-DX2FI4LU.mjs';
31
+ import '../../chunk-FQBFZAWG.mjs';
31
32
  import '../../chunk-VJS4JFBQ.mjs';
32
33
  import '../../chunk-GES7U2PM.mjs';
33
- import '../../chunk-4XEVROSP.mjs';
34
- import '../../chunk-MGD7XETB.mjs';
34
+ import '../../chunk-7XY6VD7B.mjs';
35
+ import '../../chunk-6SSVIW7Y.mjs';
35
36
  import '../../chunk-X5CV2E2B.mjs';
36
37
  import '../../chunk-7X5JST5L.mjs';
37
- import '../../chunk-RC27KF7F.mjs';
38
+ import '../../chunk-D5TFRB5G.mjs';
39
+ import '../../chunk-4UMZ7KQL.mjs';
38
40
  import '../../chunk-R6A773WK.mjs';
39
41
  import '../../chunk-YTJCGKM4.mjs';
40
42
  import '../../chunk-UJWGQIXU.mjs';
41
- import '../../chunk-XTER67YM.mjs';
43
+ import '../../chunk-HCGJKDZV.mjs';
42
44
  import '../../chunk-22YPZVMG.mjs';
43
45
  import '../../chunk-RFBLQLLZ.mjs';
44
46
  import '../../chunk-L5ORED7V.mjs';
45
- import '../../chunk-WI5Q3L43.mjs';
47
+ import '../../chunk-CZ7ISLXA.mjs';
46
48
 
47
49
  // src/persistence/durability/rebuild.ts
48
50
  async function rebuildSegmentsFromDurable(root, metadata, targets, compactionThreshold, prior, capturedPartitions = [], keepsWriteRecords = false) {
@@ -0,0 +1,329 @@
1
+ import { createBitSet, bitsetIsEmpty, GrowableUint32, bitsetHas, bitsetSet } from './chunk-JUKYYXSP.mjs';
2
+ import { MAX_QUERY_PHRASES, MAX_PHRASE_WORDS } from './chunk-FQBFZAWG.mjs';
3
+ import { PHRASE_ROWS_START, PHRASE_SORT_RADIX_BITS, PHRASE_SORT_CLOCK_ROWS } from './chunk-4UMZ7KQL.mjs';
4
+ import { NarsilError, ErrorCodes } from './chunk-CZ7ISLXA.mjs';
5
+
6
+ // src/core/partition/phrase-matching.ts
7
+ var UINT32_BITS = 32;
8
+ var WorkTally = class {
9
+ constructor(meter) {
10
+ this.meter = meter;
11
+ }
12
+ pending = 0;
13
+ add(units) {
14
+ this.pending += units;
15
+ if (this.meter !== void 0 && this.pending >= this.meter.flushUnits) this.flush();
16
+ }
17
+ tickClock(units) {
18
+ this.meter?.clock?.tick(units);
19
+ }
20
+ flush() {
21
+ const units = this.pending;
22
+ this.pending = 0;
23
+ this.meter?.add(units);
24
+ }
25
+ };
26
+ function placeRowsByDigit(docIds, from, to, shift, starts, tally) {
27
+ const count = from.length;
28
+ const mask = starts.length - 1;
29
+ starts.fill(0);
30
+ for (let row = 0; row < count; row++) starts[docIds[row] >>> shift & mask]++;
31
+ let next = 0;
32
+ for (let digit = 0; digit < starts.length; digit++) {
33
+ const held = starts[digit];
34
+ starts[digit] = next;
35
+ next += held;
36
+ }
37
+ for (let begin = 0; begin < count; begin += PHRASE_SORT_CLOCK_ROWS) {
38
+ const end = Math.min(count, begin + PHRASE_SORT_CLOCK_ROWS);
39
+ for (let at = begin; at < end; at++) {
40
+ const row = from[at];
41
+ to[starts[docIds[row] >>> shift & mask]++] = row;
42
+ }
43
+ tally.tickClock(end - begin);
44
+ }
45
+ }
46
+ function sortedRowOrder(docIds, count, tally) {
47
+ let order = new Uint32Array(count);
48
+ for (let row = 0; row < count; row++) order[row] = row;
49
+ let spare = new Uint32Array(count);
50
+ const starts = new Uint32Array(1 << PHRASE_SORT_RADIX_BITS);
51
+ for (let shift = 0; shift < UINT32_BITS; shift += PHRASE_SORT_RADIX_BITS) {
52
+ placeRowsByDigit(docIds, order, spare, shift, starts, tally);
53
+ const placed = spare;
54
+ spare = order;
55
+ order = placed;
56
+ }
57
+ return order;
58
+ }
59
+ function tokenRowsOf(list, tally) {
60
+ const store = list.positionStore ?? null;
61
+ if (store === null) return null;
62
+ const count = list.length;
63
+ const docIds = list.docIds;
64
+ if (list.ordered) {
65
+ return { list, keys: docIds, order: null, fields: list.fieldNameIndices, store, count, cursor: 0, positionRow: 0 };
66
+ }
67
+ tally.add(count);
68
+ const order = sortedRowOrder(docIds, count, tally);
69
+ const keys = new Uint32Array(count);
70
+ for (let row = 0; row < count; row++) keys[row] = docIds[order[row]];
71
+ return { list, keys, order, fields: list.fieldNameIndices, store, count, cursor: 0, positionRow: 0 };
72
+ }
73
+ function resolvePhrase(index, phrase, sharedRows, tally) {
74
+ const entryRows = [];
75
+ const rows = [];
76
+ for (const token of phrase.tokens) {
77
+ let found = sharedRows.get(token);
78
+ if (found === void 0) {
79
+ const list = index.lookupReadOnce?.(token) ?? index.lookup(token);
80
+ if (list === void 0) return null;
81
+ const built = tokenRowsOf(list, tally);
82
+ if (built === null) return null;
83
+ found = built;
84
+ sharedRows.set(token, found);
85
+ }
86
+ if (!rows.includes(found)) rows.push(found);
87
+ entryRows.push(found);
88
+ }
89
+ let leadEntry = 0;
90
+ for (let entry = 1; entry < entryRows.length; entry++) {
91
+ if (entryRows[entry].count < entryRows[leadEntry].count) leadEntry = entry;
92
+ }
93
+ return { phrase, rows, entryRows, lead: entryRows[leadEntry], leadOffset: phrase.offsets[leadEntry] };
94
+ }
95
+ function firstRowFor(rows, doc) {
96
+ const { keys, count } = rows;
97
+ let low = rows.cursor < count && keys[rows.cursor] <= doc ? rows.cursor : 0;
98
+ let high = low;
99
+ let step = 1;
100
+ while (high < count && keys[high] < doc) {
101
+ low = high + 1;
102
+ high += step;
103
+ step *= 2;
104
+ }
105
+ if (high > count) high = count;
106
+ while (low < high) {
107
+ const middle = low + high >>> 1;
108
+ if (keys[middle] < doc) low = middle + 1;
109
+ else high = middle;
110
+ }
111
+ rows.cursor = low;
112
+ return low;
113
+ }
114
+ function positionRowFor(rows, doc, field) {
115
+ const { keys, order, fields, count } = rows;
116
+ for (let at = firstRowFor(rows, doc); at < count && keys[at] === doc; at++) {
117
+ const row = order === null ? at : order[at];
118
+ if (fields[row] === field) return row;
119
+ }
120
+ return -1;
121
+ }
122
+ function countPhraseStarts(resolved, leadRow, cursors, ends, tally) {
123
+ const { entryRows, lead, leadOffset, phrase } = resolved;
124
+ const offsets = phrase.offsets;
125
+ for (let entry = 0; entry < entryRows.length; entry++) {
126
+ const rows = entryRows[entry];
127
+ const start = rows.list.positionStartAt?.(rows.positionRow) ?? 0;
128
+ cursors[entry] = start;
129
+ ends[entry] = start + (rows.list.positionCountAt?.(rows.positionRow) ?? 0);
130
+ }
131
+ const leadStore = lead.store;
132
+ const leadStart = lead.list.positionStartAt?.(leadRow) ?? 0;
133
+ const leadEnd = leadStart + (lead.list.positionCountAt?.(leadRow) ?? 0);
134
+ let starts = 0;
135
+ for (let at = leadStart; at < leadEnd; at++) {
136
+ const anchor = leadStore[at] - leadOffset;
137
+ if (anchor < 0) continue;
138
+ let holdsEveryEntry = true;
139
+ for (let entry = 0; entry < entryRows.length; entry++) {
140
+ const store = entryRows[entry].store;
141
+ const wanted = anchor + offsets[entry];
142
+ let cursor = cursors[entry];
143
+ const end = ends[entry];
144
+ let compared = 1;
145
+ while (cursor < end && store[cursor] < wanted) {
146
+ cursor++;
147
+ compared++;
148
+ }
149
+ cursors[entry] = cursor;
150
+ tally.add(compared);
151
+ if (cursor === end) {
152
+ return starts;
153
+ }
154
+ if (store[cursor] !== wanted) {
155
+ holdsEveryEntry = false;
156
+ break;
157
+ }
158
+ }
159
+ if (holdsEveryEntry) starts++;
160
+ }
161
+ return starts;
162
+ }
163
+ function collectPhraseRows(resolved, searchable, allowed, capacity, keepRows, tally) {
164
+ const hits = createBitSet(capacity);
165
+ const collected = {
166
+ phrase: resolved.phrase,
167
+ lists: resolved.entryRows.map((rows2) => rows2.list),
168
+ docIds: new GrowableUint32(PHRASE_ROWS_START),
169
+ fieldIndices: new GrowableUint32(PHRASE_ROWS_START),
170
+ frequencies: new GrowableUint32(PHRASE_ROWS_START)
171
+ };
172
+ const { lead, rows } = resolved;
173
+ const leadList = lead.list;
174
+ const docIds = leadList.docIds;
175
+ const fields = leadList.fieldNameIndices;
176
+ const deleted = leadList.deletedDocs;
177
+ const hasDeleted = deleted.size > 0;
178
+ const cursors = new Int32Array(resolved.entryRows.length);
179
+ const ends = new Int32Array(resolved.entryRows.length);
180
+ for (const each of rows) each.cursor = 0;
181
+ for (let leadRow = 0; leadRow < lead.count; leadRow++) {
182
+ tally.add(1);
183
+ const doc = docIds[leadRow];
184
+ const field = fields[leadRow];
185
+ if (searchable[field] === 0) continue;
186
+ if (hasDeleted && deleted.has(doc)) continue;
187
+ if (allowed !== void 0 && !bitsetHas(allowed, doc)) continue;
188
+ let holdsEveryToken = true;
189
+ for (const each of rows) {
190
+ if (each === lead) {
191
+ each.positionRow = leadRow;
192
+ continue;
193
+ }
194
+ const row = positionRowFor(each, doc, field);
195
+ if (row === -1) {
196
+ holdsEveryToken = false;
197
+ break;
198
+ }
199
+ each.positionRow = row;
200
+ }
201
+ if (!holdsEveryToken) continue;
202
+ const starts = countPhraseStarts(resolved, leadRow, cursors, ends, tally);
203
+ if (starts === 0) continue;
204
+ bitsetSet(hits, doc);
205
+ if (keepRows) {
206
+ collected.docIds.push(doc);
207
+ collected.fieldIndices.push(field);
208
+ collected.frequencies.push(starts);
209
+ }
210
+ }
211
+ return { hits, rows: collected };
212
+ }
213
+ function matchPhrases(index, phrases, searchable, filterBitset, capacity, meter, keepRows) {
214
+ const tally = new WorkTally(meter);
215
+ const sharedRows = /* @__PURE__ */ new Map();
216
+ const resolved = [];
217
+ for (const phrase of phrases) {
218
+ const found = resolvePhrase(index, phrase, sharedRows, tally);
219
+ if (found === null) {
220
+ tally.flush();
221
+ return { matched: createBitSet(capacity), rows: [] };
222
+ }
223
+ resolved.push(found);
224
+ }
225
+ resolved.sort((first, second) => first.lead.count - second.lead.count);
226
+ const rows = [];
227
+ let allowed = filterBitset;
228
+ for (const each of resolved) {
229
+ const collected = collectPhraseRows(each, searchable, allowed, capacity, keepRows, tally);
230
+ allowed = collected.hits;
231
+ rows.push(collected.rows);
232
+ if (bitsetIsEmpty(allowed)) break;
233
+ }
234
+ tally.flush();
235
+ return { matched: allowed ?? createBitSet(capacity), rows };
236
+ }
237
+
238
+ // src/search/phrase-analysis.ts
239
+ function phraseKeyOf(tokens, offsets) {
240
+ const slots = [];
241
+ for (let index = 0; index < tokens.length; index++) {
242
+ const gap = index === 0 ? 0 : offsets[index] - offsets[index - 1] - 1;
243
+ for (let missing = 0; missing < gap; missing++) slots.push("?");
244
+ slots.push(tokens[index]);
245
+ }
246
+ return `"${slots.join(" ")}"`;
247
+ }
248
+ function identityOf(tokens, offsets) {
249
+ return JSON.stringify([tokens, offsets]);
250
+ }
251
+ function analyseQueryPhrases(parts, analyseText) {
252
+ const wordParts = [];
253
+ const phrases = [];
254
+ const seen = /* @__PURE__ */ new Set();
255
+ let keptPhraseCount = 0;
256
+ let largestPhraseSize = 0;
257
+ let largestTokenCount = 0;
258
+ let wordsAfterLastPhrase = "";
259
+ for (let index = 0; index < parts.length; index++) {
260
+ const part = parts[index];
261
+ if (index % 2 === 0) {
262
+ wordParts.push(part);
263
+ wordsAfterLastPhrase = `${wordsAfterLastPhrase} ${part}`;
264
+ continue;
265
+ }
266
+ if (part.trim().length === 0) continue;
267
+ const entries = analyseText(part);
268
+ if (entries.length === 0) continue;
269
+ const ordered = [...entries].sort((first, second) => first.position - second.position);
270
+ const firstPosition = ordered[0].position;
271
+ const size = ordered[ordered.length - 1].position - firstPosition + 1;
272
+ keptPhraseCount++;
273
+ wordsAfterLastPhrase = "";
274
+ if (size > largestPhraseSize) largestPhraseSize = size;
275
+ if (ordered.length > largestTokenCount) largestTokenCount = ordered.length;
276
+ const tokens = ordered.map((entry) => entry.token);
277
+ const offsets = ordered.map((entry) => entry.position - firstPosition);
278
+ const identity = identityOf(tokens, offsets);
279
+ if (seen.has(identity)) continue;
280
+ seen.add(identity);
281
+ phrases.push({ key: phraseKeyOf(tokens, offsets), tokens, offsets });
282
+ }
283
+ const endsWithPhrase = keptPhraseCount > 0 && (wordsAfterLastPhrase.trim().length === 0 || analyseText(wordsAfterLastPhrase).length === 0);
284
+ return {
285
+ words: wordParts.join(" "),
286
+ phrases,
287
+ keptPhraseCount,
288
+ largestPhraseSize,
289
+ largestTokenCount,
290
+ endsWithPhrase
291
+ };
292
+ }
293
+ function withWordsOnly(params, phrases) {
294
+ return { ...params, term: phrases.words, prefix: phrases.endsWithPhrase ? false : params.prefix };
295
+ }
296
+ function refusePhraseUntilRebuilt(indexName, rebuildMode) {
297
+ const remedy = rebuildMode === "manual" ? "This engine leaves the rebuild to its caller, so somebody has to start it with rebuildAnalysis" : "Try the query again once the rebuild finishes";
298
+ throw new NarsilError(
299
+ ErrorCodes.SEARCH_PHRASE_NOT_READY,
300
+ `Index "${indexName}" holds array fields whose terms need a rebuild, so it cannot match a phrase yet. ${remedy}`,
301
+ { indexName, rebuild: rebuildMode }
302
+ );
303
+ }
304
+ function requirePhrasesWithinLimits(phrases, trackPositions) {
305
+ if (phrases.keptPhraseCount === 0) return;
306
+ if (phrases.keptPhraseCount > MAX_QUERY_PHRASES) {
307
+ throw new NarsilError(
308
+ ErrorCodes.SEARCH_INVALID_PHRASE,
309
+ `A query takes at most ${MAX_QUERY_PHRASES} phrases, while this query holds ${phrases.keptPhraseCount}`,
310
+ { limit: MAX_QUERY_PHRASES, phrases: phrases.keptPhraseCount }
311
+ );
312
+ }
313
+ if (phrases.largestPhraseSize > MAX_PHRASE_WORDS || phrases.largestTokenCount > MAX_PHRASE_WORDS) {
314
+ throw new NarsilError(
315
+ ErrorCodes.SEARCH_INVALID_PHRASE,
316
+ `A phrase takes at most ${MAX_PHRASE_WORDS} words, counting the stop words between its first and last word, while this query holds one of ${Math.max(phrases.largestPhraseSize, phrases.largestTokenCount)}`,
317
+ { limit: MAX_PHRASE_WORDS, words: Math.max(phrases.largestPhraseSize, phrases.largestTokenCount) }
318
+ );
319
+ }
320
+ if (!trackPositions) {
321
+ throw new NarsilError(
322
+ ErrorCodes.SEARCH_INVALID_PHRASE,
323
+ "This index stores no word positions because its trackPositions setting is off, so it cannot match a phrase. Remove the quotes, or create the index with trackPositions on",
324
+ { trackPositions: false }
325
+ );
326
+ }
327
+ }
328
+
329
+ export { analyseQueryPhrases, matchPhrases, refusePhraseUntilRebuilt, requirePhrasesWithinLimits, withWordsOnly };
package/dist/react.d.ts CHANGED
@@ -1,13 +1,16 @@
1
- import { N as NarsilError, L as ListParams, g as ListResult, I as IndexInfo, k as IndexStats, Q as QueryParams, P as PreflightResult, e as QueryResult, h as SuggestParams, j as SuggestResult } from './events-pM0lna7M.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 './events-pM0lna7M.js';
3
- import { e as TaskRecord, d as TaskProgress, b as ImportResult, c as TaskListQuery, T as TaskListPage } from './tasks-txGvNz6h.js';
4
- export { I as ImportError, f as TaskStatus, g as TaskType } from './tasks-txGvNz6h.js';
1
+ import { N as NarsilError, L as ListParams, f as ListResult, I as IndexInfo, k as IndexStats, Q as QueryParams, j as PreflightResult, m as QueryResult, g as SuggestParams, h as SuggestResult } from './config-D1cDv3sE.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 './config-D1cDv3sE.js';
3
+ import { e as TaskRecord, d as TaskProgress, b as ImportResult, c as TaskListQuery, T as TaskListPage } from './tasks-Co8HfRD7.js';
4
+ export { E as ErrorDetail, I as ImportError, f as TaskStatus, g as TaskType } from './tasks-Co8HfRD7.js';
5
5
  import { ReactNode, ReactElement } from 'react';
6
- import { N as Narsil } from './engine-JjRAXpT3.js';
7
- import { N as NarsilClient, I as ImportSource } from './client-BOcveV7A.js';
8
- import { A as AnyDocument } from './schema-DGAP_8HJ.js';
9
- import './synonyms-CpOAHPa-.js';
6
+ import { N as Narsil } from './engine-m_Ddr1bz.js';
7
+ import { N as NarsilClient, I as ImportSource } from './client-gNAfaHcE.js';
8
+ import { A as AnyDocument } from './schema-BTXbHCqA.js';
10
9
  import './adapters-BQFQ4PRz.js';
10
+ import './synonyms-CpOAHPa-.js';
11
+ import './index-HYnqS1SE.js';
12
+ import './config-CmYJO34X.js';
13
+ import './types-DvncmvuQ.js';
11
14
 
12
15
  /**
13
16
  * These settings apply to {@link NarsilProvider} whether it holds a client or
package/dist/react.mjs CHANGED
@@ -34,6 +34,8 @@ var ErrorCodes = {
34
34
  SEARCH_INVALID_CURSOR: "SEARCH_INVALID_CURSOR",
35
35
  SEARCH_RESULT_WINDOW_EXCEEDED: "SEARCH_RESULT_WINDOW_EXCEEDED",
36
36
  SEARCH_WORK_CAP_EXCEEDED: "SEARCH_WORK_CAP_EXCEEDED",
37
+ SEARCH_INVALID_PHRASE: "SEARCH_INVALID_PHRASE",
38
+ SEARCH_PHRASE_NOT_READY: "SEARCH_PHRASE_NOT_READY",
37
39
  BM25_NOT_READY: "BM25_NOT_READY",
38
40
  LANGUAGE_NOT_SUPPORTED: "LANGUAGE_NOT_SUPPORTED",
39
41
  ENVELOPE_VERSION_MISMATCH: "ENVELOPE_VERSION_MISMATCH",
@@ -1,11 +1,11 @@
1
- import { runRerankedQuery, rerankTextOf } from './chunk-K73PZTBR.mjs';
1
+ import { runRerankedQuery, rerankTextOf } from './chunk-SZGRYEIC.mjs';
2
2
  import './chunk-KZ3NX2P7.mjs';
3
- import { rerankOnHost } from './chunk-FRSWYMXH.mjs';
4
- import './chunk-TY64A3ZW.mjs';
3
+ import { rerankOnHost } from './chunk-PATMDIMN.mjs';
4
+ import './chunk-5LX6MOIB.mjs';
5
5
  import './chunk-HJSN7UYG.mjs';
6
- import './chunk-Y4NOHICF.mjs';
7
- import './chunk-DX2FI4LU.mjs';
8
- import { NarsilError, ErrorCodes } from './chunk-WI5Q3L43.mjs';
6
+ import './chunk-RNSC4NFI.mjs';
7
+ import './chunk-FQBFZAWG.mjs';
8
+ import { NarsilError, ErrorCodes } from './chunk-CZ7ISLXA.mjs';
9
9
 
10
10
  // src/distribution/cluster-node/reads/rerank.ts
11
11
  async function rerankClusterQuery(deps, indexName, params, firstStage, readDocuments, host) {
@@ -1,5 +1,5 @@
1
- import { resolveApiKey, buildSignal, postJsonWithRetry } from '../chunk-OPO5SE4J.mjs';
2
- import { ErrorCodes, NarsilError } from '../chunk-WI5Q3L43.mjs';
1
+ import { resolveApiKey, buildSignal, postJsonWithRetry } from '../chunk-2WBY4Y4M.mjs';
2
+ import { ErrorCodes, NarsilError } from '../chunk-CZ7ISLXA.mjs';
3
3
 
4
4
  // src/rerankers/constants.ts
5
5
  var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
@@ -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-PUVSMV7E.mjs');
21
+ const { restoreFromSnapshot } = await import('./snapshot-DOQLGGEX.mjs');
22
22
  await restoreFromSnapshot(indexName, data, restoreDepsOf(core, host));
23
23
  });
24
24
  const settled = restored.then(
@@ -1,12 +1,12 @@
1
- import { runRerankedQuery, rerankTextOf } from './chunk-K73PZTBR.mjs';
1
+ import { runRerankedQuery, rerankTextOf } from './chunk-SZGRYEIC.mjs';
2
2
  export { withRerankQueryText } from './chunk-KZ3NX2P7.mjs';
3
- import { rerankOnHost } from './chunk-FRSWYMXH.mjs';
4
- export { rerankOnHost } from './chunk-FRSWYMXH.mjs';
5
- import { fixedHybridDepthOf, requireWithinHybridDepth, pageByPosition } from './chunk-TY64A3ZW.mjs';
3
+ import { rerankOnHost } from './chunk-PATMDIMN.mjs';
4
+ export { rerankOnHost } from './chunk-PATMDIMN.mjs';
5
+ import { fixedHybridDepthOf, requireWithinHybridDepth, pageByPosition } from './chunk-5LX6MOIB.mjs';
6
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-Y4NOHICF.mjs';
8
- import { HYBRID_RESCORE_WINDOW } from './chunk-DX2FI4LU.mjs';
9
- import { NarsilError, ErrorCodes } from './chunk-WI5Q3L43.mjs';
7
+ import './chunk-RNSC4NFI.mjs';
8
+ import { HYBRID_RESCORE_WINDOW } from './chunk-FQBFZAWG.mjs';
9
+ import { NarsilError, ErrorCodes } from './chunk-CZ7ISLXA.mjs';
10
10
 
11
11
  // src/engine/query/hybrid-depth.ts
12
12
  function countOfUnion(text, vectorScored) {
@@ -186,8 +186,11 @@ interface VectorIndexConfig {
186
186
  filterThreshold?: number;
187
187
  /** These settings shape the graph: neighbours per node, build-time exploration, and the metric that ranks results. */
188
188
  hnswConfig?: {
189
+ /** The graph keeps this many neighbours per node. */
189
190
  m?: number;
191
+ /** The engine explores this many candidates as it builds the graph. */
190
192
  efConstruction?: number;
193
+ /** This metric ranks the results. */
191
194
  metric?: 'cosine' | 'dotProduct' | 'euclidean';
192
195
  };
193
196
  /** The engine codes the promoted vectors in this mode. When this is unset, it picks the mode by the field's dimension. Set `none` to rank by the vectors alone. */
@@ -245,10 +248,10 @@ interface IndexConfig {
245
248
  /** This replaces the language's tokeniser, either inline or by the name a tokeniser registered under. */
246
249
  tokenizer?: CustomTokenizer | string;
247
250
  /**
248
- * Setting this records term positions in each posting, which the `.nrsl`
249
- * format carries for readers that match phrases. This engine's highlighter
250
- * re-analyses the stored text instead of reading them, so an index that
251
- * opts out answers every query the same way and stores less.
251
+ * Setting this records term positions in each posting, which phrase search
252
+ * compares. An index that opts out stores less, and the engine refuses a
253
+ * phrase on it with `SEARCH_INVALID_PHRASE`. Highlighting works either way,
254
+ * because the engine's highlighter analyses the stored text again.
252
255
  */
253
256
  trackPositions?: boolean;
254
257
  /** These settings control when vector fields move to an HNSW graph, and how that graph is built. */
@@ -382,4 +385,4 @@ interface InsertOptions extends WriteOptions {
382
385
  skipClone?: boolean;
383
386
  }
384
387
 
385
- 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, BM25FieldParams as c, FieldType as d, ScoringMode as e, VectorQuantizationMode as f, VectorStorageMode as g };
388
+ export type { AnyDocument as A, BM25Params as B, CustomTokenizer as C, EmbeddingFieldConfig as E, FieldType as F, InsertOptions as I, PartitionConfig as P, SchemaDefinition as S, TextFieldOption as T, VectorIndexConfig as V, WriteOptions as W, IndexConfig as a, StopWordOverride as b, BM25FieldParams as c, FieldOptionChain as d, ScoringMode as e, VectorQuantizationMode as f, VectorStorageMode as g };