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

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 (168) hide show
  1. package/dist/{analysis-change-5BQOQ4BF.mjs → analysis-change-CKEMM2MC.mjs} +9 -9
  2. package/dist/{react-native/chunks/analysis-change-entry-SCVWK6OU.mjs → analysis-change-entry-SEDMJ6MW.mjs} +1 -1
  3. package/dist/browser/{analysis-change-435CUEPZ.mjs → analysis-change-ZKGJFENM.mjs} +38 -29
  4. package/dist/{analysis-change-entry-TXX6JSMX.mjs → browser/analysis-change-entry-5BFUVMHJ.mjs} +1 -1
  5. package/dist/browser/{chunk-BHFQATSC.mjs → chunk-25MTVDYD.mjs} +1 -1
  6. package/dist/browser/{chunk-IZXVW2ZJ.mjs → chunk-3NLMB5CC.mjs} +2 -2
  7. package/dist/browser/{chunk-23XRXIBW.mjs → chunk-5YWB3E2W.mjs} +8 -1
  8. package/dist/browser/chunk-AI5UI46D.mjs +12 -0
  9. package/dist/browser/{chunk-2CFI5VVV.mjs → chunk-BLT4RHCJ.mjs} +2 -2
  10. package/dist/browser/{chunk-4NGKC4H4.mjs → chunk-C26SPCGQ.mjs} +7 -6
  11. package/dist/browser/{chunk-6LWDPLTB.mjs → chunk-C4FJ3WDY.mjs} +1 -1
  12. package/dist/browser/{chunk-MGI4BCXC.mjs → chunk-CXNTHHA7.mjs} +2 -2
  13. package/dist/browser/{chunk-STOWQFT3.mjs → chunk-DUH6QUVU.mjs} +547 -2
  14. package/dist/browser/chunk-EKMGCRSR.mjs +61 -0
  15. package/dist/browser/{chunk-SSTPBZZX.mjs → chunk-GFAZPSWK.mjs} +5 -5
  16. package/dist/browser/{chunk-3SSRJMFN.mjs → chunk-HUCSHDTB.mjs} +1 -1
  17. package/dist/browser/{chunk-K4Q6KX3R.mjs → chunk-K3IPRX6D.mjs} +48 -17
  18. package/dist/browser/{chunk-MOG4OVDK.mjs → chunk-MY2XKH22.mjs} +1 -12
  19. package/dist/browser/{chunk-3V7DNNZL.mjs → chunk-N23GL72Q.mjs} +178 -801
  20. package/dist/browser/{chunk-NQAME3RK.mjs → chunk-UATIJ4KU.mjs} +2 -2
  21. package/dist/browser/{chunk-2TI4SSUP.mjs → chunk-UKOWD2K5.mjs} +3 -3
  22. package/dist/browser/{chunk-7U3WVJUP.mjs → chunk-UTMHUHUV.mjs} +2 -2
  23. package/dist/browser/{chunk-EA63E3D2.mjs → chunk-V43N6TZO.mjs} +5 -5
  24. package/dist/browser/{chunk-CRE3G7F3.mjs → chunk-VY5KW3HN.mjs} +3 -3
  25. package/dist/browser/{chunk-WI4MR75E.mjs → chunk-X7TXYUKO.mjs} +1 -1
  26. package/dist/browser/{chunk-KZWSX6BH.mjs → chunk-Y6IBAUNO.mjs} +2 -86
  27. package/dist/browser/{cold-module-2EHCIV4K.mjs → cold-module-YNUUDNOM.mjs} +12 -10
  28. package/dist/browser/{durability-wiring-A7BVG2DW.mjs → durability-wiring-GVZEE46O.mjs} +64 -21
  29. package/dist/browser/{engine-hooks-E4UD67JD.mjs → engine-hooks-HBVS6YM4.mjs} +5 -4
  30. package/dist/browser/{geo-index-HHWGMNIS.mjs → geo-index-OTV7VPIR.mjs} +2 -1
  31. package/dist/browser/{import-DXYB6756.mjs → import-5ESVMFDJ.mjs} +6 -5
  32. package/dist/browser/{module-NIYMEA5R.mjs → module-NDSQLPMQ.mjs} +11 -9
  33. package/dist/{release-BH3DKW3T.mjs → browser/release-HYXPVJVS.mjs} +0 -1
  34. package/dist/browser/{restore-hooks-YPN4ZFCY.mjs → restore-hooks-IE3GGYHG.mjs} +8 -7
  35. package/dist/browser/{restore-queue-G3RQGL3Y.mjs → restore-queue-LQBBTODR.mjs} +3 -3
  36. package/dist/browser/{retention-ZWVMNC3Q.mjs → retention-TY3L3BFN.mjs} +7 -6
  37. package/dist/browser/{snapshot-VEQNIE6C.mjs → snapshot-5FHPPCNZ.mjs} +16 -14
  38. package/dist/browser/{start-BM442C6R.mjs → start-2UZTOBG5.mjs} +8 -7
  39. package/dist/browser/{write-2EVMZWDE.mjs → write-ULXAN5B4.mjs} +10 -8
  40. package/dist/{capabilities-Da4ywVVl.d.ts → capabilities-D3AoBJoF.d.ts} +2 -2
  41. package/dist/{chunk-K5QFDYST.mjs → chunk-24FNVRKB.mjs} +1 -1
  42. package/dist/{chunk-DP5C7YFQ.mjs → chunk-2ROUFMQX.mjs} +2 -2
  43. package/dist/{chunk-PWC4VB3Q.mjs → chunk-4B7JIGQD.mjs} +2 -2
  44. package/dist/{chunk-FAKFUDZZ.mjs → chunk-4LMSZAK6.mjs} +14 -3
  45. package/dist/{chunk-6I6AYAXS.mjs → chunk-4ZTHGTVX.mjs} +2 -2
  46. package/dist/{chunk-QOW2JPUI.mjs → chunk-BNL5OPRV.mjs} +6 -6
  47. package/dist/{chunk-3HYC4JRF.mjs → chunk-C7XQYG6U.mjs} +2 -2
  48. package/dist/{chunk-WX4LAO6M.mjs → chunk-CQZXZ75V.mjs} +3 -97
  49. package/dist/{chunk-4KKXNJM6.mjs → chunk-CWS55TEX.mjs} +2 -2
  50. package/dist/{chunk-2UV4QBHW.mjs → chunk-EYD7K3H6.mjs} +5 -5
  51. package/dist/{chunk-EFBDHH5P.mjs → chunk-FEZVDOWX.mjs} +160 -245
  52. package/dist/{chunk-XAXKV65G.mjs → chunk-FUD5XSZ5.mjs} +1 -1
  53. package/dist/{chunk-JDJBQLRO.mjs → chunk-GPWMUPCA.mjs} +10 -10
  54. package/dist/{chunk-25KDNIZZ.mjs → chunk-IIRIG7H5.mjs} +1 -1
  55. package/dist/{chunk-TZTRKM33.mjs → chunk-JSV6OQ4C.mjs} +1 -1
  56. package/dist/{chunk-NF4DT3IH.mjs → chunk-JTYPJF3T.mjs} +8 -1
  57. package/dist/chunk-KCQYFO4K.mjs +62 -0
  58. package/dist/{chunk-CSLGFPFQ.mjs → chunk-LDNCLRZU.mjs} +1 -1
  59. package/dist/{chunk-MQOJIO5B.mjs → chunk-MW6BR4QP.mjs} +2 -2
  60. package/dist/{react-native/chunks/chunk-MUWD2H2S.mjs → chunk-MWD5VPN7.mjs} +2 -2
  61. package/dist/{chunk-XXHN7J46.mjs → chunk-ODYKO5TO.mjs} +1 -1
  62. package/dist/{chunk-RDXO6JST.mjs → chunk-OG7UGJ6F.mjs} +2 -2
  63. package/dist/{chunk-FYOVBEMM.mjs → chunk-OQLD2BSW.mjs} +2 -2
  64. package/dist/{chunk-I53G4JAU.mjs → chunk-OYABFKTW.mjs} +2 -2
  65. package/dist/{chunk-TZ3355VS.mjs → chunk-P5LANSH6.mjs} +1 -1
  66. package/dist/{chunk-P5ZI2P2W.mjs → chunk-PIH5SJ4N.mjs} +3 -3
  67. package/dist/{chunk-HFPMMRQT.mjs → chunk-PSZI4O24.mjs} +51 -4
  68. package/dist/{chunk-L6V6BST3.mjs → chunk-PV2CG7EJ.mjs} +3 -552
  69. package/dist/{chunk-SA5LOGO3.mjs → chunk-PWGYQXML.mjs} +1 -1
  70. package/dist/{chunk-BWZ3P4MU.mjs → chunk-QLDABJZM.mjs} +3 -3
  71. package/dist/{chunk-JWRUUCWD.mjs → chunk-RCX4WNLC.mjs} +2 -2
  72. package/dist/{chunk-DWEPMFJE.mjs → chunk-RIHIVFIQ.mjs} +5 -5
  73. package/dist/{chunk-FNGAM5B7.mjs → chunk-RWURUDSP.mjs} +8 -8
  74. package/dist/{chunk-I2KPOLOZ.mjs → chunk-SMOOSIAW.mjs} +3 -3
  75. package/dist/{chunk-TGS5UXBE.mjs → chunk-SOI6LTHM.mjs} +3 -3
  76. package/dist/{chunk-YTWZVGCB.mjs → chunk-UD5HIS4U.mjs} +1 -1
  77. package/dist/{chunk-46KY2PJD.mjs → chunk-UJDJB3NE.mjs} +37 -29
  78. package/dist/{chunk-Z2KAFCRT.mjs → chunk-VSLSGASN.mjs} +2 -2
  79. package/dist/{chunk-VTTRFF2C.mjs → chunk-VZ2ONHEE.mjs} +9 -5
  80. package/dist/chunk-W5EB5XKI.mjs +741 -0
  81. package/dist/{chunk-7LXHHCXZ.mjs → chunk-W7OSSKH5.mjs} +46 -16
  82. package/dist/{chunk-ZKP7G7TV.mjs → chunk-XXJZMTZT.mjs} +1 -1
  83. package/dist/{chunk-FRBFVQFN.mjs → chunk-ZPZ3YGXV.mjs} +4 -4
  84. package/dist/{client-DRv7UVeY.d.ts → client-kqSMevVi.d.ts} +15 -3
  85. package/dist/client.d.ts +6 -6
  86. package/dist/client.mjs +4 -0
  87. package/dist/{cold-module-6MO2XJF2.mjs → cold-module-VOJXMNZB.mjs} +13 -12
  88. package/dist/{config-DMwffLKn.d.ts → config-B4v_Htpu.d.ts} +1 -1
  89. package/dist/{config-CoSig5Ox.d.ts → config-CTP01fns.d.ts} +1 -1
  90. package/dist/{direct-executor-FTMYY3TI.mjs → direct-executor-V5DRIECI.mjs} +5 -5
  91. package/dist/distribution.d.ts +4 -4
  92. package/dist/distribution.mjs +72 -64
  93. package/dist/{durability-wiring-VIF5MOSY.mjs → durability-wiring-3TD62MBI.mjs} +38 -30
  94. package/dist/{engine-CFxPYqEk.d.ts → engine-CkPn2PWE.d.ts} +1 -1
  95. package/dist/{engine-hooks-EGUGNZYE.mjs → engine-hooks-HA3SBOBR.mjs} +8 -8
  96. package/dist/{import-XKDPJQDP.mjs → import-GPKLTSKA.mjs} +8 -8
  97. package/dist/index.browser.mjs +4 -3
  98. package/dist/index.d.ts +4 -4
  99. package/dist/index.mjs +7 -7
  100. package/dist/index.react-native.mjs +3 -3
  101. package/dist/{long-query-thread-YA4IAYSY.mjs → long-query-thread-QDFQSJD6.mjs} +13 -13
  102. package/dist/{module-FQ4JWNQJ.mjs → module-JYHFTVPS.mjs} +12 -11
  103. package/dist/{paged-partition-archive-PXW5XAYU.mjs → paged-partition-archive-RLRGOXDX.mjs} +14 -14
  104. package/dist/partial-words.mjs +3 -3
  105. package/dist/persistence/durability/checkpoint-worker.mjs +13 -12
  106. package/dist/query-suggestions/merge-worker.mjs +9 -9
  107. package/dist/query-suggestions.browser.mjs +9 -8
  108. package/dist/query-suggestions.d.ts +1 -1
  109. package/dist/query-suggestions.mjs +17 -17
  110. package/dist/react-native/chunks/{analysis-change-LT5QBQ3H.mjs → analysis-change-QUVDNABS.mjs} +37 -29
  111. package/dist/{browser/analysis-change-entry-HZXKPPGV.mjs → react-native/chunks/analysis-change-entry-OC4XASBF.mjs} +1 -1
  112. package/dist/react-native/chunks/{chunk-KV46CT4D.mjs → chunk-4AV5PPH6.mjs} +2 -2
  113. package/dist/react-native/chunks/{chunk-GXX3DQXP.mjs → chunk-4COWCEY7.mjs} +188 -163
  114. package/dist/react-native/chunks/{chunk-G43IPIDG.mjs → chunk-4NWR3NGS.mjs} +2 -2
  115. package/dist/react-native/chunks/{chunk-3JWDECAZ.mjs → chunk-5MSX5FRT.mjs} +5 -5
  116. package/dist/react-native/chunks/{chunk-6WA3C3DV.mjs → chunk-6OFDUYVX.mjs} +8 -1
  117. package/dist/react-native/chunks/{chunk-NB3LP33V.mjs → chunk-6ZELFCK5.mjs} +2 -2
  118. package/dist/react-native/chunks/{chunk-4JYO3JD2.mjs → chunk-BITYFZSZ.mjs} +2 -2
  119. package/dist/react-native/chunks/{chunk-ZXZFN7FI.mjs → chunk-DMIFXZ3Q.mjs} +1 -1
  120. package/dist/{chunk-KF4EXSM4.mjs → react-native/chunks/chunk-IAENKE2D.mjs} +2 -2
  121. package/dist/react-native/chunks/{chunk-ZLWVW734.mjs → chunk-KSBYEMCB.mjs} +1 -1
  122. package/dist/react-native/chunks/chunk-KU646XXT.mjs +164 -0
  123. package/dist/react-native/chunks/{chunk-MIP4SOR6.mjs → chunk-OCSLSH27.mjs} +164 -244
  124. package/dist/react-native/chunks/chunk-OXM66LO6.mjs +62 -0
  125. package/dist/react-native/chunks/{chunk-VWUDIOT6.mjs → chunk-TORU2OHQ.mjs} +1 -1
  126. package/dist/react-native/chunks/{chunk-PDRWWPKV.mjs → chunk-WVWJNUMN.mjs} +48 -18
  127. package/dist/react-native/chunks/{chunk-UQ4OAXKU.mjs → chunk-WW2X2AEI.mjs} +4 -4
  128. package/dist/react-native/chunks/{chunk-QUKQNI3H.mjs → chunk-ZNZ6CPAZ.mjs} +2 -87
  129. package/dist/react-native/chunks/{chunk-TP6KCKER.mjs → chunk-ZVQMBF2H.mjs} +2 -2
  130. package/dist/react-native/chunks/{chunk-POPDAGH6.mjs → chunk-ZWAIN4GG.mjs} +6 -6
  131. package/dist/react-native/chunks/{cold-module-KVZYUGRY.mjs → cold-module-N6KFNNZA.mjs} +9 -8
  132. package/dist/react-native/chunks/{durability-wiring-34OYO32E.mjs → durability-wiring-RN64S2TL.mjs} +63 -21
  133. package/dist/react-native/chunks/{engine-hooks-M7JV46NH.mjs → engine-hooks-CWA5CKCA.mjs} +4 -4
  134. package/dist/react-native/chunks/{import-H6AQREWI.mjs → import-5UAWBRJP.mjs} +4 -4
  135. package/dist/react-native/chunks/{module-LBZPGOWH.mjs → module-6RP4ZCBW.mjs} +8 -7
  136. package/dist/react-native/chunks/{release-D7ZTIANM.mjs → release-2SIHZWDO.mjs} +0 -1
  137. package/dist/react-native/chunks/{restore-hooks-IBGIY3DR.mjs → restore-hooks-ENFMDTWC.mjs} +7 -7
  138. package/dist/react-native/chunks/{restore-queue-ZZX54AH7.mjs → restore-queue-4R6AASE5.mjs} +3 -3
  139. package/dist/react-native/chunks/{retention-EW4TTDFB.mjs → retention-5GTFT3GR.mjs} +6 -6
  140. package/dist/react-native/chunks/{snapshot-REYVIN3X.mjs → snapshot-5LGPQXFS.mjs} +15 -14
  141. package/dist/react-native/chunks/{start-BQK6KN3R.mjs → start-ZQJVZ5DN.mjs} +7 -7
  142. package/dist/react-native/chunks/{write-FQAYCZF5.mjs → write-6BRYIIZ7.mjs} +7 -6
  143. package/dist/react-native/partial-words.mjs +2 -2
  144. package/dist/react-native/query-suggestions.mjs +8 -8
  145. package/dist/react-native/sync.mjs +44 -10
  146. package/dist/react.d.ts +7 -7
  147. package/dist/{browser/release-76MXRPGV.mjs → release-SMR4WJD4.mjs} +0 -1
  148. package/dist/{restore-hooks-CDERDEF4.mjs → restore-hooks-HXLIEB4A.mjs} +12 -12
  149. package/dist/{restore-queue-7NNSTROA.mjs → restore-queue-LZH7LMLR.mjs} +3 -3
  150. package/dist/{retention-QSVBBNRM.mjs → retention-3K7ARGAG.mjs} +12 -12
  151. package/dist/server.d.ts +10 -8
  152. package/dist/server.mjs +37 -29
  153. package/dist/{snapshot-RH4NSKIZ.mjs → snapshot-O7ICP7NJ.mjs} +24 -23
  154. package/dist/{start-MCKCOGIW.mjs → start-S4PFP6RS.mjs} +14 -14
  155. package/dist/sync/filesystem.d.ts +2 -2
  156. package/dist/sync/indexeddb.d.ts +2 -2
  157. package/dist/sync.browser.mjs +44 -10
  158. package/dist/sync.d.ts +3 -3
  159. package/dist/sync.mjs +44 -10
  160. package/dist/{tasks-qrJojgST.d.ts → tasks-CoNjxbop.d.ts} +2 -2
  161. package/dist/{thread-O4SBJJJS.mjs → thread-YLJ3ZPQ3.mjs} +12 -12
  162. package/dist/{types-BZCGjfLn.d.ts → types-DPMjfOr_.d.ts} +1 -1
  163. package/dist/workers/entry.mjs +5 -5
  164. package/dist/{write-3FK7NG3Y.mjs → write-2OBJGLFS.mjs} +11 -10
  165. package/openapi.json +71 -0
  166. package/package.json +7 -7
  167. package/dist/chunk-BU4SAIC4.mjs +0 -196
  168. package/dist/react-native/chunks/chunk-DNXOMPAQ.mjs +0 -191
