@delali/narsil 0.3.1-next.157 → 0.3.1-next.161

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 (565) hide show
  1. package/dist/adapters/filesystem.mjs +3 -3
  2. package/dist/adapters/gcs.mjs +3 -3
  3. package/dist/adapters/indexeddb.mjs +1 -1
  4. package/dist/adapters/s3.mjs +3 -3
  5. package/dist/browser/{chunk-N23GL72Q.mjs → chunk-4RNSFVWI.mjs} +20777 -19056
  6. package/dist/browser/chunk-MMHIIL5B.mjs +564 -0
  7. package/dist/browser/chunk-MZHQ65VI.mjs +1228 -0
  8. package/dist/browser/chunk-WC2DEXWU.mjs +29 -0
  9. package/dist/browser/{chunk-VLJQW4J6.mjs → core-leaf-TJAGWPZZ.mjs} +4674 -3102
  10. package/dist/{react-native/chunks/durability-config-QXVZEO7T.mjs → browser/durability-config-SGB5ZP5K.mjs} +8 -3
  11. package/dist/browser/embed-RF2MPGAO.mjs +222 -0
  12. package/dist/{react-native/chunks/geo-index-PX3BIHAH.mjs → browser/geo-index-GNHY4PUB.mjs} +190 -93
  13. package/dist/{react-native/chunks/module-TTEVPRCW.mjs → browser/module-362VSIGR.mjs} +1570 -275
  14. package/dist/browser/msgpack-leaf-44XNWSSY.mjs +302 -0
  15. package/dist/browser/optional-reads-XMVPG6HG.mjs +3230 -0
  16. package/dist/browser/optional-writes-WMZX4OEC.mjs +3196 -0
  17. package/dist/browser/phrase-module-22TKMXWI.mjs +616 -0
  18. package/dist/browser/resolve-vector-text-KI65IHMD.mjs +60 -0
  19. package/dist/browser/{restore-hooks-IE3GGYHG.mjs → restore-queue-S4BWOGMU.mjs} +98 -24
  20. package/dist/{react-native/chunks/runtime-R5E3TB3J.mjs → browser/runtime-NU6VOVH2.mjs} +61 -25
  21. package/dist/browser/segment-codec-leaf-A427QJUX.mjs +554 -0
  22. package/dist/browser/segment-merge-leaf-7BZ54JPI.mjs +1636 -0
  23. package/dist/browser/storage-leaf-X6CNRHJS.mjs +18221 -0
  24. package/dist/browser/store-leaf-AEMTAVHX.mjs +2069 -0
  25. package/dist/browser/{chunk-GFAZPSWK.mjs → suggestions-leaf-3Y6MR6OF.mjs} +441 -119
  26. package/dist/browser/worker-copies-WQCPP3TS.mjs +2750 -0
  27. package/dist/{capabilities-D3AoBJoF.d.ts → capabilities-BKDrry0z.d.ts} +2 -2
  28. package/dist/chunk-2JRERUNZ.mjs +217 -0
  29. package/dist/chunk-2RIS76RJ.mjs +212 -0
  30. package/dist/chunk-3B775F3C.mjs +252 -0
  31. package/dist/{chunk-24FNVRKB.mjs → chunk-3D6RZGJH.mjs} +3 -3
  32. package/dist/{chunk-INJYO3BU.mjs → chunk-4CAMH7FO.mjs} +1 -1
  33. package/dist/{chunk-U476IXKQ.mjs → chunk-4PY4JYMY.mjs} +2 -1
  34. package/dist/chunk-6EZW2GQL.mjs +978 -0
  35. package/dist/chunk-75UNINFA.mjs +271 -0
  36. package/dist/chunk-77AUVDQ5.mjs +7 -0
  37. package/dist/{chunk-JTYPJF3T.mjs → chunk-7MWYORQC.mjs} +2 -2
  38. package/dist/{chunk-TGP5M5R7.mjs → chunk-7T4LAYT4.mjs} +1 -1
  39. package/dist/{chunk-XIHUI4KB.mjs → chunk-AB27FWZM.mjs} +8 -3
  40. package/dist/{chunk-FUD5XSZ5.mjs → chunk-BXM7XM4G.mjs} +7 -3
  41. package/dist/{chunk-HJJI72X7.mjs → chunk-C7YQHCSO.mjs} +1 -1
  42. package/dist/{chunk-RVGRFOGN.mjs → chunk-D456ZFPQ.mjs} +2 -1
  43. package/dist/{chunk-KKQC526K.mjs → chunk-E2F6LZR3.mjs} +19 -21
  44. package/dist/{chunk-SMOOSIAW.mjs → chunk-FE3MRIBN.mjs} +104 -13
  45. package/dist/{chunk-KYYABCSW.mjs → chunk-FETZYCH7.mjs} +15 -1
  46. package/dist/{chunk-XXJZMTZT.mjs → chunk-FVZ5DB6Y.mjs} +3 -2
  47. package/dist/{chunk-EYD7K3H6.mjs → chunk-GF4K7IUK.mjs} +317 -120
  48. package/dist/chunk-GXCDWLQI.mjs +193 -0
  49. package/dist/{chunk-IIRIG7H5.mjs → chunk-H64YDF5M.mjs} +3 -3
  50. package/dist/{browser/chunk-VY5KW3HN.mjs → chunk-HOOR4CP5.mjs} +63 -7
  51. package/dist/chunk-IB4BYLE3.mjs +127 -0
  52. package/dist/{chunk-3C7MTCCI.mjs → chunk-IE3Q62QD.mjs} +2 -2
  53. package/dist/chunk-IH3G6SJO.mjs +40 -0
  54. package/dist/chunk-JV74RKCY.mjs +3041 -0
  55. package/dist/{chunk-ZPZ3YGXV.mjs → chunk-K67I3RF4.mjs} +261 -101
  56. package/dist/chunk-KLVMK3R5.mjs +47 -0
  57. package/dist/{chunk-5VV4R6P7.mjs → chunk-LAWIJRMJ.mjs} +4154 -2577
  58. package/dist/chunk-LF4GB4PO.mjs +281 -0
  59. package/dist/chunk-NC4QLCZC.mjs +59 -0
  60. package/dist/chunk-OOO54OVC.mjs +627 -0
  61. package/dist/chunk-OUWZKNO3.mjs +207 -0
  62. package/dist/{chunk-FJKKCV4D.mjs → chunk-P5YLI5ED.mjs} +343 -182
  63. package/dist/{chunk-4ZTHGTVX.mjs → chunk-PTTMGRG5.mjs} +9 -10
  64. package/dist/{react-native/chunks/chunk-DZ7H7D2C.mjs → chunk-Q3ZZH5Z7.mjs} +6 -0
  65. package/dist/{browser/chunk-EKMGCRSR.mjs → chunk-QBVTYY4J.mjs} +2 -9
  66. package/dist/{chunk-W5EB5XKI.mjs → chunk-R4CE4IVU.mjs} +341 -183
  67. package/dist/chunk-S2POFTLN.mjs +10 -0
  68. package/dist/{chunk-KJ3RTZDJ.mjs → chunk-S3BSDBF7.mjs} +10 -3
  69. package/dist/{chunk-4LMSZAK6.mjs → chunk-SHGN3QIF.mjs} +69 -13
  70. package/dist/chunk-SXIRM4MX.mjs +3549 -0
  71. package/dist/{chunk-TBC3XUL2.mjs → chunk-TGPKS2UM.mjs} +47 -1
  72. package/dist/chunk-TINW4BSH.mjs +31301 -0
  73. package/dist/{cold-module-VOJXMNZB.mjs → chunk-TSLV5P2J.mjs} +397 -80
  74. package/dist/{chunk-HHBUCIUY.mjs → chunk-TW543F33.mjs} +3 -3
  75. package/dist/chunk-U6B7DUQW.mjs +788 -0
  76. package/dist/{chunk-OQLD2BSW.mjs → chunk-V3SGPXWQ.mjs} +8 -9
  77. package/dist/chunk-W34VJXY7.mjs +4723 -0
  78. package/dist/chunk-YETKPX5M.mjs +5 -0
  79. package/dist/chunk-ZQ6QY42L.mjs +59 -0
  80. package/dist/{client-kqSMevVi.d.ts → client-CTp8RRiK.d.ts} +4 -4
  81. package/dist/client.d.ts +8 -8
  82. package/dist/client.mjs +66 -18
  83. package/dist/{config-B4v_Htpu.d.ts → config-PCNzWjHL.d.ts} +6 -3
  84. package/dist/{config-CTP01fns.d.ts → config-_WT5grSL.d.ts} +3 -3
  85. package/dist/core-leaf-KXFGP74A.mjs +7 -0
  86. package/dist/digest-leaf-KXBGKYHZ.mjs +1 -0
  87. package/dist/direct-executor-MKTZBR26.mjs +16 -0
  88. package/dist/distribution/coordinator/etcd.d.ts +2 -2
  89. package/dist/distribution/coordinator/etcd.mjs +7 -4
  90. package/dist/distribution/coordinator/in-memory.d.ts +2 -2
  91. package/dist/distribution/coordinator/in-memory.mjs +1 -2
  92. package/dist/distribution/transport/grpc.mjs +7 -2
  93. package/dist/distribution/transport/tcp.mjs +7 -1
  94. package/dist/distribution.d.ts +7 -7
  95. package/dist/distribution.mjs +1199 -1092
  96. package/dist/{browser/durability-config-TIYKW6XX.mjs → durability-config-XV4XR7Y4.mjs} +7 -3
  97. package/dist/embed-4H7RTBVL.mjs +221 -0
  98. package/dist/embeddings/openai.mjs +2 -2
  99. package/dist/{engine-CkPn2PWE.d.ts → engine-DBRVR_d-.d.ts} +1252 -1239
  100. package/dist/{browser/geo-index-OTV7VPIR.mjs → geo-index-2ZMMWWSK.mjs} +190 -93
  101. package/dist/{index-C4AmUnl1.d.ts → index-Ck9w5WHz.d.ts} +1 -1
  102. package/dist/index.browser.mjs +4 -16
  103. package/dist/index.d.ts +1495 -78
  104. package/dist/index.mjs +14 -50
  105. package/dist/index.react-native.mjs +11 -28
  106. package/dist/invalidation/filesystem.mjs +1 -2
  107. package/dist/languages/albanian.mjs +1 -1
  108. package/dist/languages/amharic.mjs +1 -1
  109. package/dist/languages/arabic.mjs +1 -1
  110. package/dist/languages/armenian.mjs +1 -1
  111. package/dist/languages/azerbaijani.mjs +1 -1
  112. package/dist/languages/bambara.mjs +1 -1
  113. package/dist/languages/basque.mjs +1 -1
  114. package/dist/languages/belarusian.mjs +1 -1
  115. package/dist/languages/bengali.mjs +1 -1
  116. package/dist/languages/bosnian.mjs +1 -1
  117. package/dist/languages/breton.mjs +1 -1
  118. package/dist/languages/bulgarian.mjs +1 -1
  119. package/dist/languages/burmese.mjs +1 -1
  120. package/dist/languages/catalan.mjs +1 -1
  121. package/dist/languages/chinese.mjs +1 -1
  122. package/dist/languages/croatian.mjs +1 -1
  123. package/dist/languages/czech.mjs +1 -1
  124. package/dist/languages/dagbani.mjs +1 -1
  125. package/dist/languages/danish.mjs +1 -1
  126. package/dist/languages/dutch.mjs +1 -1
  127. package/dist/languages/english.mjs +1 -1
  128. package/dist/languages/esperanto.mjs +1 -1
  129. package/dist/languages/estonian.mjs +1 -1
  130. package/dist/languages/ewe.mjs +1 -1
  131. package/dist/languages/faroese.mjs +1 -1
  132. package/dist/languages/fijian.mjs +1 -1
  133. package/dist/languages/finnish.mjs +1 -1
  134. package/dist/languages/french.mjs +1 -1
  135. package/dist/languages/ga.mjs +1 -1
  136. package/dist/languages/galician.mjs +1 -1
  137. package/dist/languages/georgian.mjs +1 -1
  138. package/dist/languages/german.mjs +1 -1
  139. package/dist/languages/greek.mjs +1 -1
  140. package/dist/languages/guarani.mjs +1 -1
  141. package/dist/languages/gujarati.mjs +1 -1
  142. package/dist/languages/haitian-creole.mjs +1 -1
  143. package/dist/languages/hausa.mjs +1 -1
  144. package/dist/languages/hawaiian.mjs +1 -1
  145. package/dist/languages/hebrew.mjs +1 -1
  146. package/dist/languages/hindi.mjs +1 -1
  147. package/dist/languages/hungarian.mjs +1 -1
  148. package/dist/languages/icelandic.mjs +1 -1
  149. package/dist/languages/igbo.mjs +1 -1
  150. package/dist/languages/indonesian.mjs +1 -1
  151. package/dist/languages/irish.mjs +1 -1
  152. package/dist/languages/italian.mjs +1 -1
  153. package/dist/languages/japanese.mjs +1 -1
  154. package/dist/languages/kannada.mjs +1 -1
  155. package/dist/languages/kazakh.mjs +1 -1
  156. package/dist/languages/khmer.mjs +1 -1
  157. package/dist/languages/kinyarwanda.mjs +1 -1
  158. package/dist/languages/kirundi.mjs +1 -1
  159. package/dist/languages/korean.mjs +1 -1
  160. package/dist/languages/kurmanji.mjs +1 -1
  161. package/dist/languages/kyrgyz.mjs +1 -1
  162. package/dist/languages/lao.mjs +1 -1
  163. package/dist/languages/latin.mjs +1 -1
  164. package/dist/languages/latvian.mjs +1 -1
  165. package/dist/languages/lingala.mjs +1 -1
  166. package/dist/languages/lithuanian.mjs +1 -1
  167. package/dist/languages/luxembourgish.mjs +1 -1
  168. package/dist/languages/macedonian.mjs +1 -1
  169. package/dist/languages/malagasy.mjs +1 -1
  170. package/dist/languages/malay.mjs +1 -1
  171. package/dist/languages/malayalam.mjs +1 -1
  172. package/dist/languages/maltese.mjs +1 -1
  173. package/dist/languages/maori.mjs +1 -1
  174. package/dist/languages/marathi.mjs +1 -1
  175. package/dist/languages/nepali.mjs +1 -1
  176. package/dist/languages/norwegian.mjs +1 -1
  177. package/dist/languages/oromo.mjs +1 -1
  178. package/dist/languages/persian.mjs +1 -1
  179. package/dist/languages/polish.mjs +1 -1
  180. package/dist/languages/portuguese.mjs +1 -1
  181. package/dist/languages/punjabi.mjs +1 -1
  182. package/dist/languages/romanian.mjs +1 -1
  183. package/dist/languages/russian.mjs +1 -1
  184. package/dist/languages/samoan.mjs +1 -1
  185. package/dist/languages/sanskrit.mjs +1 -1
  186. package/dist/languages/scottish-gaelic.mjs +1 -1
  187. package/dist/languages/serbian.mjs +1 -1
  188. package/dist/languages/shona.mjs +1 -1
  189. package/dist/languages/sinhala.mjs +1 -1
  190. package/dist/languages/slovak.mjs +1 -1
  191. package/dist/languages/slovenian.mjs +1 -1
  192. package/dist/languages/sorani.mjs +1 -1
  193. package/dist/languages/spanish.mjs +1 -1
  194. package/dist/languages/swahili.mjs +1 -1
  195. package/dist/languages/swedish.mjs +1 -1
  196. package/dist/languages/tagalog.mjs +1 -1
  197. package/dist/languages/tamil.mjs +1 -1
  198. package/dist/languages/tatar.mjs +1 -1
  199. package/dist/languages/telugu.mjs +1 -1
  200. package/dist/languages/thai.mjs +1 -1
  201. package/dist/languages/tibetan.mjs +1 -1
  202. package/dist/languages/tigrinya.mjs +1 -1
  203. package/dist/languages/tongan.mjs +1 -1
  204. package/dist/languages/turkish.mjs +1 -1
  205. package/dist/languages/twi.mjs +1 -1
  206. package/dist/languages/ukrainian.mjs +1 -1
  207. package/dist/languages/urdu.mjs +1 -1
  208. package/dist/languages/vietnamese.mjs +1 -1
  209. package/dist/languages/welsh.mjs +1 -1
  210. package/dist/languages/wolof.mjs +1 -1
  211. package/dist/languages/xhosa.mjs +1 -1
  212. package/dist/languages/yoruba.mjs +1 -1
  213. package/dist/languages/zulu.mjs +1 -1
  214. package/dist/{long-query-thread-QDFQSJD6.mjs → long-query-thread-JMGNGF6V.mjs} +74 -58
  215. package/dist/{module-N55W4Q5C.mjs → module-ZJ6ARG6V.mjs} +444 -111
  216. package/dist/msgpack-leaf-5WFRP6JM.mjs +9 -0
  217. package/dist/optional-reads-BR3BOVZW.mjs +3373 -0
  218. package/dist/optional-writes-DDFHYUOH.mjs +218 -0
  219. package/dist/{paged-partition-archive-RLRGOXDX.mjs → paged-partition-archive-G576XGVE.mjs} +29 -69
  220. package/dist/partial-words.browser.mjs +1649 -0
  221. package/dist/partial-words.mjs +15 -14
  222. package/dist/{chunk-CITFCZKF.mjs → pattern.browser.mjs} +153 -186
  223. package/dist/pattern.mjs +6 -8
  224. package/dist/persistence/durability/checkpoint-worker.d.ts +32 -24
  225. package/dist/persistence/durability/checkpoint-worker.mjs +27 -59
  226. package/dist/phrase-module-XK3T44VU.mjs +634 -0
  227. package/dist/query-actions-OMXJEC2J.mjs +118 -0
  228. package/dist/query-suggestions/merge-worker.mjs +18 -54
  229. package/dist/query-suggestions.browser.mjs +26 -227
  230. package/dist/query-suggestions.d.ts +2 -2
  231. package/dist/query-suggestions.mjs +16 -67
  232. package/dist/react-native/chunks/chunk-4EXKQ2IB.mjs +565 -0
  233. package/dist/react-native/chunks/chunk-52QD7CBJ.mjs +52 -0
  234. package/dist/react-native/chunks/chunk-72OKYHZL.mjs +969 -0
  235. package/dist/react-native/chunks/chunk-AQOWRH2C.mjs +802 -0
  236. package/dist/react-native/chunks/{chunk-4COWCEY7.mjs → chunk-FTQ7JNMU.mjs} +341 -180
  237. package/dist/react-native/chunks/chunk-G3CUQ333.mjs +42 -0
  238. package/dist/react-native/chunks/{chunk-EJ33LCHV.mjs → chunk-HRDMIQ63.mjs} +53 -1
  239. package/dist/react-native/chunks/{chunk-4AV5PPH6.mjs → chunk-IY6U6HRA.mjs} +63 -7
  240. package/dist/react-native/chunks/chunk-J2NQW353.mjs +212 -0
  241. package/dist/react-native/chunks/chunk-L4R5ITVG.mjs +29047 -0
  242. package/dist/react-native/chunks/{chunk-OXM66LO6.mjs → chunk-OK3WUA6N.mjs} +2 -10
  243. package/dist/react-native/chunks/{chunk-MVXELMJX.mjs → chunk-PVMEHBQO.mjs} +1 -1
  244. package/dist/{browser/chunk-SRMZXJSL.mjs → react-native/chunks/chunk-TQ26BKBH.mjs} +6 -0
  245. package/dist/{browser/chunk-GPPOG6PT.mjs → react-native/chunks/chunk-VUJCSQG5.mjs} +3 -1
  246. package/dist/react-native/chunks/{chunk-ENLMYKSX.mjs → chunk-XEGKQKLY.mjs} +5385 -3114
  247. package/dist/react-native/chunks/chunk-YOTP2FPE.mjs +232 -0
  248. package/dist/react-native/chunks/chunk-ZIU6TWXG.mjs +127 -0
  249. package/dist/react-native/chunks/core-leaf-5B4JXCVA.mjs +6 -0
  250. package/dist/react-native/chunks/digest-leaf-X6OIFDIU.mjs +1 -0
  251. package/dist/{durability-config-GE4U7MCZ.mjs → react-native/chunks/durability-config-3IOXIPYZ.mjs} +7 -3
  252. package/dist/react-native/chunks/embed-3WQ2CCR5.mjs +221 -0
  253. package/dist/{geo-index-MRH5JMIR.mjs → react-native/chunks/geo-index-QEYKEVPH.mjs} +190 -93
  254. package/dist/react-native/chunks/{chunk-CKNRFDTZ.mjs → gzip.react-native-DLO4WW27.mjs} +2 -1
  255. package/dist/{browser/module-TCT66FWA.mjs → react-native/chunks/module-VUA27HZZ.mjs} +1018 -540
  256. package/dist/react-native/chunks/msgpack-leaf-TR66ZVAX.mjs +7 -0
  257. package/dist/react-native/chunks/optional-reads-WDTLLHUT.mjs +3364 -0
  258. package/dist/react-native/chunks/optional-writes-FZV3QW34.mjs +267 -0
  259. package/dist/react-native/chunks/phrase-module-KCQWVXYZ.mjs +635 -0
  260. package/dist/react-native/chunks/resolve-vector-text-LXRYXF7M.mjs +59 -0
  261. package/dist/react-native/chunks/restore-queue-EI2V2I4S.mjs +179 -0
  262. package/dist/{browser/runtime-OTAGEFQW.mjs → react-native/chunks/runtime-BUCSAK4U.mjs} +61 -25
  263. package/dist/react-native/chunks/segment-codec-leaf-6ULP7H3I.mjs +12 -0
  264. package/dist/react-native/chunks/segment-merge-leaf-F4GQZNK6.mjs +13 -0
  265. package/dist/react-native/chunks/storage-leaf-OAXBU2L6.mjs +18042 -0
  266. package/dist/react-native/chunks/store-leaf-GY2ZZFXB.mjs +14 -0
  267. package/dist/react-native/chunks/{chunk-WW2X2AEI.mjs → suggestions-leaf-SQEZ4IBS.mjs} +332 -118
  268. package/dist/react-native/chunks/worker-copies-EEHSCFJW.mjs +2627 -0
  269. package/dist/react-native/partial-words.mjs +954 -35
  270. package/dist/react-native/pattern.mjs +238 -111
  271. package/dist/react-native/query-suggestions.mjs +33 -239
  272. package/dist/react-native/sync.mjs +95 -52
  273. package/dist/react-native/synonyms.mjs +256 -112
  274. package/dist/react.d.ts +9 -9
  275. package/dist/react.mjs +6 -0
  276. package/dist/{rerank-MQ37IYRV.mjs → rerank-Y6MWBMTT.mjs} +17 -8
  277. package/dist/rerankers/http.mjs +2 -2
  278. package/dist/resolve-vector-text-4PDRTPNQ.mjs +2 -0
  279. package/dist/restore-queue-KPYSRJ4A.mjs +184 -0
  280. package/dist/runtime-4GKUIAKV.mjs +595 -0
  281. package/dist/{schema-Jwt928nJ.d.ts → schema-C_7yRJLt.d.ts} +1 -1
  282. package/dist/segment-codec-leaf-6IFBSBPN.mjs +17 -0
  283. package/dist/segment-merge-leaf-VE3FUSVE.mjs +17 -0
  284. package/dist/server.d.ts +33 -13
  285. package/dist/server.mjs +81 -100
  286. package/dist/{browser/durability-wiring-GVZEE46O.mjs → storage-leaf-HMIIOUYN.mjs} +2334 -931
  287. package/dist/store-leaf-M7T7SUZJ.mjs +19 -0
  288. package/dist/stored-values-BWIMpiT_.d.ts +25 -0
  289. package/dist/suggestions-leaf-Q3Q5D6XV.mjs +53 -0
  290. package/dist/sync/filesystem.d.ts +3 -3
  291. package/dist/sync/filesystem.mjs +27 -11
  292. package/dist/sync/indexeddb.browser.mjs +287 -0
  293. package/dist/sync/indexeddb.d.ts +3 -3
  294. package/dist/sync/indexeddb.mjs +7 -2
  295. package/dist/sync.browser.mjs +88 -72
  296. package/dist/sync.d.ts +4 -4
  297. package/dist/sync.mjs +89 -59
  298. package/dist/{chunk-I5B7RXU7.mjs → synonyms.browser.mjs} +248 -135
  299. package/dist/synonyms.mjs +15 -11
  300. package/dist/{tasks-CoNjxbop.d.ts → tasks-B4tT4vmP.d.ts} +4 -4
  301. package/dist/thread-SNILJXX3.mjs +30 -0
  302. package/dist/{types-DPMjfOr_.d.ts → types-CTg0KaMy.d.ts} +2 -2
  303. package/dist/vector/search-worker.d.ts +7 -1
  304. package/dist/vector/search-worker.mjs +9 -13
  305. package/dist/worker-copies-ZLZS2CUM.mjs +2152 -0
  306. package/dist/workers/entry.mjs +60 -30
  307. package/openapi.json +66 -50
  308. package/package.json +233 -8
  309. package/dist/analysis-change-CKEMM2MC.mjs +0 -55
  310. package/dist/analysis-change-entry-SEDMJ6MW.mjs +0 -1
  311. package/dist/archive-history-E4R73RWD.mjs +0 -29
  312. package/dist/browser/analysis-change-ZKGJFENM.mjs +0 -942
  313. package/dist/browser/analysis-change-entry-5BFUVMHJ.mjs +0 -1
  314. package/dist/browser/archive-history-4IP5XQZY.mjs +0 -29
  315. package/dist/browser/chunk-25MTVDYD.mjs +0 -432
  316. package/dist/browser/chunk-3I27KXQD.mjs +0 -34
  317. package/dist/browser/chunk-3NLMB5CC.mjs +0 -217
  318. package/dist/browser/chunk-4RD3AFSB.mjs +0 -32
  319. package/dist/browser/chunk-5W3MMTLG.mjs +0 -19
  320. package/dist/browser/chunk-5YWB3E2W.mjs +0 -92
  321. package/dist/browser/chunk-7IGKGWSQ.mjs +0 -79
  322. package/dist/browser/chunk-AI5UI46D.mjs +0 -12
  323. package/dist/browser/chunk-ATEBYXP6.mjs +0 -10
  324. package/dist/browser/chunk-BLT4RHCJ.mjs +0 -241
  325. package/dist/browser/chunk-C26SPCGQ.mjs +0 -2636
  326. package/dist/browser/chunk-C4FJ3WDY.mjs +0 -177
  327. package/dist/browser/chunk-CXNTHHA7.mjs +0 -63
  328. package/dist/browser/chunk-DSXIBE6N.mjs +0 -78
  329. package/dist/browser/chunk-DUH6QUVU.mjs +0 -2374
  330. package/dist/browser/chunk-ELV4OZOI.mjs +0 -29
  331. package/dist/browser/chunk-EXQZGUQH.mjs +0 -193
  332. package/dist/browser/chunk-G64Q6OJF.mjs +0 -96
  333. package/dist/browser/chunk-HOZW3PKP.mjs +0 -9
  334. package/dist/browser/chunk-HUCSHDTB.mjs +0 -100
  335. package/dist/browser/chunk-JPTQZWJQ.mjs +0 -10
  336. package/dist/browser/chunk-K3IPRX6D.mjs +0 -2559
  337. package/dist/browser/chunk-ML7THVLJ.mjs +0 -38
  338. package/dist/browser/chunk-MY2XKH22.mjs +0 -40
  339. package/dist/browser/chunk-NLWTBAGB.mjs +0 -111
  340. package/dist/browser/chunk-NXQG7DRA.mjs +0 -318
  341. package/dist/browser/chunk-OEDCEZXJ.mjs +0 -92
  342. package/dist/browser/chunk-OIZS5KIX.mjs +0 -6
  343. package/dist/browser/chunk-RA6LSBCM.mjs +0 -43
  344. package/dist/browser/chunk-TK63WFXK.mjs +0 -90
  345. package/dist/browser/chunk-TY7L6OXO.mjs +0 -69
  346. package/dist/browser/chunk-U3JOQGWX.mjs +0 -19
  347. package/dist/browser/chunk-U4YDIBUT.mjs +0 -653
  348. package/dist/browser/chunk-UATIJ4KU.mjs +0 -21
  349. package/dist/browser/chunk-UKOWD2K5.mjs +0 -315
  350. package/dist/browser/chunk-UTMHUHUV.mjs +0 -150
  351. package/dist/browser/chunk-V43N6TZO.mjs +0 -857
  352. package/dist/browser/chunk-VI7BQR4U.mjs +0 -21
  353. package/dist/browser/chunk-WN464PTL.mjs +0 -375
  354. package/dist/browser/chunk-WXLBZJMT.mjs +0 -25
  355. package/dist/browser/chunk-X7TXYUKO.mjs +0 -86
  356. package/dist/browser/chunk-XAWNZ4G2.mjs +0 -151
  357. package/dist/browser/chunk-Y6IBAUNO.mjs +0 -561
  358. package/dist/browser/chunk-ZI2V4VD7.mjs +0 -21
  359. package/dist/browser/cold-module-YNUUDNOM.mjs +0 -761
  360. package/dist/browser/engine-hooks-HBVS6YM4.mjs +0 -18
  361. package/dist/browser/gzip-5S7ROJFJ.mjs +0 -1
  362. package/dist/browser/import-5ESVMFDJ.mjs +0 -20
  363. package/dist/browser/methods-KTQCSIN4.mjs +0 -30
  364. package/dist/browser/module-NDSQLPMQ.mjs +0 -25
  365. package/dist/browser/operations-OJ3BXS55.mjs +0 -5
  366. package/dist/browser/phrase-module-HAT3TLZN.mjs +0 -328
  367. package/dist/browser/pool-3JLET5RO.mjs +0 -297
  368. package/dist/browser/release-HYXPVJVS.mjs +0 -32
  369. package/dist/browser/restore-queue-LQBBTODR.mjs +0 -55
  370. package/dist/browser/retention-TY3L3BFN.mjs +0 -211
  371. package/dist/browser/snapshot-5FHPPCNZ.mjs +0 -965
  372. package/dist/browser/start-2UZTOBG5.mjs +0 -26
  373. package/dist/browser/sync-state-P5XG6LTQ.mjs +0 -15
  374. package/dist/browser/write-ULXAN5B4.mjs +0 -196
  375. package/dist/chunk-2NE7VCYE.mjs +0 -212
  376. package/dist/chunk-2ROUFMQX.mjs +0 -543
  377. package/dist/chunk-37CD3OKS.mjs +0 -87
  378. package/dist/chunk-3MXV3VHR.mjs +0 -46
  379. package/dist/chunk-3OH67G7R.mjs +0 -214
  380. package/dist/chunk-4B7JIGQD.mjs +0 -106
  381. package/dist/chunk-5YNRKI2C.mjs +0 -81
  382. package/dist/chunk-6HTGOXIK.mjs +0 -875
  383. package/dist/chunk-6OEGXLBX.mjs +0 -57
  384. package/dist/chunk-6RC4K46J.mjs +0 -86
  385. package/dist/chunk-7GFE3PEY.mjs +0 -40
  386. package/dist/chunk-7GXJUJ24.mjs +0 -49
  387. package/dist/chunk-7V5IUP2T.mjs +0 -63
  388. package/dist/chunk-A4L7YTKX.mjs +0 -458
  389. package/dist/chunk-BEZH7VEH.mjs +0 -23
  390. package/dist/chunk-BNL5OPRV.mjs +0 -634
  391. package/dist/chunk-BTPGQC6Z.mjs +0 -27
  392. package/dist/chunk-C7XQYG6U.mjs +0 -50
  393. package/dist/chunk-CQZXZ75V.mjs +0 -562
  394. package/dist/chunk-CWS55TEX.mjs +0 -242
  395. package/dist/chunk-CZQ33DLW.mjs +0 -78
  396. package/dist/chunk-EEBCDP36.mjs +0 -32
  397. package/dist/chunk-FB6463IN.mjs +0 -1499
  398. package/dist/chunk-FCJ553HS.mjs +0 -655
  399. package/dist/chunk-FEZVDOWX.mjs +0 -6996
  400. package/dist/chunk-FOCV4CBZ.mjs +0 -87
  401. package/dist/chunk-FQBFZAWG.mjs +0 -27
  402. package/dist/chunk-G6HRSGOU.mjs +0 -74
  403. package/dist/chunk-GES7U2PM.mjs +0 -68
  404. package/dist/chunk-GH4WQ22V.mjs +0 -34
  405. package/dist/chunk-GPWMUPCA.mjs +0 -1126
  406. package/dist/chunk-GQPTDQCL.mjs +0 -54
  407. package/dist/chunk-HJSN7UYG.mjs +0 -10
  408. package/dist/chunk-I54T6CQP.mjs +0 -117
  409. package/dist/chunk-IPN7S4KX.mjs +0 -130
  410. package/dist/chunk-J4IJTTEX.mjs +0 -226
  411. package/dist/chunk-JSV6OQ4C.mjs +0 -74
  412. package/dist/chunk-K4ZIGL2O.mjs +0 -290
  413. package/dist/chunk-KAKQ74LS.mjs +0 -53
  414. package/dist/chunk-KCQYFO4K.mjs +0 -62
  415. package/dist/chunk-KHKIRS5D.mjs +0 -113
  416. package/dist/chunk-KOKM4PQN.mjs +0 -52
  417. package/dist/chunk-KP7TYHWT.mjs +0 -92
  418. package/dist/chunk-KZ3NX2P7.mjs +0 -21
  419. package/dist/chunk-L5ORED7V.mjs +0 -25
  420. package/dist/chunk-LDNCLRZU.mjs +0 -218
  421. package/dist/chunk-LHKOSI2J.mjs +0 -58
  422. package/dist/chunk-LQG5G2LY.mjs +0 -39
  423. package/dist/chunk-MATMVH65.mjs +0 -9
  424. package/dist/chunk-MP7ABPTD.mjs +0 -189
  425. package/dist/chunk-MW6BR4QP.mjs +0 -316
  426. package/dist/chunk-MWD5VPN7.mjs +0 -21
  427. package/dist/chunk-ODYKO5TO.mjs +0 -101
  428. package/dist/chunk-OG7UGJ6F.mjs +0 -63
  429. package/dist/chunk-ORN5BLL7.mjs +0 -11
  430. package/dist/chunk-OYABFKTW.mjs +0 -1974
  431. package/dist/chunk-P5LANSH6.mjs +0 -121
  432. package/dist/chunk-PELHVTO7.mjs +0 -24
  433. package/dist/chunk-PIH5SJ4N.mjs +0 -7481
  434. package/dist/chunk-PSZI4O24.mjs +0 -253
  435. package/dist/chunk-PV2CG7EJ.mjs +0 -886
  436. package/dist/chunk-PWGYQXML.mjs +0 -470
  437. package/dist/chunk-Q2UL2TPC.mjs +0 -21
  438. package/dist/chunk-QHPYS427.mjs +0 -66
  439. package/dist/chunk-QJVOLKU6.mjs +0 -111
  440. package/dist/chunk-QLDABJZM.mjs +0 -20
  441. package/dist/chunk-QYRNLLLI.mjs +0 -99
  442. package/dist/chunk-RCX4WNLC.mjs +0 -151
  443. package/dist/chunk-RFBLQLLZ.mjs +0 -16
  444. package/dist/chunk-RIHIVFIQ.mjs +0 -240
  445. package/dist/chunk-RLOES5SX.mjs +0 -31
  446. package/dist/chunk-RWURUDSP.mjs +0 -2639
  447. package/dist/chunk-RZWWB2XR.mjs +0 -96
  448. package/dist/chunk-S5LN746F.mjs +0 -10
  449. package/dist/chunk-SOI6LTHM.mjs +0 -216
  450. package/dist/chunk-SQJWAIF4.mjs +0 -12
  451. package/dist/chunk-TDIK6NTV.mjs +0 -10
  452. package/dist/chunk-TQXHPFWT.mjs +0 -177
  453. package/dist/chunk-U55XJEIG.mjs +0 -18
  454. package/dist/chunk-UD5HIS4U.mjs +0 -382
  455. package/dist/chunk-UHICS3JI.mjs +0 -83
  456. package/dist/chunk-UJDJB3NE.mjs +0 -913
  457. package/dist/chunk-VD7J552I.mjs +0 -28
  458. package/dist/chunk-VSLSGASN.mjs +0 -30
  459. package/dist/chunk-VZ2ONHEE.mjs +0 -3715
  460. package/dist/chunk-W7OSSKH5.mjs +0 -1427
  461. package/dist/chunk-WZ7YV54N.mjs +0 -152
  462. package/dist/chunk-X5CV2E2B.mjs +0 -1
  463. package/dist/chunk-Y4WPNHMC.mjs +0 -50
  464. package/dist/chunk-YEKL4JBK.mjs +0 -96
  465. package/dist/chunk-ZXNQEW43.mjs +0 -18
  466. package/dist/chunk-ZYAY26KG.mjs +0 -29
  467. package/dist/direct-executor-V5DRIECI.mjs +0 -34
  468. package/dist/durability-wiring-3TD62MBI.mjs +0 -4072
  469. package/dist/engine-hooks-HA3SBOBR.mjs +0 -54
  470. package/dist/gzip-F4HMIEEQ.mjs +0 -1
  471. package/dist/import-GPKLTSKA.mjs +0 -56
  472. package/dist/methods-7IOINERF.mjs +0 -30
  473. package/dist/module-JYHFTVPS.mjs +0 -63
  474. package/dist/operations-G5EP6JPX.mjs +0 -5
  475. package/dist/phrase-module-XW5MKWP5.mjs +0 -330
  476. package/dist/pool-Y4A46T36.mjs +0 -298
  477. package/dist/react-native/chunks/analysis-change-QUVDNABS.mjs +0 -934
  478. package/dist/react-native/chunks/analysis-change-entry-OC4XASBF.mjs +0 -1
  479. package/dist/react-native/chunks/archive-history-MJKUQLSU.mjs +0 -29
  480. package/dist/react-native/chunks/chunk-2PRHILX3.mjs +0 -529
  481. package/dist/react-native/chunks/chunk-3NQOVO3K.mjs +0 -1
  482. package/dist/react-native/chunks/chunk-3WI35N75.mjs +0 -226
  483. package/dist/react-native/chunks/chunk-4DII3ZSM.mjs +0 -73
  484. package/dist/react-native/chunks/chunk-4J74WHQM.mjs +0 -177
  485. package/dist/react-native/chunks/chunk-4NWR3NGS.mjs +0 -151
  486. package/dist/react-native/chunks/chunk-5CQX3XXV.mjs +0 -17
  487. package/dist/react-native/chunks/chunk-5MSX5FRT.mjs +0 -858
  488. package/dist/react-native/chunks/chunk-6OFDUYVX.mjs +0 -92
  489. package/dist/react-native/chunks/chunk-6VBXNFLE.mjs +0 -9
  490. package/dist/react-native/chunks/chunk-6ZELFCK5.mjs +0 -315
  491. package/dist/react-native/chunks/chunk-AAAETEJK.mjs +0 -27
  492. package/dist/react-native/chunks/chunk-AM7RSBPF.mjs +0 -32
  493. package/dist/react-native/chunks/chunk-BITYFZSZ.mjs +0 -242
  494. package/dist/react-native/chunks/chunk-C5G6TJ7A.mjs +0 -140
  495. package/dist/react-native/chunks/chunk-CHPTFFJM.mjs +0 -43
  496. package/dist/react-native/chunks/chunk-DIYDOIM4.mjs +0 -10
  497. package/dist/react-native/chunks/chunk-DMIFXZ3Q.mjs +0 -432
  498. package/dist/react-native/chunks/chunk-DVDX4SDR.mjs +0 -375
  499. package/dist/react-native/chunks/chunk-DXRSEWA2.mjs +0 -12
  500. package/dist/react-native/chunks/chunk-F753DA54.mjs +0 -23
  501. package/dist/react-native/chunks/chunk-FHPW7P2O.mjs +0 -40
  502. package/dist/react-native/chunks/chunk-FTZHMRD2.mjs +0 -18
  503. package/dist/react-native/chunks/chunk-HJBJBH26.mjs +0 -34
  504. package/dist/react-native/chunks/chunk-IAENKE2D.mjs +0 -21
  505. package/dist/react-native/chunks/chunk-IO2SMUQD.mjs +0 -10
  506. package/dist/react-native/chunks/chunk-IYNT75CE.mjs +0 -111
  507. package/dist/react-native/chunks/chunk-JDOEEMEF.mjs +0 -38
  508. package/dist/react-native/chunks/chunk-JWUCMVRK.mjs +0 -15
  509. package/dist/react-native/chunks/chunk-KSBYEMCB.mjs +0 -100
  510. package/dist/react-native/chunks/chunk-KU646XXT.mjs +0 -164
  511. package/dist/react-native/chunks/chunk-LU3Y3P63.mjs +0 -68
  512. package/dist/react-native/chunks/chunk-LVIKKAA6.mjs +0 -93
  513. package/dist/react-native/chunks/chunk-LZSLNSUN.mjs +0 -193
  514. package/dist/react-native/chunks/chunk-MJDQU5MW.mjs +0 -1225
  515. package/dist/react-native/chunks/chunk-NNE4VDMM.mjs +0 -8
  516. package/dist/react-native/chunks/chunk-NVVRSRX5.mjs +0 -78
  517. package/dist/react-native/chunks/chunk-OCSLSH27.mjs +0 -22723
  518. package/dist/react-native/chunks/chunk-PB2YXVQW.mjs +0 -29
  519. package/dist/react-native/chunks/chunk-PJHAB5ZY.mjs +0 -79
  520. package/dist/react-native/chunks/chunk-PSWKQVVT.mjs +0 -9
  521. package/dist/react-native/chunks/chunk-RDWG33MM.mjs +0 -79
  522. package/dist/react-native/chunks/chunk-SK2PWYDH.mjs +0 -654
  523. package/dist/react-native/chunks/chunk-SUPXRTMD.mjs +0 -96
  524. package/dist/react-native/chunks/chunk-TORU2OHQ.mjs +0 -218
  525. package/dist/react-native/chunks/chunk-U4KSKA4Z.mjs +0 -23
  526. package/dist/react-native/chunks/chunk-UNUFZ2QY.mjs +0 -68
  527. package/dist/react-native/chunks/chunk-WBYQRHDY.mjs +0 -86
  528. package/dist/react-native/chunks/chunk-WVWJNUMN.mjs +0 -2562
  529. package/dist/react-native/chunks/chunk-YH7QY657.mjs +0 -288
  530. package/dist/react-native/chunks/chunk-YZW4CHM6.mjs +0 -562
  531. package/dist/react-native/chunks/chunk-ZNZ6CPAZ.mjs +0 -562
  532. package/dist/react-native/chunks/chunk-ZVQMBF2H.mjs +0 -63
  533. package/dist/react-native/chunks/chunk-ZWAIN4GG.mjs +0 -2636
  534. package/dist/react-native/chunks/chunk-ZZT7CEN7.mjs +0 -92
  535. package/dist/react-native/chunks/cold-module-N6KFNNZA.mjs +0 -773
  536. package/dist/react-native/chunks/durability-wiring-RN64S2TL.mjs +0 -4984
  537. package/dist/react-native/chunks/engine-hooks-CWA5CKCA.mjs +0 -30
  538. package/dist/react-native/chunks/gzip.react-native-HLEPDKZ3.mjs +0 -3
  539. package/dist/react-native/chunks/import-5UAWBRJP.mjs +0 -32
  540. package/dist/react-native/chunks/methods-6W5U4C3H.mjs +0 -30
  541. package/dist/react-native/chunks/module-6RP4ZCBW.mjs +0 -37
  542. package/dist/react-native/chunks/operations-GNRMD6EX.mjs +0 -5
  543. package/dist/react-native/chunks/phrase-module-QK22HSQ2.mjs +0 -329
  544. package/dist/react-native/chunks/pool-JR3NJCAF.mjs +0 -297
  545. package/dist/react-native/chunks/release-2SIHZWDO.mjs +0 -32
  546. package/dist/react-native/chunks/restore-hooks-ENFMDTWC.mjs +0 -127
  547. package/dist/react-native/chunks/restore-queue-4R6AASE5.mjs +0 -55
  548. package/dist/react-native/chunks/retention-5GTFT3GR.mjs +0 -223
  549. package/dist/react-native/chunks/snapshot-5LGPQXFS.mjs +0 -976
  550. package/dist/react-native/chunks/start-ZQJVZ5DN.mjs +0 -38
  551. package/dist/react-native/chunks/sync-state-PASCIHHT.mjs +0 -15
  552. package/dist/react-native/chunks/write-6BRYIIZ7.mjs +0 -208
  553. package/dist/release-SMR4WJD4.mjs +0 -32
  554. package/dist/restore-hooks-HXLIEB4A.mjs +0 -153
  555. package/dist/restore-queue-LZH7LMLR.mjs +0 -55
  556. package/dist/retention-3K7ARGAG.mjs +0 -66
  557. package/dist/runtime-COIUORCN.mjs +0 -177
  558. package/dist/snapshot-O7ICP7NJ.mjs +0 -783
  559. package/dist/start-S4PFP6RS.mjs +0 -66
  560. package/dist/sync-state-ZWHLAFLE.mjs +0 -15
  561. package/dist/thread-YLJ3ZPQ3.mjs +0 -50
  562. package/dist/write-2OBJGLFS.mjs +0 -233
  563. /package/dist/browser/{chunk-M3MQE2X7.mjs → digest-leaf-64IPRPZD.mjs} +0 -0
  564. /package/dist/browser/{chunk-JNOAKDUM.mjs → gzip-JF3S6PPT.mjs} +0 -0
  565. /package/dist/{chunk-ZXNNR73R.mjs → gzip-2UCZW2MM.mjs} +0 -0
