@delali/narsil 0.3.1-next.99 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +45 -0
- package/README.md +27 -8
- package/dist/adapters/filesystem.d.ts +1 -1
- package/dist/adapters/filesystem.mjs +101 -13
- package/dist/adapters/gcs.d.ts +49 -0
- package/dist/adapters/gcs.mjs +213 -0
- package/dist/adapters/indexeddb.d.ts +1 -1
- package/dist/adapters/indexeddb.mjs +2 -7
- package/dist/adapters/memory.d.ts +1 -1
- package/dist/adapters/memory.mjs +5 -0
- package/dist/adapters/s3.d.ts +53 -0
- package/dist/adapters/s3.mjs +263 -0
- package/dist/{adapters-BQFQ4PRz.d.ts → adapters-pljAqmrC.d.ts} +33 -0
- package/dist/browser/chunk-4E5APHTM.mjs +1459 -0
- package/dist/browser/chunk-NDYADQ4Y.mjs +23426 -0
- package/dist/browser/chunk-QAOVAYAG.mjs +564 -0
- package/dist/browser/chunk-WC2DEXWU.mjs +29 -0
- package/dist/browser/chunk-YINZFPLT.mjs +1239 -0
- package/dist/browser/chunk-YJHGOJAC.mjs +15 -0
- package/dist/browser/{chunk-Z7QH2XHB.mjs → core-leaf-HWAXCEWX.mjs} +3987 -2103
- package/dist/browser/custom-token-results-R5BIX7SL.mjs +59 -0
- package/dist/browser/digest-leaf-64IPRPZD.mjs +151 -0
- package/dist/browser/durability-config-75NSFCQN.mjs +97 -0
- package/dist/browser/embed-GG6PS3EA.mjs +264 -0
- package/dist/browser/geo-index-GNHY4PUB.mjs +1484 -0
- package/dist/browser/gzip-JF3S6PPT.mjs +31 -0
- package/dist/browser/module-ZZTNG5JZ.mjs +5762 -0
- package/dist/browser/msgpack-leaf-44XNWSSY.mjs +302 -0
- package/dist/browser/optional-reads-XMVPG6HG.mjs +3230 -0
- package/dist/browser/optional-writes-76DWMRQH.mjs +3603 -0
- package/dist/browser/phrase-module-6UGFVW5J.mjs +617 -0
- package/dist/browser/resolve-vector-text-XRR2OVHE.mjs +85 -0
- package/dist/browser/restore-queue-SG5O735W.mjs +196 -0
- package/dist/browser/{runtime-NYE5TB6O.mjs → runtime-OMKE7DF4.mjs} +83 -25
- package/dist/browser/segment-codec-leaf-A427QJUX.mjs +554 -0
- package/dist/browser/segment-merge-leaf-7BZ54JPI.mjs +1636 -0
- package/dist/browser/storage-leaf-5UTR5K7J.mjs +19829 -0
- package/dist/browser/store-leaf-3L33V35P.mjs +2070 -0
- package/dist/browser/suggestions-leaf-UBNDVKBD.mjs +1430 -0
- package/dist/browser/worker-copies-JXSGYR5X.mjs +2951 -0
- package/dist/{capabilities-BTTIs96E.d.ts → capabilities-DMte5K9_.d.ts} +162 -18
- package/dist/chunk-2AFZE7Y3.mjs +72 -0
- package/dist/chunk-2CKDCC65.mjs +47 -0
- package/dist/chunk-3ECIRFS5.mjs +61 -0
- package/dist/chunk-44W3CBNG.mjs +7 -0
- package/dist/chunk-4H4RG2FR.mjs +13 -0
- package/dist/chunk-4PY4JYMY.mjs +11 -0
- package/dist/chunk-4ZPVAHWF.mjs +1289 -0
- package/dist/chunk-5EI5CXO6.mjs +197 -0
- package/dist/chunk-5F5MXWS5.mjs +283 -0
- package/dist/{chunk-OHP7QR33.mjs → chunk-5FLRXF73.mjs} +25 -4
- package/dist/chunk-6FOENO4E.mjs +273 -0
- package/dist/chunk-6GHX35ZM.mjs +108 -0
- package/dist/chunk-6MSZ543Y.mjs +32 -0
- package/dist/chunk-6N6HHBCQ.mjs +4596 -0
- package/dist/{chunk-LXPIXDUJ.mjs → chunk-7P5YWDRQ.mjs} +403 -169
- package/dist/{chunk-TGP5M5R7.mjs → chunk-7T4LAYT4.mjs} +1 -1
- package/dist/{chunk-GGSH6KBQ.mjs → chunk-ASZLNVWW.mjs} +23 -3
- package/dist/chunk-AVBPB3MI.mjs +602 -0
- package/dist/{chunk-UCDF35PU.mjs → chunk-AVGUEEQ3.mjs} +494 -245
- package/dist/chunk-BUMREPLU.mjs +15 -0
- package/dist/chunk-BY6NALRK.mjs +31921 -0
- package/dist/chunk-C4ZMXXTL.mjs +92 -0
- package/dist/{chunk-2WYMG3OZ.mjs → chunk-C74KPRR7.mjs} +274 -19
- package/dist/{chunk-RSRVGAIQ.mjs → chunk-D456ZFPQ.mjs} +3 -2
- package/dist/chunk-DXZ6JDWG.mjs +797 -0
- package/dist/chunk-FJXJZUWF.mjs +209 -0
- package/dist/chunk-FS3HPPSC.mjs +212 -0
- package/dist/chunk-FT4KLZXW.mjs +1164 -0
- package/dist/chunk-GR5GMFJJ.mjs +104 -0
- package/dist/chunk-GXCDWLQI.mjs +193 -0
- package/dist/chunk-GXED6R3Q.mjs +271 -0
- package/dist/chunk-HLPRHOSO.mjs +17 -0
- package/dist/chunk-IL5DRCNU.mjs +3041 -0
- package/dist/{chunk-P36MUFEJ.mjs → chunk-JDDXV6UF.mjs} +2 -1
- package/dist/chunk-K5HSUPYS.mjs +11 -0
- package/dist/chunk-KYIRXTCA.mjs +100 -0
- package/dist/chunk-LFXS6OF7.mjs +289 -0
- package/dist/chunk-LNGE7SLY.mjs +151 -0
- package/dist/chunk-M2Z5WVWW.mjs +194 -0
- package/dist/{chunk-45AVKHMJ.mjs → chunk-M3B7SGJB.mjs} +63 -50
- package/dist/chunk-M3OW2XSP.mjs +40 -0
- package/dist/chunk-MFPSQZ6P.mjs +127 -0
- package/dist/chunk-MRCJBWJZ.mjs +1292 -0
- package/dist/chunk-MSIN4NM3.mjs +25 -0
- package/dist/chunk-MW3CJVGP.mjs +219 -0
- package/dist/chunk-MYM6CAVK.mjs +76 -0
- package/dist/chunk-NJJN4FMM.mjs +84 -0
- package/dist/chunk-NM7I3BM7.mjs +59 -0
- package/dist/chunk-OIJ64LGT.mjs +19 -0
- package/dist/{chunk-K7D4ZTSW.mjs → chunk-P4F4UWLC.mjs} +1 -1
- package/dist/chunk-Q2AP2FSN.mjs +15 -0
- package/dist/chunk-R2PJKSNL.mjs +54 -0
- package/dist/{chunk-HXJBSHXF.mjs → chunk-R724DJSG.mjs} +5056 -2619
- package/dist/chunk-S2POFTLN.mjs +10 -0
- package/dist/chunk-S5QMWECL.mjs +7 -0
- package/dist/chunk-SLAC5PAB.mjs +5008 -0
- package/dist/chunk-T4HMSZCX.mjs +5 -0
- package/dist/chunk-TACP6VK6.mjs +111 -0
- package/dist/chunk-TGPKS2UM.mjs +125 -0
- package/dist/chunk-TKKXPKEO.mjs +979 -0
- package/dist/chunk-V6EUBAIT.mjs +19 -0
- package/dist/chunk-XL56L4IR.mjs +228 -0
- package/dist/chunk-XQIAMDAG.mjs +3076 -0
- package/dist/chunk-YTUZ4R22.mjs +1063 -0
- package/dist/{chunk-KV3AZFT3.mjs → chunk-ZKOQR7EA.mjs} +45 -1
- package/dist/chunk-ZPJFGGGI.mjs +638 -0
- package/dist/chunk-ZXX5GZEX.mjs +17 -0
- package/dist/{client-i9eLJrw5.d.ts → client-BKqtl0_V.d.ts} +442 -22
- package/dist/client.d.ts +11 -10
- package/dist/client.mjs +8 -898
- package/dist/config-Bnl7L-0H.d.ts +608 -0
- package/dist/{config-P__Diiy4.d.ts → config-CJ-jfI0a.d.ts} +119 -9
- package/dist/core-leaf-6JVHEVFB.mjs +8 -0
- package/dist/custom-token-results-NXHBVY7U.mjs +59 -0
- package/dist/digest-leaf-KXBGKYHZ.mjs +1 -0
- package/dist/direct-executor-V3WOYU2Y.mjs +17 -0
- package/dist/distribution/coordinator/etcd.d.ts +63 -7
- package/dist/distribution/coordinator/etcd.mjs +725 -81
- package/dist/distribution/coordinator/in-memory.d.ts +3 -3
- package/dist/distribution/coordinator/in-memory.mjs +65 -10
- package/dist/distribution/transport/grpc.d.ts +2 -2
- package/dist/distribution/transport/grpc.mjs +39 -10
- package/dist/distribution/transport/in-memory.d.ts +2 -2
- package/dist/distribution/transport/in-memory.mjs +9 -6
- package/dist/distribution/transport/tcp.d.ts +2 -2
- package/dist/distribution/transport/tcp.mjs +20 -15
- package/dist/distribution.d.ts +267 -56
- package/dist/distribution.mjs +23156 -11362
- package/dist/durability-config-VWS2K24E.mjs +96 -0
- package/dist/embed-4PHHKGBK.mjs +263 -0
- package/dist/embeddings/openai.d.ts +1 -1
- package/dist/embeddings/openai.mjs +2 -2
- package/dist/{memory-CUEDwr-F.d.ts → engine-qjAxJSKk.d.ts} +2254 -1123
- package/dist/geo-index-2ZMMWWSK.mjs +1484 -0
- package/dist/gzip-2UCZW2MM.mjs +31 -0
- package/dist/{index-lcdGLyJH.d.ts → index-B_vmxpgW.d.ts} +260 -102
- package/dist/index.browser.mjs +4 -4
- package/dist/index.d.ts +2133 -57
- package/dist/index.mjs +16 -32
- package/dist/index.react-native.mjs +12 -0
- package/dist/invalidation/broadcast-channel.d.ts +1 -1
- package/dist/invalidation/filesystem.d.ts +1 -1
- package/dist/invalidation/filesystem.mjs +1 -2
- package/dist/invalidation/noop.d.ts +1 -1
- package/dist/languages/albanian.mjs +1 -1
- package/dist/languages/amharic.mjs +1 -1
- package/dist/languages/arabic.mjs +1 -1
- package/dist/languages/armenian.mjs +1 -1
- package/dist/languages/azerbaijani.mjs +1 -1
- package/dist/languages/bambara.mjs +1 -1
- package/dist/languages/basque.mjs +1 -1
- package/dist/languages/belarusian.mjs +1 -1
- package/dist/languages/bengali.mjs +1 -1
- package/dist/languages/bosnian.mjs +1 -1
- package/dist/languages/breton.mjs +1 -1
- package/dist/languages/bulgarian.mjs +1 -1
- package/dist/languages/burmese.mjs +1 -1
- package/dist/languages/catalan.mjs +1 -1
- package/dist/languages/chinese.mjs +1 -1
- package/dist/languages/croatian.mjs +1 -1
- package/dist/languages/czech.mjs +1 -1
- package/dist/languages/dagbani.mjs +1 -1
- package/dist/languages/danish.mjs +1 -1
- package/dist/languages/dutch.mjs +1 -1
- package/dist/languages/english.mjs +1 -1
- package/dist/languages/esperanto.mjs +1 -1
- package/dist/languages/estonian.mjs +1 -1
- package/dist/languages/ewe.mjs +1 -1
- package/dist/languages/faroese.mjs +1 -1
- package/dist/languages/fijian.mjs +1 -1
- package/dist/languages/finnish.mjs +1 -1
- package/dist/languages/french.mjs +1 -1
- package/dist/languages/ga.mjs +1 -1
- package/dist/languages/galician.mjs +1 -1
- package/dist/languages/georgian.mjs +1 -1
- package/dist/languages/german.mjs +1 -1
- package/dist/languages/greek.mjs +1 -1
- package/dist/languages/guarani.mjs +1 -1
- package/dist/languages/gujarati.mjs +1 -1
- package/dist/languages/haitian-creole.mjs +1 -1
- package/dist/languages/hausa.mjs +1 -1
- package/dist/languages/hawaiian.mjs +1 -1
- package/dist/languages/hebrew.mjs +1 -1
- package/dist/languages/hindi.mjs +1 -1
- package/dist/languages/hungarian.mjs +1 -1
- package/dist/languages/icelandic.mjs +1 -1
- package/dist/languages/igbo.mjs +1 -1
- package/dist/languages/indonesian.mjs +1 -1
- package/dist/languages/irish.mjs +1 -1
- package/dist/languages/italian.mjs +1 -1
- package/dist/languages/japanese.mjs +1 -1
- package/dist/languages/kannada.mjs +1 -1
- package/dist/languages/kazakh.mjs +1 -1
- package/dist/languages/khmer.mjs +1 -1
- package/dist/languages/kinyarwanda.mjs +1 -1
- package/dist/languages/kirundi.mjs +1 -1
- package/dist/languages/korean.mjs +1 -1
- package/dist/languages/kurmanji.mjs +1 -1
- package/dist/languages/kyrgyz.mjs +1 -1
- package/dist/languages/lao.mjs +1 -1
- package/dist/languages/latin.mjs +1 -1
- package/dist/languages/latvian.mjs +1 -1
- package/dist/languages/lingala.mjs +1 -1
- package/dist/languages/lithuanian.mjs +1 -1
- package/dist/languages/luxembourgish.mjs +1 -1
- package/dist/languages/macedonian.mjs +1 -1
- package/dist/languages/malagasy.mjs +1 -1
- package/dist/languages/malay.mjs +1 -1
- package/dist/languages/malayalam.mjs +1 -1
- package/dist/languages/maltese.mjs +1 -1
- package/dist/languages/maori.mjs +1 -1
- package/dist/languages/marathi.mjs +1 -1
- package/dist/languages/nepali.mjs +1 -1
- package/dist/languages/norwegian.mjs +1 -1
- package/dist/languages/oromo.mjs +1 -1
- package/dist/languages/persian.mjs +1 -1
- package/dist/languages/polish.mjs +1 -1
- package/dist/languages/portuguese.mjs +1 -1
- package/dist/languages/punjabi.mjs +1 -1
- package/dist/languages/romanian.mjs +1 -1
- package/dist/languages/russian.mjs +1 -1
- package/dist/languages/samoan.mjs +1 -1
- package/dist/languages/sanskrit.mjs +1 -1
- package/dist/languages/scottish-gaelic.mjs +1 -1
- package/dist/languages/serbian.mjs +1 -1
- package/dist/languages/shona.mjs +1 -1
- package/dist/languages/sinhala.mjs +1 -1
- package/dist/languages/slovak.mjs +1 -1
- package/dist/languages/slovenian.mjs +1 -1
- package/dist/languages/sorani.mjs +1 -1
- package/dist/languages/spanish.mjs +1 -1
- package/dist/languages/swahili.mjs +1 -1
- package/dist/languages/swedish.mjs +1 -1
- package/dist/languages/tagalog.mjs +1 -1
- package/dist/languages/tamil.mjs +1 -1
- package/dist/languages/tatar.mjs +1 -1
- package/dist/languages/telugu.mjs +1 -1
- package/dist/languages/thai.mjs +1 -1
- package/dist/languages/tibetan.mjs +1 -1
- package/dist/languages/tigrinya.mjs +1 -1
- package/dist/languages/tongan.mjs +1 -1
- package/dist/languages/turkish.mjs +1 -1
- package/dist/languages/twi.mjs +1 -1
- package/dist/languages/ukrainian.mjs +1 -1
- package/dist/languages/urdu.mjs +1 -1
- package/dist/languages/vietnamese.mjs +1 -1
- package/dist/languages/welsh.mjs +1 -1
- package/dist/languages/wolof.mjs +1 -1
- package/dist/languages/xhosa.mjs +1 -1
- package/dist/languages/yoruba.mjs +1 -1
- package/dist/languages/zulu.mjs +1 -1
- package/dist/long-query-thread-UCRK7MSI.mjs +154 -0
- package/dist/module-5ZSLUQII.mjs +3729 -0
- package/dist/msgpack-leaf-H5ZYW7S7.mjs +9 -0
- package/dist/optional-reads-5HFMF2QZ.mjs +3373 -0
- package/dist/optional-writes-4UOQKETU.mjs +247 -0
- package/dist/paged-partition-archive-BBRLZCIF.mjs +253 -0
- package/dist/partial-words.browser.mjs +1650 -0
- package/dist/partial-words.mjs +17 -11
- package/dist/{chunk-ASY5PHYI.mjs → pattern.browser.mjs} +253 -311
- package/dist/pattern.mjs +6 -7
- package/dist/persistence/durability/checkpoint-worker.d.ts +93 -25
- package/dist/persistence/durability/checkpoint-worker.mjs +51 -41
- package/dist/phrase-module-EFESWOCR.mjs +635 -0
- package/dist/query-actions-HMJUVWGT.mjs +119 -0
- package/dist/query-suggestions/merge-worker.d.ts +55 -0
- package/dist/query-suggestions/merge-worker.mjs +53 -0
- package/dist/query-suggestions-CBYkrQ5T.d.ts +311 -0
- package/dist/query-suggestions.browser.mjs +47 -0
- package/dist/query-suggestions.d.ts +20 -0
- package/dist/query-suggestions.mjs +19 -0
- package/dist/react-native/chunks/chunk-3OEFSHVV.mjs +970 -0
- package/dist/{browser/chunk-RELZRJNR.mjs → react-native/chunks/chunk-43R4GCM7.mjs} +49 -50
- package/dist/react-native/chunks/chunk-AKRYHAVG.mjs +6729 -0
- package/dist/react-native/chunks/chunk-CW2ZFXSE.mjs +14 -0
- package/dist/react-native/chunks/chunk-G3WCDTOF.mjs +29640 -0
- package/dist/react-native/chunks/chunk-GXXHHA2T.mjs +212 -0
- package/dist/react-native/chunks/chunk-H3MDVPBO.mjs +151 -0
- package/dist/react-native/chunks/chunk-HQEVQEDJ.mjs +52 -0
- package/dist/react-native/chunks/chunk-HRDMIQ63.mjs +131 -0
- package/dist/react-native/chunks/chunk-HTBY4GON.mjs +565 -0
- package/dist/react-native/chunks/chunk-LX62Y4B5.mjs +61 -0
- package/dist/react-native/chunks/chunk-MRH36RN3.mjs +902 -0
- package/dist/react-native/chunks/chunk-Q32DDFKX.mjs +19 -0
- package/dist/react-native/chunks/chunk-UE4ANHSX.mjs +127 -0
- package/dist/react-native/chunks/chunk-UNZPWLVL.mjs +1063 -0
- package/dist/react-native/chunks/chunk-UO44MA5M.mjs +232 -0
- package/dist/react-native/chunks/chunk-UYKIV2KT.mjs +42 -0
- package/dist/react-native/chunks/chunk-VUJCSQG5.mjs +11 -0
- package/dist/react-native/chunks/chunk-WVHF4ZAK.mjs +802 -0
- package/dist/react-native/chunks/chunk-ZUJCUPVS.mjs +54 -0
- package/dist/react-native/chunks/core-leaf-S2KNBWDY.mjs +7 -0
- package/dist/react-native/chunks/custom-token-results-3OZEMRE7.mjs +59 -0
- package/dist/react-native/chunks/digest-leaf-X6OIFDIU.mjs +1 -0
- package/dist/react-native/chunks/durability-config-FCSD4MXY.mjs +96 -0
- package/dist/react-native/chunks/embed-HA2I7RCF.mjs +263 -0
- package/dist/react-native/chunks/geo-index-QEYKEVPH.mjs +1484 -0
- package/dist/react-native/chunks/gzip.react-native-CVM4NQG2.mjs +12 -0
- package/dist/react-native/chunks/module-FMBX75GP.mjs +5209 -0
- package/dist/react-native/chunks/msgpack-leaf-JMNGSTRW.mjs +7 -0
- package/dist/react-native/chunks/optional-reads-AFPO2FEB.mjs +3364 -0
- package/dist/react-native/chunks/optional-writes-XOH25XZI.mjs +296 -0
- package/dist/react-native/chunks/phrase-module-IGYBK7XH.mjs +636 -0
- package/dist/react-native/chunks/replace-IMZUVUOE.mjs +57 -0
- package/dist/react-native/chunks/resolve-vector-text-GE2CRJKI.mjs +84 -0
- package/dist/react-native/chunks/restore-queue-LLNMYB4Z.mjs +187 -0
- package/dist/react-native/chunks/runtime-UOHD2XUJ.mjs +615 -0
- package/dist/react-native/chunks/segment-codec-leaf-VR6O5GLC.mjs +13 -0
- package/dist/react-native/chunks/segment-merge-leaf-LLMWU4EW.mjs +14 -0
- package/dist/react-native/chunks/storage-leaf-JD7PIDO4.mjs +19633 -0
- package/dist/react-native/chunks/store-leaf-4UVCMYGN.mjs +15 -0
- package/dist/react-native/chunks/suggestions-leaf-J5VT5RHY.mjs +1321 -0
- package/dist/react-native/chunks/worker-copies-ZYHY7FKJ.mjs +2831 -0
- package/dist/react-native/partial-words.mjs +1658 -0
- package/dist/react-native/pattern.mjs +2570 -0
- package/dist/react-native/query-suggestions.mjs +55 -0
- package/dist/react-native/sync.mjs +2759 -0
- package/dist/react-native/synonyms.mjs +676 -0
- package/dist/react.d.ts +12 -8
- package/dist/react.mjs +45 -1
- package/dist/{rerank-NWTKK636.mjs → rerank-RI2PMNOD.mjs} +22 -12
- package/dist/rerankers/http.d.ts +1 -1
- package/dist/rerankers/http.mjs +2 -2
- package/dist/resolve-vector-text-OD4J3WHF.mjs +3 -0
- package/dist/restore-queue-PCKWDAKQ.mjs +192 -0
- package/dist/runtime-USQYKN3I.mjs +615 -0
- package/dist/{schema-4W_7tk1f.d.ts → schema-CzG9OUw5.d.ts} +70 -30
- package/dist/segment-codec-leaf-QJM7I6QG.mjs +18 -0
- package/dist/segment-merge-leaf-4BJGIJHY.mjs +18 -0
- package/dist/server.d.ts +348 -22
- package/dist/server.mjs +2211 -327
- package/dist/storage-leaf-GRRRI7UV.mjs +5962 -0
- package/dist/store-leaf-6VMMSVBE.mjs +20 -0
- package/dist/stored-values-BWIMpiT_.d.ts +25 -0
- package/dist/suggestions-leaf-4KPTMPTL.mjs +54 -0
- package/dist/sync/filesystem.d.ts +30 -0
- package/dist/sync/filesystem.mjs +288 -0
- package/dist/sync/indexeddb.browser.mjs +287 -0
- package/dist/sync/indexeddb.d.ts +30 -0
- package/dist/sync/indexeddb.mjs +242 -0
- package/dist/sync.browser.mjs +1271 -0
- package/dist/sync.d.ts +23 -0
- package/dist/sync.mjs +2712 -0
- package/dist/synonyms.browser.mjs +658 -0
- package/dist/synonyms.mjs +17 -7
- package/dist/tasks-65b6t6lk.d.ts +782 -0
- package/dist/thread-UJ3W5LVI.mjs +31 -0
- package/dist/{types-B3b68nfF.d.ts → types-Ck97nB3D.d.ts} +1 -1
- package/dist/types-CpCg-Gq-.d.ts +227 -0
- package/dist/{types-Cb9kiY5P.d.ts → types-DvncmvuQ.d.ts} +12 -1
- package/dist/vector/search-worker.d.ts +10 -2
- package/dist/vector/search-worker.mjs +11 -11
- package/dist/worker-copies-YSXZXIGC.mjs +2232 -0
- package/dist/workers/entry.mjs +75 -15
- package/openapi.json +6840 -0
- package/package.json +406 -19
- package/dist/browser/chunk-CN4I4FZU.mjs +0 -602
- package/dist/browser/chunk-HOZW3PKP.mjs +0 -9
- package/dist/browser/chunk-JPTQZWJQ.mjs +0 -10
- package/dist/browser/chunk-LD55ZGU3.mjs +0 -347
- package/dist/browser/chunk-NAFT3K6X.mjs +0 -24546
- package/dist/browser/chunk-NNG3EEB6.mjs +0 -2728
- package/dist/browser/chunk-QWES44AW.mjs +0 -473
- package/dist/browser/durability-wiring-PY3L7DES.mjs +0 -3679
- package/dist/browser/module-PDXYHT75.mjs +0 -2822
- package/dist/browser/release-76MXRPGV.mjs +0 -33
- package/dist/browser/restore-queue-DVIYJ7RU.mjs +0 -35
- package/dist/browser/snapshot-J57MZK6L.mjs +0 -1207
- package/dist/browser/write-L7FAQA47.mjs +0 -208
- package/dist/chunk-37CD3OKS.mjs +0 -87
- package/dist/chunk-5XNIRLFC.mjs +0 -96
- package/dist/chunk-7X5JST5L.mjs +0 -114
- package/dist/chunk-AV4IJKD2.mjs +0 -35
- package/dist/chunk-AY3AQ3UH.mjs +0 -73
- package/dist/chunk-BKB3XTMI.mjs +0 -707
- package/dist/chunk-C7SLA6CM.mjs +0 -19
- package/dist/chunk-COVCQ73F.mjs +0 -587
- package/dist/chunk-DJHHF2L5.mjs +0 -17
- package/dist/chunk-E74YLAIG.mjs +0 -24
- package/dist/chunk-FMWRCP2C.mjs +0 -57
- package/dist/chunk-GES7U2PM.mjs +0 -68
- package/dist/chunk-HJSN7UYG.mjs +0 -10
- package/dist/chunk-JFRNNBOM.mjs +0 -35
- package/dist/chunk-K25LZA54.mjs +0 -8484
- package/dist/chunk-KEHK2O6P.mjs +0 -13
- package/dist/chunk-KOKM4PQN.mjs +0 -52
- package/dist/chunk-KZ3NX2P7.mjs +0 -21
- package/dist/chunk-L3L5YFXC.mjs +0 -614
- package/dist/chunk-L5ORED7V.mjs +0 -25
- package/dist/chunk-LH4NZNJJ.mjs +0 -1731
- package/dist/chunk-LU2CE5AE.mjs +0 -507
- package/dist/chunk-LXWDQLTW.mjs +0 -30
- package/dist/chunk-MHOSCQCQ.mjs +0 -948
- package/dist/chunk-NKRBEGJZ.mjs +0 -1705
- package/dist/chunk-NTRMFARG.mjs +0 -462
- package/dist/chunk-NW4XDSP2.mjs +0 -212
- package/dist/chunk-OOEXLUGR.mjs +0 -117
- package/dist/chunk-ORBLD3EL.mjs +0 -6
- package/dist/chunk-OWNZYMRE.mjs +0 -3591
- package/dist/chunk-PPY2GSIB.mjs +0 -44
- package/dist/chunk-QY7GC2MW.mjs +0 -33
- package/dist/chunk-R6A773WK.mjs +0 -226
- package/dist/chunk-R6PR4WYZ.mjs +0 -68
- package/dist/chunk-R7EEKAJE.mjs +0 -593
- package/dist/chunk-RONEOEON.mjs +0 -426
- package/dist/chunk-VWULPWRJ.mjs +0 -7469
- package/dist/chunk-WCJKUGHB.mjs +0 -262
- package/dist/chunk-WQBCBKY3.mjs +0 -8
- package/dist/chunk-X5CV2E2B.mjs +0 -1
- package/dist/chunk-YA7XLE2R.mjs +0 -1256
- package/dist/chunk-YTJCGKM4.mjs +0 -56
- package/dist/chunk-ZG477IPV.mjs +0 -526
- package/dist/chunk-ZYNAMIYX.mjs +0 -113
- package/dist/config-BGB_fDtq.d.ts +0 -237
- package/dist/direct-executor-CXZ66ACP.mjs +0 -22
- package/dist/durability-wiring-QTHOGFMZ.mjs +0 -3229
- package/dist/engine-BGCEm9E_.d.ts +0 -577
- package/dist/module-3NONKBZX.mjs +0 -1860
- package/dist/release-BH3DKW3T.mjs +0 -33
- package/dist/restore-queue-JPRBUYII.mjs +0 -35
- package/dist/runtime-ZKYZFJJC.mjs +0 -177
- package/dist/snapshot-HOGXNO5W.mjs +0 -793
- package/dist/tasks-HG3rlxx6.d.ts +0 -302
- package/dist/thread-B657LQXK.mjs +0 -692
- package/dist/write-XLIGTXBU.mjs +0 -238
|
@@ -1,793 +0,0 @@
|
|
|
1
|
-
import { unpackIndexSnapshotEnvelope, loadSegmentedCheckpoint, writeMetadataEnvelope, documentsOfPayloadV2, deserializePayloadV1 } from './chunk-BKB3XTMI.mjs';
|
|
2
|
-
import { buildArchiveFromMemory, archiveStream, memoryCheckpointStore, readSnapshotArchive } from './chunk-NTRMFARG.mjs';
|
|
3
|
-
import './chunk-COVCQ73F.mjs';
|
|
4
|
-
import { indexMetadataOf, readVectorFile, readGraphParts, SINGLE_NODE_PRIMARY_TERM } from './chunk-ZG477IPV.mjs';
|
|
5
|
-
import { decodeVectorIndexParts, bytesToVectors } from './chunk-WCJKUGHB.mjs';
|
|
6
|
-
import './chunk-HXJBSHXF.mjs';
|
|
7
|
-
import './chunk-DJHHF2L5.mjs';
|
|
8
|
-
import './chunk-37CD3OKS.mjs';
|
|
9
|
-
import { manifestKey, encodeSegmentManifest, manifestFileRefs, readSegmentFile } from './chunk-LH4NZNJJ.mjs';
|
|
10
|
-
import './chunk-L3L5YFXC.mjs';
|
|
11
|
-
import './chunk-P36MUFEJ.mjs';
|
|
12
|
-
import './chunk-OHP7QR33.mjs';
|
|
13
|
-
import { encodeIndexConfiguration, createByteReader, hasNrslMagic, HEADER_SIZE, readHeader, validateRequiredFieldsInSchema, validateEmbeddingConfig, decodeIndexConfiguration, prepareStoredSynonyms, insertDocumentVectors } from './chunk-VWULPWRJ.mjs';
|
|
14
|
-
import { validatePatternValueLimit, requireSurfaceFormsForPartialFields } from './chunk-NKRBEGJZ.mjs';
|
|
15
|
-
import { restoredConfigFields, restoredEmbedding, rejectSnapshot } from './chunk-R7EEKAJE.mjs';
|
|
16
|
-
import { MAX_FILE_BYTES } from './chunk-AY3AQ3UH.mjs';
|
|
17
|
-
import './chunk-AV4IJKD2.mjs';
|
|
18
|
-
import { readHeapStatistics, readResidentMemory, decodeEveryStoredDocument } from './chunk-OWNZYMRE.mjs';
|
|
19
|
-
import './chunk-K25LZA54.mjs';
|
|
20
|
-
import { getLanguage } from './chunk-JFRNNBOM.mjs';
|
|
21
|
-
import './chunk-HJSN7UYG.mjs';
|
|
22
|
-
import './chunk-LXWDQLTW.mjs';
|
|
23
|
-
import './chunk-TGP5M5R7.mjs';
|
|
24
|
-
import './chunk-U2BKYEC7.mjs';
|
|
25
|
-
import './chunk-KOKM4PQN.mjs';
|
|
26
|
-
import './chunk-QY7GC2MW.mjs';
|
|
27
|
-
import './chunk-GGSH6KBQ.mjs';
|
|
28
|
-
import './chunk-ASY5PHYI.mjs';
|
|
29
|
-
import './chunk-WQBCBKY3.mjs';
|
|
30
|
-
import { parseVectorDimension } from './chunk-MHOSCQCQ.mjs';
|
|
31
|
-
import { raiseEarlierReleaseGraphSetting, validateSchema, validateVectorPromotion, validateVectorStorage, extractVectorFieldsFromSchema, flattenSchema } from './chunk-LXPIXDUJ.mjs';
|
|
32
|
-
import './chunk-E74YLAIG.mjs';
|
|
33
|
-
import './chunk-KEHK2O6P.mjs';
|
|
34
|
-
import './chunk-GES7U2PM.mjs';
|
|
35
|
-
import './chunk-OOEXLUGR.mjs';
|
|
36
|
-
import { resolveIndexAnalysis } from './chunk-RONEOEON.mjs';
|
|
37
|
-
import './chunk-X5CV2E2B.mjs';
|
|
38
|
-
import './chunk-7X5JST5L.mjs';
|
|
39
|
-
import './chunk-LU2CE5AE.mjs';
|
|
40
|
-
import './chunk-R6A773WK.mjs';
|
|
41
|
-
import './chunk-YTJCGKM4.mjs';
|
|
42
|
-
import { collectAndReturnPages } from './chunk-5XNIRLFC.mjs';
|
|
43
|
-
import './chunk-R6PR4WYZ.mjs';
|
|
44
|
-
import { loadVectorCodeFor } from './chunk-PPY2GSIB.mjs';
|
|
45
|
-
import './chunk-L5ORED7V.mjs';
|
|
46
|
-
import { NarsilError, ErrorCodes } from './chunk-KV3AZFT3.mjs';
|
|
47
|
-
import { decode } from '@msgpack/msgpack';
|
|
48
|
-
|
|
49
|
-
// src/persistence/archive/validate.ts
|
|
50
|
-
function requireDimension(key, found, expected) {
|
|
51
|
-
if (expected === found) return;
|
|
52
|
-
throw new NarsilError(
|
|
53
|
-
ErrorCodes.PERSISTENCE_LOAD_FAILED,
|
|
54
|
-
`The vector file "${key}" holds vectors of ${found} dimensions where the schema gives ${String(expected)}`,
|
|
55
|
-
{ key, found, expected }
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
function requireSchemaOfManifest(key, schema, manifest) {
|
|
59
|
-
for (const [field, type] of Object.entries(schema)) {
|
|
60
|
-
const listed = manifest.schema[field];
|
|
61
|
-
if (listed === void 0 || listed === type) continue;
|
|
62
|
-
throw new NarsilError(
|
|
63
|
-
ErrorCodes.PERSISTENCE_LOAD_FAILED,
|
|
64
|
-
`The segment "${key}" gives field "${field}" the type "${type}", while the manifest gives it "${listed}"`,
|
|
65
|
-
{ key, field }
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
async function validateStagedCheckpoint(store, manifest) {
|
|
70
|
-
for (const partition of manifest.partitions) {
|
|
71
|
-
for (const ref of partition.segments) {
|
|
72
|
-
const contents = await readSegmentFile(store, ref);
|
|
73
|
-
requireSchemaOfManifest(ref.key, contents.schema, manifest);
|
|
74
|
-
decodeEveryStoredDocument(contents.arrays.documentTable);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
for (const field of manifest.vectors) {
|
|
78
|
-
const fieldType = manifest.schema[field.fieldPath];
|
|
79
|
-
const dimension = fieldType === void 0 ? null : parseVectorDimension(fieldType);
|
|
80
|
-
for (const file of field.files) {
|
|
81
|
-
const { payload } = await readVectorFile(store, file, field.fieldPath);
|
|
82
|
-
requireDimension(file.key, payload.dimension, dimension);
|
|
83
|
-
}
|
|
84
|
-
await readGraphParts(store, field);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// src/engine/snapshot/constants.ts
|
|
89
|
-
var RESTORE_WORST_HEAP_BYTES_PER_STORED_BYTE = 0.2;
|
|
90
|
-
var RESTORE_WORST_HEAP_BYTES_PER_EARLIER_SNAPSHOT_BYTE = 7.86;
|
|
91
|
-
var RESTORE_WORST_HEAP_BYTES_PER_VECTOR = 264;
|
|
92
|
-
var RESTORE_WORST_HEAP_BYTES_PER_VECTOR_DIMENSION = 0.24;
|
|
93
|
-
var RESTORE_WORST_HEAP_BYTES_PER_EARLIER_SNAPSHOT_VECTOR = 738;
|
|
94
|
-
var RESTORE_WORST_HEAP_BYTES_PER_EARLIER_SNAPSHOT_VECTOR_DIMENSION = 0.2;
|
|
95
|
-
var RESTORE_WORST_EXTERNAL_BYTES_PER_STORED_BYTE = 4.06;
|
|
96
|
-
var RESTORE_WORST_EXTERNAL_BYTES_PER_EARLIER_SNAPSHOT_BYTE = 14.5;
|
|
97
|
-
var RESTORE_WORST_EXTERNAL_BYTES_PER_VECTOR = 1482;
|
|
98
|
-
var RESTORE_WORST_EXTERNAL_BYTES_PER_VECTOR_DIMENSION = 9.29;
|
|
99
|
-
var RESTORE_WORST_EXTERNAL_BYTES_PER_EARLIER_SNAPSHOT_VECTOR = 2141;
|
|
100
|
-
var RESTORE_WORST_EXTERNAL_BYTES_PER_EARLIER_SNAPSHOT_VECTOR_DIMENSION = 24.15;
|
|
101
|
-
var RESTORE_FLOOR_HEAP_BYTES_PER_STORED_BYTE = 0.16;
|
|
102
|
-
var RESTORE_FLOOR_HEAP_BYTES_PER_EARLIER_SNAPSHOT_BYTE = 6.16;
|
|
103
|
-
var RESTORE_FLOOR_HEAP_BYTES_PER_VECTOR = 204;
|
|
104
|
-
var RESTORE_FLOOR_HEAP_BYTES_PER_VECTOR_DIMENSION = 0.17;
|
|
105
|
-
var RESTORE_FLOOR_HEAP_BYTES_PER_EARLIER_SNAPSHOT_VECTOR = 695;
|
|
106
|
-
var RESTORE_FLOOR_HEAP_BYTES_PER_EARLIER_SNAPSHOT_VECTOR_DIMENSION = 0.04;
|
|
107
|
-
var RESTORE_FLOOR_EXTERNAL_BYTES_PER_STORED_BYTE = 2.14;
|
|
108
|
-
var RESTORE_FLOOR_EXTERNAL_BYTES_PER_EARLIER_SNAPSHOT_BYTE = 5.05;
|
|
109
|
-
var RESTORE_FLOOR_EXTERNAL_BYTES_PER_VECTOR = 1080;
|
|
110
|
-
var RESTORE_FLOOR_EXTERNAL_BYTES_PER_VECTOR_DIMENSION = 0.72;
|
|
111
|
-
var RESTORE_FLOOR_EXTERNAL_BYTES_PER_EARLIER_SNAPSHOT_VECTOR = 1744;
|
|
112
|
-
var RESTORE_FLOOR_EXTERNAL_BYTES_PER_EARLIER_SNAPSHOT_VECTOR_DIMENSION = 20.05;
|
|
113
|
-
var RESTORE_ESTIMATE_MARGIN = 1.25;
|
|
114
|
-
|
|
115
|
-
// src/engine/snapshot/memory-budget.ts
|
|
116
|
-
var MEGABYTE_BYTES = 1048576;
|
|
117
|
-
var ARCHIVE_RATES = {
|
|
118
|
-
worst: {
|
|
119
|
-
heap: {
|
|
120
|
-
perStoredByte: RESTORE_WORST_HEAP_BYTES_PER_STORED_BYTE,
|
|
121
|
-
perVector: RESTORE_WORST_HEAP_BYTES_PER_VECTOR,
|
|
122
|
-
perVectorDimension: RESTORE_WORST_HEAP_BYTES_PER_VECTOR_DIMENSION
|
|
123
|
-
},
|
|
124
|
-
external: {
|
|
125
|
-
perStoredByte: RESTORE_WORST_EXTERNAL_BYTES_PER_STORED_BYTE,
|
|
126
|
-
perVector: RESTORE_WORST_EXTERNAL_BYTES_PER_VECTOR,
|
|
127
|
-
perVectorDimension: RESTORE_WORST_EXTERNAL_BYTES_PER_VECTOR_DIMENSION
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
floor: {
|
|
131
|
-
heap: {
|
|
132
|
-
perStoredByte: RESTORE_FLOOR_HEAP_BYTES_PER_STORED_BYTE,
|
|
133
|
-
perVector: RESTORE_FLOOR_HEAP_BYTES_PER_VECTOR,
|
|
134
|
-
perVectorDimension: RESTORE_FLOOR_HEAP_BYTES_PER_VECTOR_DIMENSION
|
|
135
|
-
},
|
|
136
|
-
external: {
|
|
137
|
-
perStoredByte: RESTORE_FLOOR_EXTERNAL_BYTES_PER_STORED_BYTE,
|
|
138
|
-
perVector: RESTORE_FLOOR_EXTERNAL_BYTES_PER_VECTOR,
|
|
139
|
-
perVectorDimension: RESTORE_FLOOR_EXTERNAL_BYTES_PER_VECTOR_DIMENSION
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
var EARLIER_SNAPSHOT_RATES = {
|
|
144
|
-
worst: {
|
|
145
|
-
heap: {
|
|
146
|
-
perStoredByte: RESTORE_WORST_HEAP_BYTES_PER_EARLIER_SNAPSHOT_BYTE,
|
|
147
|
-
perVector: RESTORE_WORST_HEAP_BYTES_PER_EARLIER_SNAPSHOT_VECTOR,
|
|
148
|
-
perVectorDimension: RESTORE_WORST_HEAP_BYTES_PER_EARLIER_SNAPSHOT_VECTOR_DIMENSION
|
|
149
|
-
},
|
|
150
|
-
external: {
|
|
151
|
-
perStoredByte: RESTORE_WORST_EXTERNAL_BYTES_PER_EARLIER_SNAPSHOT_BYTE,
|
|
152
|
-
perVector: RESTORE_WORST_EXTERNAL_BYTES_PER_EARLIER_SNAPSHOT_VECTOR,
|
|
153
|
-
perVectorDimension: RESTORE_WORST_EXTERNAL_BYTES_PER_EARLIER_SNAPSHOT_VECTOR_DIMENSION
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
floor: {
|
|
157
|
-
heap: {
|
|
158
|
-
perStoredByte: RESTORE_FLOOR_HEAP_BYTES_PER_EARLIER_SNAPSHOT_BYTE,
|
|
159
|
-
perVector: RESTORE_FLOOR_HEAP_BYTES_PER_EARLIER_SNAPSHOT_VECTOR,
|
|
160
|
-
perVectorDimension: RESTORE_FLOOR_HEAP_BYTES_PER_EARLIER_SNAPSHOT_VECTOR_DIMENSION
|
|
161
|
-
},
|
|
162
|
-
external: {
|
|
163
|
-
perStoredByte: RESTORE_FLOOR_EXTERNAL_BYTES_PER_EARLIER_SNAPSHOT_BYTE,
|
|
164
|
-
perVector: RESTORE_FLOOR_EXTERNAL_BYTES_PER_EARLIER_SNAPSHOT_VECTOR,
|
|
165
|
-
perVectorDimension: RESTORE_FLOOR_EXTERNAL_BYTES_PER_EARLIER_SNAPSHOT_VECTOR_DIMENSION
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
function bytesAt(rate, storedBytes, vectors) {
|
|
170
|
-
let bytes = storedBytes * rate.perStoredByte;
|
|
171
|
-
for (const { dimension, count } of vectors) bytes += count * (rate.perVector + dimension * rate.perVectorDimension);
|
|
172
|
-
return bytes;
|
|
173
|
-
}
|
|
174
|
-
function footprintAt(rates, replacesIndex, storedBytes, vectors) {
|
|
175
|
-
const chosen = replacesIndex ? rates.worst : rates.floor;
|
|
176
|
-
const scale = replacesIndex ? RESTORE_ESTIMATE_MARGIN : 1 / RESTORE_ESTIMATE_MARGIN;
|
|
177
|
-
return {
|
|
178
|
-
heapBytes: bytesAt(chosen.heap, storedBytes, vectors) * scale,
|
|
179
|
-
externalBytes: bytesAt(chosen.external, storedBytes, vectors) * scale
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
function deadCountOf(dead) {
|
|
183
|
-
if (dead === null) return 0;
|
|
184
|
-
let count = 0;
|
|
185
|
-
for (const byte of dead) {
|
|
186
|
-
for (let bits = byte; bits !== 0; bits &= bits - 1) count += 1;
|
|
187
|
-
}
|
|
188
|
-
return count;
|
|
189
|
-
}
|
|
190
|
-
function archiveFootprint(prepared, manifest, replacesIndex) {
|
|
191
|
-
let segmentBytes = 0;
|
|
192
|
-
for (const partition of manifest.partitions) {
|
|
193
|
-
for (const segment of partition.segments) segmentBytes += segment.bytes;
|
|
194
|
-
}
|
|
195
|
-
const dimensions = extractVectorFieldsFromSchema(prepared.config.schema);
|
|
196
|
-
const vectors = [];
|
|
197
|
-
for (const field of manifest.vectors) {
|
|
198
|
-
const dimension = dimensions.get(field.fieldPath) ?? 0;
|
|
199
|
-
for (const file of field.files) vectors.push({ dimension, count: Math.max(0, file.count - deadCountOf(file.dead)) });
|
|
200
|
-
}
|
|
201
|
-
return footprintAt(ARCHIVE_RATES, replacesIndex, segmentBytes, vectors);
|
|
202
|
-
}
|
|
203
|
-
function earlierSnapshotFootprint(prepared, partitionBytes, vectorCounts, replacesIndex) {
|
|
204
|
-
const dimensions = extractVectorFieldsFromSchema(prepared.config.schema);
|
|
205
|
-
const vectors = [...vectorCounts].map(([fieldPath, count]) => ({ dimension: dimensions.get(fieldPath) ?? 0, count }));
|
|
206
|
-
return footprintAt(EARLIER_SNAPSHOT_RATES, replacesIndex, partitionBytes, vectors);
|
|
207
|
-
}
|
|
208
|
-
function inMegabytes(bytes) {
|
|
209
|
-
return Math.ceil(bytes / MEGABYTE_BYTES);
|
|
210
|
-
}
|
|
211
|
-
function shortfallOf(heapBytes, processBytes, countInUse) {
|
|
212
|
-
const heap = readHeapStatistics();
|
|
213
|
-
if (heap !== null) {
|
|
214
|
-
const limitBytes = heap.configuredLimitBytes ?? heap.limitBytes;
|
|
215
|
-
const availableBytes = countInUse ? limitBytes - heap.usedBytes : limitBytes;
|
|
216
|
-
if (heapBytes > availableBytes) return { budget: "heap", neededBytes: heapBytes, availableBytes };
|
|
217
|
-
}
|
|
218
|
-
const resident = readResidentMemory();
|
|
219
|
-
if (resident !== null) {
|
|
220
|
-
const availableBytes = countInUse ? resident.limitBytes - resident.residentBytes : resident.limitBytes;
|
|
221
|
-
if (processBytes > availableBytes) return { budget: "process", neededBytes: processBytes, availableBytes };
|
|
222
|
-
}
|
|
223
|
-
return null;
|
|
224
|
-
}
|
|
225
|
-
function refuse(indexName, replacesIndex, shortfall) {
|
|
226
|
-
const { budget, neededBytes, availableBytes } = shortfall;
|
|
227
|
-
const where = budget === "heap" ? "of JavaScript heap" : "of process memory";
|
|
228
|
-
const outcome = replacesIndex ? "so the index keeps its earlier contents. Drop the index first to free the memory that it holds, or give the process more memory, then restore again" : "so the engine creates no index. Give the process more memory, then restore again";
|
|
229
|
-
throw new NarsilError(
|
|
230
|
-
ErrorCodes.RESTORE_MEMORY_EXCEEDED,
|
|
231
|
-
`The restore of index "${indexName}" needs about ${inMegabytes(neededBytes)} MB ${where}, and this process has ${inMegabytes(Math.max(0, availableBytes))} MB free, ${outcome}`,
|
|
232
|
-
{ indexName, budget, neededBytes, availableBytes }
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
function requireRestoreMemory(indexName, footprint, replacesIndex) {
|
|
236
|
-
const processBytes = footprint.heapBytes + footprint.externalBytes;
|
|
237
|
-
if (shortfallOf(footprint.heapBytes, processBytes, true) === null) return;
|
|
238
|
-
const collected = collectAndReturnPages();
|
|
239
|
-
const shortfall = shortfallOf(footprint.heapBytes, processBytes, collected || replacesIndex);
|
|
240
|
-
if (shortfall !== null) refuse(indexName, replacesIndex, shortfall);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// src/workers/detached-index.ts
|
|
244
|
-
function attachablePolicy(shared) {
|
|
245
|
-
let attached = false;
|
|
246
|
-
const policy = {
|
|
247
|
-
get enabled() {
|
|
248
|
-
return attached && shared.enabled;
|
|
249
|
-
},
|
|
250
|
-
get count() {
|
|
251
|
-
return shared.count;
|
|
252
|
-
},
|
|
253
|
-
get host() {
|
|
254
|
-
return shared.host;
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
return {
|
|
258
|
-
policy,
|
|
259
|
-
attach() {
|
|
260
|
-
attached = true;
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
function createDetachedIndex(indexName, config, language, synonyms, executor) {
|
|
265
|
-
const { policy, attach } = attachablePolicy(executor.vectorWorkerCopies);
|
|
266
|
-
const entry = executor.createDetachedEntry(indexName, config, language, policy);
|
|
267
|
-
entry.manager.synonyms = synonyms;
|
|
268
|
-
return { indexName, manager: entry.manager, entry, attach };
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// src/engine/snapshot/restore-setup.ts
|
|
272
|
-
function prepareRestoredIndex(configuration, deps, reject) {
|
|
273
|
-
const configFields = restoredConfigFields(configuration, reject);
|
|
274
|
-
const embedding = restoredEmbedding(configuration.embedding, reject);
|
|
275
|
-
const languageName = configuration.language ?? "";
|
|
276
|
-
const language = getLanguage(languageName);
|
|
277
|
-
const schema = validateSchema(configuration.schema);
|
|
278
|
-
validatePatternValueLimit(configFields.patternValueLimit);
|
|
279
|
-
requireSurfaceFormsForPartialFields(schema, configFields.surfaceForms);
|
|
280
|
-
validateVectorPromotion(configFields.vectorPromotion);
|
|
281
|
-
validateVectorStorage(configFields.vectorPromotion, deps.filesystemDurability);
|
|
282
|
-
if (configFields.required !== void 0 && configFields.required.length > 0) {
|
|
283
|
-
validateRequiredFieldsInSchema(configFields.required, schema);
|
|
284
|
-
}
|
|
285
|
-
const config = {
|
|
286
|
-
schema,
|
|
287
|
-
language: languageName,
|
|
288
|
-
...configFields,
|
|
289
|
-
...embedding !== void 0 ? {
|
|
290
|
-
embedding: {
|
|
291
|
-
fields: embedding.fields,
|
|
292
|
-
...embedding.adapter !== void 0 ? { adapter: embedding.adapter } : {}
|
|
293
|
-
}
|
|
294
|
-
} : {}
|
|
295
|
-
};
|
|
296
|
-
resolveIndexAnalysis(config);
|
|
297
|
-
const adapterName = embedding?.adapter ?? null;
|
|
298
|
-
let embeddingAdapter = null;
|
|
299
|
-
if (embedding !== void 0) {
|
|
300
|
-
const candidate = adapterName !== null ? deps.embeddingAdapters.get(adapterName) ?? null : deps.defaultEmbeddingAdapter;
|
|
301
|
-
if (candidate) {
|
|
302
|
-
validateEmbeddingConfig({ fields: embedding.fields, adapter: candidate }, schema, void 0);
|
|
303
|
-
embeddingAdapter = candidate;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
const storedRevision = typeof configuration.analysisRevision === "string" ? configuration.analysisRevision : null;
|
|
307
|
-
const synonyms = restoredSynonyms(configuration.synonyms, config, language, reject ?? rejectSnapshot);
|
|
308
|
-
return { config, language, embeddingAdapter, adapterName, storedRevision, synonyms };
|
|
309
|
-
}
|
|
310
|
-
function restoredSynonyms(raw, config, language, reject) {
|
|
311
|
-
if (raw === void 0 || raw === null) return null;
|
|
312
|
-
return prepareStoredSynonyms(raw, config, language, (message) => reject(`synonyms: ${message}`));
|
|
313
|
-
}
|
|
314
|
-
async function prepareDetachedIndex(indexName, prepared, partitionCount, deps) {
|
|
315
|
-
const loadingVectorCode = loadVectorCodeFor(prepared.config.schema);
|
|
316
|
-
if (loadingVectorCode !== null) await loadingVectorCode;
|
|
317
|
-
const detached = createDetachedIndex(
|
|
318
|
-
indexName,
|
|
319
|
-
prepared.config,
|
|
320
|
-
prepared.language,
|
|
321
|
-
prepared.synonyms?.lookup ?? null,
|
|
322
|
-
deps.executor
|
|
323
|
-
);
|
|
324
|
-
while (detached.manager.partitionCount < partitionCount) detached.manager.addPartition();
|
|
325
|
-
return detached;
|
|
326
|
-
}
|
|
327
|
-
function restoredRegistryEntry(prepared, manager, deps) {
|
|
328
|
-
return {
|
|
329
|
-
config: prepared.config,
|
|
330
|
-
language: prepared.language,
|
|
331
|
-
embeddingAdapter: prepared.embeddingAdapter,
|
|
332
|
-
embeddingAdapterName: prepared.adapterName,
|
|
333
|
-
vectorFieldPaths: deps.getVectorFieldPaths(prepared.config.schema),
|
|
334
|
-
indexUuid: null,
|
|
335
|
-
heldPartitions: null,
|
|
336
|
-
documentCount: manager.countDocuments(),
|
|
337
|
-
partitionCount: manager.partitionCount,
|
|
338
|
-
analysisRevision: prepared.storedRevision,
|
|
339
|
-
synonyms: prepared.synonyms?.encoded ?? null
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// src/engine/snapshot/replace.ts
|
|
344
|
-
function releaseTimedOut(indexName, timeoutMs) {
|
|
345
|
-
return new NarsilError(
|
|
346
|
-
ErrorCodes.WORKER_TIMEOUT,
|
|
347
|
-
`The restore of index "${indexName}" stopped because a worker held the index past ${timeoutMs} ms, and the index keeps its earlier contents`,
|
|
348
|
-
{ indexName, timeoutMs }
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
async function withinLimit(indexName, release, work, deps) {
|
|
352
|
-
release.settled = work.catch(() => {
|
|
353
|
-
release.reloads = true;
|
|
354
|
-
});
|
|
355
|
-
let timer;
|
|
356
|
-
const limit = new Promise((_, reject) => {
|
|
357
|
-
timer = setTimeout(() => {
|
|
358
|
-
release.timedOut = true;
|
|
359
|
-
reject(releaseTimedOut(indexName, deps.releaseTimeoutMs));
|
|
360
|
-
}, deps.releaseTimeoutMs);
|
|
361
|
-
});
|
|
362
|
-
try {
|
|
363
|
-
await Promise.race([work, limit]);
|
|
364
|
-
} finally {
|
|
365
|
-
clearTimeout(timer);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
function vectorIndexesOf(indexName, deps) {
|
|
369
|
-
const manager = deps.executor.getManager(indexName);
|
|
370
|
-
return manager === void 0 ? [] : [...manager.getVectorIndexes().values()];
|
|
371
|
-
}
|
|
372
|
-
async function holdVectorCopies(vectorIndexes, release) {
|
|
373
|
-
for (const vectorIndex of vectorIndexes) {
|
|
374
|
-
if (release.held.includes(vectorIndex)) continue;
|
|
375
|
-
release.held.push(vectorIndex);
|
|
376
|
-
await vectorIndex.holdWorkerCopies();
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
async function releaseCopies(indexName, release, deps) {
|
|
380
|
-
release.reloads = await deps.copies.releaseIndexCopies(indexName);
|
|
381
|
-
await holdVectorCopies(vectorIndexesOf(indexName, deps), release);
|
|
382
|
-
}
|
|
383
|
-
async function endRelease(indexName, release, deps) {
|
|
384
|
-
await release.settled;
|
|
385
|
-
for (const vectorIndex of release.held) vectorIndex.resumeWorkerCopies();
|
|
386
|
-
await deps.copies.endCopyRelease(indexName, release.reloads);
|
|
387
|
-
}
|
|
388
|
-
function persistedCheckpoint(indexName, partitionCount, deps) {
|
|
389
|
-
const durable = deps.durability?.manager;
|
|
390
|
-
if (durable === void 0) return [];
|
|
391
|
-
return Array.from({ length: partitionCount }, (_, partitionId) => ({
|
|
392
|
-
partitionId,
|
|
393
|
-
lastSeqNo: durable.highestPersistedSeqNo(indexName, partitionId),
|
|
394
|
-
primaryTerm: SINGLE_NODE_PRIMARY_TERM
|
|
395
|
-
}));
|
|
396
|
-
}
|
|
397
|
-
async function commitToStorage(indexName, restored, previousPartitions, deps) {
|
|
398
|
-
const durable = deps.durability?.manager;
|
|
399
|
-
const staging = restored.staging;
|
|
400
|
-
if (durable === void 0 || staging === null) return;
|
|
401
|
-
const previous = persistedCheckpoint(indexName, previousPartitions, deps);
|
|
402
|
-
if (previousPartitions > 0) await durable.unloadIndex(indexName);
|
|
403
|
-
const vectorIndexes = [...restored.detached.manager.getVectorIndexes().values()];
|
|
404
|
-
try {
|
|
405
|
-
for (const vectorIndex of vectorIndexes) await vectorIndex.releaseVectorFiles();
|
|
406
|
-
await staging.commit();
|
|
407
|
-
} catch (error) {
|
|
408
|
-
if (previousPartitions > 0) durable.adoptRestoredCheckpoint?.(indexName, previous);
|
|
409
|
-
throw error;
|
|
410
|
-
}
|
|
411
|
-
await staging.finish();
|
|
412
|
-
const relocate = await staging.relocation().catch(() => null);
|
|
413
|
-
if (relocate !== null) for (const vectorIndex of vectorIndexes) vectorIndex.relocateVectorFiles(relocate);
|
|
414
|
-
}
|
|
415
|
-
function activate(indexName, restored, entry, deps) {
|
|
416
|
-
deps.executor.installDetachedIndex(restored.detached);
|
|
417
|
-
deps.indexRegistry.set(indexName, entry);
|
|
418
|
-
restored.detached.attach();
|
|
419
|
-
deps.clearAnalysisStale(indexName);
|
|
420
|
-
const { prepared } = restored;
|
|
421
|
-
if (prepared.storedRevision !== prepared.language.revision) {
|
|
422
|
-
deps.markAnalysisStale({
|
|
423
|
-
indexName,
|
|
424
|
-
language: prepared.language.name,
|
|
425
|
-
storedRevision: prepared.storedRevision,
|
|
426
|
-
currentRevision: prepared.language.revision
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
if (restored.staging !== null) deps.durability?.manager.adoptRestoredCheckpoint?.(indexName, restored.checkpoint);
|
|
430
|
-
deps.forgetWatermark(indexName);
|
|
431
|
-
}
|
|
432
|
-
async function replaceExisting(indexName, restored, entry, deps) {
|
|
433
|
-
const release = { reloads: false, held: [], settled: Promise.resolve(), timedOut: false };
|
|
434
|
-
try {
|
|
435
|
-
await withinLimit(indexName, release, releaseCopies(indexName, release, deps), deps);
|
|
436
|
-
await deps.indexState.replace(indexName, async (wasOpen) => {
|
|
437
|
-
await deps.abandonAnalysisRebuild(indexName);
|
|
438
|
-
const previous = wasOpen ? deps.executor.getManager(indexName) : void 0;
|
|
439
|
-
const vectorIndexes = previous === void 0 ? [] : vectorIndexesOf(indexName, deps);
|
|
440
|
-
await withinLimit(indexName, release, holdVectorCopies(vectorIndexes, release), deps);
|
|
441
|
-
for (const vectorIndex of vectorIndexes) await vectorIndex.releaseVectorFiles();
|
|
442
|
-
await commitToStorage(indexName, restored, previous?.partitionCount ?? 0, deps);
|
|
443
|
-
activate(indexName, restored, entry, deps);
|
|
444
|
-
});
|
|
445
|
-
} finally {
|
|
446
|
-
const ending = endRelease(indexName, release, deps).catch(() => void 0);
|
|
447
|
-
if (!release.timedOut) await ending;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
async function createFresh(indexName, restored, entry, deps) {
|
|
451
|
-
deps.copies.desyncIndex(indexName);
|
|
452
|
-
deps.executor.installDetachedIndex(restored.detached);
|
|
453
|
-
deps.indexRegistry.set(indexName, entry);
|
|
454
|
-
try {
|
|
455
|
-
await deps.indexState.registerReplacing(indexName, async () => {
|
|
456
|
-
await commitToStorage(indexName, restored, 0, deps);
|
|
457
|
-
activate(indexName, restored, entry, deps);
|
|
458
|
-
});
|
|
459
|
-
} catch (error) {
|
|
460
|
-
if (deps.indexRegistry.get(indexName) === entry) deps.indexRegistry.delete(indexName);
|
|
461
|
-
throw error;
|
|
462
|
-
} finally {
|
|
463
|
-
await deps.copies.resyncIndex(indexName, false).catch(() => void 0);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
async function stageMetadata(indexName, staging, entry) {
|
|
467
|
-
const metadata = indexMetadataOf(indexName, entry, entry.partitionCount);
|
|
468
|
-
await staging.store.write(`${indexName}/meta`, [await writeMetadataEnvelope(metadata, { checksum: true })]);
|
|
469
|
-
}
|
|
470
|
-
async function installRestoredIndex(indexName, restored, deps) {
|
|
471
|
-
const entry = restoredRegistryEntry(restored.prepared, restored.detached.manager, deps);
|
|
472
|
-
let replaced;
|
|
473
|
-
try {
|
|
474
|
-
if (restored.staging !== null) await stageMetadata(indexName, restored.staging, entry);
|
|
475
|
-
replaced = deps.indexRegistry.get(indexName);
|
|
476
|
-
if (replaced !== void 0) await replaceExisting(indexName, restored, entry, deps);
|
|
477
|
-
else await createFresh(indexName, restored, entry, deps);
|
|
478
|
-
} catch (error) {
|
|
479
|
-
if (deps.executor.getManager(indexName) === restored.detached.manager) deps.executor.dropIndex(indexName);
|
|
480
|
-
else deps.executor.discardDetachedIndex(restored.detached);
|
|
481
|
-
throw error;
|
|
482
|
-
}
|
|
483
|
-
await restored.staging?.removeRetired().catch(() => void 0);
|
|
484
|
-
const durable = deps.durability?.manager;
|
|
485
|
-
if (restored.staging === null && durable !== void 0) {
|
|
486
|
-
await durable.persistMetadata(indexName);
|
|
487
|
-
await durable.checkpoint(indexName);
|
|
488
|
-
}
|
|
489
|
-
if (replaced !== void 0) await deps.announceIndexDropped(indexName, replaced.config);
|
|
490
|
-
await deps.announceIndexCreated(indexName, restored.prepared.config);
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
// src/engine/snapshot/archive-restore.ts
|
|
494
|
-
function rejectConfiguration(message) {
|
|
495
|
-
throw new NarsilError(ErrorCodes.CONFIG_INVALID, `Invalid index configuration: ${message}`);
|
|
496
|
-
}
|
|
497
|
-
function renamed(manifest, sourceName, indexName) {
|
|
498
|
-
const rename = (key) => `${indexName}/${key.slice(sourceName.length + 1)}`;
|
|
499
|
-
return {
|
|
500
|
-
...manifest,
|
|
501
|
-
partitions: manifest.partitions.map((partition) => ({
|
|
502
|
-
...partition,
|
|
503
|
-
segments: partition.segments.map((segment) => ({ ...segment, key: rename(segment.key) }))
|
|
504
|
-
})),
|
|
505
|
-
vectors: manifest.vectors.map((field) => ({
|
|
506
|
-
...field,
|
|
507
|
-
files: field.files.map((file) => ({ ...file, key: rename(file.key) })),
|
|
508
|
-
graphParts: field.graphParts.map((part) => ({ ...part, key: rename(part.key) }))
|
|
509
|
-
}))
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
function requireSameSchema(prepared, manifest) {
|
|
513
|
-
const configured = flattenSchema(prepared.config.schema);
|
|
514
|
-
const keys = /* @__PURE__ */ new Set([...Object.keys(configured), ...Object.keys(manifest.schema)]);
|
|
515
|
-
for (const field of keys) {
|
|
516
|
-
if (configured[field] === manifest.schema[field]) continue;
|
|
517
|
-
throw new NarsilError(
|
|
518
|
-
ErrorCodes.PERSISTENCE_LOAD_FAILED,
|
|
519
|
-
`The archive's configuration gives field "${field}" another type than its manifest does`,
|
|
520
|
-
{ field }
|
|
521
|
-
);
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
function partitionCountOf(manifest) {
|
|
525
|
-
let count = 1;
|
|
526
|
-
for (const partition of manifest.partitions) count = Math.max(count, partition.partitionId + 1);
|
|
527
|
-
return count;
|
|
528
|
-
}
|
|
529
|
-
function missingPart(what) {
|
|
530
|
-
throw new NarsilError(ErrorCodes.PERSISTENCE_LOAD_FAILED, `The archive holds no ${what}`);
|
|
531
|
-
}
|
|
532
|
-
async function stageArchive(indexName, reader, staging, deps) {
|
|
533
|
-
const staged = { prepared: null, manifest: null };
|
|
534
|
-
await readSnapshotArchive(reader, {
|
|
535
|
-
config: async (bytes) => {
|
|
536
|
-
staged.prepared = prepareRestoredIndex(await decodeIndexConfiguration(bytes), deps, rejectConfiguration);
|
|
537
|
-
},
|
|
538
|
-
manifest: async (manifest2, sourceName) => {
|
|
539
|
-
if (staged.prepared === null) missingPart("configuration");
|
|
540
|
-
requireSameSchema(staged.prepared, manifest2);
|
|
541
|
-
const replacesIndex = deps.indexRegistry.has(indexName);
|
|
542
|
-
requireRestoreMemory(indexName, archiveFootprint(staged.prepared, manifest2, replacesIndex), replacesIndex);
|
|
543
|
-
staged.manifest = renamed(manifest2, sourceName, indexName);
|
|
544
|
-
},
|
|
545
|
-
file: async (entryName, _ref, bytes) => {
|
|
546
|
-
if (staged.manifest === null) missingPart("manifest");
|
|
547
|
-
await staging.write(`${indexName}/${entryName}`, [bytes]);
|
|
548
|
-
}
|
|
549
|
-
});
|
|
550
|
-
const { prepared, manifest } = staged;
|
|
551
|
-
if (prepared === null) missingPart("configuration");
|
|
552
|
-
if (manifest === null) missingPart("manifest");
|
|
553
|
-
await validateStagedCheckpoint(staging, manifest);
|
|
554
|
-
return { prepared, manifest };
|
|
555
|
-
}
|
|
556
|
-
async function loadStagedIndex(indexName, staged, staging, store, deps) {
|
|
557
|
-
const { prepared, manifest } = staged;
|
|
558
|
-
await store.write(manifestKey(indexName), (await encodeSegmentManifest(manifest)).chunks);
|
|
559
|
-
const detached = await prepareDetachedIndex(indexName, prepared, partitionCountOf(manifest), deps);
|
|
560
|
-
try {
|
|
561
|
-
await loadSegmentedCheckpoint(
|
|
562
|
-
store,
|
|
563
|
-
indexName,
|
|
564
|
-
manifest,
|
|
565
|
-
{ manager: detached.manager, vectorIndexes: detached.manager.getVectorIndexes() },
|
|
566
|
-
true
|
|
567
|
-
);
|
|
568
|
-
} catch (error) {
|
|
569
|
-
deps.executor.discardDetachedIndex(detached);
|
|
570
|
-
throw error;
|
|
571
|
-
}
|
|
572
|
-
return { prepared, detached, staging, checkpoint: manifest.checkpoint };
|
|
573
|
-
}
|
|
574
|
-
async function restoreArchive(indexName, reader, deps) {
|
|
575
|
-
const staging = deps.durability?.manager.stageRestore?.(indexName) ?? null;
|
|
576
|
-
const store = staging?.store ?? memoryCheckpointStore();
|
|
577
|
-
try {
|
|
578
|
-
const staged = await stageArchive(indexName, reader, store, deps);
|
|
579
|
-
await installRestoredIndex(indexName, await loadStagedIndex(indexName, staged, staging, store, deps), deps);
|
|
580
|
-
} finally {
|
|
581
|
-
await staging?.discard().catch(() => void 0);
|
|
582
|
-
await reader.close();
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
function invalidSnapshot(message, details) {
|
|
586
|
-
throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, message, details);
|
|
587
|
-
}
|
|
588
|
-
async function decodeEarlierSnapshot(data) {
|
|
589
|
-
const payloadBytes = await unpackIndexSnapshotEnvelope(data);
|
|
590
|
-
let decoded;
|
|
591
|
-
try {
|
|
592
|
-
decoded = decode(payloadBytes);
|
|
593
|
-
} catch (err) {
|
|
594
|
-
invalidSnapshot(`Snapshot data is not a Narsil snapshot: ${err instanceof Error ? err.message : String(err)}`, {
|
|
595
|
-
bytes: data.length
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
if (typeof decoded !== "object" || decoded === null || Array.isArray(decoded)) {
|
|
599
|
-
invalidSnapshot("Snapshot data does not hold a snapshot envelope", { bytes: data.length });
|
|
600
|
-
}
|
|
601
|
-
const envelope = decoded;
|
|
602
|
-
if (envelope.version !== 1 && envelope.version !== 2) {
|
|
603
|
-
invalidSnapshot(`Unsupported snapshot version: ${envelope.version}. Expected version 1 or 2`, {
|
|
604
|
-
version: envelope.version
|
|
605
|
-
});
|
|
606
|
-
}
|
|
607
|
-
if (!envelope.schema || typeof envelope.schema !== "object")
|
|
608
|
-
invalidSnapshot("Invalid snapshot: missing or invalid schema");
|
|
609
|
-
if (!envelope.language || typeof envelope.language !== "string") {
|
|
610
|
-
invalidSnapshot("Invalid snapshot: missing or invalid language");
|
|
611
|
-
}
|
|
612
|
-
if (!Array.isArray(envelope.partitions)) invalidSnapshot("Invalid snapshot: missing partitions");
|
|
613
|
-
return { ...envelope, vectorPromotion: raiseEarlierReleaseGraphSetting(envelope.vectorPromotion) };
|
|
614
|
-
}
|
|
615
|
-
function vectorsOfSnapshot(envelope) {
|
|
616
|
-
const byDocument = /* @__PURE__ */ new Map();
|
|
617
|
-
for (const [fieldPath, rawParts] of Object.entries(envelope.vectorIndexes ?? {})) {
|
|
618
|
-
for (const part of decodeVectorIndexParts(rawParts)) {
|
|
619
|
-
const values = bytesToVectors(part.vectors);
|
|
620
|
-
for (let i = 0; i < part.docIds.length; i++) {
|
|
621
|
-
let fields = byDocument.get(part.docIds[i]);
|
|
622
|
-
if (fields === void 0) {
|
|
623
|
-
fields = /* @__PURE__ */ new Map();
|
|
624
|
-
byDocument.set(part.docIds[i], fields);
|
|
625
|
-
}
|
|
626
|
-
fields.set(fieldPath, values.slice(i * part.dimension, (i + 1) * part.dimension));
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
return byDocument;
|
|
631
|
-
}
|
|
632
|
-
function footprintOf(envelope, prepared, replacesIndex) {
|
|
633
|
-
let partitionBytes = 0;
|
|
634
|
-
for (const payload of envelope.partitions ?? []) partitionBytes += payload.byteLength;
|
|
635
|
-
const vectorCounts = /* @__PURE__ */ new Map();
|
|
636
|
-
for (const [fieldPath, rawParts] of Object.entries(envelope.vectorIndexes ?? {})) {
|
|
637
|
-
let count = 0;
|
|
638
|
-
for (const part of decodeVectorIndexParts(rawParts)) count += part.docIds.length;
|
|
639
|
-
vectorCounts.set(fieldPath, count);
|
|
640
|
-
}
|
|
641
|
-
return earlierSnapshotFootprint(prepared, partitionBytes, vectorCounts, replacesIndex);
|
|
642
|
-
}
|
|
643
|
-
function documentsOfPartition(envelope, payload) {
|
|
644
|
-
return envelope.version === 2 ? documentsOfPayloadV2(payload).documents : deserializePayloadV1(payload).documents;
|
|
645
|
-
}
|
|
646
|
-
function insertRestoredDocument(manager, docId, fields, vectors) {
|
|
647
|
-
manager.insert(docId, fields, { skipClone: true });
|
|
648
|
-
if (vectors === void 0) return;
|
|
649
|
-
try {
|
|
650
|
-
insertDocumentVectors(docId, vectors, manager.getVectorIndexes(), manager.partitionIdOf(docId));
|
|
651
|
-
} catch (err) {
|
|
652
|
-
manager.remove(docId);
|
|
653
|
-
throw err;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
function insertSnapshotDocuments(envelope, manager) {
|
|
657
|
-
const vectors = vectorsOfSnapshot(envelope);
|
|
658
|
-
for (const payload of envelope.partitions ?? []) {
|
|
659
|
-
for (const [docId, stored] of Object.entries(documentsOfPartition(envelope, payload))) {
|
|
660
|
-
insertRestoredDocument(manager, docId, stored.fields, vectors.get(docId));
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
for (const vectorIndex of manager.getVectorIndexes().values()) vectorIndex.scheduleBuild();
|
|
664
|
-
}
|
|
665
|
-
async function stageBuiltIndex(indexName, prepared, built, staging, deps) {
|
|
666
|
-
const entry = restoredRegistryEntry(prepared, built.manager, deps);
|
|
667
|
-
const archive = await buildArchiveFromMemory({
|
|
668
|
-
indexName,
|
|
669
|
-
metadata: indexMetadataOf(indexName, entry, built.manager.partitionCount),
|
|
670
|
-
manager: built.manager,
|
|
671
|
-
vectorIndexes: built.manager.getVectorIndexes(),
|
|
672
|
-
appliedSeqNo: () => 0,
|
|
673
|
-
partitionId: null
|
|
674
|
-
});
|
|
675
|
-
try {
|
|
676
|
-
for (const ref of manifestFileRefs(archive.manifest))
|
|
677
|
-
await staging.store.write(ref.key, [await archive.readFile(ref)]);
|
|
678
|
-
} finally {
|
|
679
|
-
archive.release();
|
|
680
|
-
}
|
|
681
|
-
await validateStagedCheckpoint(staging.store, archive.manifest);
|
|
682
|
-
return archive.manifest;
|
|
683
|
-
}
|
|
684
|
-
async function buildRestoredIndex(indexName, envelope, prepared, staging, deps) {
|
|
685
|
-
const built = await prepareDetachedIndex(indexName, prepared, envelope.partitions?.length ?? 0, deps);
|
|
686
|
-
let manifest;
|
|
687
|
-
try {
|
|
688
|
-
insertSnapshotDocuments(envelope, built.manager);
|
|
689
|
-
if (staging === null) return { prepared, detached: built, staging: null, checkpoint: [] };
|
|
690
|
-
manifest = await stageBuiltIndex(indexName, prepared, built, staging, deps);
|
|
691
|
-
} catch (err) {
|
|
692
|
-
deps.executor.discardDetachedIndex(built);
|
|
693
|
-
throw err;
|
|
694
|
-
}
|
|
695
|
-
deps.executor.discardDetachedIndex(built);
|
|
696
|
-
return loadStagedIndex(indexName, { prepared, manifest }, staging, staging.store, deps);
|
|
697
|
-
}
|
|
698
|
-
async function restoreEarlierSnapshot(indexName, data, deps) {
|
|
699
|
-
const envelope = await decodeEarlierSnapshot(data);
|
|
700
|
-
const prepared = prepareRestoredIndex(envelope, deps);
|
|
701
|
-
const replacesIndex = deps.indexRegistry.has(indexName);
|
|
702
|
-
requireRestoreMemory(indexName, footprintOf(envelope, prepared, replacesIndex), replacesIndex);
|
|
703
|
-
const analysedNow = { ...prepared, storedRevision: prepared.language.revision };
|
|
704
|
-
const staging = deps.durability?.manager.stageRestore?.(indexName) ?? null;
|
|
705
|
-
try {
|
|
706
|
-
await installRestoredIndex(
|
|
707
|
-
indexName,
|
|
708
|
-
await buildRestoredIndex(indexName, envelope, analysedNow, staging, deps),
|
|
709
|
-
deps
|
|
710
|
-
);
|
|
711
|
-
} finally {
|
|
712
|
-
await staging?.discard().catch(() => void 0);
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
// src/engine/snapshot/index.ts
|
|
717
|
-
var NRSL_MAGIC_BYTES = 4;
|
|
718
|
-
async function checkpointForArchive(deps) {
|
|
719
|
-
const durable = deps.durability?.manager;
|
|
720
|
-
if (durable?.openArchiveCheckpoint !== void 0) return durable.openArchiveCheckpoint(deps.indexName);
|
|
721
|
-
return buildArchiveFromMemory({
|
|
722
|
-
indexName: deps.indexName,
|
|
723
|
-
metadata: indexMetadataOf(deps.indexName, deps.entry, deps.manager.partitionCount),
|
|
724
|
-
manager: deps.manager,
|
|
725
|
-
vectorIndexes: deps.manager.getVectorIndexes(),
|
|
726
|
-
appliedSeqNo: (partitionId) => durable?.highestPersistedSeqNo(deps.indexName, partitionId) ?? 0,
|
|
727
|
-
partitionId: null
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
async function createSnapshot(deps) {
|
|
731
|
-
const config = await encodeIndexConfiguration(deps.entry);
|
|
732
|
-
const checkpoint = await checkpointForArchive(deps);
|
|
733
|
-
return archiveStream({ ...checkpoint, config, sourceIndexName: deps.indexName });
|
|
734
|
-
}
|
|
735
|
-
function requireSnapshotSource(data) {
|
|
736
|
-
if (data instanceof Uint8Array) return data;
|
|
737
|
-
if (data !== null && typeof data === "object") {
|
|
738
|
-
if (typeof data.getReader === "function") return data;
|
|
739
|
-
if (typeof data[Symbol.asyncIterator] === "function") {
|
|
740
|
-
return data;
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
throw new NarsilError(
|
|
744
|
-
ErrorCodes.DOC_VALIDATION_FAILED,
|
|
745
|
-
"Snapshot data must be a Uint8Array, a ReadableStream of bytes, or an async iterable of bytes"
|
|
746
|
-
);
|
|
747
|
-
}
|
|
748
|
-
async function readEarlierSnapshotFile(reader) {
|
|
749
|
-
const length = HEADER_SIZE + readHeader(await reader.peek(HEADER_SIZE)).payloadLength;
|
|
750
|
-
if (length > MAX_FILE_BYTES) {
|
|
751
|
-
throw new NarsilError(
|
|
752
|
-
ErrorCodes.PERSISTENCE_LOAD_FAILED,
|
|
753
|
-
`The snapshot declares ${length} bytes, above the file size limit of ${MAX_FILE_BYTES}`,
|
|
754
|
-
{ bytes: length }
|
|
755
|
-
);
|
|
756
|
-
}
|
|
757
|
-
const bytes = await reader.readExactly(length) ?? new Uint8Array(0);
|
|
758
|
-
if (bytes.byteLength < length) {
|
|
759
|
-
throw new NarsilError(
|
|
760
|
-
ErrorCodes.PERSISTENCE_LOAD_FAILED,
|
|
761
|
-
"The snapshot ends before the payload its header declares"
|
|
762
|
-
);
|
|
763
|
-
}
|
|
764
|
-
const trailing = await reader.readExactly(1);
|
|
765
|
-
if (trailing !== null && trailing.byteLength > 0) {
|
|
766
|
-
throw new NarsilError(
|
|
767
|
-
ErrorCodes.PERSISTENCE_LOAD_FAILED,
|
|
768
|
-
"The snapshot holds bytes after the payload its header declares"
|
|
769
|
-
);
|
|
770
|
-
}
|
|
771
|
-
return bytes;
|
|
772
|
-
}
|
|
773
|
-
async function restoreFromSnapshot(indexName, data, deps) {
|
|
774
|
-
const reader = createByteReader(requireSnapshotSource(data));
|
|
775
|
-
const head = await reader.peek(NRSL_MAGIC_BYTES);
|
|
776
|
-
if (head.byteLength >= NRSL_MAGIC_BYTES && hasNrslMagic(head)) {
|
|
777
|
-
let bytes;
|
|
778
|
-
try {
|
|
779
|
-
bytes = await readEarlierSnapshotFile(reader);
|
|
780
|
-
} finally {
|
|
781
|
-
await reader.close();
|
|
782
|
-
}
|
|
783
|
-
await restoreEarlierSnapshot(indexName, bytes, deps);
|
|
784
|
-
return;
|
|
785
|
-
}
|
|
786
|
-
if (head.byteLength === 0) {
|
|
787
|
-
await reader.close();
|
|
788
|
-
throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, "Snapshot data is empty");
|
|
789
|
-
}
|
|
790
|
-
await restoreArchive(indexName, reader, deps);
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
export { checkpointForArchive, createSnapshot, restoreFromSnapshot };
|