@@ -1,14 +1,15 @@
1
1
  import { emitSyncChange, withOpenIndex, oneAtATime } from './chunk-ML7THVLJ.mjs';
2
2
  import { createRequestId, isValidWorkerResponse } from './chunk-VI7BQR4U.mjs';
3
3
  import { DEFAULT_MAX_RERANK_WINDOW, DEFAULT_RERANK_TIMEOUT_MS } from './chunk-JPTQZWJQ.mjs';
4
- import { parsedTypeOf, flattenSchema, isSingleStringFieldType, partialFieldsOf, resolveIndexAnalysis, schemaFieldsOf, isWordIndexedBase, MIN_PATTERN_VALUE_LIMIT, MAX_PATTERN_VALUE_LIMIT, requireWithinFileLimit, HEADER_SIZE, payloadByteLength, checksumOfChunks, packEnvelopeWithEngineVersion, INDEX_CONFIGURATION_ENVELOPE_VERSION, validateSchema, requireCreatableSchema, getLanguage, DEFAULT_PATTERN_VALUE_LIMIT, MAX_DOCUMENT_NESTING_DEPTH, PROTOTYPE_POLLUTION_KEYS, encodeDocument, extractVectorFieldsFromSchema, isPlainObject, isWordIndexedFieldType, readHeapStatistics, VECTOR_PATTERN, parseFieldType, isStringValuedBase, MAX_NESTING_DEPTH, withSortableOption, isGeopointOrVectorType, isListBase, MAX_DOCUMENT_BYTES } from './chunk-STOWQFT3.mjs';
4
+ import { parsedTypeOf, isLatitude, isLongitude, flattenSchema, isSingleStringFieldType, partialFieldsOf, resolveIndexAnalysis, getNestedValue, schemaFieldsOf, tokenizeOptions, isWordIndexedBase, raiseEarlierReleaseGraphSetting, MIN_PATTERN_VALUE_LIMIT, MAX_PATTERN_VALUE_LIMIT, requireWithinFileLimit, HEADER_SIZE, payloadByteLength, checksumOfChunks, packEnvelopeWithEngineVersion, messagePackUpperBoundBytes, INDEX_CONFIGURATION_ENVELOPE_VERSION, validateSchema, requireCreatableSchema, validateVectorPromotion, validateVectorStorage, validateTextStorage, getLanguage, validateDocument, validateDocumentStrict, textFieldsChanged, PROTOTYPE_POLLUTION_KEYS, encodeDocument, extractVectorFieldsFromSchema, getFlatSchema, isPlainObject, isWordIndexedFieldType, getOrCreateFieldNameIndex, readHeapStatistics, isStringValuedBase, MAX_NESTING_DEPTH, withSortableOption, isGeopointOrVectorType, isListBase, VECTOR_PATTERN, validateRequiredFields, requireDocumentWithinSizeLimit } from './chunk-DUH6QUVU.mjs';
5
5
  import { fnv1a, FNV_OFFSET_BASIS, fnv1aContinue, fnv1aContinueTaggedNumbers } from './chunk-RA6LSBCM.mjs';
6
- import { MAX_LATITUDE_DEGREES, MAX_LONGITUDE_DEGREES, MIN_POLYGON_POINTS, highWord, SMALLEST_NORMAL_HIGH_WORD, MAGNITUDE_MASK, lowWord, INFINITE_HIGH_WORD, withHighWord } from './chunk-MOG4OVDK.mjs';
6
+ import { highWord, SMALLEST_NORMAL_HIGH_WORD, MAGNITUDE_MASK, lowWord, INFINITE_HIGH_WORD, withHighWord } from './chunk-MY2XKH22.mjs';
7
+ import { MAX_LATITUDE_DEGREES, MAX_LONGITUDE_DEGREES, MIN_POLYGON_POINTS } from './chunk-AI5UI46D.mjs';
7
8
  import { TARGET_BLOCK_ENTRIES, bitsetHas, createBitSet, LOOKUP_KEY_SCRATCH_BYTES, GrowableUint32, SEGMENT_TOKEN_TABLE_START, SEGMENT_POSTING_LOG_START, SEGMENT_POSITION_POOL_START, SEGMENT_FIELD_SCRATCH_START, bitsetIsEmpty, bitsetSet, SCORE_BUFFER_INITIAL_TOUCHED_CAPACITY, PRUNING_REJECTION_SLACK, bitsetOrInto, bitsetAndNotInto, FIELD_RUN_ENTRIES_START, bitsetAndInto, SORT_COLUMN_MINIMUM_REBUILD_THRESHOLD, SORT_COLUMN_REBUILD_FRACTION_SHIFT, bitsetFromSet } from './chunk-TK63WFXK.mjs';
8
9
  import { createDocIdMap, turnsAreBudgeted, turnIsSpent, yieldTurn, indexChangeOutsideExternalWaits, changeIndexOutsideExternalWaits, detectRuntime, resolveWorkerEntry, missingWorkerEntry, countWrite, MIN_OVERSAMPLE, noteThreadSlotGone, threadSlotOfWorker } from './chunk-XAWNZ4G2.mjs';
9
10
  import { splitWorkerBudget, resolveWorkerCount, resolveRequestThreadCount, DEFAULT_REQUEST_TIMEOUT_MS, MAX_RENUMBERED_SEARCH_ATTEMPTS, SHUTDOWN_TIMEOUT_MS, DEFAULT_BACKPRESSURE_LIMIT, CONSECUTIVE_TIMEOUTS_BEFORE_DEATH } from './chunk-TY7L6OXO.mjs';
10
11
  import { MAX_INDEX_CONFIGURATION_BYTES, BATCH_CHUNK_SIZE, MAX_INDEX_NAME_LENGTH, INDEX_NAME_PATTERN, MAX_DOC_ID_LENGTH, ABSOLUTE_WINDOWS_PATH_PATTERN, MODULE_URL_SCHEME_PATTERN, MAX_SWEEP_INTERVAL_MS, MIN_SWEEP_INTERVAL_MS, STATISTICS_BROADCAST_INTERVAL_MS, HEAP_PRESSURE_WARNING_FRACTION, MAX_SUGGEST_LIMIT, FOREIGN_STATS_TTL_MS, DEFAULT_SUGGEST_LIMIT, DEFAULT_LIMIT, DEFAULT_OFFSET, MIN_DOCUMENTS_FOR_SEGMENTS, HEAP_PRESSURE_REARM_FRACTION } from './chunk-4RD3AFSB.mjs';
11
- import { singleFoldTable, appendFoldedCodePoint, EARLIER_RELEASE_MIN_M, MIN_M, MAX_M, compareCodePoints, toReducedSortValue, compareComparableValues, defaultSortMode, withUnpairedSurrogatesReplaced, holdsUnpairedSurrogate, readSortField, truncateSortString, exceedsCodePoints, toComparableSortValue, SORT_VALUE_MAX_CODE_POINTS, compareComparableKeys, sortModeOf, isSortMode, SORT_MODES, compareSortValues, codePointCount } from './chunk-NXQG7DRA.mjs';
12
+ import { singleFoldTable, appendFoldedCodePoint, compareCodePoints, toReducedSortValue, compareComparableValues, defaultSortMode, withUnpairedSurrogatesReplaced, holdsUnpairedSurrogate, readSortField, truncateSortString, toComparableSortValue, exceedsCodePoints, SORT_VALUE_MAX_CODE_POINTS, compareComparableKeys, sortModeOf, isSortMode, SORT_MODES, compareSortValues, codePointCount } from './chunk-NXQG7DRA.mjs';
12
13
  import { BM25_DISPLAYED_NAME_LENGTH, DEFAULT_FUZZY_PREFIX_LENGTH, MAX_CURSOR_LENGTH, MAX_CURSOR_ANCHOR_CODE_POINTS, MAX_SORT_FIELDS, MAX_SORT_FIELD_NAME_LENGTH, RESULT_WINDOW, DEFAULT_LINEAR_ALPHA, MIN_LINEAR_ALPHA, MAX_LINEAR_ALPHA, DEFAULT_RANK_CONSTANT, MIN_RANK_CONSTANT, DEFAULT_PAGE_SIZE, DEFAULT_MAX_PER_GROUP, PREFIX_MAX_EXPANSIONS, MAX_TOLERANCE, MAX_PREFIX_LENGTH } from './chunk-WXLBZJMT.mjs';
13
14
  import { ErrorCodes, NarsilError, createNarsilError } from './chunk-SRMZXJSL.mjs';
14
15
  import { Decoder, decode, encode } from '@msgpack/msgpack';
@@ -934,488 +935,6 @@ function registerEngineRerankAdapter(core, name, adapter) {
934
935
  core.rerankAdapters.set(name, adapter);
935
936
  }
936
937
 