@@ -1,1974 +0,0 @@
1
- import { admittedHeapBytes } from './chunk-XIHUI4KB.mjs';
2
- import { MAX_INDEX_NAME_LENGTH, INDEX_NAME_PATTERN, MAX_DOC_ID_LENGTH, DEFAULT_LIMIT, DEFAULT_SUGGEST_LIMIT, MAX_SUGGEST_LIMIT, MAX_SUGGEST_SCATTER_LIMIT, ABSOLUTE_WINDOWS_PATH_PATTERN, MODULE_URL_SCHEME_PATTERN, DEFAULT_OFFSET } from './chunk-EEBCDP36.mjs';
3
- import { normalizeSort, requireMatchingCursor, encodePageCursor, decodePageCursor, projectionKeepsField, resolveProjection, clampRowCount, sortSignatureOf, requireSortableFields, fanOutQuery, requireWithinResultWindow, sortModesOf, applySorting, applyPagination, countsWithoutScores, fanOutMatchCount, validatedFilterOf, createPatternWorkMeter, partialWordsToHighlight, partialWordHighlighter, pruneStatsToQueryTerms, everyValueFacetConfig, fulltextMatches, mergeFacets, applyPartitionFiltersBitset, readResidentMemory, partitionsIn, undeclaredFieldOnStrictIndex } from './chunk-PIH5SJ4N.mjs';
4
- import { readOldGenerationStatistics } from './chunk-IPN7S4KX.mjs';
5
- import { FNV_OFFSET_BASIS, fnv1aContinue, fnv1aContinueTaggedNumbers } from './chunk-KAKQ74LS.mjs';
6
- import { engineThreadYoungGenerationBytes } from './chunk-Q2UL2TPC.mjs';
7
- import { DEFAULT_MAX_PER_GROUP, DEFAULT_FUZZY_PREFIX_LENGTH, BM25_DISPLAYED_NAME_LENGTH, DEFAULT_LINEAR_ALPHA, MIN_LINEAR_ALPHA, MAX_LINEAR_ALPHA, DEFAULT_RANK_CONSTANT, MIN_RANK_CONSTANT, RESULT_WINDOW, MAX_TOLERANCE, MAX_PREFIX_LENGTH } from './chunk-FQBFZAWG.mjs';
8
- import { flattenSchema, partialFieldsOf } from './chunk-W5EB5XKI.mjs';
9
- import { fuzzyTermMatches } from './chunk-GES7U2PM.mjs';
10
- import { isStringValuedBase, parsedTypeOf, isWordIndexedFieldType } from './chunk-I54T6CQP.mjs';
11
- import { bm25SetsValue, analyseQueryPhrases, requireLoadedPhraseCode, loadPhraseCodeFor, mergeBM25Levels, MAX_BM25_K1, MAX_BM25_B } from './chunk-FB6463IN.mjs';
12
- import { MIN_PATTERN_VALUE_LIMIT, MAX_PATTERN_VALUE_LIMIT, isPlainObject, isGeopointOrVectorType, VECTOR_PATTERN } from './chunk-L5ORED7V.mjs';
13
- import { tokenize } from './chunk-A4L7YTKX.mjs';
14
- import { MIN_OVERSAMPLE } from './chunk-ORN5BLL7.mjs';
15
- import { MAX_RENUMBERED_SEARCH_ATTEMPTS } from './chunk-BTPGQC6Z.mjs';
16
- import { turnIsSpent, yieldTurn } from './chunk-LQG5G2LY.mjs';
17
- import { NarsilError, ErrorCodes } from './chunk-MP7ABPTD.mjs';
18
- import { compareComparableKeys } from './chunk-J4IJTTEX.mjs';
19
- import { compareCodePoints, holdsUnpairedSurrogate } from './chunk-TBC3XUL2.mjs';
20
-
21
- // src/engine/memory/constants.ts
22
- var DEFAULT_BLOCK_WRITES_ABOVE = 0.9;
23
- var DEFAULT_RESUME_WRITES_BELOW = 0.8;
24
- var RECENT_MEMORY_FIGURES_MAX_AGE_MS = 10;
25
- var RECENT_MEMORY_FIGURES_MAX_ADMITTED_FRACTION = 0.01;
26
- var FULL_MEMORY_COLLECTION_INTERVAL_MS = 5e3;
27
- var ENGINE_MEMORY_FIGURES_MAX_AGE_MS = 1e3;
28
- var DOCUMENT_HEAP_BYTES_PER_ESTIMATED_BYTE = 24;
29
- var DOCUMENT_VALUE_HEAP_BYTES = 256;
30
- var DOCUMENT_PROPERTY_HEAP_BYTES = 128;
31
- var DISTINCT_TERM_HEAP_BYTES = 2048;
32
- var TERM_UNIT_HEAP_BYTES = 24;
33
- var PARTIAL_SPELLING_HEAP_BYTES = 512;
34
- var PATTERN_RUN_HEAP_BYTES = 512;
35
- var ENUM_VALUE_HEAP_BYTES = 256;
36
- var VECTOR_COMPONENT_HEAP_BYTES = 80;
37
- var VECTOR_DOCUMENT_HEAP_BYTES = 5120;
38
- var NORMALIZATION_EXPANSION_FACTOR = 3;
39
- var CASE_FOLD_EXPANSION_FACTOR = 3;
40
-
41
- // src/engine/memory/measure.ts
42
- var lastFigures = null;
43
- var lastFiguresComplete = false;
44
- var lastFiguresReadAt = Number.NEGATIVE_INFINITY;
45
- var admittedBytesAtLastFigures = 0;
46
- var recentFigures = {
47
- processBytes: 0,
48
- processLimitBytes: 0,
49
- heapBytes: 0,
50
- heapLimitBytes: 0,
51
- youngHeapBytes: 0,
52
- heapCommittedBytes: 0,
53
- youngCeilingBytes: 0,
54
- youngReserveBytes: 0
55
- };
56
- function readFreshFigures() {
57
- try {
58
- const heap = readOldGenerationStatistics();
59
- const resident = readResidentMemory();
60
- lastFiguresComplete = heap !== null && resident !== null;
61
- if (heap === null && resident === null) return null;
62
- return {
63
- processBytes: resident?.residentBytes ?? 0,
64
- processLimitBytes: resident?.limitBytes ?? Number.POSITIVE_INFINITY,
65
- heapBytes: heap?.usedBytes ?? 0,
66
- heapLimitBytes: heap?.limitBytes ?? Number.POSITIVE_INFINITY,
67
- youngHeapBytes: heap?.youngUsedBytes ?? 0,
68
- heapCommittedBytes: heap === null ? 0 : Math.max(heap.committedBytes, heap.usedBytes),
69
- youngCeilingBytes: heap?.youngCeilingBytes ?? 0,
70
- youngReserveBytes: (heap?.youngReserveBytes ?? 0) + engineThreadYoungGenerationBytes()
71
- };
72
- } catch {
73
- lastFiguresComplete = false;
74
- return null;
75
- }
76
- }
77
- function measure() {
78
- const figures = readFreshFigures();
79
- lastFigures = figures;
80
- lastFiguresReadAt = performance.now();
81
- admittedBytesAtLastFigures = admittedHeapBytes();
82
- return figures;
83
- }
84
- function recent(maxAgeMs) {
85
- const admittedSince = admittedHeapBytes() - admittedBytesAtLastFigures;
86
- if (lastFigures === null || performance.now() - lastFiguresReadAt >= maxAgeMs || admittedSince > RECENT_MEMORY_FIGURES_MAX_ADMITTED_FRACTION * lastFigures.heapLimitBytes) {
87
- return measure();
88
- }
89
- recentFigures.processLimitBytes = lastFigures.processLimitBytes;
90
- recentFigures.heapLimitBytes = lastFigures.heapLimitBytes;
91
- recentFigures.processBytes = lastFigures.processBytes + admittedSince;
92
- recentFigures.heapBytes = lastFigures.heapBytes + admittedSince;
93
- recentFigures.youngHeapBytes = lastFigures.youngHeapBytes;
94
- recentFigures.heapCommittedBytes = lastFigures.heapCommittedBytes + admittedSince;
95
- recentFigures.youngCeilingBytes = lastFigures.youngCeilingBytes;
96
- recentFigures.youngReserveBytes = lastFigures.youngReserveBytes;
97
- return recentFigures;
98
- }
99
- function readMemoryFigures() {
100
- const figures = measure();
101
- return lastFiguresComplete ? figures : null;
102
- }
103
- function readRecentMemoryFigures() {
104
- const figures = recent(RECENT_MEMORY_FIGURES_MAX_AGE_MS);
105
- return lastFiguresComplete ? figures : null;
106
- }
107
- function readEngineMemoryFigures() {
108
- return measure();
109
- }
110
-
111
- // src/engine/validation.ts
112
- function now() {
113
- if (typeof performance !== "undefined" && typeof performance.now === "function") {
114
- return performance.now();
115
- }
116
- return Date.now();
117
- }
118
- function validateIndexName(name) {
119
- const given = name;
120
- if (typeof given !== "string" || name.length === 0) {
121
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, "Index name must be a string of at least one character", {
122
- received: given === null ? "null" : typeof given
123
- });
124
- }
125
- if (name.length > MAX_INDEX_NAME_LENGTH) {
126
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, `Index name must not exceed ${MAX_INDEX_NAME_LENGTH} characters`, {
127
- indexName: name,
128
- length: name.length
129
- });
130
- }
131
- if (!INDEX_NAME_PATTERN.test(name)) {
132
- throw new NarsilError(
133
- ErrorCodes.CONFIG_INVALID,
134
- `Index name "${name}" contains invalid characters; use alphanumeric, dots, hyphens, and underscores only`,
135
- { indexName: name }
136
- );
137
- }
138
- if (name.includes("..")) {
139
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, `Index name "${name}" must not contain ".."`, { indexName: name });
140
- }
141
- }
142
- function validateDocId(docId) {
143
- const given = docId;
144
- if (typeof given !== "string") {
145
- throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, "Document ID must be a string", {
146
- received: given === null ? "null" : Array.isArray(given) ? "array" : typeof given
147
- });
148
- }
149
- if (docId.length === 0) {
150
- throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, "Document ID must not be empty", { docId });
151
- }
152
- if (docId.length > MAX_DOC_ID_LENGTH) {
153
- throw new NarsilError(
154
- ErrorCodes.DOC_VALIDATION_FAILED,
155
- `Document ID must not exceed ${MAX_DOC_ID_LENGTH} characters`,
156
- {
157
- docId,
158
- length: docId.length
159
- }
160
- );
161
- }
162
- if (docId.includes("\0")) {
163
- throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, "Document ID must not contain null bytes", { docId });
164
- }
165
- if (holdsUnpairedSurrogate(docId)) {
166
- throw new NarsilError(
167
- ErrorCodes.DOC_VALIDATION_FAILED,
168
- "Document ID holds an unpaired surrogate, the half of a character such as an emoji whose other half is missing, so the engine cannot store it as UTF-8",
169
- { docId }
170
- );
171
- }
172
- }
173
- function validateBatchList(given, listed) {
174
- if (Array.isArray(given)) return;
175
- throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, `A batch takes its ${listed} as an array`, {
176
- received: given === null ? "null" : typeof given
177
- });
178
- }
179
- function validatePartitionConfig(partitions) {
180
- const { maxDocsPerPartition, maxPartitions, watermark } = partitions;
181
- if (maxDocsPerPartition !== void 0 && (!Number.isInteger(maxDocsPerPartition) || maxDocsPerPartition < 1)) {
182
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, "partitions.maxDocsPerPartition must be a positive integer", {
183
- maxDocsPerPartition
184
- });
185
- }
186
- if (maxPartitions !== void 0 && (!Number.isInteger(maxPartitions) || maxPartitions < 1)) {
187
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, "partitions.maxPartitions must be a positive integer", {
188
- maxPartitions
189
- });
190
- }
191
- if (watermark !== void 0 && (typeof watermark !== "number" || !(watermark > 0) || watermark > 1)) {
192
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, "partitions.watermark must be above 0 and at most 1", {
193
- watermark
194
- });
195
- }
196
- }
197
- function requireSurfaceFormsForPartialFields(schema, surfaceForms) {
198
- if (surfaceForms !== false) return;
199
- const partialFields = partialFieldsOf(schema);
200
- if (partialFields.length === 0) return;
201
- throw new NarsilError(
202
- ErrorCodes.CONFIG_INVALID,
203
- `Field "${partialFields[0]}" declares "partial", which compares words as the documents wrote them, so its index needs surfaceForms left on`,
204
- { fields: [...partialFields], surfaceForms: false }
205
- );
206
- }
207
- function validatePatternValueLimit(limit) {
208
- if (limit === void 0) return;
209
- if (typeof limit !== "number" || !Number.isInteger(limit) || limit < MIN_PATTERN_VALUE_LIMIT || limit > MAX_PATTERN_VALUE_LIMIT) {
210
- throw new NarsilError(
211
- ErrorCodes.CONFIG_INVALID,
212
- `patternValueLimit must be a whole number of code points from ${MIN_PATTERN_VALUE_LIMIT} to ${MAX_PATTERN_VALUE_LIMIT}`,
213
- { patternValueLimit: typeof limit === "number" ? limit : String(limit) }
214
- );
215
- }
216
- }
217
- function requirePositiveSafeInteger(field, value) {
218
- if (value === void 0) return;
219
- if (!Number.isSafeInteger(value) || value < 1) {
220
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, `${field} must be a positive safe integer`, { field, value });
221
- }
222
- }
223
- function validateBootstrapModule(bootstrapModule) {
224
- if (bootstrapModule === void 0) return;
225
- const absolute = bootstrapModule.startsWith("/") || ABSOLUTE_WINDOWS_PATH_PATTERN.test(bootstrapModule) || MODULE_URL_SCHEME_PATTERN.test(bootstrapModule);
226
- if (absolute) return;
227
- throw new NarsilError(
228
- ErrorCodes.CONFIG_INVALID,
229
- `workers.bootstrapModule is "${bootstrapModule}", which a worker would resolve against Narsil's own directory, so pass an absolute path or a URL such as new URL('./bootstrap.js', import.meta.url).href`,
230
- { bootstrapModule }
231
- );
232
- }
233
- function validateWorkerConfig(workers, lifecycle) {
234
- if (workers === void 0) return;
235
- requirePositiveSafeInteger("workers.count", workers.count);
236
- requirePositiveSafeInteger("workers.promotionThreshold", workers.promotionThreshold);
237
- requirePositiveSafeInteger("workers.idleTimeoutMs", workers.idleTimeoutMs);
238
- if (workers.mainCopyQueries !== void 0 && workers.mainCopyQueries !== "lone" && workers.mainCopyQueries !== "none") {
239
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, "workers.mainCopyQueries must be 'lone' or 'none'", {
240
- mainCopyQueries: workers.mainCopyQueries
241
- });
242
- }
243
- validateBootstrapModule(workers.bootstrapModule);
244
- const closeAfter = lifecycle?.idleTimeoutMs;
245
- if (workers.idleTimeoutMs !== void 0 && closeAfter !== void 0 && workers.idleTimeoutMs > closeAfter) {
246
- throw new NarsilError(
247
- ErrorCodes.CONFIG_INVALID,
248
- "workers.idleTimeoutMs must be at most lifecycle.idleTimeoutMs, so that an index drops its copies before it closes",
249
- { workersIdleTimeoutMs: workers.idleTimeoutMs, lifecycleIdleTimeoutMs: closeAfter }
250
- );
251
- }
252
- }
253
- function clampLimit(limit) {
254
- return clampRowCount(limit, DEFAULT_LIMIT);
255
- }
256
- function clampOffset(offset) {
257
- return clampRowCount(offset, DEFAULT_OFFSET);
258
- }
259
-
260
- // src/search/bm25-params.ts
261
- var BM25_KEYS = /* @__PURE__ */ new Set(["k1", "b", "fields"]);
262
- var BM25_FIELD_KEYS = /* @__PURE__ */ new Set(["k1", "b"]);
263
- function displayed(value) {
264
- if (typeof value === "string") return `"${value.slice(0, BM25_DISPLAYED_NAME_LENGTH)}"`;
265
- if (typeof value === "number" || typeof value === "boolean" || value === null) return String(value);
266
- return `a value of type ${typeof value}`;
267
- }
268
- function requireValue(label, value, maximum, ranges) {
269
- if (value === void 0) return;
270
- const usable = typeof value === "number" && Number.isFinite(value) && (ranges === "stored" || value >= 0 && value <= maximum);
271
- if (usable) return;
272
- throw new NarsilError(
273
- ErrorCodes.CONFIG_INVALID,
274
- `${label} must be a finite number from 0 to ${maximum}, and this request sets ${displayed(value)}`,
275
- { parameter: label }
276
- );
277
- }
278
- function requireKnownKeys(label, value, known) {
279
- for (const key of Object.keys(value)) {
280
- if (known.has(key)) continue;
281
- throw new NarsilError(
282
- ErrorCodes.CONFIG_INVALID,
283
- `${label} takes ${[...known].join(", ")}, and this request sets ${displayed(key)}`,
284
- { parameter: label }
285
- );
286
- }
287
- }
288
- function requireFieldPair(name, pair, ranges) {
289
- const label = `bm25.fields.${name.slice(0, BM25_DISPLAYED_NAME_LENGTH)}`;
290
- if (!isPlainObject(pair)) {
291
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, `${label} must be an object that sets k1 or b`, {
292
- parameter: label
293
- });
294
- }
295
- requireKnownKeys(label, pair, BM25_FIELD_KEYS);
296
- requireValue(`${label}.k1`, pair.k1, MAX_BM25_K1, ranges);
297
- requireValue(`${label}.b`, pair.b, MAX_BM25_B, ranges);
298
- }
299
- function requireScoredField(name, flatSchema, unknownFieldCode) {
300
- const fieldType = Object.hasOwn(flatSchema, name) ? flatSchema[name] : void 0;
301
- if (typeof fieldType === "string" && isWordIndexedFieldType(fieldType)) return;
302
- throw new NarsilError(
303
- unknownFieldCode,
304
- fieldType === void 0 ? `BM25 parameters apply to a text field that the schema declares, and the schema declares no field ${displayed(name)}` : `BM25 parameters apply to a text field alone, and the schema declares field ${displayed(name)} as ${displayed(fieldType)}`,
305
- { field: name.slice(0, BM25_DISPLAYED_NAME_LENGTH) }
306
- );
307
- }
308
- function fieldsOfCheckedSetting(raw, ranges) {
309
- if (!isPlainObject(raw)) {
310
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, "bm25 must be an object that sets k1, b, or fields");
311
- }
312
- requireKnownKeys("bm25", raw, BM25_KEYS);
313
- requireValue("bm25.k1", raw.k1, MAX_BM25_K1, ranges);
314
- requireValue("bm25.b", raw.b, MAX_BM25_B, ranges);
315
- const fields = raw.fields;
316
- if (fields === void 0) return void 0;
317
- if (!isPlainObject(fields)) {
318
- throw new NarsilError(
319
- ErrorCodes.CONFIG_INVALID,
320
- "bm25.fields must be an object that maps a field to its parameters"
321
- );
322
- }
323
- return fields;
324
- }
325
- function validateBM25Shape(raw, ranges) {
326
- const fields = fieldsOfCheckedSetting(raw, ranges);
327
- if (fields === void 0) return;
328
- for (const name of Object.keys(fields)) requireFieldPair(name, fields[name], ranges);
329
- }
330
- function validateBM25Params(raw, schema, unknownFieldCode, ranges = "settable") {
331
- const fields = fieldsOfCheckedSetting(raw, ranges);
332
- if (fields === void 0) return;
333
- const names = Object.keys(fields);
334
- if (names.length === 0) return;
335
- const flatSchema = flattenSchema(schema);
336
- for (const name of names) {
337
- requireScoredField(name, flatSchema, unknownFieldCode);
338
- requireFieldPair(name, fields[name], ranges);
339
- }
340
- }
341
- function presentPair(pair) {
342
- return {
343
- ...pair.k1 !== void 0 ? { k1: pair.k1 } : {},
344
- ...pair.b !== void 0 ? { b: pair.b } : {}
345
- };
346
- }
347
- function storedBM25Params(params) {
348
- const stored = presentPair(params);
349
- const fields = params.fields;
350
- if (fields !== void 0) {
351
- const kept = /* @__PURE__ */ Object.create(null);
352
- let holdsField = false;
353
- for (const name of Object.keys(fields)) {
354
- const pair = presentPair(fields[name]);
355
- if (pair.k1 === void 0 && pair.b === void 0) continue;
356
- kept[name] = pair;
357
- holdsField = true;
358
- }
359
- if (holdsField) stored.fields = kept;
360
- }
361
- return Object.keys(stored).length === 0 ? void 0 : stored;
362
- }
363
-
364
- // src/search/cursor-binding.ts
365
- var ABSENT_TAG = 0;
366
- var NULL_TAG = 1;
367
- var FALSE_TAG = 2;
368
- var TRUE_TAG = 3;
369
- var NUMBER_TAG = 4;
370
- var STRING_TAG = 5;
371
- var LIST_TAG = 6;
372
- var MAP_TAG = 7;
373
- var LENGTH_BYTES = 4;
374
- var LAST_ASCII_UNIT = 127;
375
- var encoder = new TextEncoder();
376
- function flush(stream) {
377
- stream.hash = fnv1aContinue(stream.hash, stream.bytes, stream.length);
378
- stream.length = 0;
379
- }
380
- function ensureCapacity(stream, extra) {
381
- if (stream.length + extra <= stream.bytes.length) return;
382
- const grown = new Uint8Array(Math.max(stream.bytes.length * 2, stream.length + extra));
383
- grown.set(stream.bytes.subarray(0, stream.length));
384
- stream.bytes = grown;
385
- }
386
- function writeByte(stream, value) {
387
- ensureCapacity(stream, 1);
388
- stream.bytes[stream.length] = value;
389
- stream.length += 1;
390
- }
391
- function writeUint32(stream, value) {
392
- ensureCapacity(stream, 4);
393
- stream.bytes[stream.length] = value >>> 24 & 255;
394
- stream.bytes[stream.length + 1] = value >>> 16 & 255;
395
- stream.bytes[stream.length + 2] = value >>> 8 & 255;
396
- stream.bytes[stream.length + 3] = value & 255;
397
- stream.length += 4;
398
- }
399
- var numberBytes = new DataView(new ArrayBuffer(8));
400
- function writeNumber(stream, value) {
401
- numberBytes.setFloat64(0, value, false);
402
- ensureCapacity(stream, 8);
403
- for (let i = 0; i < 8; i++) {
404
- stream.bytes[stream.length + i] = numberBytes.getUint8(i);
405
- }
406
- stream.length += 8;
407
- }
408
- function writeEncodedString(stream, value) {
409
- const encoded = encoder.encode(value);
410
- writeUint32(stream, encoded.length);
411
- ensureCapacity(stream, encoded.length);
412
- stream.bytes.set(encoded, stream.length);
413
- stream.length += encoded.length;
414
- }
415
- function writeString(stream, value) {
416
- if (stream.clock !== void 0) stream.clock.tick(value.length);
417
- ensureCapacity(stream, LENGTH_BYTES + value.length);
418
- const start = stream.length + LENGTH_BYTES;
419
- const bytes = stream.bytes;
420
- for (let at = 0; at < value.length; at++) {
421
- const unit = value.charCodeAt(at);
422
- if (unit > LAST_ASCII_UNIT) {
423
- writeEncodedString(stream, value);
424
- return;
425
- }
426
- bytes[start + at] = unit;
427
- }
428
- writeUint32(stream, value.length);
429
- stream.length += value.length;
430
- }
431
- var NumberList = class {
432
- constructor(members) {
433
- this.members = members;
434
- }
435
- };
436
- function writeNumberList(stream, list) {
437
- if (stream.clock !== void 0) stream.clock.tick(list.members.length);
438
- writeByte(stream, LIST_TAG);
439
- writeUint32(stream, list.members.length);
440
- flush(stream);
441
- stream.hash = fnv1aContinueTaggedNumbers(stream.hash, NUMBER_TAG, list.members);
442
- }
443
- function writeValue(stream, value) {
444
- if (value instanceof NumberList) {
445
- writeNumberList(stream, value);
446
- return;
447
- }
448
- if (value === void 0) {
449
- writeByte(stream, ABSENT_TAG);
450
- return;
451
- }
452
- if (value === null) {
453
- writeByte(stream, NULL_TAG);
454
- return;
455
- }
456
- if (typeof value === "boolean") {
457
- writeByte(stream, value ? TRUE_TAG : FALSE_TAG);
458
- return;
459
- }
460
- if (typeof value === "number") {
461
- writeByte(stream, NUMBER_TAG);
462
- writeNumber(stream, value);
463
- return;
464
- }
465
- if (typeof value === "string") {
466
- writeByte(stream, STRING_TAG);
467
- writeString(stream, value);
468
- return;
469
- }
470
- if (Array.isArray(value)) {
471
- writeByte(stream, LIST_TAG);
472
- writeUint32(stream, value.length);
473
- for (const member of value) {
474
- writeValue(stream, member ?? null);
475
- }
476
- return;
477
- }
478
- const record = value;
479
- const keys = Object.keys(record).sort(compareCodePoints);
480
- writeByte(stream, MAP_TAG);
481
- writeUint32(stream, keys.length);
482
- for (const key of keys) {
483
- writeByte(stream, STRING_TAG);
484
- writeString(stream, key);
485
- writeValue(stream, record[key] ?? null);
486
- }
487
- }
488
- function boundVectorOf(vector) {
489
- if (vector === void 0) return void 0;
490
- const bound = { ...vector };
491
- if (vector.value !== void 0) {
492
- bound.value = new NumberList(vector.value);
493
- }
494
- if (vector.text !== void 0) {
495
- delete bound.value;
496
- }
497
- return bound;
498
- }
499
- function boundRerankOf(rerank) {
500
- if (typeof rerank !== "object" || rerank === null || Array.isArray(rerank)) return rerank;
501
- const present = {};
502
- for (const [key, value] of Object.entries(rerank)) {
503
- if (value !== void 0) present[key] = value;
504
- }
505
- return present;
506
- }
507
- function presentMembersOf(record) {
508
- const present = {};
509
- for (const [key, value] of Object.entries(record)) {
510
- if (value !== void 0) present[key] = value;
511
- }
512
- return present;
513
- }
514
- function boundBm25Of(bm25) {
515
- const bound = presentMembersOf(bm25);
516
- const fields = bm25.fields;
517
- if (typeof fields !== "object" || fields === null) return bound;
518
- const boundFields = {};
519
- for (const [name, pair] of Object.entries(fields)) {
520
- const members = typeof pair === "object" && pair !== null ? presentMembersOf(pair) : pair;
521
- if (typeof members === "object" && members !== null && Object.keys(members).length === 0) continue;
522
- boundFields[name] = members;
523
- }
524
- if (Object.keys(boundFields).length === 0) delete bound.fields;
525
- else bound.fields = boundFields;
526
- return bound;
527
- }
528
- var FILTERS_SLOT = 2;
529
- var BOUND_SLOT_COUNT = 16;
530
- function bindingOf(values, clock) {
531
- const stream = { bytes: new Uint8Array(256), length: 0, hash: FNV_OFFSET_BASIS, clock };
532
- for (const value of values) {
533
- writeValue(stream, value);
534
- }
535
- flush(stream);
536
- return (stream.hash >>> 0).toString(16).padStart(8, "0");
537
- }
538
- function queryBindingOf(params, clock) {
539
- const values = [
540
- params.term,
541
- params.fields,
542
- params.filters,
543
- params.boost,
544
- params.minScore,
545
- params.termMatch,
546
- params.tolerance,
547
- params.prefixLength,
548
- params.prefix,
549
- params.partialWords,
550
- params.exact,
551
- params.pinned,
552
- params.mode,
553
- params.hybrid,
554
- boundVectorOf(params.vector),
555
- params.scoring ?? "local"
556
- ];
557
- if (params.rerank !== void 0) values.push(boundRerankOf(params.rerank));
558
- if (params.bm25 !== void 0 && bm25SetsValue(params.bm25)) values.push(boundBm25Of(params.bm25));
559
- return bindingOf(values, clock);
560
- }
561
- function lazyQueryBinding(params, clock) {
562
- let binding;
563
- return () => {
564
- binding ??= queryBindingOf(params, clock);
565
- return binding;
566
- };
567
- }
568
- function listBindingOf(filters) {
569
- const values = new Array(BOUND_SLOT_COUNT).fill(void 0);
570
- values[FILTERS_SLOT] = filters;
571
- return bindingOf(values);
572
- }
573
-
574
- // src/search/query-fields.ts
575
- function requireBoostableFields(boost, flatSchema) {
576
- for (const [field, weight] of Object.entries(boost)) {
577
- const fieldType = flatSchema[field];
578
- if (fieldType === void 0 || !isWordIndexedFieldType(fieldType)) {
579
- throw new NarsilError(
580
- ErrorCodes.SEARCH_INVALID_FIELD,
581
- fieldType === void 0 ? `The engine boosts a text field that the schema declares, and the schema declares no field "${field}"` : `The engine boosts a text field alone, and the schema declares field "${field}" as "${fieldType}"`,
582
- { field, ...fieldType === void 0 ? {} : { fieldType } }
583
- );
584
- }
585
- if (typeof weight !== "number" || !Number.isFinite(weight)) {
586
- throw new NarsilError(
587
- ErrorCodes.CONFIG_INVALID,
588
- `The boost on field "${field}" must be a finite number, and this query sets ${String(weight)}`,
589
- { field, boost: String(weight) }
590
- );
591
- }
592
- }
593
- }
594
- function requireFacetableFields(facets, flatSchema, strict) {
595
- for (const field of Object.keys(facets)) {
596
- const fieldType = flatSchema[field];
597
- if (strict && fieldType === void 0) throw undeclaredFieldOnStrictIndex(field, "facet");
598
- if (isGeopointOrVectorType(fieldType)) {
599
- throw new NarsilError(
600
- ErrorCodes.SEARCH_INVALID_FIELD,
601
- `The engine counts the values of a text, number, boolean, or enum field, and the schema declares field "${field}" as "${fieldType}"`,
602
- { field, fieldType }
603
- );
604
- }
605
- }
606
- }
607
- function requireGroupableFields(fields, flatSchema, strict) {
608
- for (const field of fields) {
609
- const fieldType = flatSchema[field];
610
- if (strict && fieldType === void 0) throw undeclaredFieldOnStrictIndex(field, "group");
611
- if (fieldType !== void 0 && VECTOR_PATTERN.test(fieldType)) {
612
- throw new NarsilError(
613
- ErrorCodes.SEARCH_INVALID_FIELD,
614
- `The engine groups hits by a text, number, boolean, enum, or geopoint field, and the schema declares field "${field}" as "${fieldType}"`,
615
- { field, fieldType }
616
- );
617
- }
618
- }
619
- }
620
- function requireUsableQueryFields(params, schema, strict = false) {
621
- if (params.bm25 !== void 0) validateBM25Params(params.bm25, schema, ErrorCodes.SEARCH_INVALID_FIELD);
622
- const groupFields = params.group?.fields;
623
- const checksGroup = Array.isArray(groupFields) && groupFields.length > 0;
624
- if (params.boost === void 0 && params.facets === void 0 && !checksGroup) return;
625
- const flatSchema = flattenSchema(schema);
626
- if (params.boost !== void 0) requireBoostableFields(params.boost, flatSchema);
627
- if (params.facets !== void 0) requireFacetableFields(params.facets, flatSchema, strict);
628
- if (checksGroup) requireGroupableFields(groupFields, flatSchema, strict);
629
- }
630
-
631
- // src/search/typo-tolerance.ts
632
- function requireIntegerUpTo(option, value, maximum) {
633
- if (value === void 0 || Number.isInteger(value) && value >= 0 && value <= maximum) return;
634
- throw new NarsilError(
635
- ErrorCodes.CONFIG_INVALID,
636
- `The query option "${option}" takes an integer from 0 to ${maximum}, and this query sets ${String(value)}`,
637
- { option, value: String(value), maximum }
638
- );
639
- }
640
- function requireValidTypoTolerance(params) {
641
- requireIntegerUpTo("tolerance", params.tolerance, MAX_TOLERANCE);
642
- requireIntegerUpTo("prefixLength", params.prefixLength, MAX_PREFIX_LENGTH);
643
- }
644
-
645
- // src/engine/query/shared.ts
646
- function withPatternWork(context) {
647
- return { ...context, patternWork: createPatternWorkMeter(context.patternWorkCap, context.clock) };
648
- }
649
- function partitionsFor(manager, partitionIds) {
650
- return partitionsIn(manager, partitionIds);
651
- }
652
- function coverageFor(manager, partitionIds) {
653
- if (partitionIds === void 0) {
654
- return {
655
- totalPartitions: manager.partitionCount,
656
- queriedPartitions: manager.partitionCount,
657
- timedOutPartitions: 0,
658
- failedPartitions: 0
659
- };
660
- }
661
- const queriedPartitions = partitionsFor(manager, partitionIds).length;
662
- return {
663
- totalPartitions: partitionIds.length,
664
- queriedPartitions,
665
- timedOutPartitions: 0,
666
- failedPartitions: partitionIds.length - queriedPartitions
667
- };
668
- }
669
- function partitionsForVectorSearch(manager, vecIndex, partitionIds) {
670
- if (partitionIds === void 0) {
671
- return void 0;
672
- }
673
- if (!vecIndex.partitionsKnown()) {
674
- vecIndex.assignPartitions((docId) => manager.partitionIdOf(docId));
675
- }
676
- return new Set(partitionIds);
677
- }
678
- function scoringConfigFor(params, context) {
679
- const scoringMode = params.scoring ?? context.config.defaultScoring ?? "local";
680
- if (scoringMode !== "broadcast") {
681
- return { scoringMode, partitionIds: context.partitionIds };
682
- }
683
- return { scoringMode, globalStats: context.broadcastStats?.(context.indexName), partitionIds: context.partitionIds };
684
- }
685
- function broadcastStatsForWorker(params, context, scoring) {
686
- if (scoring.scoringMode !== "broadcast" || scoring.globalStats === void 0) {
687
- return void 0;
688
- }
689
- const term = params.term;
690
- if (term === void 0 || term.trim().length === 0) {
691
- return void 0;
692
- }
693
- const { manager } = context;
694
- const analysis = { ...manager.analysis, synonyms: manager.synonyms };
695
- return pruneStatsToQueryTerms(scoring.globalStats, term, context.language, analysis, {
696
- partitions: partitionsFor(manager, context.partitionIds),
697
- expansion: { options: params, schema: context.config.schema }
698
- });
699
- }
700
- function bm25SettingFor(params, context) {
701
- return mergeBM25Levels(params.bm25, context.indexBm25 ?? context.config.bm25);
702
- }
703
- function searchOptionsFor(params, context) {
704
- const { manager, patternWork } = context;
705
- return {
706
- bm25Params: bm25SettingFor(params, context),
707
- stopWords: manager.analysis.stopWords,
708
- customTokenizer: manager.analysis.customTokenizer,
709
- synonyms: manager.synonyms,
710
- patternWork
711
- };
712
- }
713
- function vectorResultsToScored(results) {
714
- return results.map((r) => ({
715
- docId: r.docId,
716
- score: r.score,
717
- termFrequencies: {},
718
- fieldLengths: {},
719
- idf: {}
720
- }));
721
- }
722
- function vectorSearchersOf(context) {
723
- return context.vectorSearchers ?? context.manager.getVectorIndexes();
724
- }
725
- function resolveVectorIndex(context, fieldName) {
726
- return vectorSearchersOf(context).get(fieldName);
727
- }
728
- var SEARCH_MODES = /* @__PURE__ */ new Set(["fulltext", "vector", "hybrid"]);
729
- function requireKnownMode(params) {
730
- if (params.mode === void 0 || SEARCH_MODES.has(params.mode)) return;
731
- throw new NarsilError(
732
- ErrorCodes.SEARCH_INVALID_MODE,
733
- `A search takes the mode "fulltext", "vector", or "hybrid", while this query names "${String(params.mode)}"`,
734
- { mode: String(params.mode), modes: [...SEARCH_MODES] }
735
- );
736
- }
737
- function requireBooleanPartialWords(params) {
738
- const setting = params.partialWords;
739
- if (setting === void 0 || typeof setting === "boolean") return;
740
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, 'The "partialWords" query option takes true or false', {
741
- option: "partialWords",
742
- received: setting === null ? "null" : typeof setting
743
- });
744
- }
745
- function validQueryParams(params, config) {
746
- const strict = config.strict === true;
747
- requireValidTypoTolerance(params);
748
- requireBooleanPartialWords(params);
749
- requireSortableFields(params.sort, config.schema, strict);
750
- const filters = validQueryFilter(params.filters, config.schema);
751
- requireUsableQueryFields(params, config.schema, strict);
752
- return filters === params.filters ? params : { ...params, filters };
753
- }
754
- function validQueryFilter(filters, schema) {
755
- if (filters === void 0 || filters === null) return filters;
756
- return validatedFilterOf(filters, flattenSchema(schema));
757
- }
758
- function requireUsablePhrases(params, context) {
759
- if (params.term === void 0) return;
760
- const quoted = analyseQueryPhrases(params.term, context.language, context.manager.analysis);
761
- if (quoted === null || quoted.keptPhraseCount === 0) return;
762
- requireLoadedPhraseCode().requirePhrasesWithinLimits(quoted, context.config.trackPositions !== false);
763
- context.requirePhraseReady?.();
764
- }
765
- function requireVectorSearchable(params, context, needsVector) {
766
- if (!needsVector) return;
767
- const field = params.vector?.field;
768
- if (field === void 0) {
769
- throw new NarsilError(
770
- ErrorCodes.SEARCH_INVALID_MODE,
771
- `A "${params.mode}" query needs a vector clause naming the field to search`,
772
- { mode: params.mode }
773
- );
774
- }
775
- if (vectorSearchersOf(context).has(field)) return;
776
- throw new NarsilError(
777
- ErrorCodes.SEARCH_INVALID_FIELD,
778
- `Field "${field}" has no vector index, so a vector search cannot use it`,
779
- { field, vectorFields: [...vectorSearchersOf(context).keys()] }
780
- );
781
- }
782
-
783
- // src/engine/list-documents/index.ts
784
- function clampListLimit(limit) {
785
- const clamped = Math.max(1, clampLimit(limit));
786
- requireWithinResultWindow(clamped, 0);
787
- return clamped;
788
- }
789
- function firstIdAfter(sorted, anchor) {
790
- let low = 0;
791
- let high = sorted.length;
792
- while (low < high) {
793
- const mid = low + high >>> 1;
794
- if (compareCodePoints(sorted[mid], anchor) <= 0) low = mid + 1;
795
- else high = mid;
796
- }
797
- return low;
798
- }
799
- function collectFilterMatches(partitions, filters, schema, patternWorkCap) {
800
- const meter = createPatternWorkMeter(patternWorkCap);
801
- const perPartition = partitions.map((partition) => partition.filterMatches(filters, schema, meter));
802
- let total = 0;
803
- for (const matches of perPartition) total += matches.count;
804
- return { matchesFor: (partitionIndex) => perPartition[partitionIndex] ?? null, total };
805
- }
806
- function collectCandidates(partition, anchor, matches, wanted, out) {
807
- const sorted = partition.sortedDocIds();
808
- let index = anchor === null ? 0 : firstIdAfter(sorted, anchor);
809
- let taken = 0;
810
- while (index < sorted.length && taken < wanted) {
811
- const docId = sorted[index];
812
- index++;
813
- if (matches !== null && !matches.hasExternal(docId)) continue;
814
- out.push(docId);
815
- taken++;
816
- }
817
- }
818
- function pageInIdOrder(partitions, cursor, filtered, limit, binding) {
819
- const anchor = cursor === null ? null : cursor.anchor;
820
- const candidates = [];
821
- for (let index = 0; index < partitions.length; index++) {
822
- collectCandidates(
823
- partitions[index],
824
- anchor,
825
- filtered === null ? null : filtered.matchesFor(index),
826
- limit + 1,
827
- candidates
828
- );
829
- }
830
- candidates.sort(compareCodePoints);
831
- const hasMore = candidates.length > limit;
832
- const ids = hasMore ? candidates.slice(0, limit) : candidates;
833
- const nextCursor = hasMore && ids.length > 0 ? { anchor: ids[ids.length - 1], score: null, sortKey: null, sortSignature: null, binding } : null;
834
- return { ids, nextCursor };
835
- }
836
- function pageInSortOrder(partitions, cursor, filtered, limit, sort, signature, schema, binding) {
837
- const normalized = normalizeSort(sort);
838
- const fields = normalized.map((entry) => entry.field);
839
- const directions = normalized.map((entry) => entry.direction);
840
- const flatSchema = flattenSchema(schema);
841
- const fieldTypes = fields.map((field) => flatSchema[field]);
842
- const request = {
843
- fields,
844
- directions,
845
- fieldTypes,
846
- modes: sortModesOf(normalized),
847
- limit: limit + 1,
848
- anchorKey: cursor === null ? null : cursor.sortKey,
849
- anchorId: cursor === null ? null : cursor.anchor
850
- };
851
- const merged = [];
852
- for (let index = 0; index < partitions.length; index++) {
853
- const matches = filtered === null ? null : filtered.matchesFor(index);
854
- for (const entry of partitions[index].sortedPage({ ...request, matches })) merged.push(entry);
855
- }
856
- merged.sort((a, b) => compareComparableKeys(a.key, b.key, directions) || compareCodePoints(a.id, b.id));
857
- const hasMore = merged.length > limit;
858
- const page = hasMore ? merged.slice(0, limit) : merged;
859
- const last = page[page.length - 1];
860
- const nextCursor = hasMore && last !== void 0 ? { anchor: last.id, score: null, sortKey: last.key, sortSignature: signature, binding } : null;
861
- return { ids: page.map((entry) => entry.id), nextCursor };
862
- }
863
- function countAcrossPartitions(manager, partitionIds, partitions) {
864
- if (partitionIds === void 0) {
865
- return manager.countDocuments();
866
- }
867
- let total = 0;
868
- for (const partition of partitions) {
869
- total += partition.count();
870
- }
871
- return total;
872
- }
873
- function executeListDocuments(params, context) {
874
- const { manager, schema } = context;
875
- const startTime = now();
876
- const limit = clampListLimit(params.limit);
877
- const signature = sortSignatureOf(params.sort);
878
- requireSortableFields(params.sort, schema, context.strict === true);
879
- const filters = validQueryFilter(params.filters, schema);
880
- const projection = resolveProjection(params.document);
881
- const binding = listBindingOf(params.filters);
882
- let cursor = null;
883
- if (params.cursor !== void 0) {
884
- cursor = decodePageCursor(params.cursor);
885
- requireMatchingCursor(cursor, params.cursor, signature, false, binding);
886
- }
887
- const partitions = context.partitionIds === void 0 ? manager.getAllPartitions() : context.partitionIds.map((partitionId) => manager.partitionAt(partitionId)).filter((partition) => partition !== void 0);
888
- const filtered = filters === void 0 ? null : collectFilterMatches(partitions, filters, schema, context.patternWorkCap);
889
- const total = filtered === null ? countAcrossPartitions(manager, context.partitionIds, partitions) : filtered.total;
890
- const page = params.sort === void 0 || signature === null ? pageInIdOrder(partitions, cursor, filtered, limit, binding) : pageInSortOrder(partitions, cursor, filtered, limit, params.sort, signature, schema, binding);
891
- const documents = [];
892
- for (const docId of page.ids) {
893
- if (projection.kind === "none") {
894
- documents.push({ id: docId, document: {} });
895
- continue;
896
- }
897
- const stored = manager.get(docId, projection);
898
- if (stored === void 0) continue;
899
- documents.push({ id: docId, document: stored });
900
- }
901
- if (page.nextCursor === null) {
902
- for (const partition of partitions) partition.releaseSortedDocIds();
903
- }
904
- return {
905
- documents,
906
- cursor: page.nextCursor === null ? null : encodePageCursor(page.nextCursor),
907
- total,
908
- elapsed: now() - startTime
909
- };
910
- }
911
-
912
- // src/search/grouping.ts
913
- function hitsKeptPerGroup(maxPerGroup) {
914
- if (maxPerGroup === void 0 || !Number.isFinite(maxPerGroup) || maxPerGroup < 1) return DEFAULT_MAX_PER_GROUP;
915
- return Math.floor(maxPerGroup);
916
- }
917
- function applyGrouping(hits, group, documents) {
918
- if (!group.fields || group.fields.length === 0) {
919
- return [{ values: {}, hits }];
920
- }
921
- const groupMap = /* @__PURE__ */ new Map();
922
- for (const hit of hits) {
923
- const stored = documents.fieldValues(hit.id, group.fields);
924
- const fieldValues = [];
925
- const valuesRecord = {};
926
- for (let at = 0; at < group.fields.length; at++) {
927
- const value = stored?.[at];
928
- fieldValues.push(value);
929
- valuesRecord[group.fields[at]] = value;
930
- }
931
- const compositeKey = JSON.stringify(fieldValues);
932
- const existing = groupMap.get(compositeKey);
933
- if (existing) {
934
- existing.hits.push(hit);
935
- } else {
936
- groupMap.set(compositeKey, { values: valuesRecord, hits: [hit] });
937
- }
938
- }
939
- const groups = [];
940
- const keptPerGroup = hitsKeptPerGroup(group.maxPerGroup);
941
- for (const entry of groupMap.values()) {
942
- const everyHit = entry.hits;
943
- const result = { values: entry.values, hits: everyHit.slice(0, keptPerGroup) };
944
- if (group.reduce) {
945
- const folded = foldGroupReducer(
946
- group.reduce,
947
- everyHit.map((hit) => ({ document: documents.document(hit.id), score: hit.score ?? 0 }))
948
- );
949
- if (folded.reducerError !== void 0) {
950
- result.reducerError = folded.reducerError;
951
- } else {
952
- result.reduced = folded.reduced;
953
- }
954
- }
955
- groups.push(result);
956
- }
957
- groups.sort((a, b) => {
958
- const aScore = a.hits.length > 0 ? a.hits[0].score ?? 0 : 0;
959
- const bScore = b.hits.length > 0 ? b.hits[0].score ?? 0 : 0;
960
- if (aScore !== bScore) return bScore - aScore;
961
- const aId = a.hits.length > 0 ? a.hits[0].id : "";
962
- const bId = b.hits.length > 0 ? b.hits[0].id : "";
963
- return compareCodePoints(aId, bId);
964
- });
965
- if (group.limit !== void 0 && Number.isFinite(group.limit) && group.limit >= 0) {
966
- const cap = Math.floor(group.limit);
967
- if (groups.length > cap) {
968
- groups.length = cap;
969
- }
970
- }
971
- return groups;
972
- }
973
- function foldGroupReducer(reduce, rows) {
974
- try {
975
- let accumulator = reduce.initialValue();
976
- for (const row of rows) {
977
- if (row.document !== void 0) {
978
- accumulator = reduce.reducer(accumulator, row.document, row.score);
979
- }
980
- }
981
- return { reduced: accumulator };
982
- } catch (err) {
983
- return { reducerError: err instanceof Error ? err.message : String(err) };
984
- }
985
- }
986
-
987
- // src/search/pinning.ts
988
- function dedupePinnedEntries(pinned) {
989
- const deduped = [];
990
- const seen = /* @__PURE__ */ new Set();
991
- for (const entry of pinned) {
992
- if (seen.has(entry.docId)) continue;
993
- seen.add(entry.docId);
994
- deduped.push(entry);
995
- }
996
- return deduped;
997
- }
998
- function placePinned(hits, pinned, resolveDoc) {
999
- const result = hits.slice();
1000
- const deduped = dedupePinnedEntries(pinned);
1001
- const pinnedDocIds = new Set(deduped.map((entry) => entry.docId));
1002
- const listedPins = /* @__PURE__ */ new Set();
1003
- for (let i = result.length - 1; i >= 0; i--) {
1004
- if (pinnedDocIds.has(result[i].id)) {
1005
- listedPins.add(result[i].id);
1006
- result.splice(i, 1);
1007
- }
1008
- }
1009
- const sorted = deduped.sort((a, b) => a.position - b.position);
1010
- let placedFromOutside = 0;
1011
- for (const entry of sorted) {
1012
- const doc = resolveDoc(entry.docId);
1013
- if (!doc) continue;
1014
- if (!listedPins.has(entry.docId)) placedFromOutside++;
1015
- const pos = Math.max(0, Math.min(entry.position, result.length));
1016
- result.splice(pos, 0, doc);
1017
- }
1018
- return { hits: result, placedFromOutside };
1019
- }
1020
-
1021
- // src/highlighting/highlighter.ts
1022
- function buildTokenCharOffsets(text, originalTokens) {
1023
- const offsets = [];
1024
- let searchFrom = 0;
1025
- for (const token of originalTokens) {
1026
- const idx = text.indexOf(token, searchFrom);
1027
- if (idx === -1) continue;
1028
- offsets.push({ start: idx, end: idx + token.length });
1029
- searchFrom = idx + token.length;
1030
- }
1031
- return offsets;
1032
- }
1033
- function mergeOverlapping(ranges) {
1034
- if (ranges.length === 0) return [];
1035
- const sorted = [...ranges].sort((a, b) => a.start - b.start);
1036
- const merged = [sorted[0]];
1037
- for (let i = 1; i < sorted.length; i++) {
1038
- const prev = merged[merged.length - 1];
1039
- const curr = sorted[i];
1040
- if (curr.start <= prev.end) {
1041
- prev.end = Math.max(prev.end, curr.end);
1042
- } else {
1043
- merged.push(curr);
1044
- }
1045
- }
1046
- return merged;
1047
- }
1048
- function findDensestWindow(positions, text, windowSize) {
1049
- if (positions.length === 0) {
1050
- return { start: 0, end: Math.min(windowSize, text.length) };
1051
- }
1052
- let bestStart = 0;
1053
- let bestCount = 0;
1054
- for (const pos of positions) {
1055
- const windowStart = Math.max(0, pos.start - Math.floor(windowSize / 2));
1056
- const windowEnd = Math.min(text.length, windowStart + windowSize);
1057
- const adjustedStart = Math.max(0, windowEnd - windowSize);
1058
- let count = 0;
1059
- for (const p of positions) {
1060
- if (p.start >= adjustedStart && p.end <= windowEnd) {
1061
- count++;
1062
- }
1063
- }
1064
- if (count > bestCount) {
1065
- bestCount = count;
1066
- bestStart = adjustedStart;
1067
- }
1068
- }
1069
- return { start: bestStart, end: Math.min(text.length, bestStart + windowSize) };
1070
- }
1071
- function applySnippetTruncation(taggedText, originalText, positions, maxLen, preTag, postTag) {
1072
- if (maxLen <= 0 || originalText.length <= maxLen) {
1073
- return { snippet: taggedText, visiblePositions: positions };
1074
- }
1075
- const window = findDensestWindow(positions, originalText, maxLen);
1076
- const snippetRaw = originalText.substring(window.start, window.end);
1077
- const visiblePositions = [];
1078
- const withinSnippet = [];
1079
- for (const pos of positions) {
1080
- if (pos.start < window.start || pos.end > window.end) continue;
1081
- visiblePositions.push(pos);
1082
- withinSnippet.push({ start: pos.start - window.start, end: pos.end - window.start });
1083
- }
1084
- let snippet = snippetRaw;
1085
- const sortedDesc = [...withinSnippet].sort((a, b) => b.start - a.start);
1086
- for (const pos of sortedDesc) {
1087
- snippet = snippet.substring(0, pos.start) + preTag + snippet.substring(pos.start, pos.end) + postTag + snippet.substring(pos.end);
1088
- }
1089
- const needsLeadingEllipsis = window.start > 0;
1090
- const needsTrailingEllipsis = window.end < originalText.length;
1091
- if (needsLeadingEllipsis) snippet = `...${snippet}`;
1092
- if (needsTrailingEllipsis) snippet = `${snippet}...`;
1093
- return { snippet, visiblePositions };
1094
- }
1095
- function highlightField(text, queryTokens, language, options) {
1096
- const preTag = options?.preTag ?? "<mark>";
1097
- const postTag = options?.postTag ?? "</mark>";
1098
- const maxSnippetLength = options?.maxSnippetLength ?? 200;
1099
- if (text.length === 0) {
1100
- return { snippet: text, positions: [] };
1101
- }
1102
- const fieldResult = tokenize(text, language, { stem: false, removeStopWords: false });
1103
- if (fieldResult.tokens.length === 0) {
1104
- return { snippet: text, positions: [] };
1105
- }
1106
- const lowercaseText = text.normalize("NFC").toLowerCase();
1107
- const charOffsets = buildTokenCharOffsets(lowercaseText, fieldResult.originalTokens);
1108
- const stemmedQueryTokens = queryTokens.map((qt) => {
1109
- if (language.stemmer) {
1110
- return language.stemmer(qt.token.toLowerCase());
1111
- }
1112
- return qt.token.toLowerCase();
1113
- });
1114
- const matchedRanges = [];
1115
- const prefixToken = options?.prefixToken;
1116
- const tolerance = options?.tolerance ?? 0;
1117
- const prefixLength = options?.prefixLength ?? 0;
1118
- const completedToken = options?.completedToken;
1119
- const queryTolerances = queryTokens.map((qt) => qt.token === completedToken ? 0 : tolerance);
1120
- const synonyms = options?.synonyms;
1121
- const matchByFieldToken = /* @__PURE__ */ new Map();
1122
- const matchesQuery = (fieldToken) => {
1123
- const known = matchByFieldToken.get(fieldToken);
1124
- if (known !== void 0) return known;
1125
- const stemmedField = language.stemmer ? language.stemmer(fieldToken) : fieldToken;
1126
- const matches = synonyms?.includes(stemmedField) === true || stemmedQueryTokens.some(
1127
- (stemmedQuery, index) => fuzzyTermMatches(stemmedQuery, stemmedField, queryTolerances[index], prefixLength)
1128
- );
1129
- matchByFieldToken.set(fieldToken, matches);
1130
- return matches;
1131
- };
1132
- const matchesInside = options?.partialWords === void 0 ? null : partialWordHighlighter(text, language, options.partialWords);
1133
- for (let i = 0; i < fieldResult.tokens.length; i++) {
1134
- if (i >= charOffsets.length) break;
1135
- const fieldToken = fieldResult.tokens[i].token;
1136
- const prefixMatch = prefixToken !== void 0 && fieldToken.startsWith(prefixToken);
1137
- const insideMatch = matchesInside?.(fieldResult.tokens[i].position, fieldToken) === true;
1138
- if (prefixMatch || insideMatch || matchesQuery(fieldToken)) {
1139
- matchedRanges.push({ start: charOffsets[i].start, end: charOffsets[i].end });
1140
- }
1141
- }
1142
- const mergedPositions = mergeOverlapping(matchedRanges);
1143
- if (mergedPositions.length === 0) {
1144
- if (maxSnippetLength > 0 && text.length > maxSnippetLength) {
1145
- const truncated = text.substring(0, maxSnippetLength);
1146
- return { snippet: `${truncated}...`, positions: [] };
1147
- }
1148
- return { snippet: text, positions: [] };
1149
- }
1150
- if (maxSnippetLength > 0 && text.length > maxSnippetLength) {
1151
- const { snippet, visiblePositions } = applySnippetTruncation(
1152
- text,
1153
- text,
1154
- mergedPositions,
1155
- maxSnippetLength,
1156
- preTag,
1157
- postTag
1158
- );
1159
- return { snippet, positions: visiblePositions };
1160
- }
1161
- let result = text;
1162
- const sortedDesc = [...mergedPositions].sort((a, b) => b.start - a.start);
1163
- for (const pos of sortedDesc) {
1164
- result = result.substring(0, pos.start) + preTag + result.substring(pos.start, pos.end) + postTag + result.substring(pos.end);
1165
- }
1166
- return { snippet: result, positions: mergedPositions };
1167
- }
1168
-
1169
- // src/engine/query/highlight.ts
1170
- function writtenWordsOf(term, language, analysis) {
1171
- return tokenize(term, language, {
1172
- stem: false,
1173
- removeStopWords: true,
1174
- customTokenizer: analysis.customTokenizer,
1175
- stopWordOverride: analysis.stopWords
1176
- }).tokens;
1177
- }
1178
- function partialWordTagging(params, schema, queryTokens, written, analysis) {
1179
- if (params.partialWords !== true || params.exact === true) return null;
1180
- const fields = partialFieldsOf(schema).filter((field) => params.fields === void 0 || params.fields.includes(field));
1181
- if (fields.length === 0) return null;
1182
- const words = partialWordsToHighlight(queryTokens, written);
1183
- if (words.length === 0) return null;
1184
- return {
1185
- fields: new Set(fields),
1186
- highlight: { words, customTokenizer: analysis.customTokenizer, stopWordOverride: analysis.stopWords }
1187
- };
1188
- }
1189
- function applyHighlights(hits, request, language, analysis, schema, readStoredDocument, synonymLookup) {
1190
- if (!request.highlight) return;
1191
- const quoted = analyseQueryPhrases(request.term ?? "", language, analysis);
1192
- const params = quoted === null ? request : requireLoadedPhraseCode().withWordsOnly(request, quoted);
1193
- const words = params.term ?? "";
1194
- const highlightConfig = request.highlight;
1195
- const queryTokens = quoted !== null && words.trim().length === 0 ? [] : tokenize(words, language, {
1196
- stem: true,
1197
- removeStopWords: true,
1198
- customTokenizer: analysis.customTokenizer,
1199
- stopWordOverride: analysis.stopWords
1200
- }).tokens;
1201
- const usesPrefix = params.prefix === true && params.exact !== true && queryTokens.length > 0;
1202
- const usesPartialWords = params.partialWords === true && params.exact !== true && queryTokens.length > 0;
1203
- const written = usesPrefix || usesPartialWords ? writtenWordsOf(words, language, analysis) : [];
1204
- let prefixToken;
1205
- let completedToken;
1206
- if (usesPrefix) {
1207
- const lastToken = queryTokens[queryTokens.length - 1];
1208
- for (const t of written) {
1209
- if (t.position === lastToken.position) {
1210
- prefixToken = t.token;
1211
- completedToken = lastToken.token;
1212
- break;
1213
- }
1214
- }
1215
- }
1216
- const partialWords = usesPartialWords ? partialWordTagging(params, schema, queryTokens, written, analysis) : null;
1217
- const wordSynonyms = params.exact === true || queryTokens.length === 0 ? void 0 : synonymLookup?.expand(queryTokens.map((qt) => qt.token))?.tokens;
1218
- const phraseTokens = quoted?.phrases.flatMap((phrase) => phrase.tokens) ?? [];
1219
- const synonyms = phraseTokens.length === 0 ? wordSynonyms : [...wordSynonyms ?? [], ...phraseTokens];
1220
- for (const hit of hits) {
1221
- const highlights = {};
1222
- const projected = hit.document;
1223
- let stored;
1224
- for (const field of highlightConfig.fields) {
1225
- let fieldValue = projected[field];
1226
- if (typeof fieldValue !== "string" && readStoredDocument !== void 0) {
1227
- stored ??= readStoredDocument(hit.id);
1228
- fieldValue = stored?.[field];
1229
- }
1230
- if (typeof fieldValue === "string") {
1231
- highlights[field] = highlightField(fieldValue, queryTokens, language, {
1232
- preTag: highlightConfig.preTag,
1233
- postTag: highlightConfig.postTag,
1234
- maxSnippetLength: highlightConfig.maxSnippetLength,
1235
- prefixToken,
1236
- completedToken,
1237
- tolerance: params.exact === true ? 0 : params.tolerance ?? 0,
1238
- prefixLength: params.prefixLength ?? DEFAULT_FUZZY_PREFIX_LENGTH,
1239
- partialWords: partialWords?.fields.has(field) === true ? partialWords.highlight : void 0,
1240
- synonyms
1241
- });
1242
- }
1243
- }
1244
- hit.highlights = highlights;
1245
- }
1246
- }
1247
-
1248
- // src/search/fusion.ts
1249
- function rankConstantOf(k) {
1250
- if (k === void 0 || k === null) return DEFAULT_RANK_CONSTANT;
1251
- if (!Number.isInteger(k) || k < MIN_RANK_CONSTANT) {
1252
- throw new NarsilError(
1253
- ErrorCodes.CONFIG_INVALID,
1254
- `hybrid.k must be a whole number of at least ${MIN_RANK_CONSTANT}`,
1255
- { k }
1256
- );
1257
- }
1258
- return k;
1259
- }
1260
- function linearAlphaOf(alpha) {
1261
- if (alpha === void 0 || alpha === null) return DEFAULT_LINEAR_ALPHA;
1262
- if (!Number.isFinite(alpha) || alpha < MIN_LINEAR_ALPHA || alpha > MAX_LINEAR_ALPHA) {
1263
- throw new NarsilError(
1264
- ErrorCodes.CONFIG_INVALID,
1265
- `hybrid.alpha must be a number from ${MIN_LINEAR_ALPHA} to ${MAX_LINEAR_ALPHA}`,
1266
- { alpha }
1267
- );
1268
- }
1269
- return alpha;
1270
- }
1271
- function resolveHybridFusion(hybrid) {
1272
- const strategy = hybrid?.strategy ?? "rrf";
1273
- if (strategy !== "rrf" && strategy !== "linear") {
1274
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, `hybrid.strategy must be "rrf" or "linear"`, { strategy });
1275
- }
1276
- return { strategy, k: rankConstantOf(hybrid?.k), alpha: linearAlphaOf(hybrid?.alpha) };
1277
- }
1278
- function reciprocalRankFusion(lists, options) {
1279
- const k = options.k;
1280
- const positions = /* @__PURE__ */ new Map();
1281
- const result = [];
1282
- for (const list of lists) {
1283
- for (let rank = 0; rank < list.length; rank++) {
1284
- const doc = list[rank];
1285
- const rrfContribution = 1 / (k + rank + 1);
1286
- const position = positions.get(doc.docId);
1287
- if (position === void 0) {
1288
- positions.set(doc.docId, result.length);
1289
- result.push({
1290
- docId: doc.docId,
1291
- score: rrfContribution,
1292
- termFrequencies: doc.termFrequencies,
1293
- fieldLengths: doc.fieldLengths,
1294
- idf: doc.idf
1295
- });
1296
- } else {
1297
- result[position].score += rrfContribution;
1298
- }
1299
- }
1300
- }
1301
- result.sort((a, b) => b.score - a.score || compareCodePoints(a.docId, b.docId));
1302
- return result;
1303
- }
1304
- function linearCombination(textResults, vectorResults, options) {
1305
- const { alpha } = options;
1306
- const normalizedText = minMaxNormalize(textResults);
1307
- const normalizedVector = minMaxNormalize(vectorResults);
1308
- const textScoreMap = /* @__PURE__ */ new Map();
1309
- for (const doc of normalizedText) {
1310
- textScoreMap.set(doc.docId, doc.score);
1311
- }
1312
- const textDocMap = /* @__PURE__ */ new Map();
1313
- for (const doc of textResults) {
1314
- textDocMap.set(doc.docId, doc);
1315
- }
1316
- const vectorScoreMap = /* @__PURE__ */ new Map();
1317
- for (const doc of normalizedVector) {
1318
- vectorScoreMap.set(doc.docId, doc.score);
1319
- }
1320
- const allDocIds = /* @__PURE__ */ new Set();
1321
- for (const doc of textResults) allDocIds.add(doc.docId);
1322
- for (const doc of vectorResults) allDocIds.add(doc.docId);
1323
- const result = [];
1324
- for (const docId of allDocIds) {
1325
- const tScore = textScoreMap.get(docId) ?? 0;
1326
- const vScore = vectorScoreMap.get(docId) ?? 0;
1327
- const combined = alpha * vScore + (1 - alpha) * tScore;
1328
- const original = textDocMap.get(docId);
1329
- result.push({
1330
- docId,
1331
- score: combined,
1332
- termFrequencies: original?.termFrequencies ?? {},
1333
- fieldLengths: original?.fieldLengths ?? {},
1334
- idf: original?.idf ?? {}
1335
- });
1336
- }
1337
- result.sort((a, b) => b.score - a.score || compareCodePoints(a.docId, b.docId));
1338
- return result;
1339
- }
1340
- function minMaxNormalize(docs) {
1341
- if (docs.length === 0) return [];
1342
- let min = docs[0].score;
1343
- let max = docs[0].score;
1344
- for (let i = 1; i < docs.length; i++) {
1345
- if (docs[i].score < min) min = docs[i].score;
1346
- if (docs[i].score > max) max = docs[i].score;
1347
- }
1348
- const range = max - min;
1349
- if (range === 0) {
1350
- return docs.map((d) => ({ docId: d.docId, score: 1 }));
1351
- }
1352
- return docs.map((d) => ({ docId: d.docId, score: (d.score - min) / range }));
1353
- }
1354
-
1355
- // src/engine/query/filter-subsets.ts
1356
- function collectFilterSubsets(manager, filters, schema, partitionIds, patternWork) {
1357
- const subsets = [];
1358
- for (const partition of partitionsFor(manager, partitionIds)) {
1359
- for (const state of partition.readStates()) {
1360
- subsets.push({
1361
- owner: state,
1362
- bits: applyPartitionFiltersBitset(state, filters, schema, patternWork),
1363
- numberingGeneration: state.docStore.numberingGeneration()
1364
- });
1365
- }
1366
- }
1367
- return subsets;
1368
- }
1369
- function filterSubsetsMatchNothing(subsets) {
1370
- for (const subset of subsets) {
1371
- for (let wordIndex = 0; wordIndex < subset.bits.length; wordIndex++) {
1372
- if (subset.bits[wordIndex] !== 0) return false;
1373
- }
1374
- }
1375
- return true;
1376
- }
1377
- function filterSubsetsRenumbered(subsets) {
1378
- return subsets.some((subset) => subset.owner.docStore.numberingGeneration() !== subset.numberingGeneration);
1379
- }
1380
- async function searchCurrentSubsets(fieldName, first, collectAgain, search) {
1381
- let subsets = first;
1382
- for (let attempt = 1; ; attempt++) {
1383
- const answer = await search(subsets);
1384
- if (!filterSubsetsRenumbered(subsets)) return answer;
1385
- if (attempt >= MAX_RENUMBERED_SEARCH_ATTEMPTS) {
1386
- throw new NarsilError(
1387
- ErrorCodes.WORKER_BUSY,
1388
- `The index renumbered its documents during each of ${attempt} filtered searches of vector field "${fieldName}"`,
1389
- { fieldName, attempts: attempt }
1390
- );
1391
- }
1392
- subsets = collectAgain();
1393
- }
1394
- }
1395
-
1396
- // src/engine/query/vector.ts
1397
- function oversampleOf(vectorConfig) {
1398
- const oversample = vectorConfig.oversample;
1399
- if (oversample === void 0) return void 0;
1400
- if (typeof oversample !== "number" || !Number.isFinite(oversample) || oversample < MIN_OVERSAMPLE) {
1401
- throw new NarsilError(
1402
- ErrorCodes.CONFIG_INVALID,
1403
- `vector.oversample must be a finite number of at least ${MIN_OVERSAMPLE}`,
1404
- { oversample }
1405
- );
1406
- }
1407
- return oversample;
1408
- }
1409
- function vectorFetchDepth(limit, offset, cursorDepth) {
1410
- const reach = cursorDepth + offset + limit;
1411
- if (reach > RESULT_WINDOW) {
1412
- throw new NarsilError(
1413
- ErrorCodes.SEARCH_RESULT_WINDOW_EXCEEDED,
1414
- `The engine pages a vector search through the first ${RESULT_WINDOW} results, and this page ends at ${reach}. Narrow the search with a filter or a similarity floor`,
1415
- { limit, offset, cursorDepth, window: RESULT_WINDOW }
1416
- );
1417
- }
1418
- return Math.min(reach + 1, RESULT_WINDOW);
1419
- }
1420
- function filteredSearchOf(params, context) {
1421
- const filters = params.filters;
1422
- if (!filters) return void 0;
1423
- const { manager, config, partitionIds, patternWork } = context;
1424
- const collectAgain = () => collectFilterSubsets(manager, filters, config.schema, partitionIds, patternWork);
1425
- return { first: collectAgain(), collectAgain };
1426
- }
1427
- function searchField(vecIndex, vectorConfig, queryVector, k, context, filtered, rescoreWindow) {
1428
- const options = {
1429
- clock: context.patternWork.clock,
1430
- metric: vectorConfig.metric ?? "cosine",
1431
- minSimilarity: vectorConfig.similarity ?? -Infinity,
1432
- efSearch: vectorConfig.efSearch,
1433
- oversample: oversampleOf(vectorConfig),
1434
- ...rescoreWindow !== void 0 ? { rescoreWindow } : {}
1435
- };
1436
- if (filtered !== void 0) {
1437
- return searchCurrentSubsets(
1438
- vecIndex.fieldName,
1439
- filtered.first,
1440
- filtered.collectAgain,
1441
- (filterSubsets) => vecIndex.searchParallel(queryVector, k, { ...options, filterSubsets })
1442
- );
1443
- }
1444
- const filterPartitions = partitionsForVectorSearch(context.manager, vecIndex, context.partitionIds);
1445
- return vecIndex.searchParallel(
1446
- queryVector,
1447
- k,
1448
- filterPartitions === void 0 ? options : { ...options, filterPartitions }
1449
- );
1450
- }
1451
- async function executeVectorSearch(params, context, limit, offset, cursorDepth = 0) {
1452
- const vectorConfig = params.vector;
1453
- if (!vectorConfig || !vectorConfig.value) {
1454
- return { scored: [], totalMatched: 0 };
1455
- }
1456
- const vecIndex = resolveVectorIndex(context, vectorConfig.field);
1457
- if (!vecIndex) {
1458
- return { scored: [], totalMatched: 0 };
1459
- }
1460
- const filtered = filteredSearchOf(params, context);
1461
- if (filtered !== void 0 && filterSubsetsMatchNothing(filtered.first)) {
1462
- return { scored: [], totalMatched: 0 };
1463
- }
1464
- const queryVec = new Float32Array(vectorConfig.value);
1465
- const k = vectorFetchDepth(limit, offset, cursorDepth);
1466
- const outcome = await searchField(vecIndex, vectorConfig, queryVec, k, context, filtered, context.rescoreWindow);
1467
- const scored = vectorResultsToScored(outcome.results);
1468
- return { scored, totalMatched: outcome.matched, matchedExact: outcome.matchedExact };
1469
- }
1470
- async function textLeg(textOnlyParams, context) {
1471
- const { manager, language, config, workerSearch, indexName } = context;
1472
- const scoring = scoringConfigFor(textOnlyParams, context);
1473
- if (workerSearch) {
1474
- const viaWorker = await workerSearch(
1475
- indexName,
1476
- textOnlyParams,
1477
- broadcastStatsForWorker(textOnlyParams, context, scoring),
1478
- context.partitionIds,
1479
- context.patternWork,
1480
- bm25SettingFor(textOnlyParams, context)
1481
- );
1482
- if (viaWorker) return viaWorker;
1483
- }
1484
- return fanOutQuery(
1485
- manager,
1486
- textOnlyParams,
1487
- language,
1488
- config.schema,
1489
- scoring,
1490
- searchOptionsFor(textOnlyParams, context)
1491
- );
1492
- }
1493
- async function vectorLeg(vectorConfig, queryVector, context, filtered, k, rescoreWindow) {
1494
- const vecIndex = resolveVectorIndex(context, vectorConfig.field);
1495
- if (!vecIndex) return { scored: [], holdsEveryMatch: true };
1496
- const outcome = await searchField(vecIndex, vectorConfig, queryVector, k, context, filtered, rescoreWindow);
1497
- return {
1498
- scored: vectorResultsToScored(outcome.results),
1499
- holdsEveryMatch: outcome.matchedExact && outcome.results.length === outcome.matched
1500
- };
1501
- }
1502
- async function executeHybridSearch(params, context, limit, offset, cursorDepth = 0) {
1503
- const { vector: vectorConfig, mode: _mode, hybrid: _hybrid, ...textOnlyParams } = params;
1504
- const fusion = resolveHybridFusion(params.hybrid);
1505
- const filtered = filteredSearchOf(params, context);
1506
- if (filtered !== void 0 && filterSubsetsMatchNothing(filtered.first)) {
1507
- return { scored: [], totalMatched: 0 };
1508
- }
1509
- if (!vectorConfig || !vectorConfig.value) {
1510
- const textOnly = await textLeg(textOnlyParams, context);
1511
- return { scored: textOnly.scored, totalMatched: textOnly.totalMatched, facets: textOnly.facets };
1512
- }
1513
- const vectorPending = vectorLeg(
1514
- vectorConfig,
1515
- new Float32Array(vectorConfig.value),
1516
- context,
1517
- filtered,
1518
- vectorFetchDepth(limit, offset, cursorDepth)
1519
- );
1520
- const [textFanOutResult, vectorOutcome] = await Promise.all([textLeg(textOnlyParams, context), vectorPending]);
1521
- const vectorScored = vectorOutcome.scored;
1522
- let fusedScored;
1523
- if (fusion.strategy === "rrf") {
1524
- fusedScored = reciprocalRankFusion([textFanOutResult.scored, vectorScored], { k: fusion.k });
1525
- } else {
1526
- fusedScored = linearCombination(textFanOutResult.scored, vectorScored, { alpha: fusion.alpha });
1527
- }
1528
- if (params.minScore !== void 0 && params.minScore > 0) {
1529
- const threshold = params.minScore;
1530
- fusedScored = fusedScored.filter((doc) => doc.score >= threshold);
1531
- }
1532
- const textHoldsEveryMatch = textFanOutResult.scored.length === textFanOutResult.totalMatched;
1533
- return {
1534
- scored: fusedScored,
1535
- totalMatched: fusedScored.length,
1536
- matchedExact: vectorOutcome.holdsEveryMatch && textHoldsEveryMatch,
1537
- facets: textFanOutResult.facets
1538
- };
1539
- }
1540
-
1541
- // src/engine/query/runtime-host.ts
1542
- var runtimeHost = {
1543
- now,
1544
- compareCodePoints,
1545
- clampRowCount,
1546
- resolveProjection,
1547
- projectionKeepsField,
1548
- decodePageCursor,
1549
- encodePageCursor,
1550
- requireMatchingCursor,
1551
- dedupePinnedEntries,
1552
- placePinned,
1553
- normalizeSort,
1554
- flattenSchema,
1555
- parsedTypeOf,
1556
- isStringValuedBase,
1557
- applyHighlights,
1558
- textLeg,
1559
- vectorLeg,
1560
- filteredSearchOf,
1561
- filterSubsetsMatchNothing,
1562
- reciprocalRankFusion,
1563
- linearCombination,
1564
- resolveHybridFusion
1565
- };
1566
-
1567
- // src/engine/query/sorted.ts
1568
- function sortsWithoutScores(params) {
1569
- return params.includeScores !== true && params.includeScoreComponents !== true && params.minScore === void 0 && params.group === void 0 && params.pinned === void 0 && (params.termMatch === void 0 || params.termMatch === "any");
1570
- }
1571
- async function executeSortedQueryPage(params, context, limit, offset, sortSignature) {
1572
- const { manager, language, config } = context;
1573
- const schema = config.schema;
1574
- let anchorKey = null;
1575
- let anchorId = null;
1576
- if (params.searchAfter !== void 0) {
1577
- const decoded = decodePageCursor(params.searchAfter);
1578
- requireMatchingCursor(decoded, params.searchAfter, sortSignature, true, context.cursorBinding());
1579
- anchorKey = decoded.sortKey;
1580
- anchorId = decoded.anchor;
1581
- }
1582
- const normalized = normalizeSort(params.sort);
1583
- const fields = normalized.map((entry) => entry.field);
1584
- const directions = normalized.map((entry) => entry.direction);
1585
- const flatSchema = flattenSchema(schema);
1586
- const fieldTypes = fields.map((field) => flatSchema[field]);
1587
- const modes = sortModesOf(normalized);
1588
- const options = searchOptionsFor(params, context);
1589
- const partitions = partitionsFor(manager, context.partitionIds);
1590
- const partitionLimit = offset + limit + 1;
1591
- const merged = [];
1592
- const partitionFacets = [];
1593
- const partitionFacetConfig = params.facets !== void 0 && partitions.length > 1 ? everyValueFacetConfig(params.facets) : params.facets;
1594
- let count = 0;
1595
- const clock = context.patternWork.clock;
1596
- for (const partition of partitions) {
1597
- if (turnIsSpent()) await yieldTurn();
1598
- partition.prepareSortedPage({ fields, directions, fieldTypes, modes });
1599
- if (partitionFacetConfig !== void 0) {
1600
- if (turnIsSpent()) await yieldTurn();
1601
- partition.prepareFacets(partitionFacetConfig, schema);
1602
- }
1603
- if (turnIsSpent()) await yieldTurn();
1604
- clock?.check();
1605
- const matches = fulltextMatches(partition, params, language, schema, options);
1606
- clock?.check();
1607
- if (partitionFacetConfig !== void 0) {
1608
- partitionFacets.push(
1609
- partition.computeFacets(
1610
- matches === null ? /* @__PURE__ */ new Set() : { ordinalBitset: matches.ordinalBitset() },
1611
- partitionFacetConfig,
1612
- schema
1613
- )
1614
- );
1615
- }
1616
- if (matches === null || matches.count === 0) continue;
1617
- count += matches.count;
1618
- clock?.check();
1619
- const page2 = partition.sortedPage({
1620
- fields,
1621
- directions,
1622
- fieldTypes,
1623
- modes,
1624
- limit: partitionLimit,
1625
- anchorKey,
1626
- anchorId,
1627
- matches
1628
- });
1629
- for (const entry of page2) merged.push(entry);
1630
- }
1631
- clock?.check();
1632
- merged.sort((a, b) => compareComparableKeys(a.key, b.key, directions) || compareCodePoints(a.id, b.id));
1633
- const hasMore = merged.length > offset + limit;
1634
- const page = merged.slice(offset, offset + limit);
1635
- const last = page[page.length - 1];
1636
- let cursor;
1637
- if (hasMore && last !== void 0) {
1638
- cursor = encodePageCursor({
1639
- anchor: last.id,
1640
- score: null,
1641
- sortKey: last.key,
1642
- sortSignature,
1643
- binding: context.cursorBinding()
1644
- });
1645
- }
1646
- return {
1647
- hits: page.map((entry) => ({ id: entry.id, document: void 0 })),
1648
- count,
1649
- cursor,
1650
- facets: params.facets !== void 0 && partitionFacets.length > 0 ? mergeFacets(partitionFacets, params.facets) : void 0
1651
- };
1652
- }
1653
-
1654
- // src/engine/query/index.ts
1655
- function requireCursorDepth(cursor, signature, binding) {
1656
- if (cursor === void 0) return 0;
1657
- const decoded = decodePageCursor(cursor);
1658
- requireMatchingCursor(decoded, cursor, signature, true, binding());
1659
- return decoded.depth ?? 0;
1660
- }
1661
- function hybridSearchOf(params, context, limit, offset, cursorDepth) {
1662
- if ((params.hybrid?.depth ?? null) === null) return executeHybridSearch(params, context, limit, offset, cursorDepth);
1663
- return import('./runtime-COIUORCN.mjs').then(
1664
- (runtime) => runtime.searchFixedDepthHybrid(params, context, { cursorDepth: cursorDepth ?? 0, offset, limit }, runtimeHost)
1665
- );
1666
- }
1667
- function executeQuery(request, callerContext) {
1668
- if (request.rerank === void 0) {
1669
- const loadingPhraseCode = loadPhraseCodeFor(request.term);
1670
- if (loadingPhraseCode === null) return runQuery(request, callerContext);
1671
- return loadingPhraseCode.then(() => runQuery(request, callerContext));
1672
- }
1673
- return import('./runtime-COIUORCN.mjs').then(
1674
- (runtime) => runtime.executeRerankedQuery(request, callerContext, executeQuery, runtimeHost)
1675
- );
1676
- }
1677
- async function runQuery(request, callerContext) {
1678
- const context = withPatternWork(callerContext);
1679
- const { manager, language, config, workerSearch, indexName } = context;
1680
- const startTime = now();
1681
- const limit = clampLimit(request.limit);
1682
- const offset = clampOffset(request.offset);
1683
- requireWithinResultWindow(limit, offset);
1684
- const sortFields = normalizeSort(request.sort);
1685
- requireKnownMode(request);
1686
- const sortSignature = sortSignatureOf(request.sort);
1687
- const hasTerm = request.term !== void 0 && request.term.trim().length > 0;
1688
- const hasVector = request.vector !== void 0 && request.vector.value !== void 0;
1689
- const isHybridMode = request.mode === "hybrid" || hasTerm && hasVector;
1690
- const isVectorOnly = (request.mode === "vector" || hasVector && !hasTerm) && !isHybridMode;
1691
- if (sortSignature !== null && (isHybridMode || request.hybrid !== void 0)) {
1692
- throw new NarsilError(
1693
- ErrorCodes.SEARCH_INVALID_MODE,
1694
- "A hybrid query cannot carry a sort, because fusion defines the order of hybrid results",
1695
- { sort: sortFields.map((entry) => entry.field) }
1696
- );
1697
- }
1698
- const params = validQueryParams(request, config);
1699
- requireVectorSearchable(params, context, isVectorOnly || isHybridMode);
1700
- if (!isVectorOnly) requireUsablePhrases(params, context);
1701
- const projection = resolveProjection(params.document);
1702
- let paginated;
1703
- let nextCursor;
1704
- let count;
1705
- let countExact = true;
1706
- let facets;
1707
- let groups;
1708
- if (sortSignature !== null && hasTerm && !isVectorOnly && !isHybridMode && sortsWithoutScores(params)) {
1709
- const page = await executeSortedQueryPage(params, context, limit, offset, sortSignature);
1710
- paginated = page.hits;
1711
- nextCursor = page.cursor;
1712
- count = page.count;
1713
- facets = page.facets;
1714
- } else {
1715
- const requestedVectorField = params.vector?.field;
1716
- const hasGlobalVectorIndex = requestedVectorField !== void 0 && vectorSearchersOf(context).has(requestedVectorField);
1717
- let fanOutResult;
1718
- if (isVectorOnly && hasGlobalVectorIndex) {
1719
- const depth = requireCursorDepth(params.searchAfter, sortSignature, context.cursorBinding);
1720
- fanOutResult = await executeVectorSearch(params, context, limit, offset, depth);
1721
- } else if (isHybridMode && hasGlobalVectorIndex) {
1722
- const depth = requireCursorDepth(params.searchAfter, sortSignature, context.cursorBinding);
1723
- fanOutResult = await hybridSearchOf(params, context, limit, offset, depth);
1724
- } else {
1725
- const scoring = scoringConfigFor(params, context);
1726
- const workerResult = workerSearch ? await workerSearch(
1727
- indexName,
1728
- params,
1729
- broadcastStatsForWorker(params, context, scoring),
1730
- context.partitionIds,
1731
- context.patternWork,
1732
- bm25SettingFor(params, context)
1733
- ) : null;
1734
- if (workerResult) {
1735
- fanOutResult = workerResult;
1736
- } else {
1737
- fanOutResult = await fanOutQuery(
1738
- manager,
1739
- params,
1740
- language,
1741
- config.schema,
1742
- scoring,
1743
- searchOptionsFor(params, context)
1744
- );
1745
- }
1746
- }
1747
- const needsFullHits = params.sort !== void 0 || params.group !== void 0 || params.pinned !== void 0 || params.searchAfter !== void 0;
1748
- let hits;
1749
- if (needsFullHits) {
1750
- hits = fanOutResult.scored.map((scored) => ({
1751
- id: scored.docId,
1752
- score: scored.score,
1753
- document: void 0,
1754
- scoreComponents: params.includeScoreComponents ? { termFrequencies: scored.termFrequencies, fieldLengths: scored.fieldLengths, idf: scored.idf } : void 0
1755
- }));
1756
- } else {
1757
- const end = Math.min(offset + limit + 1, fanOutResult.scored.length);
1758
- hits = new Array(end);
1759
- for (let i = 0; i < end; i++) {
1760
- const scored = fanOutResult.scored[i];
1761
- hits[i] = {
1762
- id: scored.docId,
1763
- score: scored.score,
1764
- document: void 0,
1765
- scoreComponents: params.includeScoreComponents ? { termFrequencies: scored.termFrequencies, fieldLengths: scored.fieldLengths, idf: scored.idf } : void 0
1766
- };
1767
- }
1768
- }
1769
- const sortFieldNames = sortFields.map((entry) => entry.field);
1770
- const sortFlatSchema = sortFieldNames.length === 0 ? {} : flattenSchema(config.schema);
1771
- const sortFieldTypes = sortFieldNames.map((field) => sortFlatSchema[field]);
1772
- const sortModes = sortModesOf(sortFields);
1773
- const sortKeyCache = /* @__PURE__ */ new Map();
1774
- const sortKeyOf = (docId) => {
1775
- let key = sortKeyCache.get(docId);
1776
- if (key === void 0) {
1777
- key = manager.sortValues(docId, sortFieldNames, sortFieldTypes, sortModes);
1778
- sortKeyCache.set(docId, key);
1779
- }
1780
- return key;
1781
- };
1782
- if (params.sort) {
1783
- hits = applySorting(hits, params.sort, sortKeyOf);
1784
- }
1785
- if (params.group) {
1786
- groups = applyGrouping(hits, params.group, {
1787
- fieldValues: (docId, fieldPaths) => manager.fieldValues(docId, fieldPaths),
1788
- document: (docId) => manager.getRef(docId)
1789
- });
1790
- }
1791
- let pinsFromOutside = 0;
1792
- if (params.pinned && params.searchAfter === void 0 && context.partitionIds === void 0) {
1793
- const placement = placePinned(hits, params.pinned, (docId) => {
1794
- const doc = manager.getRef(docId);
1795
- if (!doc) return void 0;
1796
- return { id: docId, score: 0, document: doc };
1797
- });
1798
- hits = placement.hits;
1799
- pinsFromOutside = placement.placedFromOutside;
1800
- }
1801
- let sortContext;
1802
- if (sortSignature !== null) {
1803
- sortContext = {
1804
- signature: sortSignature,
1805
- directions: sortFields.map((entry) => entry.direction),
1806
- sortKeyOf
1807
- };
1808
- }
1809
- const pinnedIds = params.pinned !== void 0 && params.searchAfter === void 0 ? new Set(params.pinned.map((entry) => entry.docId)) : void 0;
1810
- const paged = (fanOutResult.paginate ?? applyPagination)(
1811
- hits,
1812
- limit,
1813
- offset,
1814
- context.cursorBinding,
1815
- params.searchAfter,
1816
- sortContext,
1817
- pinnedIds
1818
- );
1819
- paginated = paged.paginated;
1820
- nextCursor = paged.nextCursor;
1821
- const holdsEveryMatch = fanOutResult.matchedExact !== false && fanOutResult.scored.length === fanOutResult.totalMatched;
1822
- count = fanOutResult.totalMatched + (holdsEveryMatch ? pinsFromOutside : 0);
1823
- countExact = fanOutResult.matchedExact !== false && (holdsEveryMatch || pinsFromOutside === 0);
1824
- facets = fanOutResult.facets;
1825
- if (sortSignature !== null && params.includeScores !== true) {
1826
- for (const hit of hits) hit.score = void 0;
1827
- }
1828
- }
1829
- if (projection.kind === "none") {
1830
- for (const hit of paginated) {
1831
- hit.document = {};
1832
- }
1833
- } else {
1834
- for (const hit of paginated) {
1835
- hit.document = manager.get(hit.id, projection) ?? {};
1836
- }
1837
- }
1838
- if (groups) {
1839
- for (const group of groups) {
1840
- for (const hit of group.hits) {
1841
- if (projection.kind === "none") {
1842
- hit.document = {};
1843
- continue;
1844
- }
1845
- hit.document = manager.get(hit.id, projection) ?? {};
1846
- }
1847
- }
1848
- }
1849
- if (params.highlight) {
1850
- const dropped = params.highlight.fields.some((field) => !projectionKeepsField(projection, field));
1851
- const readStoredDocument = dropped ? (docId) => manager.get(docId, { kind: "full" }) : void 0;
1852
- applyHighlights(paginated, params, language, manager.analysis, manager.schema, readStoredDocument, manager.synonyms);
1853
- }
1854
- const elapsed = now() - startTime;
1855
- return {
1856
- hits: paginated,
1857
- count,
1858
- countExact,
1859
- elapsed,
1860
- cursor: nextCursor,
1861
- facets,
1862
- groups,
1863
- coverage: coverageFor(manager, context.partitionIds)
1864
- };
1865
- }
1866
- async function executePreflight(request, callerContext) {
1867
- const context = withPatternWork(callerContext);
1868
- const { manager, language, config, workerSearch, indexName } = context;
1869
- const startTime = now();
1870
- requireKnownMode(request);
1871
- const params = validQueryParams(request, config);
1872
- const hasTerm = params.term !== void 0 && params.term.trim().length > 0;
1873
- const hasVector = params.vector !== void 0 && params.vector.value !== void 0;
1874
- const isHybridMode = params.mode === "hybrid" || hasTerm && hasVector;
1875
- const isVectorOnly = (params.mode === "vector" || hasVector && !hasTerm) && !isHybridMode;
1876
- requireVectorSearchable(params, context, isVectorOnly || isHybridMode);
1877
- const loadingPhraseCode = loadPhraseCodeFor(params.term);
1878
- if (loadingPhraseCode !== null) await loadingPhraseCode;
1879
- if (!isVectorOnly) requireUsablePhrases(params, context);
1880
- const requestedVectorField = params.vector?.field;
1881
- const hasGlobalVectorIndex = requestedVectorField !== void 0 && vectorSearchersOf(context).has(requestedVectorField);
1882
- let totalMatched;
1883
- let countExact = true;
1884
- const preflightLimit = 1e3;
1885
- const preflightOffset = 0;
1886
- if (isVectorOnly && hasGlobalVectorIndex) {
1887
- const result = await executeVectorSearch(params, context, preflightLimit, preflightOffset);
1888
- totalMatched = result.totalMatched;
1889
- countExact = result.matchedExact !== false;
1890
- } else if (isHybridMode && hasGlobalVectorIndex) {
1891
- const result = await hybridSearchOf(params, context, preflightLimit, preflightOffset);
1892
- totalMatched = result.totalMatched;
1893
- countExact = result.matchedExact !== false;
1894
- } else if (countsWithoutScores(params)) {
1895
- totalMatched = fanOutMatchCount(manager, params, language, config.schema, {
1896
- searchOptions: searchOptionsFor(params, context),
1897
- partitionIds: context.partitionIds
1898
- });
1899
- } else {
1900
- const scoring = scoringConfigFor(params, context);
1901
- const workerResult = workerSearch ? await workerSearch(
1902
- indexName,
1903
- params,
1904
- broadcastStatsForWorker(params, context, scoring),
1905
- context.partitionIds,
1906
- context.patternWork,
1907
- bm25SettingFor(params, context)
1908
- ) : null;
1909
- if (workerResult) {
1910
- totalMatched = workerResult.totalMatched;
1911
- } else {
1912
- const fanOutResult = await fanOutQuery(
1913
- manager,
1914
- params,
1915
- language,
1916
- config.schema,
1917
- scoring,
1918
- searchOptionsFor(params, context)
1919
- );
1920
- totalMatched = fanOutResult.totalMatched;
1921
- }
1922
- }
1923
- const elapsed = now() - startTime;
1924
- return { count: totalMatched, countExact, elapsed };
1925
- }
1926
-
1927
- // src/engine/suggest.ts
1928
- function executeSuggest(manager, language, params, partitionIds) {
1929
- const t0 = performance.now();
1930
- const ceiling = partitionIds === void 0 ? MAX_SUGGEST_LIMIT : MAX_SUGGEST_SCATTER_LIMIT;
1931
- const limit = Math.max(1, Math.min(clampRowCount(params.limit, DEFAULT_SUGGEST_LIMIT), ceiling));
1932
- const rawPrefix = params.prefix.trim();
1933
- if (rawPrefix.length === 0) {
1934
- return { terms: [], elapsed: performance.now() - t0 };
1935
- }
1936
- const unstemmed = tokenize(rawPrefix, language, { stem: false, removeStopWords: false });
1937
- const lastToken = unstemmed.tokens.length > 0 ? unstemmed.tokens[unstemmed.tokens.length - 1].token : rawPrefix.toLowerCase();
1938
- if (lastToken.length === 0) {
1939
- return { terms: [], elapsed: performance.now() - t0 };
1940
- }
1941
- const stemmed = language.stemmer ? language.stemmer(lastToken) : lastToken;
1942
- const merged = /* @__PURE__ */ new Map();
1943
- const perPartitionLimit = limit * 2;
1944
- const partitions = partitionIds === void 0 ? manager.getAllPartitions() : partitionIds.map((partitionId) => manager.partitionAt(partitionId)).filter((partition) => partition !== void 0);
1945
- for (const partition of partitions) {
1946
- for (const suggestion of partition.suggestTerms(lastToken, stemmed, perPartitionLimit)) {
1947
- let entry = merged.get(suggestion.token);
1948
- if (!entry) {
1949
- entry = { documentFrequency: 0, surfaceOccurrences: /* @__PURE__ */ new Map() };
1950
- merged.set(suggestion.token, entry);
1951
- }
1952
- entry.documentFrequency += suggestion.documentFrequency;
1953
- for (const s of suggestion.surfaces) {
1954
- entry.surfaceOccurrences.set(s.surface, (entry.surfaceOccurrences.get(s.surface) ?? 0) + s.occurrences);
1955
- }
1956
- }
1957
- }
1958
- const terms = Array.from(merged.values()).map((entry) => ({ term: pickDisplaySurface(entry.surfaceOccurrences), documentFrequency: entry.documentFrequency })).sort((a, b) => b.documentFrequency - a.documentFrequency || compareCodePoints(a.term, b.term));
1959
- if (terms.length > limit) terms.length = limit;
1960
- return { terms, elapsed: performance.now() - t0 };
1961
- }
1962
- function pickDisplaySurface(surfaceOccurrences) {
1963
- let best = "";
1964
- let bestCount = -1;
1965
- for (const [surface, occurrences] of surfaceOccurrences) {
1966
- if (occurrences > bestCount || occurrences === bestCount && compareCodePoints(surface, best) < 0) {
1967
- best = surface;
1968
- bestCount = occurrences;
1969
- }
1970
- }
1971
- return best;
1972
- }
1973
-
1974
- export { CASE_FOLD_EXPANSION_FACTOR, DEFAULT_BLOCK_WRITES_ABOVE, DEFAULT_RESUME_WRITES_BELOW, DISTINCT_TERM_HEAP_BYTES, DOCUMENT_HEAP_BYTES_PER_ESTIMATED_BYTE, DOCUMENT_PROPERTY_HEAP_BYTES, DOCUMENT_VALUE_HEAP_BYTES, ENGINE_MEMORY_FIGURES_MAX_AGE_MS, ENUM_VALUE_HEAP_BYTES, FULL_MEMORY_COLLECTION_INTERVAL_MS, NORMALIZATION_EXPANSION_FACTOR, PARTIAL_SPELLING_HEAP_BYTES, PATTERN_RUN_HEAP_BYTES, TERM_UNIT_HEAP_BYTES, VECTOR_COMPONENT_HEAP_BYTES, VECTOR_DOCUMENT_HEAP_BYTES, clampLimit, dedupePinnedEntries, executeListDocuments, executePreflight, executeQuery, executeSuggest, foldGroupReducer, hitsKeptPerGroup, lazyQueryBinding, listBindingOf, now, queryBindingOf, readEngineMemoryFigures, readMemoryFigures, readRecentMemoryFigures, requireSurfaceFormsForPartialFields, resolveHybridFusion, runtimeHost, storedBM25Params, validateBM25Params, validateBM25Shape, validateBatchList, validateDocId, validateIndexName, validatePartitionConfig, validatePatternValueLimit, validateWorkerConfig };