937
- // src/geo/coordinates.ts
938
- function isLatitude(value) {
939
- return value >= -MAX_LATITUDE_DEGREES && value <= MAX_LATITUDE_DEGREES;
940
- }
941
- function isLongitude(value) {
942
- return value >= -MAX_LONGITUDE_DEGREES && value <= MAX_LONGITUDE_DEGREES;
943
- }
944
-
945
- // src/schema/validator/field-values.ts
946
- function validateGeopoint(path, value) {
947
- if (!isPlainObject(value)) {
948
- throw new NarsilError(
949
- ErrorCodes.SCHEMA_INVALID_GEOPOINT,
950
- `Field "${path}" expected a geopoint object with lat and lon`,
951
- {
952
- field: path,
953
- received: Array.isArray(value) ? "array" : typeof value
954
- }
955
- );
956
- }
957
- if (typeof value.lat !== "number" || typeof value.lon !== "number" || Number.isNaN(value.lat) || Number.isNaN(value.lon)) {
958
- throw new NarsilError(ErrorCodes.SCHEMA_INVALID_GEOPOINT, `Field "${path}" geopoint requires numeric lat and lon`, {
959
- field: path,
960
- lat: Number.isNaN(value.lat) ? "NaN" : typeof value.lat,
961
- lon: Number.isNaN(value.lon) ? "NaN" : typeof value.lon
962
- });
963
- }
964
- if (!isLatitude(value.lat)) {
965
- throw new NarsilError(
966
- ErrorCodes.SCHEMA_INVALID_GEOPOINT,
967
- `Field "${path}" geopoint lat must be between -90 and 90`,
968
- {
969
- field: path,
970
- lat: value.lat
971
- }
972
- );
973
- }
974
- if (!isLongitude(value.lon)) {
975
- throw new NarsilError(
976
- ErrorCodes.SCHEMA_INVALID_GEOPOINT,
977
- `Field "${path}" geopoint lon must be between -180 and 180`,
978
- {
979
- field: path,
980
- lon: value.lon
981
- }
982
- );
983
- }
984
- }
985
- function validateVector(path, value, expectedDimension) {
986
- const isArray = Array.isArray(value);
987
- const isFloat32 = value instanceof Float32Array;
988
- if (!isArray && !isFloat32) {
989
- throw new NarsilError(
990
- ErrorCodes.DOC_VALIDATION_FAILED,
991
- `Field "${path}" expected a vector (Array or Float32Array)`,
992
- { field: path, received: typeof value }
993
- );
994
- }
995
- const arr = value;
996
- if (arr.length !== expectedDimension) {
997
- throw new NarsilError(
998
- ErrorCodes.DOC_VALIDATION_FAILED,
999
- `Field "${path}" expected vector of dimension ${expectedDimension}, got ${arr.length}`,
1000
- { field: path, expected: expectedDimension, received: arr.length }
1001
- );
1002
- }
1003
- for (let i = 0; i < arr.length; i++) {
1004
- if (typeof arr[i] !== "number" || !Number.isFinite(arr[i])) {
1005
- throw new NarsilError(
1006
- ErrorCodes.DOC_VALIDATION_FAILED,
1007
- `Field "${path}" vector element at index ${i} is not a valid number`,
1008
- { field: path, index: i, value: arr[i] }
1009
- );
1010
- }
1011
- }
1012
- }
1013
- function validateTypedArray(path, value, elementType) {
1014
- if (!Array.isArray(value)) {
1015
- throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, `Field "${path}" expected an array`, {
1016
- field: path,
1017
- received: typeof value
1018
- });
1019
- }
1020
- for (let i = 0; i < value.length; i++) {
1021
- const el = value[i];
1022
- if (typeof el !== elementType) {
1023
- throw new NarsilError(
1024
- ErrorCodes.DOC_VALIDATION_FAILED,
1025
- `Field "${path}" array element at index ${i} expected ${elementType}, got ${typeof el}`,
1026
- { field: path, index: i, expected: elementType, received: typeof el }
1027
- );
1028
- }
1029
- if (elementType === "number" && !Number.isFinite(el)) {
1030
- throw new NarsilError(
1031
- ErrorCodes.DOC_VALIDATION_FAILED,
1032
- `Field "${path}" array element at index ${i} is ${String(el)}, while a number field holds finite numbers alone`,
1033
- { field: path, index: i }
1034
- );
1035
- }
1036
- }
1037
- }
1038
- function validatePatternValue(path, value, patternValueLimit, index) {
1039
- if (!exceedsCodePoints(value, patternValueLimit)) return;
1040
- const subject = index === void 0 ? `The value of field "${path}"` : `Element ${index} of field "${path}"`;
1041
- throw new NarsilError(
1042
- ErrorCodes.DOC_VALIDATION_FAILED,
1043
- `${subject} is longer than ${patternValueLimit} code points, which is the pattern value limit of this index`,
1044
- { field: path, limit: patternValueLimit, ...index === void 0 ? {} : { index } }
1045
- );
1046
- }
1047
- function validateFieldValue(path, value, type, patternValueLimit) {
1048
- switch (type.base) {
1049
- case "string":
1050
- case "verbatim":
1051
- if (typeof value !== "string") {
1052
- throw new NarsilError(
1053
- ErrorCodes.DOC_VALIDATION_FAILED,
1054
- `Field "${path}" expected string, got ${typeof value}`,
1055
- {
1056
- field: path,
1057
- expected: "string",
1058
- received: typeof value
1059
- }
1060
- );
1061
- }
1062
- if (type.pattern) validatePatternValue(path, value, patternValueLimit);
1063
- return;
1064
- case "number":
1065
- if (typeof value !== "number" || !Number.isFinite(value)) {
1066
- throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, `Field "${path}" expected a finite number`, {
1067
- field: path,
1068
- expected: "number",
1069
- received: typeof value === "number" ? String(value) : typeof value
1070
- });
1071
- }
1072
- return;
1073
- case "boolean":
1074
- if (typeof value !== "boolean") {
1075
- throw new NarsilError(
1076
- ErrorCodes.DOC_VALIDATION_FAILED,
1077
- `Field "${path}" expected boolean, got ${typeof value}`,
1078
- {
1079
- field: path,
1080
- expected: "boolean",
1081
- received: typeof value
1082
- }
1083
- );
1084
- }
1085
- return;
1086
- case "enum":
1087
- if (typeof value !== "string") {
1088
- throw new NarsilError(
1089
- ErrorCodes.DOC_VALIDATION_FAILED,
1090
- `Field "${path}" expected enum (string), got ${typeof value}`,
1091
- {
1092
- field: path,
1093
- expected: "enum",
1094
- received: typeof value
1095
- }
1096
- );
1097
- }
1098
- return;
1099
- case "geopoint":
1100
- validateGeopoint(path, value);
1101
- return;
1102
- case "string[]":
1103
- case "verbatim[]":
1104
- validateTypedArray(path, value, "string");
1105
- if (type.pattern) {
1106
- const elements = value;
1107
- for (let i = 0; i < elements.length; i++) validatePatternValue(path, elements[i], patternValueLimit, i);
1108
- }
1109
- return;
1110
- case "number[]":
1111
- validateTypedArray(path, value, "number");
1112
- return;
1113
- case "boolean[]":
1114
- validateTypedArray(path, value, "boolean");
1115
- return;
1116
- case "enum[]":
1117
- validateTypedArray(path, value, "string");
1118
- return;
1119
- case "vector":
1120
- validateVector(path, value, type.dimension);
1121
- return;
1122
- }
1123
- }
1124
-
1125
- // src/schema/validator/storable.ts
1126
- var RESERVED_OBJECT_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
1127
- var UNPAIRED_SURROGATE_REASON = "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";
1128
- function reject(path, reason) {
1129
- throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, `Field "${path === "" ? "(document)" : path}" ${reason}`, {
1130
- field: path
1131
- });
1132
- }
1133
- function isPlainObject2(value) {
1134
- const proto = Object.getPrototypeOf(value);
1135
- return proto === Object.prototype || proto === null;
1136
- }
1137
- function walkStorable(value, path, depth, ancestors, skip) {
1138
- if (value === null || value === void 0) return;
1139
- const kind = typeof value;
1140
- if (kind === "string") {
1141
- if (holdsUnpairedSurrogate(value)) reject(path, UNPAIRED_SURROGATE_REASON);
1142
- return;
1143
- }
1144
- if (kind === "boolean" || kind === "number") return;
1145
- if (kind === "bigint" || kind === "symbol" || kind === "function") {
1146
- reject(path, `holds a ${kind}, which cannot be stored or recovered`);
1147
- }
1148
- const container = value;
1149
- if (container instanceof Date) {
1150
- if (Number.isNaN(container.getTime())) reject(path, "holds an invalid date, which the engine cannot store");
1151
- return;
1152
- }
1153
- if (container instanceof Uint8Array) return;
1154
- const isArray = Array.isArray(container);
1155
- if (!isArray && !isPlainObject2(container)) {
1156
- reject(
1157
- path,
1158
- "holds a value that does not survive storage; use plain objects, arrays, strings, numbers, booleans, dates, or Uint8Array bytes"
1159
- );
1160
- }
1161
- if (depth >= MAX_DOCUMENT_NESTING_DEPTH) {
1162
- reject(path, `nests deeper than ${MAX_DOCUMENT_NESTING_DEPTH} levels`);
1163
- }
1164
- if (ancestors.has(container)) {
1165
- reject(path, "refers back to one of its own ancestors");
1166
- }
1167
- ancestors.add(container);
1168
- if (isArray) {
1169
- const items = container;
1170
- for (let i = 0; i < items.length; i++) {
1171
- walkStorable(items[i], `${path}[${i}]`, depth + 1, ancestors, skip);
1172
- }
1173
- } else {
1174
- const record = container;
1175
- for (const key of Object.keys(record)) {
1176
- const keyPath = path === "" ? key : `${path}.${key}`;
1177
- if (RESERVED_OBJECT_KEYS.has(key)) {
1178
- reject(keyPath, "uses a reserved object key");
1179
- }
1180
- if (holdsUnpairedSurrogate(key)) reject(keyPath, `has a name that ${UNPAIRED_SURROGATE_REASON}`);
1181
- if (skip.has(keyPath)) continue;
1182
- walkStorable(record[key], keyPath, depth + 1, ancestors, skip);
1183
- }
1184
- }
1185
- ancestors.delete(container);
1186
- }
1187
- function assertStorableDocument(document, skipFieldPaths) {
1188
- walkStorable(document, "", 0, /* @__PURE__ */ new Set(), skipFieldPaths ?? /* @__PURE__ */ new Set());
1189
- }
1190
-
1191
- // src/schema/validator/document.ts
1192
- var vectorPathCache = /* @__PURE__ */ new WeakMap();
1193
- function vectorFieldPaths(schema) {
1194
- let paths = vectorPathCache.get(schema);
1195
- if (paths !== void 0) return paths;
1196
- paths = /* @__PURE__ */ new Set();
1197
- const collect = (level, prefix) => {
1198
- for (const [field, type] of Object.entries(level)) {
1199
- const path = prefix === "" ? field : `${prefix}.${field}`;
1200
- if (typeof type === "string" && VECTOR_PATTERN.test(type)) {
1201
- paths?.add(path);
1202
- } else if (isPlainObject(type)) {
1203
- collect(type, path);
1204
- }
1205
- }
1206
- };
1207
- collect(schema, "");
1208
- vectorPathCache.set(schema, paths);
1209
- return paths;
1210
- }
1211
- var parsedLevelCache = /* @__PURE__ */ new WeakMap();
1212
- function parsedLevel(schema, prefix) {
1213
- let entries = parsedLevelCache.get(schema);
1214
- if (entries !== void 0) return entries;
1215
- entries = Object.entries(schema).map(([field, type]) => {
1216
- if (isPlainObject(type)) return { field, nested: type, type: null };
1217
- const path = prefix ? `${prefix}.${field}` : field;
1218
- return { field, nested: null, type: parseFieldType(type, path) };
1219
- });
1220
- parsedLevelCache.set(schema, entries);
1221
- return entries;
1222
- }
1223
- function validateDocumentFields(doc, schema, prefix, patternValueLimit) {
1224
- for (const { field, nested, type } of parsedLevel(schema, prefix)) {
1225
- const value = doc[field];
1226
- if (value === void 0 || value === null) continue;
1227
- const path = prefix ? `${prefix}.${field}` : field;
1228
- if (nested !== null) {
1229
- if (!isPlainObject(value)) {
1230
- throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, `Field "${path}" expected an object`, {
1231
- field: path,
1232
- received: Array.isArray(value) ? "array" : typeof value
1233
- });
1234
- }
1235
- validateDocumentFields(value, nested, path, patternValueLimit);
1236
- continue;
1237
- }
1238
- if (type !== null) validateFieldValue(path, value, type, patternValueLimit);
1239
- }
1240
- }
1241
- function validateDocument(document, schema, patternValueLimit = DEFAULT_PATTERN_VALUE_LIMIT) {
1242
- if (!isPlainObject(document)) {
1243
- throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, "Document must be a plain object", {
1244
- received: typeof document
1245
- });
1246
- }
1247
- requireIdFieldKey(document);
1248
- assertStorableDocument(document, vectorFieldPaths(schema));
1249
- validateDocumentFields(document, schema, "", patternValueLimit);
1250
- }
1251
- function requireIdFieldKey(document) {
1252
- if (!Object.hasOwn(document, "id")) return;
1253
- const id = document.id;
1254
- if (typeof id === "string" && id.length > 0) return;
1255
- throw new NarsilError(
1256
- ErrorCodes.DOC_VALIDATION_FAILED,
1257
- `Field "id" holds ${typeof id === "string" ? "an empty string" : id === null ? "null" : `a ${typeof id}`}, while the engine stores a document under its id field, so that field must hold a non-empty string`,
1258
- { field: "id", received: id === null ? "null" : typeof id }
1259
- );
1260
- }
1261
- function collectExtraFields(doc, schema, prefix, extras) {
1262
- for (const key of Object.keys(doc)) {
1263
- if (key === "id") continue;
1264
- const path = prefix ? `${prefix}.${key}` : key;
1265
- if (!Object.hasOwn(schema, key)) {
1266
- extras.push(path);
1267
- continue;
1268
- }
1269
- const schemaType = schema[key];
1270
- if (isPlainObject(schemaType) && isPlainObject(doc[key])) {
1271
- collectExtraFields(doc[key], schemaType, path, extras);
1272
- }
1273
- }
1274
- }
1275
- function validateDocumentStrict(document, schema) {
1276
- const extras = [];
1277
- collectExtraFields(document, schema, "", extras);
1278
- if (extras.length > 0) {
1279
- throw new NarsilError(
1280
- ErrorCodes.DOC_VALIDATION_FAILED,
1281
- `Document contains fields not defined in schema: ${extras.join(", ")}`,
1282
- { extraFields: extras }
1283
- );
1284
- }
1285
- }
1286
- function resolveNestedValue(document, path) {
1287
- if (!path.includes(".")) return document[path];
1288
- const segments = path.split(".");
1289
- let current = document;
1290
- for (const segment of segments) {
1291
- if (current === null || current === void 0 || typeof current !== "object") return void 0;
1292
- current = current[segment];
1293
- }
1294
- return current;
1295
- }
1296
- function validateRequiredFields(document, required) {
1297
- if (required.length === 0) return;
1298
- for (const field of required) {
1299
- const value = resolveNestedValue(document, field);
1300
- if (value === void 0 || value === null) {
1301
- throw new NarsilError(ErrorCodes.DOC_MISSING_REQUIRED_FIELD, `Document is missing required field "${field}"`, {
1302
- field
1303
- });
1304
- }
1305
- }
1306
- }
1307
-
1308
- // src/schema/validator/document-size.ts
1309
- var LARGEST_HEADER_BYTES = 5;
1310
- var LARGEST_NUMBER_BYTES = 9;
1311
- var LARGEST_TIMESTAMP_BYTES = 15;
1312
- var LARGEST_UTF8_BYTES_PER_UNIT = 3;
1313
- function upperBoundBytes(value, budget, depth) {
1314
- if (value === null || value === void 0 || typeof value === "boolean") return 1;
1315
- if (typeof value === "number") return LARGEST_NUMBER_BYTES;
1316
- if (typeof value === "string") return LARGEST_HEADER_BYTES + value.length * LARGEST_UTF8_BYTES_PER_UNIT;
1317
- if (value instanceof Date) return LARGEST_TIMESTAMP_BYTES;
1318
- if (ArrayBuffer.isView(value)) return LARGEST_HEADER_BYTES + value.byteLength;
1319
- if (typeof value !== "object" || depth > MAX_DOCUMENT_NESTING_DEPTH) return LARGEST_NUMBER_BYTES;
1320
- let total = LARGEST_HEADER_BYTES;
1321
- if (Array.isArray(value)) {
1322
- for (const item of value) {
1323
- total += upperBoundBytes(item, budget - total, depth + 1);
1324
- if (total > budget) return total;
1325
- }
1326
- return total;
1327
- }
1328
- const record = value;
1329
- for (const key of Object.keys(record)) {
1330
- total += LARGEST_HEADER_BYTES + key.length * LARGEST_UTF8_BYTES_PER_UNIT;
1331
- total += upperBoundBytes(record[key], budget - total, depth + 1);
1332
- if (total > budget) return total;
1333
- }
1334
- return total;
1335
- }
1336
- function messagePackUpperBoundBytes(value) {
1337
- return upperBoundBytes(value, Number.POSITIVE_INFINITY, 0);
1338
- }
1339
- function encodedBytesOf(document) {
1340
- try {
1341
- return encodeDocument(document).byteLength;
1342
- } catch {
1343
- return null;
1344
- }
1345
- }
1346
- function requireDocumentWithinSizeLimit(document) {
1347
- if (upperBoundBytes(document, MAX_DOCUMENT_BYTES, 0) <= MAX_DOCUMENT_BYTES) return;
1348
- const encodedBytes = encodedBytesOf(document);
1349
- if (encodedBytes === null || encodedBytes <= MAX_DOCUMENT_BYTES) return;
1350
- throw new NarsilError(
1351
- ErrorCodes.DOC_VALIDATION_FAILED,
1352
- `The document takes ${encodedBytes} bytes as MessagePack, vector values included, but a document may take at most ${MAX_DOCUMENT_BYTES}`,
1353
- { bytes: encodedBytes, maximum: MAX_DOCUMENT_BYTES }
1354
- );
1355
- }
1356
-
1357
- // src/schema/validator/vector-promotion.ts
1358
- var QUANTIZATION_MODES = /* @__PURE__ */ new Set(["osq8", "osq4", "osq2", "osq1", "none"]);
1359
- var STORAGE_MODES = /* @__PURE__ */ new Set(["memory", "disk"]);
1360
- function fail(message, details) {
1361
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, message, details);
1362
- }
1363
- function isPositiveInteger(value) {
1364
- return Number.isInteger(value) && value >= 1;
1365
- }
1366
- function isQuantizationMode(value) {
1367
- return typeof value === "string" && QUANTIZATION_MODES.has(value);
1368
- }
1369
- function isStorageMode(value) {
1370
- return typeof value === "string" && STORAGE_MODES.has(value);
1371
- }
1372
- function validateVectorStorage(config, filesystemDurability) {
1373
- if (config?.storage === "disk" && !filesystemDurability) {
1374
- fail("vectorPromotion.storage 'disk' needs filesystem durability, because a checkpoint file holds the vectors", {
1375
- storage: config.storage
1376
- });
1377
- }
1378
- }
1379
- function validateTextStorage(textStorage, filesystemDurability) {
1380
- if (textStorage === void 0 || textStorage === "memory" || textStorage === "disk" && filesystemDurability) return;
1381
- fail("textStorage must be 'memory', or 'disk' with filesystem durability", { textStorage });
1382
- }
1383
- function raiseEarlierReleaseGraphSetting(config) {
1384
- if (typeof config !== "object" || config === null) return config;
1385
- const hnsw = config.hnswConfig;
1386
- if (typeof hnsw !== "object" || hnsw === null) return config;
1387
- if (hnsw.m !== EARLIER_RELEASE_MIN_M) return config;
1388
- return { ...config, hnswConfig: { ...hnsw, m: MIN_M } };
1389
- }
1390
- function validateVectorPromotion(config) {
1391
- if (config === void 0) return;
1392
- if (config.threshold !== void 0 && !isPositiveInteger(config.threshold)) {
1393
- fail("vectorPromotion.threshold must be a positive integer", { threshold: config.threshold });
1394
- }
1395
- const quantization = config.quantization;
1396
- if (quantization !== void 0 && !isQuantizationMode(quantization)) {
1397
- fail("vectorPromotion.quantization must be 'osq8', 'osq4', 'osq2', 'osq1', or 'none'", { quantization });
1398
- }
1399
- const storage = config.storage;
1400
- if (storage !== void 0 && !isStorageMode(storage)) {
1401
- fail("vectorPromotion.storage must be 'memory' or 'disk'", { storage });
1402
- }
1403
- const hnsw = config.hnswConfig;
1404
- if (hnsw === void 0) return;
1405
- if (hnsw.m !== void 0 && (!Number.isInteger(hnsw.m) || hnsw.m < MIN_M || hnsw.m > MAX_M)) {
1406
- fail(`vectorPromotion.hnswConfig.m must be a whole number from ${MIN_M} to ${MAX_M}`, { m: hnsw.m });
1407
- }
1408
- if (hnsw.efConstruction !== void 0 && !isPositiveInteger(hnsw.efConstruction)) {
1409
- fail("vectorPromotion.hnswConfig.efConstruction must be a positive integer", {
1410
- efConstruction: hnsw.efConstruction
1411
- });
1412
- }
1413
- const metric = hnsw.metric;
1414
- if (metric !== void 0 && metric !== "cosine" && metric !== "dotProduct" && metric !== "euclidean") {
1415
- fail("vectorPromotion.hnswConfig.metric must be 'cosine', 'dotProduct', or 'euclidean'", { metric });
1416
- }
1417
- }
1418
-
1419
938
  // src/schema/embedding-validator.ts
1420
939
  var VECTOR_DIMENSION_PATTERN = /^vector\[(\d+)]$/;
1421
940
  function validateEmbeddingConfig(embeddingConfig, schema, instanceAdapter) {
@@ -1533,68 +1052,6 @@ function validateRequiredFieldsInSchema(required, schema) {
1533
1052
  }
1534
1053
  }
1535
1054
 
1536
- // src/core/partition/utils.ts
1537
- function getOrCreateFieldNameIndex(table, fieldName) {
1538
- const existing = table.indexMap.get(fieldName);
1539
- if (existing !== void 0) return existing;
1540
- const idx = table.names.length;
1541
- table.names.push(fieldName);
1542
- table.indexMap.set(fieldName, idx);
1543
- return idx;
1544
- }
1545
- var VECTOR_PATTERN2 = /^vector\[(\d+)]$/;
1546
- function getNestedValue(obj, path) {
1547
- const parts = path.split(".");
1548
- let current = obj;
1549
- for (let i = 0; i < parts.length; i++) {
1550
- if (current === null || current === void 0 || typeof current !== "object") return void 0;
1551
- if (!Object.hasOwn(current, parts[i])) return void 0;
1552
- current = current[parts[i]];
1553
- }
1554
- return current;
1555
- }
1556
- function stringArraysEqual(a, b) {
1557
- if (a === b) return true;
1558
- if (!a || !b) return false;
1559
- if (a.length !== b.length) return false;
1560
- for (let i = 0; i < a.length; i++) {
1561
- if (a[i] !== b[i]) return false;
1562
- }
1563
- return true;
1564
- }
1565
- function textFieldsChanged(oldDoc, newDoc, fields) {
1566
- for (const { path, base } of fields) {
1567
- if (!isWordIndexedBase(base)) continue;
1568
- const oldVal = getNestedValue(oldDoc, path);
1569
- const newVal = getNestedValue(newDoc, path);
1570
- if (base === "string") {
1571
- if (oldVal !== newVal) return true;
1572
- } else {
1573
- if (!stringArraysEqual(oldVal, newVal)) return true;
1574
- }
1575
- }
1576
- return false;
1577
- }
1578
- function parseVectorDimension(fieldType) {
1579
- const match = VECTOR_PATTERN2.exec(fieldType);
1580
- return match ? Number.parseInt(match[1], 10) : null;
1581
- }
1582
- function tokenizeOptions(options) {
1583
- return {
1584
- stem: true,
1585
- removeStopWords: true,
1586
- collectSurfaces: options?.collectSurfaces === true,
1587
- stopWordOverride: options?.stopWordOverride,
1588
- customTokenizer: options?.customTokenizer
1589
- };
1590
- }
1591
- function getFlatSchema(state, schema) {
1592
- if (state.lastSchemaRef === schema && state.flatSchemaCache) return state.flatSchemaCache;
1593
- state.flatSchemaCache = flattenSchema(schema);
1594
- state.lastSchemaRef = schema;
1595
- return state.flatSchemaCache;
1596
- }
1597
-
1598
1055
  // src/core/document-copy.browser.ts
1599
1056
  function copyStoredValue(value) {
1600
1057
  return structuredClone(value);
@@ -3445,7 +2902,7 @@ function codeLoader(importCode, typeName) {
3445
2902
  }
3446
2903
 
3447
2904
  // src/geo/geo-code.ts
3448
- var geoCode = codeLoader(() => import('./geo-index-HHWGMNIS.mjs'), "geopoint");
2905
+ var geoCode = codeLoader(() => import('./geo-index-OTV7VPIR.mjs'), "geopoint");
3449
2906
  var loadGeoCodeFor = geoCode.loadFor;
3450
2907
  function createLoadedGeoIndex() {
3451
2908
  return geoCode.require().createGeoIndex(PENDING_REMOVAL_MERGE_FLOOR, PENDING_REMOVAL_MERGE_DIVISOR);
@@ -13692,7 +13149,7 @@ async function attachSegments(entry, action) {
13692
13149
  growPartitionsTo(entry.manager, segment.partitionId);
13693
13150
  const surfaceForms = segment.survivingSurfaceForms;
13694
13151
  const spellings = surfaceForms === void 0 ? void 0 : NO_REMOVED_SPELLINGS;
13695
- const frozen = isPagedSnapshot(segment.snapshot) ? (await import('./module-NIYMEA5R.mjs')).createPagedFrozenSegment(segment.snapshot) : createSharedFrozenSegment(segment.snapshot, surfaceForms);
13152
+ const frozen = isPagedSnapshot(segment.snapshot) ? (await import('./module-NDSQLPMQ.mjs')).createPagedFrozenSegment(segment.snapshot) : createSharedFrozenSegment(segment.snapshot, surfaceForms);
13696
13153
  for (const docId of segment.tombstonedDocIds ?? []) frozen.tombstoneDocument(docId, spellings);
13697
13154
  entry.manager.attachFrozenSegment(segment.partitionId, frozen);
13698
13155
  }
@@ -13747,7 +13204,7 @@ function runSegmentAction(entry, action) {
13747
13204
  case "attachSegments":
13748
13205
  return attachSegments(entry, action);
13749
13206
  case "adoptDiskSegments":
13750
- return import('./module-NIYMEA5R.mjs').then((code) => code.adoptSegmentsOnWorker(entry.manager, action));
13207
+ return import('./module-NDSQLPMQ.mjs').then((code) => code.adoptSegmentsOnWorker(entry.manager, action));
13751
13208
  case "compactSegments": {
13752
13209
  const partition = requireComposite(entry, action.indexName, action.partitionId, "compact");
13753
13210
  return mergeFrozenSegments(
@@ -14038,16 +13495,19 @@ function createDirectExecutor(options) {
14038
13495
  case "insert": {
14039
13496
  const entry = requireIndex(action.indexName);
14040
13497
  entry.manager.insert(action.docId, action.document, action.skipClone ? { skipClone: true } : void 0);
13498
+ options?.onDocumentWrite?.(action);
14041
13499
  return void 0;
14042
13500
  }
14043
13501
  case "remove": {
14044
13502
  const entry = requireIndex(action.indexName);
14045
13503
  entry.manager.remove(action.docId, action.removedSpellings);
13504
+ options?.onDocumentWrite?.(action);
14046
13505
  return void 0;
14047
13506
  }
14048
13507
  case "update": {
14049
13508
  const entry = requireIndex(action.indexName);
14050
13509
  entry.manager.update(action.docId, action.document, void 0, action.removedSpellings);
13510
+ options?.onDocumentWrite?.(action);
14051
13511
  return void 0;
14052
13512
  }
14053
13513
  case "query":
@@ -14094,6 +13554,7 @@ function createDirectExecutor(options) {
14094
13554
  entry.manager.resetVectorIndexes(vectorIndexesFor(action.indexName, entry.config));
14095
13555
  entry.vectorIndexes = entry.manager.getVectorIndexes();
14096
13556
  entry.vectorCopies = createHeldVectorCopies();
13557
+ options?.onDocumentWrite?.(action);
14097
13558
  return void 0;
14098
13559
  }
14099
13560
  case "serialize": {
@@ -14170,7 +13631,7 @@ var TEXT_REBUILD_SWITCH_BACKLOG_DOCUMENTS = 1e3;
14170
13631
  // src/partitioning/rewrite-spill-of.ts
14171
13632
  async function rewriteSpillOf(storage, manager, target) {
14172
13633
  if (storage === void 0 || (target?.config ?? manager.config).textStorage !== "disk") return null;
14173
- const { openRewriteSpill } = await import('./module-NIYMEA5R.mjs');
13634
+ const { openRewriteSpill } = await import('./module-NDSQLPMQ.mjs');
14174
13635
  return openRewriteSpill(storage, manager, target);
14175
13636
  }
14176
13637
 
@@ -14778,7 +14239,7 @@ async function createIndexFromMetadata(deps, metadata, loadData) {
14778
14239
  const existing = deps.indexRegistry.get(metadata.indexName);
14779
14240
  if (existing !== void 0) {
14780
14241
  if ((metadata.analysisGeneration ?? 0) > existing.analysisGeneration) {
14781
- const { adoptSavedAnalysis } = await import('./analysis-change-435CUEPZ.mjs');
14242
+ const { adoptSavedAnalysis } = await import('./analysis-change-ZKGJFENM.mjs');
14782
14243
  adoptSavedAnalysis(deps.executor.getManager(metadata.indexName), existing, metadata);
14783
14244
  }
14784
14245
  if (loadData && deps.executor.getManager(metadata.indexName) === void 0) {
@@ -15798,12 +15259,12 @@ function validateVectorDimensions(vectors, vecIndexes) {
15798
15259
  }
15799
15260
  }
15800
15261
  }
15801
- function prepareDocumentVectors(document, vectorFieldPaths2) {
15802
- if (vectorFieldPaths2.size === 0) {
15262
+ function prepareDocumentVectors(document, vectorFieldPaths) {
15263
+ if (vectorFieldPaths.size === 0) {
15803
15264
  return { partitionDoc: document, extractedVectors: /* @__PURE__ */ new Map() };
15804
15265
  }
15805
15266
  const extractedVectors = /* @__PURE__ */ new Map();
15806
- for (const fieldPath of vectorFieldPaths2) {
15267
+ for (const fieldPath of vectorFieldPaths) {
15807
15268
  const vec = extractVectorFromDoc(document, fieldPath);
15808
15269
  if (vec) {
15809
15270
  extractedVectors.set(fieldPath, vec);
@@ -16017,16 +15478,16 @@ function documentWeight(action) {
16017
15478
  }
16018
15479
  return 1;
16019
15480
  }
15481
+ var NO_VECTOR_FIELDS = /* @__PURE__ */ new Set();
16020
15482
  function vectorFieldPathsOf(state, indexName) {
16021
- const entry = state.indexRegistry.get(indexName);
16022
- if (entry === void 0) return /* @__PURE__ */ new Set();
16023
- return new Set(extractVectorFieldsFromSchema(entry.config.schema).keys());
15483
+ return state.indexRegistry.get(indexName)?.vectorFieldPaths ?? NO_VECTOR_FIELDS;
16024
15484
  }
16025
15485
  function withoutVectors(document, fieldPaths) {
15486
+ if (fieldPaths.size === 0) return document;
16026
15487
  return prepareDocumentVectors(document, fieldPaths).partitionDoc;
16027
15488
  }
16028
15489
  function detachCallerDocuments(state, action) {
16029
- if (!("indexName" in action)) return action;
15490
+ if (action.type !== "insert" && action.type !== "update" && action.type !== "mergeSegments") return action;
16030
15491
  const fieldPaths = vectorFieldPathsOf(state, action.indexName);
16031
15492
  if (action.type === "insert") {
16032
15493
  const stripped = withoutVectors(action.document, fieldPaths);
@@ -16037,17 +15498,14 @@ function detachCallerDocuments(state, action) {
16037
15498
  const stripped = withoutVectors(action.document, fieldPaths);
16038
15499
  return { ...action, document: stripped !== action.document ? stripped : structuredClone(stripped) };
16039
15500
  }
16040
- if (action.type === "mergeSegments") {
16041
- return {
16042
- ...action,
16043
- segments: action.segments.map((segment) => {
16044
- const documents = segment.documents.map((document) => withoutVectors(document, fieldPaths));
16045
- const cloned = action.skipClone === true || fieldPaths.size > 0 ? documents : structuredClone(documents);
16046
- return { ...segment, documents: cloned };
16047
- })
16048
- };
16049
- }
16050
- return action;
15501
+ return {
15502
+ ...action,
15503
+ segments: action.segments.map((segment) => {
15504
+ const documents = segment.documents.map((document) => withoutVectors(document, fieldPaths));
15505
+ const cloned = action.skipClone === true || fieldPaths.size > 0 ? documents : structuredClone(documents);
15506
+ return { ...segment, documents: cloned };
15507
+ })
15508
+ };
16051
15509
  }
16052
15510
  function partitionLedger(state, indexName, partitionId) {
16053
15511
  let byPartition = state.segmentLedger.get(indexName);
@@ -16063,6 +15521,10 @@ function partitionLedger(state, indexName, partitionId) {
16063
15521
  return entries;
16064
15522
  }
16065
15523
  function recordSegmentBroadcast(state, action) {
15524
+ if (action.type === "clear") {
15525
+ state.segmentLedger.delete(action.indexName);
15526
+ return;
15527
+ }
16066
15528
  if (action.type === "attachSegments") {
16067
15529
  for (const segment of action.segments) {
16068
15530
  partitionLedger(state, action.indexName, segment.partitionId).push({
@@ -16146,19 +15608,9 @@ async function replicateToWorkers(state, action) {
16146
15608
  await dispatchToWorkers(state, action);
16147
15609
  return;
16148
15610
  }
16149
- if (!copiesWillReceive(state, action.indexName)) return;
16150
- const detached = detachCallerDocuments(state, action);
16151
- const loading2 = state.copyLoadBuffers.get(action.indexName);
16152
- if (loading2 !== void 0) {
16153
- queueForCopies(state, detached);
16154
- if (loading2.length % LOAD_BUFFER_YIELD_INTERVAL === 0) await yieldToEventLoop2();
16155
- return;
16156
- }
16157
- const queue = state.replicationQueues.get(action.indexName);
16158
- if (queue !== void 0 && queue.pendingDocuments + documentWeight(detached) > MAX_PENDING_REPLICATION_DOCUMENTS) {
16159
- await new Promise((resume) => queue.drainWaiters.push(resume));
16160
- }
16161
- queueForCopies(state, detached);
15611
+ recordMainWrite(state, action);
15612
+ const waiting = replicationRoomWait(state, action.indexName);
15613
+ if (waiting !== null) await waiting;
16162
15614
  }
16163
15615
  function queueForCopies(state, action) {
16164
15616
  if (!("indexName" in action)) return;
@@ -16170,6 +15622,22 @@ function queueForCopies(state, action) {
16170
15622
  if (state.workerPool === null || !state.scaledOutIndexes.has(action.indexName)) return;
16171
15623
  enqueueReplication(state, action.indexName, action);
16172
15624
  }
15625
+ function recordMainWrite(state, action) {
15626
+ if (!("indexName" in action) || !copiesWillReceive(state, action.indexName)) return;
15627
+ queueForCopies(state, detachCallerDocuments(state, action));
15628
+ }
15629
+ function replicationRoomWait(state, indexName) {
15630
+ const loading2 = state.copyLoadBuffers.get(indexName);
15631
+ if (loading2 !== void 0) {
15632
+ const lastYield = state.copyLoadBufferYieldMarks.get(loading2) ?? 0;
15633
+ if (loading2.length - lastYield < LOAD_BUFFER_YIELD_INTERVAL) return null;
15634
+ state.copyLoadBufferYieldMarks.set(loading2, loading2.length);
15635
+ return yieldToEventLoop2();
15636
+ }
15637
+ const queue = state.replicationQueues.get(indexName);
15638
+ if (queue === void 0 || queue.pendingDocuments < MAX_PENDING_REPLICATION_DOCUMENTS) return null;
15639
+ return new Promise((resume) => queue.drainWaiters.push(resume));
15640
+ }
16173
15641
  function settled(queue) {
16174
15642
  return Promise.all([...queue.inFlight, queue.tail]).then(() => void 0);
16175
15643
  }
@@ -16246,6 +15714,7 @@ function freezeLiveTail(state, indexName, manager, partitionId, floor) {
16246
15714
  }
16247
15715
  }
16248
15716
  function flushGrownTails(state, indexName) {
15717
+ if (!state.scaledOutIndexes.has(indexName)) return;
16249
15718
  const manager = state.executor.getManager(indexName);
16250
15719
  if (manager === void 0) return;
16251
15720
  for (let partitionId = 0; partitionId < manager.partitionCount; partitionId++) {
@@ -16268,25 +15737,10 @@ function mainCompositeOf(manager, partitionId) {
16268
15737
  const partition = manager.getPartition(partitionId);
16269
15738
  return isCompositePartition(partition) ? partition : null;
16270
15739
  }
16271
- function holdUnbroadcastSegments(state, indexName, segmentIds) {
16272
- let held = state.unbroadcastSegments.get(indexName);
16273
- if (held === void 0) {
16274
- held = /* @__PURE__ */ new Set();
16275
- state.unbroadcastSegments.set(indexName, held);
16276
- }
16277
- for (const segmentId of segmentIds) held.add(segmentId);
16278
- }
16279
- function releaseUnbroadcastSegments(state, indexName, segmentIds) {
16280
- const held = state.unbroadcastSegments.get(indexName);
16281
- if (held === void 0) return;
16282
- for (const segmentId of segmentIds) held.delete(segmentId);
16283
- if (held.size === 0) state.unbroadcastSegments.delete(indexName);
16284
- }
16285
15740
  function candidateSegmentIds(state, indexName, manager, partitionId, policy) {
16286
- const unbroadcast = state.unbroadcastSegments.get(indexName);
16287
15741
  const composite = mainCompositeOf(manager, partitionId);
16288
15742
  if (composite !== null) {
16289
- const sizes = composite.frozenSegmentSizes().filter((size) => unbroadcast === void 0 || !unbroadcast.has(size.segmentId)).map((size) => ({ segmentId: size.segmentId, documentCount: size.liveDocumentCount }));
15743
+ const sizes = composite.frozenSegmentSizes().map((size) => ({ segmentId: size.segmentId, documentCount: size.liveDocumentCount }));
16290
15744
  const picks = pickSegmentIds(sizes, policy);
16291
15745
  if (picks !== null) return picks;
16292
15746
  }
@@ -16320,6 +15774,17 @@ async function compactOnWorker(state, indexName, partitionId, segmentIds) {
16320
15774
  lease.release();
16321
15775
  }
16322
15776
  }
15777
+ function ledgerHoldsAll(state, indexName, partitionId, segmentIds) {
15778
+ const entries = state.segmentLedger.get(indexName)?.get(partitionId);
15779
+ if (entries === void 0) return false;
15780
+ const held = new Set(entries.map((entry) => entry.segmentId));
15781
+ return segmentIds.every((segmentId) => held.has(segmentId));
15782
+ }
15783
+ function segmentsStillHeld(state, indexName, manager, partitionId, segmentIds, mergedOnMain) {
15784
+ if (state.executor.getManager(indexName) !== manager) return false;
15785
+ if (mergedOnMain === null) return ledgerHoldsAll(state, indexName, partitionId, segmentIds);
15786
+ return mainCompositeOf(manager, partitionId) === mergedOnMain && mainHoldsAll(mergedOnMain, segmentIds);
15787
+ }
16323
15788
  function forgetLedgerSegments(state, indexName, partitionId, segmentIds) {
16324
15789
  const entries = state.segmentLedger.get(indexName)?.get(partitionId);
16325
15790
  if (entries === void 0) return;
@@ -16345,8 +15810,10 @@ async function compactPartitionSegments(state, indexName, manager, partitionId,
16345
15810
  if (!mainCanMerge) forgetLedgerSegments(state, indexName, partitionId, segmentIds);
16346
15811
  return false;
16347
15812
  }
16348
- const removedSpellings = mainCanMerge && composite !== null ? composite.swapFrozenSegments(segmentIds, createSharedFrozenSegment(snapshot)) : void 0;
16349
- await replicateToWorkers(state, {
15813
+ const mergedOnMain = mainCanMerge ? composite : null;
15814
+ if (!segmentsStillHeld(state, indexName, manager, partitionId, segmentIds, mergedOnMain)) return false;
15815
+ const removedSpellings = mergedOnMain?.swapFrozenSegments(segmentIds, createSharedFrozenSegment(snapshot));
15816
+ recordMainWrite(state, {
16350
15817
  type: "swapSegments",
16351
15818
  indexName,
16352
15819
  partitionId,
@@ -16388,19 +15855,34 @@ function maybeCompactSegments(state, indexName, policy = "ingest") {
16388
15855
  });
16389
15856
  state.compactionsInFlight.set(indexName, run);
16390
15857
  }
16391
- function scheduleIdleMerge(state, indexName) {
16392
- cancelIdleMerge(state, indexName);
15858
+ function armIdleMerge(state, indexName, dueAt, delayMs) {
16393
15859
  const timer = setTimeout(() => {
15860
+ const pending = state.idleMergeTimers.get(indexName);
15861
+ if (pending === void 0 || pending.timer !== timer) return;
15862
+ const remainingMs = pending.dueAt - Date.now();
15863
+ if (remainingMs > 0) {
15864
+ armIdleMerge(state, indexName, pending.dueAt, remainingMs);
15865
+ return;
15866
+ }
16394
15867
  state.idleMergeTimers.delete(indexName);
16395
15868
  maybeCompactSegments(state, indexName, "idle");
16396
- }, IDLE_MERGE_DELAY_MS);
15869
+ }, delayMs);
16397
15870
  if (typeof timer.unref === "function") timer.unref();
16398
- state.idleMergeTimers.set(indexName, timer);
15871
+ state.idleMergeTimers.set(indexName, { timer, dueAt });
15872
+ }
15873
+ function scheduleIdleMerge(state, indexName) {
15874
+ const dueAt = Date.now() + IDLE_MERGE_DELAY_MS;
15875
+ const pending = state.idleMergeTimers.get(indexName);
15876
+ if (pending !== void 0) {
15877
+ pending.dueAt = dueAt;
15878
+ return;
15879
+ }
15880
+ armIdleMerge(state, indexName, dueAt, IDLE_MERGE_DELAY_MS);
16399
15881
  }
16400
15882
  function cancelIdleMerge(state, indexName) {
16401
- const timer = state.idleMergeTimers.get(indexName);
16402
- if (timer === void 0) return;
16403
- clearTimeout(timer);
15883
+ const pending = state.idleMergeTimers.get(indexName);
15884
+ if (pending === void 0) return;
15885
+ clearTimeout(pending.timer);
16404
15886
  state.idleMergeTimers.delete(indexName);
16405
15887
  }
16406
15888
  async function awaitCompactions(state) {
@@ -16551,10 +16033,10 @@ function createWorkerExecutor(worker, config) {
16551
16033
  }
16552
16034
  const requestId = createRequestId();
16553
16035
  const taggedAction = { ...action, requestId };
16554
- return new Promise((resolve, reject2) => {
16036
+ return new Promise((resolve, reject) => {
16555
16037
  const entry = {
16556
16038
  resolve,
16557
- reject: reject2,
16039
+ reject,
16558
16040
  timeoutId: setTimeout(() => {
16559
16041
  entry.timeoutId = setTimeout(() => declareTimedOut(requestId, entry), 0);
16560
16042
  }, requestTimeout)
@@ -17342,13 +16824,13 @@ function createWorkerOrchestrator(config, executor, indexRegistry, callbacks, ve
17342
16824
  desyncedIndexes: /* @__PURE__ */ new Set(),
17343
16825
  copyReleaseHolds: /* @__PURE__ */ new Map(),
17344
16826
  copyLoadBuffers: /* @__PURE__ */ new Map(),
16827
+ copyLoadBufferYieldMarks: /* @__PURE__ */ new WeakMap(),
17345
16828
  copyTransitions: /* @__PURE__ */ new Map(),
17346
16829
  droppedCopies: /* @__PURE__ */ new Map(),
17347
16830
  lastAccessAt: /* @__PURE__ */ new Map(),
17348
16831
  copyReloadCounts: /* @__PURE__ */ new Map(),
17349
16832
  replicationQueues: /* @__PURE__ */ new Map(),
17350
16833
  segmentLedger: /* @__PURE__ */ new Map(),
17351
- unbroadcastSegments: /* @__PURE__ */ new Map(),
17352
16834
  compactionsInFlight: /* @__PURE__ */ new Map(),
17353
16835
  idleMergeTimers: /* @__PURE__ */ new Map(),
17354
16836
  sharedVectorFields: /* @__PURE__ */ new Map(),
@@ -17503,7 +16985,6 @@ function createWorkerOrchestrator(config, executor, indexRegistry, callbacks, ve
17503
16985
  state.lastAccessAt.delete(indexName);
17504
16986
  state.replicationQueues.delete(indexName);
17505
16987
  state.segmentLedger.delete(indexName);
17506
- state.unbroadcastSegments.delete(indexName);
17507
16988
  }
17508
16989
  async function replicate(action) {
17509
16990
  await replicateToWorkers(state, action);
@@ -17514,10 +16995,31 @@ function createWorkerOrchestrator(config, executor, indexRegistry, callbacks, ve
17514
16995
  scheduleIdleMerge(state, action.indexName);
17515
16996
  }
17516
16997
  }
16998
+ function afterMainWrites(indexName, growth) {
16999
+ if (growth === "segments") maybeCompactSegments(state, indexName);
17000
+ if (growth === "liveTail") flushGrownTails(state, indexName);
17001
+ if (state.scaledOutIndexes.has(indexName) || state.copyLoadBuffers.has(indexName)) {
17002
+ scheduleIdleMerge(state, indexName);
17003
+ }
17004
+ }
17005
+ function copiesFollow(indexName) {
17006
+ return state.scaledOutIndexes.has(indexName) || state.copyLoadBuffers.has(indexName) || state.replicationQueues.has(indexName);
17007
+ }
17008
+ function settleMainWrites(indexName, growth = "liveTail") {
17009
+ if (growth !== "segments" && !copiesFollow(indexName)) return null;
17010
+ const waiting = replicationRoomWait(state, indexName);
17011
+ if (waiting === null) {
17012
+ afterMainWrites(indexName, growth);
17013
+ return null;
17014
+ }
17015
+ return waiting.then(() => afterMainWrites(indexName, growth));
17016
+ }
17517
17017
  return {
17518
17018
  scaleOutReadyIndexes: () => scaleOutReadyIndexes(state),
17519
17019
  scaleOutBeforeBatch: (indexName, incomingCount) => scaleOutBeforeBatch(state, indexName, incomingCount),
17520
17020
  replicateToWorkers: replicate,
17021
+ recordMainWrite: (action) => recordMainWrite(state, action),
17022
+ settleMainWrites,
17521
17023
  awaitReplication: (indexName) => awaitReplicationIdle(state, indexName),
17522
17024
  queueDiskAdoption: (action) => queueForCopies(state, action),
17523
17025
  awaitWrites: (indexName) => awaitWritesApplied(state, indexName),
@@ -17527,8 +17029,6 @@ function createWorkerOrchestrator(config, executor, indexRegistry, callbacks, ve
17527
17029
  isIndexBusy: (indexName) => isIndexBusy(state, indexName),
17528
17030
  buildSegments: (requests) => buildSegments(state, requests),
17529
17031
  segmentBuildConcurrency: (indexName) => segmentBuildConcurrency(state, indexName),
17530
- holdUnbroadcastSegments: (indexName, segmentIds) => holdUnbroadcastSegments(state, indexName, segmentIds),
17531
- releaseUnbroadcastSegments: (indexName, segmentIds) => releaseUnbroadcastSegments(state, indexName, segmentIds),
17532
17032
  searchViaWorker: (indexName, params, globalStats, partitionIds, patternWork, bm25) => searchViaWorker(state, indexName, params, globalStats, partitionIds, patternWork, bm25),
17533
17033
  hasWorkerPool: () => state.workerPool !== null,
17534
17034
  mainCopyQueries: () => state.mainCopyQueries ?? "lone",
@@ -17551,11 +17051,11 @@ function createWorkerOrchestrator(config, executor, indexRegistry, callbacks, ve
17551
17051
  if (hold === void 0) state.copyReleaseHolds.set(indexName, { holders: 1, reloads: false });
17552
17052
  else hold.holders += 1;
17553
17053
  state.desyncedIndexes.add(indexName);
17554
- const { releaseIndexCopies } = await import('./release-76MXRPGV.mjs');
17054
+ const { releaseIndexCopies } = await import('./release-HYXPVJVS.mjs');
17555
17055
  return releaseIndexCopies(state, indexName, copyReleaseSteps);
17556
17056
  },
17557
17057
  async endCopyRelease(indexName, reloads) {
17558
- const { endCopyRelease } = await import('./release-76MXRPGV.mjs');
17058
+ const { endCopyRelease } = await import('./release-HYXPVJVS.mjs');
17559
17059
  await endCopyRelease(state, indexName, reloads, copyReleaseSteps);
17560
17060
  },
17561
17061
  resyncIndex,
@@ -17604,12 +17104,13 @@ async function createEngineCore(config, hooks, capacityScope = "index") {
17604
17104
  if (config?.lifecycle !== void 0 && durabilityTier === null) {
17605
17105
  throw new NarsilError(ErrorCodes.CONFIG_INVALID, "Index lifecycle settings require durability");
17606
17106
  }
17607
- const durabilityWiring = durabilityTier === null ? null : await import('./durability-wiring-A7BVG2DW.mjs');
17107
+ const durabilityWiring = durabilityTier === null ? null : await import('./durability-wiring-GVZEE46O.mjs');
17608
17108
  const filesystemDurability = durabilityTier?.kind === "wal";
17609
17109
  const executor = createDirectExecutor({
17610
17110
  vectorWorkerCopies: vectorCopyPolicy,
17611
17111
  vectorStorage: filesystemDurability ? "disk" : "memory",
17612
- onVectorGraphRepaired: (indexName) => void durability?.manager.checkpointAfterInFlight(indexName)
17112
+ onVectorGraphRepaired: (indexName) => void durability?.manager.checkpointAfterInFlight(indexName),
17113
+ onDocumentWrite: (action) => orchestrator.recordMainWrite(action)
17613
17114
  });
17614
17115
  const pluginRegistry = createPluginRegistry();
17615
17116
  if (config?.plugins) {
@@ -17748,7 +17249,7 @@ async function createEngineCore(config, hooks, capacityScope = "index") {
17748
17249
  reloadIndex: (indexName) => emitWriteEventAfter(
17749
17250
  { eventHandlers, mutationCtx },
17750
17251
  indexName,
17751
- durability?.manager.reloadIndex?.(indexName) ?? Promise.resolve()
17252
+ durabilityWiring?.reloadIndexAndCopies(orchestrator, durability, indexName) ?? Promise.resolve()
17752
17253
  ),
17753
17254
  onError(error) {
17754
17255
  if (emitEngineEvent(eventHandlers, "invalidationError", { error }) === 0) {
@@ -17790,7 +17291,7 @@ async function createEngineCore(config, hooks, capacityScope = "index") {
17790
17291
  requireManager,
17791
17292
  resumeChange: async (indexName) => {
17792
17293
  if ((indexRegistry.get(indexName)?.pendingAnalysis ?? null) === null) return;
17793
- await (await import('./analysis-change-entry-HZXKPPGV.mjs')).resumeChangeOf(engineCore, indexName);
17294
+ await (await import('./analysis-change-entry-5BFUVMHJ.mjs')).resumeChangeOf(engineCore, indexName);
17794
17295
  },
17795
17296
  onClose: hooks?.onIndexClose,
17796
17297
  onOpen: (indexName) => {
@@ -17875,7 +17376,7 @@ async function startEngineCore(core, config) {
17875
17376
  checkHeapAfterRecovery(core);
17876
17377
  }
17877
17378
  if (core.invalidation) await core.invalidation.start();
17878
- if (core.durability) await (await import('./analysis-change-entry-HZXKPPGV.mjs')).resumeEveryChange(core);
17379
+ if (core.durability) await (await import('./analysis-change-entry-5BFUVMHJ.mjs')).resumeEveryChange(core);
17879
17380
  if (config?.lifecycle === void 0) await core.analysisRebuild.reviewStaleIndexes();
17880
17381
  } catch (err) {
17881
17382
  await core.durability?.manager.shutdown().catch(() => void 0);
@@ -18290,7 +17791,7 @@ async function dropEngineIndex(core, name) {
18290
17791
  const entry = core.requireIndex(name);
18291
17792
  const changeRecorded = () => entry.pendingAnalysis !== null || entry.durableAnalysis !== null;
18292
17793
  const abandonChange = async () => {
18293
- await (await import('./analysis-change-entry-HZXKPPGV.mjs')).abandonChangeOf(core, name);
17794
+ await (await import('./analysis-change-entry-5BFUVMHJ.mjs')).abandonChangeOf(core, name);
18294
17795
  };
18295
17796
  if (changeRecorded()) await abandonChange();
18296
17797
  await core.indexState.drop(name, async () => {
@@ -18357,7 +17858,7 @@ function assertDocumentCarriesMappedVectors(document, embeddingConfig, adapterNa
18357
17858
  }
18358
17859
  }
18359
17860
  }
18360
- function validateVector2(vector, targetField, expectedDimensions) {
17861
+ function validateVector(vector, targetField, expectedDimensions) {
18361
17862
  if (!(vector instanceof Float32Array)) {
18362
17863
  throw new NarsilError(
18363
17864
  ErrorCodes.EMBEDDING_FAILED,
@@ -18470,7 +17971,7 @@ async function embedDocumentFields(document, embeddingConfig, adapter, signal) {
18470
17971
  let vector;
18471
17972
  try {
18472
17973
  const raw = await adapter.embed(text, "document", signal);
18473
- vector = validateVector2(raw, targetField, adapter.dimensions);
17974
+ vector = validateVector(raw, targetField, adapter.dimensions);
18474
17975
  } catch (err) {
18475
17976
  throw wrapAdapterError(err, targetField);
18476
17977
  }
@@ -18541,7 +18042,7 @@ async function embedBatchDocumentFields(documents, embeddingConfig, adapter, sig
18541
18042
  }
18542
18043
  for (let j = 0; j < needsEmbedding.length; j++) {
18543
18044
  const { docIndex } = needsEmbedding[j];
18544
- const validated = validateVector2(vectors[j], targetField, adapter.dimensions);
18045
+ const validated = validateVector(vectors[j], targetField, adapter.dimensions);
18545
18046
  setFieldValue(documents[docIndex], targetField, validated);
18546
18047
  let fieldSet = embedded.get(docIndex);
18547
18048
  if (!fieldSet) {
@@ -18846,14 +18347,8 @@ async function insertDocument(ctx, indexName, document, docId, options) {
18846
18347
  } catch (err) {
18847
18348
  console.warn("afterInsert plugin hook error:", err instanceof Error ? err.message : String(err));
18848
18349
  }
18849
- await ctx.orchestrator.replicateToWorkers({
18850
- type: "insert",
18851
- indexName,
18852
- docId: resolvedDocId,
18853
- document: partitionDoc,
18854
- requestId: `replicate-insert-${resolvedDocId}`,
18855
- skipClone: options?.skipClone
18856
- });
18350
+ const roomForCopies = ctx.orchestrator.settleMainWrites(indexName);
18351
+ if (roomForCopies !== null) await roomForCopies;
18857
18352
  for (const fieldPath of extractedVectors.keys()) {
18858
18353
  const vecIndex = insertVecIndexes.get(fieldPath);
18859
18354
  if (vecIndex) {
@@ -18967,7 +18462,7 @@ async function admitBatchDocuments(ctx, indexName, documents, failed) {
18967
18462
  const entry = ctx.requireIndex(indexName);
18968
18463
  const manager = ctx.requireManager(indexName);
18969
18464
  const vecIndexes = manager.getVectorIndexes();
18970
- const vectorFieldPaths2 = vecIndexes.size > 0 ? entry.vectorFieldPaths : /* @__PURE__ */ new Set();
18465
+ const vectorFieldPaths = vecIndexes.size > 0 ? entry.vectorFieldPaths : /* @__PURE__ */ new Set();
18971
18466
  const hasBeforeHook = ctx.pluginRegistry.hasHooks("beforeInsert");
18972
18467
  const strict = entry.config.strict === true;
18973
18468
  const required = entry.config.required;
@@ -19002,7 +18497,7 @@ async function admitBatchDocuments(ctx, indexName, documents, failed) {
19002
18497
  }
19003
18498
  const { partitionDoc, extractedVectors } = prepareDocumentVectors(
19004
18499
  documents[i],
19005
- vectorFieldPaths2
18500
+ vectorFieldPaths
19006
18501
  );
19007
18502
  if (extractedVectors.size > 0) {
19008
18503
  validateVectorDimensions(extractedVectors, vecIndexes);
@@ -19064,6 +18559,8 @@ async function applyAdmittedDocuments(ctx, indexName, admitted, options, failed)
19064
18559
  }
19065
18560
  succeeded.push(doc.docId);
19066
18561
  }
18562
+ const roomForCopies = ctx.orchestrator.settleMainWrites(indexName);
18563
+ if (roomForCopies !== null) await roomForCopies;
19067
18564
  const applied = chunkStart + BATCH_CHUNK_SIZE;
19068
18565
  if (applied < admitted.length) {
19069
18566
  ctx.checkHeapPressure(indexName);
@@ -19108,75 +18605,34 @@ function buildSegmentRequests(indexName, docIds, documents, partitionCount, skip
19108
18605
  }
19109
18606
  return { requests, memberIndexes };
19110
18607
  }
19111
- function freezeSegmentsForAttach(segments) {
19112
- const frozen = [];
19113
- for (const segment of segments) {
19114
- const snapshot = segment.snapshot ?? (segment.payload === null ? null : freezeSegmentShared(segment.payload, segment.documents, segment.segmentId));
19115
- if (snapshot === null) return null;
19116
- frozen.push({ partitionId: segment.partitionId, snapshot });
19117
- }
19118
- return frozen;
19119
- }
19120
- function tryFreezeSegmentsForAttach(segments) {
18608
+ function sharedSnapshotOf(segment) {
18609
+ if (segment.snapshot !== null) return segment.snapshot;
18610
+ if (segment.payload === null) return null;
19121
18611
  try {
19122
- return freezeSegmentsForAttach(segments);
18612
+ return freezeSegmentShared(segment.payload, segment.documents, segment.segmentId);
19123
18613
  } catch (err) {
19124
18614
  console.warn("Segment freeze failed, replicating by merge instead:", err);
19125
18615
  return null;
19126
18616
  }
19127
18617
  }
19128
- function payloadSegments(segments) {
19129
- const plain = [];
19130
- for (const segment of segments) {
19131
- if (segment.payload !== null) {
19132
- plain.push({ partitionId: segment.partitionId, payload: segment.payload, documents: segment.documents });
19133
- }
19134
- }
19135
- return plain;
19136
- }
19137
- function snapshotSegments(segments) {
19138
- const shared = [];
19139
- for (const segment of segments) {
19140
- if (segment.snapshot !== null) shared.push({ partitionId: segment.partitionId, snapshot: segment.snapshot });
19141
- }
19142
- return shared;
19143
- }
19144
- function attachSegments2(orchestrator, indexName, segments) {
19145
- return orchestrator.replicateToWorkers({
19146
- type: "attachSegments",
19147
- indexName,
19148
- segments,
19149
- requestId: `attach-segments-${indexName}-${segments.length}`
19150
- });
19151
- }
19152
- async function broadcastBuiltSegments(orchestrator, indexName, segments, skipClone) {
19153
- const frozen = tryFreezeSegmentsForAttach(segments);
19154
- if (frozen !== null) {
19155
- await attachSegments2(orchestrator, indexName, frozen);
19156
- return;
18618
+ function copyActionOfSegment(indexName, segment, skipClone) {
18619
+ const snapshot = sharedSnapshotOf(segment);
18620
+ if (snapshot !== null) {
18621
+ return {
18622
+ type: "attachSegments",
18623
+ indexName,
18624
+ segments: [{ partitionId: segment.partitionId, snapshot }],
18625
+ requestId: `attach-segments-${indexName}-${segment.segmentId}`
18626
+ };
19157
18627
  }
19158
- const shared = snapshotSegments(segments);
19159
- if (shared.length > 0) await attachSegments2(orchestrator, indexName, shared);
19160
- const plain = payloadSegments(segments);
19161
- if (plain.length === 0) return;
19162
- await orchestrator.replicateToWorkers({
18628
+ if (segment.payload === null) return null;
18629
+ return {
19163
18630
  type: "mergeSegments",
19164
18631
  indexName,
19165
- segments: plain,
19166
- requestId: `merge-segments-${indexName}-${plain.length}`,
18632
+ segments: [{ partitionId: segment.partitionId, payload: segment.payload, documents: segment.documents }],
18633
+ requestId: `merge-segments-${indexName}-${segment.segmentId}`,
19167
18634
  skipClone: skipClone === true ? true : void 0
19168
- });
19169
- }
19170
- async function replicateAsSegments(ctx, indexName, docIds, documents, skipClone) {
19171
- if (docIds.length < MIN_DOCUMENTS_FOR_SEGMENTS) return false;
19172
- const workers = ctx.orchestrator.segmentBuildConcurrency(indexName);
19173
- if (workers <= 0) return false;
19174
- const manager = ctx.requireManager(indexName);
19175
- const { requests } = buildSegmentRequests(indexName, docIds, documents, manager.partitionCount, skipClone);
19176
- const built = await ctx.orchestrator.buildSegments(requests);
19177
- if (built === null || built.length === 0) return false;
19178
- await broadcastBuiltSegments(ctx.orchestrator, indexName, built, skipClone);
19179
- return true;
18635
+ };
19180
18636
  }
19181
18637
 
19182
18638
  // src/engine/mutations/insert-batch-segments.ts
@@ -19184,26 +18640,11 @@ function mainStoreDocument(doc, options) {
19184
18640
  if (doc.extractedVectors.size > 0 || options?.skipClone === true) return doc.partitionDoc;
19185
18641
  return structuredClone(doc.partitionDoc);
19186
18642
  }
19187
- async function replicateDocuments(ctx, indexName, docs, options) {
19188
- for (const doc of docs) {
19189
- await ctx.orchestrator.replicateToWorkers({
19190
- type: "insert",
19191
- indexName,
19192
- docId: doc.docId,
19193
- document: doc.partitionDoc,
19194
- requestId: `replicate-insert-${doc.docId}`,
19195
- skipClone: options?.skipClone
19196
- });
19197
- }
19198
- }
19199
18643
  async function applyIndividually(ctx, indexName, admitted, options, failed) {
19200
18644
  const applied = await applyAdmittedDocuments(ctx, indexName, admitted, options, failed);
19201
- const succeededIds = new Set(applied.succeeded);
19202
- const replicable = admitted.filter((doc) => succeededIds.has(doc.docId) && !applied.buffered.has(doc.docId));
19203
- await replicateDocuments(ctx, indexName, replicable, options);
19204
18645
  return { succeeded: applied.succeeded, touchedVectorFields: applied.touchedVectorFields };
19205
18646
  }
19206
- function attachOnce(manager, attachment) {
18647
+ function attachOnce(ctx, manager, attachment) {
19207
18648
  if (attachment.failure !== void 0) throw attachment.failure;
19208
18649
  if (attachment.attached) return;
19209
18650
  try {
@@ -19215,11 +18656,12 @@ function attachOnce(manager, attachment) {
19215
18656
  attachment.failure = error;
19216
18657
  throw error;
19217
18658
  }
18659
+ if (attachment.copyAction !== null) ctx.orchestrator.recordMainWrite(attachment.copyAction);
19218
18660
  }
19219
18661
  function applyOfMergedDocument(ctx, indexName, doc, attachment, progress) {
19220
18662
  const manager = ctx.requireManager(indexName);
19221
18663
  const attachToIndex = async () => {
19222
- attachOnce(manager, attachment);
18664
+ attachOnce(ctx, manager, attachment);
19223
18665
  progress.applied = true;
19224
18666
  try {
19225
18667
  insertDocumentVectors(
@@ -19243,13 +18685,14 @@ function applyOfMergedDocument(ctx, indexName, doc, attachment, progress) {
19243
18685
  };
19244
18686
  return indexChangeOutsideExternalWaits(attachToIndex);
19245
18687
  }
19246
- function chunksOfWholeSegments(built, frozen, memberIndexes, admitted) {
18688
+ function chunksOfWholeSegments(indexName, built, frozen, memberIndexes, admitted, options) {
19247
18689
  const chunks = [];
19248
18690
  let chunk = { docs: [], attachmentOf: /* @__PURE__ */ new Map() };
19249
18691
  for (let i = 0; i < built.length; i++) {
19250
18692
  const attachment = {
19251
18693
  partitionId: built[i].partitionId,
19252
18694
  segments: [frozen[i]],
18695
+ copyAction: copyActionOfSegment(indexName, built[i], options?.skipClone),
19253
18696
  attached: false,
19254
18697
  failure: void 0
19255
18698
  };
@@ -19266,12 +18709,12 @@ function chunksOfWholeSegments(built, frozen, memberIndexes, admitted) {
19266
18709
  if (chunk.docs.length > 0) chunks.push(chunk);
19267
18710
  return chunks;
19268
18711
  }
19269
- async function recordMergedDocuments(ctx, indexName, built, frozen, memberIndexes, admitted, failed) {
18712
+ async function recordMergedDocuments(ctx, indexName, built, frozen, memberIndexes, admitted, options, failed) {
19270
18713
  const hasAfterHook = ctx.pluginRegistry.hasHooks("afterInsert");
19271
18714
  const succeededIds = /* @__PURE__ */ new Set();
19272
18715
  const errorOf = /* @__PURE__ */ new Map();
19273
18716
  const touchedVectorFields = /* @__PURE__ */ new Set();
19274
- const chunks = chunksOfWholeSegments(built, frozen, memberIndexes, admitted);
18717
+ const chunks = chunksOfWholeSegments(indexName, built, frozen, memberIndexes, admitted, options);
19275
18718
  for (let index = 0; index < chunks.length; index++) {
19276
18719
  const { docs, attachmentOf } = chunks[index];
19277
18720
  const progress = docs.map(() => ({ applied: false }));
@@ -19306,40 +18749,23 @@ async function recordMergedDocuments(ctx, indexName, built, frozen, memberIndexe
19306
18749
  }
19307
18750
  succeededIds.add(doc.docId);
19308
18751
  }
18752
+ const roomForCopies = ctx.orchestrator.settleMainWrites(indexName, "segments");
18753
+ if (roomForCopies !== null) await roomForCopies;
19309
18754
  if (index + 1 < chunks.length) {
19310
18755
  ctx.checkHeapPressure(indexName);
19311
18756
  await new Promise((r) => setTimeout(r, 0));
19312
18757
  }
19313
18758
  }
19314
18759
  const succeeded = [];
19315
- const failedDocIds = /* @__PURE__ */ new Set();
19316
18760
  for (const doc of admitted) {
19317
18761
  if (succeededIds.has(doc.docId)) {
19318
18762
  succeeded.push(doc.docId);
19319
18763
  continue;
19320
18764
  }
19321
18765
  if (!errorOf.has(doc.docId)) continue;
19322
- failedDocIds.add(doc.docId);
19323
18766
  failed.push({ docId: doc.docId, error: asBatchInsertError(errorOf.get(doc.docId)) });
19324
18767
  }
19325
- return { succeeded, touchedVectorFields, failedDocIds };
19326
- }
19327
- async function broadcastSegments(ctx, indexName, built, memberIndexes, admitted, failedDocIds, options) {
19328
- const clean = [];
19329
- const retryDocs = [];
19330
- for (let i = 0; i < built.length; i++) {
19331
- const members = memberIndexes[i].map((m) => admitted[m]);
19332
- if (members.some((doc) => failedDocIds.has(doc.docId))) {
19333
- retryDocs.push(...members.filter((doc) => !failedDocIds.has(doc.docId)));
19334
- continue;
19335
- }
19336
- clean.push(built[i]);
19337
- }
19338
- if (clean.length > 0) {
19339
- await broadcastBuiltSegments(ctx.orchestrator, indexName, clean, options?.skipClone);
19340
- }
19341
- await replicateDocuments(ctx, indexName, retryDocs, options);
19342
- return clean.map((segment) => segment.segmentId);
18768
+ return { succeeded, touchedVectorFields };
19343
18769
  }
19344
18770
  function frozenSegmentOf(segment, members, options) {
19345
18771
  if (segment.snapshot !== null) return createSharedFrozenSegment(segment.snapshot);
@@ -19393,20 +18819,7 @@ async function ingestAdmitted(ctx, indexName, admitted, options, failed) {
19393
18819
  for (const doc of admitted) {
19394
18820
  if (manager.has(doc.docId)) return applyIndividually(ctx, indexName, admitted, options, failed);
19395
18821
  }
19396
- const segmentIds = built.map((segment) => segment.segmentId);
19397
- ctx.orchestrator.holdUnbroadcastSegments(indexName, segmentIds);
19398
- const recorded = await recordMergedDocuments(ctx, indexName, built, frozen, memberIndexes, admitted, failed);
19399
- const broadcast = await broadcastSegments(
19400
- ctx,
19401
- indexName,
19402
- built,
19403
- memberIndexes,
19404
- admitted,
19405
- recorded.failedDocIds,
19406
- options
19407
- );
19408
- ctx.orchestrator.releaseUnbroadcastSegments(indexName, broadcast);
19409
- return { succeeded: recorded.succeeded, touchedVectorFields: recorded.touchedVectorFields };
18822
+ return recordMergedDocuments(ctx, indexName, built, frozen, memberIndexes, admitted, options, failed);
19410
18823
  }
19411
18824
  async function insertBatchViaSegments(ctx, indexName, documents, options) {
19412
18825
  const failed = [];
@@ -19434,7 +18847,6 @@ async function insertDocumentBatch(ctx, indexName, documents, options) {
19434
18847
  return insertBatchViaSegments(ctx, indexName, documents, options);
19435
18848
  }
19436
18849
  const succeeded = [];
19437
- const succeededDocs = [];
19438
18850
  const failed = [];
19439
18851
  const hasBeforeHook = ctx.pluginRegistry.hasHooks("beforeInsert");
19440
18852
  const hasAfterHook = ctx.pluginRegistry.hasHooks("afterInsert");
@@ -19443,7 +18855,6 @@ async function insertDocumentBatch(ctx, indexName, documents, options) {
19443
18855
  const batchVecIndexes = batchManager.getVectorIndexes();
19444
18856
  const batchVectorFieldPaths = batchVecIndexes.size > 0 ? entry.vectorFieldPaths : /* @__PURE__ */ new Set();
19445
18857
  const touchedVectorFields = /* @__PURE__ */ new Set();
19446
- const bufferedDocIds = /* @__PURE__ */ new Set();
19447
18858
  for (let chunkStart = 0; chunkStart < documents.length; chunkStart += BATCH_CHUNK_SIZE) {
19448
18859
  if (ctx.abortController.signal.aborted) break;
19449
18860
  const chunkEnd = Math.min(chunkStart + BATCH_CHUNK_SIZE, documents.length);
@@ -19471,9 +18882,7 @@ async function insertDocumentBatch(ctx, indexName, documents, options) {
19471
18882
  continue;
19472
18883
  }
19473
18884
  if (application.status === "buffered") {
19474
- bufferedDocIds.add(doc.docId);
19475
18885
  succeeded.push(doc.docId);
19476
- succeededDocs.push(doc.partitionDoc);
19477
18886
  continue;
19478
18887
  }
19479
18888
  for (const fieldPath of doc.extractedVectors.keys()) {
@@ -19487,7 +18896,6 @@ async function insertDocumentBatch(ctx, indexName, documents, options) {
19487
18896
  }
19488
18897
  }
19489
18898
  succeeded.push(doc.docId);
19490
- succeededDocs.push(doc.partitionDoc);
19491
18899
  }
19492
18900
  }
19493
18901
  const prepared = [];
@@ -19521,32 +18929,13 @@ async function insertDocumentBatch(ctx, indexName, documents, options) {
19521
18929
  }
19522
18930
  }
19523
18931
  if (prepared.length > 0) await applyPrepared(prepared);
18932
+ const roomForCopies = ctx.orchestrator.settleMainWrites(indexName);
18933
+ if (roomForCopies !== null) await roomForCopies;
19524
18934
  if (chunkEnd < documents.length) {
19525
18935
  ctx.checkHeapPressure(indexName);
19526
18936
  await new Promise((r) => setTimeout(r, 0));
19527
18937
  }
19528
18938
  }
19529
- const replicableIds = [];
19530
- const replicableDocs = [];
19531
- for (let i = 0; i < succeeded.length; i++) {
19532
- if (bufferedDocIds.has(succeeded[i])) continue;
19533
- replicableIds.push(succeeded[i]);
19534
- replicableDocs.push(succeededDocs[i]);
19535
- }
19536
- const replicatedAsSegments = copiesBuildSegments && await replicateAsSegments(ctx, indexName, replicableIds, replicableDocs, options?.skipClone);
19537
- if (!replicatedAsSegments) {
19538
- for (let i = 0; i < replicableIds.length; i++) {
19539
- if (turnsAreBudgeted && turnIsSpent()) await yieldTurn();
19540
- await ctx.orchestrator.replicateToWorkers({
19541
- type: "insert",
19542
- indexName,
19543
- docId: replicableIds[i],
19544
- document: replicableDocs[i],
19545
- requestId: `replicate-insert-${replicableIds[i]}`,
19546
- skipClone: options?.skipClone
19547
- });
19548
- }
19549
- }
19550
18939
  for (const fieldPath of touchedVectorFields) {
19551
18940
  const vecIndex = batchVecIndexes.get(fieldPath);
19552
18941
  if (vecIndex) {
@@ -19602,19 +18991,14 @@ function applyOfRemoval(ctx, indexName, prepared) {
19602
18991
  return indexChangeOutsideExternalWaits(removeFromIndex);
19603
18992
  }
19604
18993
  async function settleRemoval(ctx, indexName, prepared) {
19605
- const { docId, removedSpellings } = prepared;
18994
+ const { docId } = prepared;
19606
18995
  try {
19607
18996
  await ctx.pluginRegistry.runHook("afterRemove", { indexName, docId });
19608
18997
  } catch (err) {
19609
18998
  console.warn("afterRemove plugin hook error:", err instanceof Error ? err.message : String(err));
19610
18999
  }
19611
- await ctx.orchestrator.replicateToWorkers({
19612
- type: "remove",
19613
- indexName,
19614
- docId,
19615
- requestId: `replicate-remove-${docId}`,
19616
- removedSpellings
19617
- });
19000
+ const roomForCopies = ctx.orchestrator.settleMainWrites(indexName, "none");
19001
+ if (roomForCopies !== null) await roomForCopies;
19618
19002
  }
19619
19003
  async function removeDocument(ctx, indexName, docId, options) {
19620
19004
  ctx.guardShutdown();
@@ -19712,14 +19096,8 @@ async function settleUpdate(ctx, indexName, prepared) {
19712
19096
  } catch (err) {
19713
19097
  console.warn("afterUpdate plugin hook error:", err instanceof Error ? err.message : String(err));
19714
19098
  }
19715
- await ctx.orchestrator.replicateToWorkers({
19716
- type: "update",
19717
- indexName,
19718
- docId: prepared.docId,
19719
- document: prepared.partitionDoc,
19720
- requestId: `replicate-update-${prepared.docId}`,
19721
- removedSpellings: prepared.removedSpellings
19722
- });
19099
+ const roomForCopies = ctx.orchestrator.settleMainWrites(indexName);
19100
+ if (roomForCopies !== null) await roomForCopies;
19723
19101
  const vecIndexes = ctx.requireManager(indexName).getVectorIndexes();
19724
19102
  for (const [fieldPath, vec] of prepared.extractedVectors) {
19725
19103
  if (vec === null) continue;
@@ -19940,7 +19318,6 @@ async function withRenewedSyncEpoch(core, indexName, change) {
19940
19318
  function clearEngineIndex(core, indexName) {
19941
19319
  return withRenewedSyncEpoch(core, indexName, async () => {
19942
19320
  await core.executor.execute({ type: "clear", indexName, requestId: indexName });
19943
- await core.orchestrator.replicateToWorkers({ type: "clear", indexName, requestId: `replicate-clear-${indexName}` });
19944
19321
  core.watermarkNotifier.forget(indexName);
19945
19322
  const durable = core.durability?.manager;
19946
19323
  await (durable?.checkpointFromMemory?.(indexName) ?? durable?.checkpoint(indexName));
@@ -20037,7 +19414,7 @@ function portabilityOperations(core, config, engine) {
20037
19414
  const { restoresInFlight } = core;
20038
19415
  const previous = restoresInFlight.get(indexName) ?? Promise.resolve();
20039
19416
  const restored = previous.then(async () => {
20040
- const { runRestore } = await import('./restore-queue-G3RQGL3Y.mjs');
19417
+ const { runRestore } = await import('./restore-queue-LQBBTODR.mjs');
20041
19418
  await runRestore(core, restoreHost, indexName, data, engine());
20042
19419
  });
20043
19420
  const settled2 = restored.then(
@@ -20068,7 +19445,7 @@ function portabilityOperations(core, config, engine) {
20068
19445
  return {
20069
19446
  snapshot(indexName, options) {
20070
19447
  return withOpenIndex2(indexName, async () => {
20071
- const { createSnapshot } = await import('./snapshot-VEQNIE6C.mjs');
19448
+ const { createSnapshot } = await import('./snapshot-5FHPPCNZ.mjs');
20072
19449
  return createSnapshot(snapshotDepsOf(indexName), options?.queryHistory === true ? core : null);
20073
19450
  });
20074
19451
  },
@@ -20081,8 +19458,8 @@ function portabilityOperations(core, config, engine) {
20081
19458
  exportDocuments(indexName) {
20082
19459
  return withOpenIndex2(indexName, async () => {
20083
19460
  const [{ checkpointForArchive }, { documentExportStream }] = await Promise.all([
20084
- import('./snapshot-VEQNIE6C.mjs'),
20085
- import('./write-2EVMZWDE.mjs')
19461
+ import('./snapshot-5FHPPCNZ.mjs'),
19462
+ import('./write-ULXAN5B4.mjs')
20086
19463
  ]);
20087
19464
  const header = indexConfigurationOf(core.requireIndex(indexName));
20088
19465
  return documentExportStream(header, await checkpointForArchive(snapshotDepsOf(indexName)));
@@ -20090,7 +19467,7 @@ function portabilityOperations(core, config, engine) {
20090
19467
  },
20091
19468
  importDocumentExport(indexName, data) {
20092
19469
  core.guardShutdown();
20093
- const imported = import('./import-DXYB6756.mjs').then(
19470
+ const imported = import('./import-5ESVMFDJ.mjs').then(
20094
19471
  ({ readDocumentExport }) => readDocumentExport(engine(), indexName, data)
20095
19472
  );
20096
19473
  return emitWriteEventAfter(core, indexName, imported);
@@ -22111,7 +21488,7 @@ function createNarsilFromCore(core, config) {
22111
21488
  const entry = requireIndex(indexName);
22112
21489
  await withOpenIndexWrite(indexName, async () => {
22113
21490
  if (entry.pendingAnalysis === null) return core.analysisRebuild.rebuild(indexName);
22114
- return (await import('./analysis-change-435CUEPZ.mjs')).resumeAnalysisChange(core, indexName);
21491
+ return (await import('./analysis-change-ZKGJFENM.mjs')).resumeAnalysisChange(core, indexName);
22115
21492
  });
22116
21493
  },
22117
21494
  async changeAnalysis(indexName, change) {
@@ -22119,7 +21496,7 @@ function createNarsilFromCore(core, config) {
22119
21496
  requireIndex(indexName);
22120
21497
  const changed = withOpenIndex2(
22121
21498
  indexName,
22122
- async () => (await import('./analysis-change-435CUEPZ.mjs')).changeIndexAnalysis(core, indexName, change)
21499
+ async () => (await import('./analysis-change-ZKGJFENM.mjs')).changeIndexAnalysis(core, indexName, change)
22123
21500
  );
22124
21501
  await emitWriteEventAfter(core, indexName, changed);
22125
21502
  },
@@ -22154,7 +21531,7 @@ function createNarsilFromCore(core, config) {
22154
21531
  const rebalanced = withOpenIndex2(
22155
21532
  indexName,
22156
21533
  () => withRenewedSyncEpoch(core, indexName, async () => {
22157
- const { executeRebalance } = await import('./analysis-change-435CUEPZ.mjs');
21534
+ const { executeRebalance } = await import('./analysis-change-ZKGJFENM.mjs');
22158
21535
  const running = executeRebalance(requireManager(indexName), indexName, targetPartitionCount, rebalanceCtx);
22159
21536
  releaseWrites();
22160
21537
  await running;
@@ -22278,7 +21655,7 @@ async function createNarsil(config) {
22278
21655
  await startEngineCore(core, runnableConfig);
22279
21656
  const engine = createNarsilFromCore(core, runnableConfig);
22280
21657
  if (runnableConfig?.querySuggestions !== void 0 || core.durability !== null) {
22281
- await (await import('./engine-hooks-E4UD67JD.mjs')).startQuerySuggestions(core, engine, runnableConfig);
21658
+ await (await import('./engine-hooks-HBVS6YM4.mjs')).startQuerySuggestions(core, engine, runnableConfig);
22282
21659
  }
22283
21660
  return engine;
22284
21661
  }
@@ -22286,4 +21663,4 @@ async function createNarsil(config) {
22286
21663
  // src/index.ts
22287
21664
  var VERSION = "0.1.0";
22288
21665
 
22289
- export { ARRAY_POSITION_GAP, DEFAULT_BM25_B, DEFAULT_BM25_K1, DEFAULT_WRITE_AHEAD_QUEUE_MAX_SIZE, REBALANCE_CHUNK_SIZE, VERSION, arrayPositionsAreStale, assemblePagedFrozenSegment, buildPartialWordTableFrom, buildSegmentPayload, clearNormalizationCache, configureNormalizationCache, createCompositePartition, createEncodedDocumentSource, createEngineIndex, createFrozenSegment, createNarsil, createPartitionIndex, createPartitionManager, createPartitionRouter, createSharedFrozenSegment, decodeEveryStoredDocument, decodeMapWithoutFields, decodeStoredDocument, decodeSurfaceTable, deleteNestedValue, dropEngineIndex, emitEngineEvent, emitWriteEventAfter, encodeIndexConfiguration, encodeSurfaceTable, endOfValue, engineCoreOf, engineVersionParts, extractVectorFromDoc, fieldIndexRemapOf, freezeSegmentShared, generateId, getNestedValue, getNormalizationCacheSize, holdSyncEpochChange, holdsADiscardedField, insertDocumentVectors, isCompositePartition, isQuantizationMode, isStorageMode, loadSchemaCodeFor, mergeDocFrequencies, mergeFieldIndexes2 as mergeFieldIndexes, mergeFieldLengths, mergePartialWords, mergeSegmentContents, mergeSurfaceForms2 as mergeSurfaceForms, messagePackUpperBoundBytes, packChecksummedEnvelope, packEnvelopeWithChecksum, parseVectorDimension, partitionStateOf, prepareConfiguredSynonyms, prepareDocumentVectors, prepareStoredSynonyms, raiseEarlierReleaseGraphSetting, readResidentMemory, rebuildTextIndexes, reconstructSchemaFromMetadata, registerPartialWordSearch, registerPatternSearch, registerSynonyms, removeDocumentBatch, removeDocumentVectors, requireConfigurationWithinSizeLimit, requireSurfaceFormsForPartialFields, resetNormalizationCache, resolvePartialWordAnalysis, resolvePartitionInsertOptions, rewriteSpillOf, rulesOfStoredSynonyms, scanPostingBlocks, segmentArraysOf, selectionKeeps, shareSegmentArrays, storedArrayPositionGap, survivorDocumentsOf, textRebuildTargetOf, toError2 as toError, validateEmbeddingConfig, validatePatternValueLimit, validateRequiredFieldsInSchema, validateTextStorage, validateVectorPromotion, validateVectorStorage, vectorsEqual, wrapFrozenTokenTable, yieldToEventLoop2 as yieldToEventLoop };
21666
+ export { ARRAY_POSITION_GAP, DEFAULT_BM25_B, DEFAULT_BM25_K1, DEFAULT_WRITE_AHEAD_QUEUE_MAX_SIZE, REBALANCE_CHUNK_SIZE, VERSION, arrayPositionsAreStale, assemblePagedFrozenSegment, buildPartialWordTableFrom, buildSegmentPayload, clearNormalizationCache, configureNormalizationCache, createCompositePartition, createEncodedDocumentSource, createEngineIndex, createFrozenSegment, createNarsil, createPartitionIndex, createPartitionManager, createPartitionRouter, createSharedFrozenSegment, decodeEveryStoredDocument, decodeMapWithoutFields, decodeStoredDocument, decodeSurfaceTable, deleteNestedValue, dropEngineIndex, emitEngineEvent, emitWriteEventAfter, encodeIndexConfiguration, encodeSurfaceTable, endOfValue, engineCoreOf, engineVersionParts, extractVectorFromDoc, fieldIndexRemapOf, freezeSegmentShared, generateId, getNormalizationCacheSize, holdSyncEpochChange, holdsADiscardedField, insertDocumentVectors, isCompositePartition, loadSchemaCodeFor, mergeDocFrequencies, mergeFieldIndexes2 as mergeFieldIndexes, mergeFieldLengths, mergePartialWords, mergeSegmentContents, mergeSurfaceForms2 as mergeSurfaceForms, packChecksummedEnvelope, packEnvelopeWithChecksum, partitionStateOf, prepareConfiguredSynonyms, prepareDocumentVectors, prepareStoredSynonyms, readResidentMemory, rebuildTextIndexes, reconstructSchemaFromMetadata, registerPartialWordSearch, registerPatternSearch, registerSynonyms, removeDocumentBatch, removeDocumentVectors, requireConfigurationWithinSizeLimit, requireSurfaceFormsForPartialFields, resetNormalizationCache, resolvePartialWordAnalysis, resolvePartitionInsertOptions, rewriteSpillOf, rulesOfStoredSynonyms, scanPostingBlocks, segmentArraysOf, selectionKeeps, shareSegmentArrays, storedArrayPositionGap, survivorDocumentsOf, textRebuildTargetOf, toError2 as toError, validateEmbeddingConfig, validatePatternValueLimit, validateRequiredFieldsInSchema, vectorsEqual, wrapFrozenTokenTable, yieldToEventLoop2 as yieldToEventLoop };