@delali/narsil 0.3.1-next.102 → 0.3.1-next.103

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 (41) hide show
  1. package/dist/browser/{chunk-BDOSMEEP.mjs → chunk-6DHYBN7M.mjs} +2 -2
  2. package/dist/browser/{chunk-EJDUFWSO.mjs → chunk-74OXU3R2.mjs} +1 -1
  3. package/dist/browser/{chunk-RIJSLY2I.mjs → chunk-AQZDOKDT.mjs} +1 -1
  4. package/dist/browser/{chunk-PGIM3HIM.mjs → chunk-CRNQAT2Q.mjs} +4 -4
  5. package/dist/browser/{chunk-JOVZ6HMT.mjs → chunk-MM7WIDI5.mjs} +64 -40
  6. package/dist/browser/{chunk-KPJMDPHG.mjs → chunk-YMDH3JID.mjs} +7 -7
  7. package/dist/browser/{durability-wiring-SRUYT3VV.mjs → durability-wiring-SGY7CZHD.mjs} +5 -5
  8. package/dist/browser/{module-CBB2ETYP.mjs → module-QJ55JCJ6.mjs} +4 -4
  9. package/dist/browser/{restore-queue-EEZQO6RF.mjs → restore-queue-LPKB6QJR.mjs} +1 -1
  10. package/dist/browser/{snapshot-OAAA5UJ7.mjs → snapshot-R7GY6PAG.mjs} +6 -6
  11. package/dist/browser/{write-7D6VIK6O.mjs → write-GFFRUCJD.mjs} +4 -4
  12. package/dist/{chunk-OZDFA4WC.mjs → chunk-5WT7BKQZ.mjs} +1 -1
  13. package/dist/{chunk-R27EMH5M.mjs → chunk-64MXRJZ7.mjs} +1 -1
  14. package/dist/{chunk-UA3AUGNV.mjs → chunk-AHVWSZTY.mjs} +4 -4
  15. package/dist/{chunk-LGAMKHA2.mjs → chunk-BQ2JSVAG.mjs} +63 -39
  16. package/dist/{chunk-PNFKUCG3.mjs → chunk-HMPYTBBN.mjs} +3 -3
  17. package/dist/{chunk-KWTW6VTG.mjs → chunk-IQYUFGQ6.mjs} +1 -1
  18. package/dist/{chunk-SP3NM3ZG.mjs → chunk-JTNDFNDP.mjs} +1 -1
  19. package/dist/{chunk-GBEEG5AN.mjs → chunk-QSK35UC2.mjs} +2 -2
  20. package/dist/{chunk-XADZPPZI.mjs → chunk-SDFIFGOL.mjs} +1 -1
  21. package/dist/{chunk-J5QP52HA.mjs → chunk-SM7S3HAP.mjs} +3 -3
  22. package/dist/{chunk-Q6XWVUZX.mjs → chunk-TXV375YK.mjs} +1 -1
  23. package/dist/{chunk-S7GNDRPS.mjs → chunk-TZRWRIZ6.mjs} +1 -1
  24. package/dist/{chunk-RF7PLG43.mjs → chunk-U4436DZG.mjs} +1 -1
  25. package/dist/{chunk-CVXLLEQ3.mjs → chunk-XKLUOODW.mjs} +2 -2
  26. package/dist/{chunk-ZI34TVOA.mjs → chunk-XRTFWD3E.mjs} +3 -3
  27. package/dist/{chunk-WVCOCKBU.mjs → chunk-YVDYMXR2.mjs} +9 -9
  28. package/dist/{direct-executor-ZD64PPEZ.mjs → direct-executor-QG7LEP6P.mjs} +2 -2
  29. package/dist/distribution.mjs +13 -13
  30. package/dist/{durability-wiring-FEUBR5BT.mjs → durability-wiring-2LOZIIJN.mjs} +12 -12
  31. package/dist/index.browser.mjs +2 -2
  32. package/dist/index.mjs +6 -6
  33. package/dist/{module-3S65MVCM.mjs → module-H37P44S6.mjs} +7 -7
  34. package/dist/persistence/durability/checkpoint-worker.mjs +9 -9
  35. package/dist/{restore-queue-KQHA7ZV2.mjs → restore-queue-KVCG36SI.mjs} +1 -1
  36. package/dist/{snapshot-QGZPODM5.mjs → snapshot-YQ2CIFOZ.mjs} +13 -13
  37. package/dist/{thread-N3IUGUS3.mjs → thread-5IYXJDWO.mjs} +2 -2
  38. package/dist/vector/search-worker.mjs +3 -3
  39. package/dist/workers/entry.mjs +4 -4
  40. package/dist/{write-U5RI7MAX.mjs → write-7UCWA3GX.mjs} +7 -7
  41. package/package.json +7 -7
@@ -384,7 +384,7 @@ var MAX_RENUMBERED_SEARCH_ATTEMPTS = 3;
384
384
  var LOCK_SPIN_ITERATIONS = 128;
385
385
  var LOCK_WAIT_SLICE_MS = 20;
386
386
  var GRAPH_LOCK_WAIT_SLICE_MS = 1;
387
- var GRAPH_EXCLUSIVE_WAIT_DEADLINE_MS = 1e4;
387
+ var GRAPH_LOCK_WAIT_DEADLINE_MS = 1e4;
388
388
  var GRAPH_BUILD_DISPATCH_CHUNK = 64;
389
389
  var GRAPH_BUILD_CHUNKS_IN_FLIGHT_PER_WORKER = 2;
390
390
 
@@ -490,4 +490,4 @@ function missingWorkerEntry(moduleUrl) {
490
490
  );
491
491
  }
492
492
 
493
- export { CHECKSUM_YIELD_CHUNK_BYTES, COMPACTION_ABSOLUTE_THRESHOLD, COMPACTION_TOMBSTONE_RATIO, CONSECUTIVE_TIMEOUTS_BEFORE_DEATH, DEFAULT_BACKPRESSURE_LIMIT, DEFAULT_EF_SEARCH, DEFAULT_REQUEST_TIMEOUT_MS, DISK_STORAGE_BLOCK_BYTES, DOCUMENT_ENCODER_RETAINED_BUFFER_BYTES, EARLIER_RELEASE_MIN_M, FARTHEST_REJECTED_LINKS_KEPT, GRAPH_BUILD_CHUNKS_IN_FLIGHT_PER_WORKER, GRAPH_BUILD_DISPATCH_CHUNK, GRAPH_EXCLUSIVE_WAIT_DEADLINE_MS, GRAPH_LOCK_WAIT_SLICE_MS, INITIAL_LIST_CAPACITY, INITIAL_UPPER_SLOTS, LOCK_SPIN_ITERATIONS, LOCK_WAIT_SLICE_MS, MAX_DOCUMENT_ENCODING_DEPTH, MAX_DOC_ID_TABLE_BYTES, MAX_FILE_BYTES, MAX_LAYER_CAP, MAX_M, MAX_RENUMBERED_SEARCH_ATTEMPTS, MAX_VECTOR_ORDINALS, MAX_WASM_PAGES, MIN_M, MIN_OVERSAMPLE, NATIVE_ATTACH_RETRY_MS, NATIVE_CRC32_MIN_BYTES, OSQ_GRID, OSQ_LAMBDA, OSQ_PLACEMENT_QUERY_BITS, OSQ_QUERY_BITS, OSQ_REFINE_ROUNDS, OSQ_REFINE_TOLERANCE, OSQ_STEPS, PLACEMENT_ROOM_REQUESTS, SHUTDOWN_TIMEOUT_MS, SORT_MODES, SORT_VALUE_MAX_CODE_POINTS, UNPLACED_FLAG_CHUNK_ORDINALS, VALID_HNSW_METRICS, VECTOR_BLOCK_INITIAL_SLOTS, VECTOR_INSERT_TIMEOUT_MS, VECTOR_SCRATCH_SLOTS, VECTOR_SEARCH_LOAD_TIMEOUT_MS, VECTOR_SEARCH_TIMEOUT_MS, VECTOR_STORE_INITIAL_CAPACITY, WASM_PAGE_BYTES, WORKER_YOUNG_GENERATION_MB, appendFoldedCodePoint, codePointCount, compareCodePoints, compareComparableKeys, compareComparableValues, compareSortValues, defaultSortMode, detectRuntime, exceedsCodePoints, holdsUnpairedSurrogate, isSimdAvailable, isSortMode, markSimdUnavailable, missingWorkerEntry, noteThreadSlotGone, noteThreadSlotLive, readSortField, resolveRequestThreadCount, resolveWorkerCount, resolveWorkerEntry, singleFoldTable, sortModeOf, splitWorkerBudget, threadSlotGone, threadSlotOfWorker, toComparableSortValue, toReducedSortValue, truncateSortString };
493
+ export { CHECKSUM_YIELD_CHUNK_BYTES, COMPACTION_ABSOLUTE_THRESHOLD, COMPACTION_TOMBSTONE_RATIO, CONSECUTIVE_TIMEOUTS_BEFORE_DEATH, DEFAULT_BACKPRESSURE_LIMIT, DEFAULT_EF_SEARCH, DEFAULT_REQUEST_TIMEOUT_MS, DISK_STORAGE_BLOCK_BYTES, DOCUMENT_ENCODER_RETAINED_BUFFER_BYTES, EARLIER_RELEASE_MIN_M, FARTHEST_REJECTED_LINKS_KEPT, GRAPH_BUILD_CHUNKS_IN_FLIGHT_PER_WORKER, GRAPH_BUILD_DISPATCH_CHUNK, GRAPH_LOCK_WAIT_DEADLINE_MS, GRAPH_LOCK_WAIT_SLICE_MS, INITIAL_LIST_CAPACITY, INITIAL_UPPER_SLOTS, LOCK_SPIN_ITERATIONS, LOCK_WAIT_SLICE_MS, MAX_DOCUMENT_ENCODING_DEPTH, MAX_DOC_ID_TABLE_BYTES, MAX_FILE_BYTES, MAX_LAYER_CAP, MAX_M, MAX_RENUMBERED_SEARCH_ATTEMPTS, MAX_VECTOR_ORDINALS, MAX_WASM_PAGES, MIN_M, MIN_OVERSAMPLE, NATIVE_ATTACH_RETRY_MS, NATIVE_CRC32_MIN_BYTES, OSQ_GRID, OSQ_LAMBDA, OSQ_PLACEMENT_QUERY_BITS, OSQ_QUERY_BITS, OSQ_REFINE_ROUNDS, OSQ_REFINE_TOLERANCE, OSQ_STEPS, PLACEMENT_ROOM_REQUESTS, SHUTDOWN_TIMEOUT_MS, SORT_MODES, SORT_VALUE_MAX_CODE_POINTS, UNPLACED_FLAG_CHUNK_ORDINALS, VALID_HNSW_METRICS, VECTOR_BLOCK_INITIAL_SLOTS, VECTOR_INSERT_TIMEOUT_MS, VECTOR_SCRATCH_SLOTS, VECTOR_SEARCH_LOAD_TIMEOUT_MS, VECTOR_SEARCH_TIMEOUT_MS, VECTOR_STORE_INITIAL_CAPACITY, WASM_PAGE_BYTES, WORKER_YOUNG_GENERATION_MB, appendFoldedCodePoint, codePointCount, compareCodePoints, compareComparableKeys, compareComparableValues, compareSortValues, defaultSortMode, detectRuntime, exceedsCodePoints, holdsUnpairedSurrogate, isSimdAvailable, isSortMode, markSimdUnavailable, missingWorkerEntry, noteThreadSlotGone, noteThreadSlotLive, readSortField, resolveRequestThreadCount, resolveWorkerCount, resolveWorkerEntry, singleFoldTable, sortModeOf, splitWorkerBudget, threadSlotGone, threadSlotOfWorker, toComparableSortValue, toReducedSortValue, truncateSortString };
@@ -1,4 +1,4 @@
1
- import { removeDocumentVectors, prepareDocumentVectors, insertDocumentVectors, getNestedValue, requireValidFieldTypes, VECTOR_PATTERN } from './chunk-KPJMDPHG.mjs';
1
+ import { removeDocumentVectors, prepareDocumentVectors, insertDocumentVectors, getNestedValue, requireValidFieldTypes, VECTOR_PATTERN } from './chunk-YMDH3JID.mjs';
2
2
  import { NarsilError, ErrorCodes } from './chunk-RHG4O77A.mjs';
3
3
  import { decode } from '@msgpack/msgpack';
4
4
 
@@ -1,4 +1,4 @@
1
- import { MAX_M, EARLIER_RELEASE_MIN_M, MIN_M } from './chunk-BDOSMEEP.mjs';
1
+ import { MAX_M, EARLIER_RELEASE_MIN_M, MIN_M } from './chunk-6DHYBN7M.mjs';
2
2
  import { NarsilError, ErrorCodes } from './chunk-RHG4O77A.mjs';
3
3
 
4
4
  // src/vector/vector-index/dead-bits.ts
@@ -1,7 +1,7 @@
1
- import { KEYWORD_SEGMENT_ENVELOPE_VERSION, decodeKeywordSegment, restoreVectorFields, KEYWORD_SEGMENT_PAYLOAD_VERSION, littleEndianBytes } from './chunk-EJDUFWSO.mjs';
2
- import { VERSION, rulesOfStoredSynonyms, flattenSchema, packChecksummedEnvelope, openChecksummedEnvelope, requireValidFieldTypes, isCompositePartition, crc32, reconstructSchemaFromMetadata, extractVectorFieldsFromSchema, readHeader, HEADER_SIZE, engineVersionParts, writeHeader, partialFieldsOf, getLanguage, decodeEveryStoredDocument, createSharedFrozenSegment, shareSegmentArrays, VECTOR_PATTERN, isQuantizationMode, isStorageMode, survivorDocumentsOf, partitionStateOf, freezeSegmentShared, createFrozenSegment, createPartitionManager, createPartitionRouter, buildSegmentPayload, resolvePartitionInsertOptions, fnv1a, selectionKeeps, decodeMapWithoutFields, prepareDocumentVectors, messagePackUpperBoundBytes, segmentArraysOf, mergeSegmentContents, resolveIndexAnalysis } from './chunk-KPJMDPHG.mjs';
3
- import { decodeVectorGraphPartPayload, assembleGraphParts, decodeVectorFilePayload, countDead, VECTOR_FILE_MAX_VECTORS, deadBytesFor } from './chunk-RIJSLY2I.mjs';
4
- import { compareCodePoints, MAX_FILE_BYTES, VALID_HNSW_METRICS } from './chunk-BDOSMEEP.mjs';
1
+ import { KEYWORD_SEGMENT_ENVELOPE_VERSION, decodeKeywordSegment, restoreVectorFields, KEYWORD_SEGMENT_PAYLOAD_VERSION, littleEndianBytes } from './chunk-74OXU3R2.mjs';
2
+ import { VERSION, rulesOfStoredSynonyms, flattenSchema, packChecksummedEnvelope, openChecksummedEnvelope, requireValidFieldTypes, isCompositePartition, crc32, reconstructSchemaFromMetadata, extractVectorFieldsFromSchema, readHeader, HEADER_SIZE, engineVersionParts, writeHeader, partialFieldsOf, getLanguage, decodeEveryStoredDocument, createSharedFrozenSegment, shareSegmentArrays, VECTOR_PATTERN, isQuantizationMode, isStorageMode, survivorDocumentsOf, partitionStateOf, freezeSegmentShared, createFrozenSegment, createPartitionManager, createPartitionRouter, buildSegmentPayload, resolvePartitionInsertOptions, fnv1a, selectionKeeps, decodeMapWithoutFields, prepareDocumentVectors, messagePackUpperBoundBytes, segmentArraysOf, mergeSegmentContents, resolveIndexAnalysis } from './chunk-YMDH3JID.mjs';
3
+ import { decodeVectorGraphPartPayload, assembleGraphParts, decodeVectorFilePayload, countDead, VECTOR_FILE_MAX_VECTORS, deadBytesFor } from './chunk-AQZDOKDT.mjs';
4
+ import { compareCodePoints, MAX_FILE_BYTES, VALID_HNSW_METRICS } from './chunk-6DHYBN7M.mjs';
5
5
  import { NarsilError, ErrorCodes } from './chunk-RHG4O77A.mjs';
6
6
  import { decode, encode } from '@msgpack/msgpack';
7
7
 
@@ -1,5 +1,5 @@
1
- import { unpackLevels, osqRecordBytes, VECTOR_FILE_MAX_VECTORS, NO_LIVE_VECTOR_AT_POSITION, readTrailer, stageQueryLevels, osqCodeBytes, osqStagedQueryBytes, bytesToVectors, VECTOR_GRAPH_PART_VECTORS, VECTOR_GRAPH_PART_PAYLOAD_VERSION, VECTOR_FILE_PAYLOAD_VERSION, deadBitsWhere, vectorsToBytes, writeRecord } from './chunk-RIJSLY2I.mjs';
2
- import { markSimdUnavailable, MAX_WASM_PAGES, WASM_PAGE_BYTES, VECTOR_SCRATCH_SLOTS, UNPLACED_FLAG_CHUNK_ORDINALS, COMPACTION_TOMBSTONE_RATIO, COMPACTION_ABSOLUTE_THRESHOLD, MAX_FILE_BYTES, VECTOR_BLOCK_INITIAL_SLOTS, MAX_VECTOR_ORDINALS, VECTOR_STORE_INITIAL_CAPACITY, PLACEMENT_ROOM_REQUESTS, LOCK_SPIN_ITERATIONS, LOCK_WAIT_SLICE_MS, MAX_LAYER_CAP, INITIAL_LIST_CAPACITY, OSQ_PLACEMENT_QUERY_BITS, GRAPH_EXCLUSIVE_WAIT_DEADLINE_MS, OSQ_STEPS, OSQ_GRID, OSQ_QUERY_BITS, compareCodePoints, INITIAL_UPPER_SLOTS, GRAPH_LOCK_WAIT_SLICE_MS, threadSlotGone, OSQ_REFINE_ROUNDS, OSQ_REFINE_TOLERANCE, DEFAULT_EF_SEARCH, OSQ_LAMBDA, FARTHEST_REJECTED_LINKS_KEPT, MAX_DOC_ID_TABLE_BYTES } from './chunk-BDOSMEEP.mjs';
1
+ import { unpackLevels, osqRecordBytes, VECTOR_FILE_MAX_VECTORS, NO_LIVE_VECTOR_AT_POSITION, readTrailer, stageQueryLevels, osqCodeBytes, osqStagedQueryBytes, bytesToVectors, VECTOR_GRAPH_PART_VECTORS, VECTOR_GRAPH_PART_PAYLOAD_VERSION, VECTOR_FILE_PAYLOAD_VERSION, deadBitsWhere, vectorsToBytes, writeRecord } from './chunk-AQZDOKDT.mjs';
2
+ import { markSimdUnavailable, MAX_WASM_PAGES, WASM_PAGE_BYTES, VECTOR_SCRATCH_SLOTS, UNPLACED_FLAG_CHUNK_ORDINALS, COMPACTION_TOMBSTONE_RATIO, COMPACTION_ABSOLUTE_THRESHOLD, MAX_FILE_BYTES, VECTOR_BLOCK_INITIAL_SLOTS, MAX_VECTOR_ORDINALS, VECTOR_STORE_INITIAL_CAPACITY, PLACEMENT_ROOM_REQUESTS, LOCK_SPIN_ITERATIONS, LOCK_WAIT_SLICE_MS, MAX_LAYER_CAP, INITIAL_LIST_CAPACITY, OSQ_PLACEMENT_QUERY_BITS, GRAPH_LOCK_WAIT_SLICE_MS, OSQ_STEPS, OSQ_GRID, OSQ_QUERY_BITS, GRAPH_LOCK_WAIT_DEADLINE_MS, compareCodePoints, INITIAL_UPPER_SLOTS, OSQ_REFINE_ROUNDS, OSQ_REFINE_TOLERANCE, threadSlotGone, DEFAULT_EF_SEARCH, OSQ_LAMBDA, FARTHEST_REJECTED_LINKS_KEPT, MAX_DOC_ID_TABLE_BYTES } from './chunk-6DHYBN7M.mjs';
3
3
  import { NarsilError, ErrorCodes, MAX_DOC_ID_LENGTH } from './chunk-RHG4O77A.mjs';
4
4
 
5
5
  // src/vector/shared-buffers/growable.ts
@@ -75,6 +75,7 @@ var HELD_WRITE_VERSION = 1;
75
75
  var HELD_GRAPH = 2;
76
76
  var HELD_FENCE = 3;
77
77
  var HELD_GRAPH_WAITING = 4;
78
+ var HELD_ENTRY = 5;
78
79
  var HELD_WORDS_PER_THREAD = 32;
79
80
  var METRIC_CODES = ["cosine", "dotProduct", "euclidean"];
80
81
  function perOrdinal(bytesPerOrdinal, initialOrdinals) {
@@ -162,33 +163,16 @@ function waitOn(words, index, seen, sliceMs = LOCK_WAIT_SLICE_MS) {
162
163
  function heldIndex(locks, kind) {
163
164
  return locks.threadSlot * HELD_WORDS_PER_THREAD + kind;
164
165
  }
165
- function acquireExclusive(words, index) {
166
- let spins = 0;
167
- for (; ; ) {
168
- const seen = Atomics.compareExchange(words, index, FREE, EXCLUSIVE);
169
- if (seen === FREE) return;
170
- if (spins < LOCK_SPIN_ITERATIONS) {
171
- spins += 1;
172
- continue;
173
- }
174
- waitOn(words, index, seen, GRAPH_LOCK_WAIT_SLICE_MS);
175
- }
176
- }
177
- function acquireExclusiveWithin(words, index, deadlineMs) {
178
- let spins = 0;
179
- let deadline = Number.NaN;
180
- for (; ; ) {
181
- const seen = Atomics.compareExchange(words, index, FREE, EXCLUSIVE);
182
- if (seen === FREE) return true;
183
- if (spins < LOCK_SPIN_ITERATIONS) {
184
- spins += 1;
185
- continue;
186
- }
187
- const now = performance.now();
188
- if (Number.isNaN(deadline)) deadline = now + deadlineMs;
189
- else if (now >= deadline) return false;
190
- waitOn(words, index, seen, GRAPH_LOCK_WAIT_SLICE_MS);
191
- }
166
+ function waitedSince(locks, startedAt, lock) {
167
+ const now = performance.now();
168
+ if (Number.isNaN(startedAt)) return now;
169
+ if (now - startedAt < GRAPH_LOCK_WAIT_DEADLINE_MS) return startedAt;
170
+ if (releaseGoneThreads(locks) > 0) return now;
171
+ throw new NarsilError(
172
+ ErrorCodes.WORKER_TIMEOUT,
173
+ `Another thread held a lock on the vector graph for ${GRAPH_LOCK_WAIT_DEADLINE_MS} ms, so this thread stopped waiting for it`,
174
+ { waitedMs: GRAPH_LOCK_WAIT_DEADLINE_MS, threadSlot: locks.threadSlot, lock }
175
+ );
192
176
  }
193
177
  function releaseExclusive(words, index) {
194
178
  Atomics.store(words, index, FREE);
@@ -199,9 +183,22 @@ var WRITER_WAITING = 2;
199
183
  var VERSION_STEP = 4;
200
184
  function beginNodeRead(locks, ord) {
201
185
  const words = locks.words(ord);
186
+ const seen = Atomics.load(words, ord);
187
+ if ((seen & WRITE_HELD) === 0) return seen;
188
+ return waitForNodeRead(locks, words, ord);
189
+ }
190
+ function waitForNodeRead(locks, words, ord) {
191
+ let spins = 0;
192
+ let startedAt = Number.NaN;
202
193
  for (; ; ) {
203
194
  const seen = Atomics.load(words, ord);
204
195
  if ((seen & WRITE_HELD) === 0) return seen;
196
+ if (spins < LOCK_SPIN_ITERATIONS) {
197
+ spins += 1;
198
+ continue;
199
+ }
200
+ spins = 0;
201
+ startedAt = waitedSince(locks, startedAt, "node");
205
202
  }
206
203
  }
207
204
  function nodeReadHeld(locks, ord, version) {
@@ -211,6 +208,7 @@ function nodeReadHeld(locks, ord, version) {
211
208
  function lockNodeWrite(locks, ord) {
212
209
  const words = locks.words(ord);
213
210
  let spins = 0;
211
+ let startedAt = Number.NaN;
214
212
  for (; ; ) {
215
213
  const seen = Atomics.load(words, ord);
216
214
  if ((seen & WRITE_HELD) === 0) {
@@ -226,6 +224,7 @@ function lockNodeWrite(locks, ord) {
226
224
  spins += 1;
227
225
  continue;
228
226
  }
227
+ startedAt = waitedSince(locks, startedAt, "node");
229
228
  const waiting = seen | WRITER_WAITING;
230
229
  if (waiting === seen || Atomics.compareExchange(words, ord, seen, waiting) === seen) {
231
230
  waitOn(words, ord, waiting);
@@ -244,6 +243,7 @@ function unlockNodeWrite(locks, ord) {
244
243
  function lockGraphShared(locks) {
245
244
  const { header } = locks;
246
245
  let spins = 0;
246
+ let startedAt = Number.NaN;
247
247
  for (; ; ) {
248
248
  const seen = Atomics.load(header, GRAPH_LOCK);
249
249
  if (seen >= FREE && Atomics.load(header, GRAPH_WRITERS_WAITING) === 0) {
@@ -257,6 +257,7 @@ function lockGraphShared(locks) {
257
257
  spins += 1;
258
258
  continue;
259
259
  }
260
+ startedAt = waitedSince(locks, startedAt, "graph");
260
261
  waitOn(header, GRAPH_LOCK, seen, GRAPH_LOCK_WAIT_SLICE_MS);
261
262
  }
262
263
  }
@@ -266,17 +267,22 @@ function unlockGraphShared(locks) {
266
267
  if (Atomics.sub(header, GRAPH_LOCK, 1) === 1 && canWait(header)) Atomics.notify(header, GRAPH_LOCK);
267
268
  }
268
269
  function lockGraphExclusive(locks) {
270
+ const { header } = locks;
269
271
  Atomics.store(locks.held, heldIndex(locks, HELD_GRAPH_WAITING), 1);
270
- Atomics.add(locks.header, GRAPH_WRITERS_WAITING, 1);
272
+ Atomics.add(header, GRAPH_WRITERS_WAITING, 1);
271
273
  try {
272
- if (acquireExclusiveWithin(locks.header, GRAPH_LOCK, GRAPH_EXCLUSIVE_WAIT_DEADLINE_MS)) return;
273
- const released = releaseGoneThreads(locks);
274
- if (released > 0 && acquireExclusiveWithin(locks.header, GRAPH_LOCK, GRAPH_EXCLUSIVE_WAIT_DEADLINE_MS)) return;
275
- throw new NarsilError(
276
- ErrorCodes.WORKER_TIMEOUT,
277
- `Another thread held the vector graph for ${GRAPH_EXCLUSIVE_WAIT_DEADLINE_MS} ms, so this change to the graph gave up`,
278
- { waitedMs: GRAPH_EXCLUSIVE_WAIT_DEADLINE_MS, threadSlot: locks.threadSlot }
279
- );
274
+ let spins = 0;
275
+ let startedAt = Number.NaN;
276
+ for (; ; ) {
277
+ const seen = Atomics.compareExchange(header, GRAPH_LOCK, FREE, EXCLUSIVE);
278
+ if (seen === FREE) return;
279
+ if (spins < LOCK_SPIN_ITERATIONS) {
280
+ spins += 1;
281
+ continue;
282
+ }
283
+ startedAt = waitedSince(locks, startedAt, "graphAlone");
284
+ waitOn(header, GRAPH_LOCK, seen, GRAPH_LOCK_WAIT_SLICE_MS);
285
+ }
280
286
  } finally {
281
287
  Atomics.sub(locks.header, GRAPH_WRITERS_WAITING, 1);
282
288
  Atomics.store(locks.held, heldIndex(locks, HELD_GRAPH_WAITING), 0);
@@ -286,9 +292,25 @@ function unlockGraphExclusive(locks) {
286
292
  releaseExclusive(locks.header, GRAPH_LOCK);
287
293
  }
288
294
  function lockEntry(locks) {
289
- acquireExclusive(locks.header, GRAPH_ENTRY_LOCK);
295
+ const { header } = locks;
296
+ let spins = 0;
297
+ let startedAt = Number.NaN;
298
+ for (; ; ) {
299
+ const seen = Atomics.compareExchange(header, GRAPH_ENTRY_LOCK, FREE, EXCLUSIVE);
300
+ if (seen === FREE) {
301
+ Atomics.store(locks.held, heldIndex(locks, HELD_ENTRY), 1);
302
+ return;
303
+ }
304
+ if (spins < LOCK_SPIN_ITERATIONS) {
305
+ spins += 1;
306
+ continue;
307
+ }
308
+ startedAt = waitedSince(locks, startedAt, "entry");
309
+ waitOn(header, GRAPH_ENTRY_LOCK, seen, GRAPH_LOCK_WAIT_SLICE_MS);
310
+ }
290
311
  }
291
312
  function unlockEntry(locks) {
313
+ Atomics.store(locks.held, heldIndex(locks, HELD_ENTRY), 0);
292
314
  releaseExclusive(locks.header, GRAPH_ENTRY_LOCK);
293
315
  }
294
316
  function releaseGoneThreads(locks) {
@@ -300,7 +322,8 @@ function releaseGoneThreads(locks) {
300
322
  const writeOrd = Atomics.load(locks.held, base + HELD_WRITE) - 1;
301
323
  const holdsGraph = Atomics.load(locks.held, base + HELD_GRAPH) === 1;
302
324
  const waitsForGraph = Atomics.load(locks.held, base + HELD_GRAPH_WAITING) === 1;
303
- if (!holdsGraph && !waitsForGraph && writeOrd < 0) continue;
325
+ const holdsEntry = Atomics.load(locks.held, base + HELD_ENTRY) === 1;
326
+ if (!holdsGraph && !waitsForGraph && !holdsEntry && writeOrd < 0) continue;
304
327
  releaseSlot(locks.header, locks.held, writeOrd >= 0 ? locks.words(writeOrd) : null, slot);
305
328
  released += 1;
306
329
  }
@@ -314,6 +337,7 @@ function releaseSlot(header, held, words, threadSlot) {
314
337
  if (Atomics.exchange(held, base + HELD_GRAPH_WAITING, 0) === 1) {
315
338
  Atomics.sub(header, GRAPH_WRITERS_WAITING, 1);
316
339
  }
340
+ if (Atomics.exchange(held, base + HELD_ENTRY, 0) === 1) releaseExclusive(header, GRAPH_ENTRY_LOCK);
317
341
  const writeOrd = Atomics.exchange(held, base + HELD_WRITE, 0) - 1;
318
342
  const writeVersion = Atomics.load(held, base + HELD_WRITE_VERSION);
319
343
  if (words !== null && writeOrd >= 0 && writeOrd < words.length) {
@@ -1,4 +1,4 @@
1
- import { MAX_DOCUMENT_ENCODING_DEPTH, singleFoldTable, appendFoldedCodePoint, compareCodePoints, EARLIER_RELEASE_MIN_M, MIN_M, MAX_M, DOCUMENT_ENCODER_RETAINED_BUFFER_BYTES, MAX_FILE_BYTES, detectRuntime, splitWorkerBudget, resolveWorkerCount, CHECKSUM_YIELD_CHUNK_BYTES, resolveWorkerEntry, missingWorkerEntry, DEFAULT_REQUEST_TIMEOUT_MS, toReducedSortValue, resolveRequestThreadCount, defaultSortMode, holdsUnpairedSurrogate, compareComparableValues, readSortField, exceedsCodePoints, toComparableSortValue, SORT_VALUE_MAX_CODE_POINTS, compareComparableKeys, truncateSortString, sortModeOf, isSortMode, SORT_MODES, SHUTDOWN_TIMEOUT_MS, MIN_OVERSAMPLE, MAX_RENUMBERED_SEARCH_ATTEMPTS, compareSortValues, DEFAULT_BACKPRESSURE_LIMIT, CONSECUTIVE_TIMEOUTS_BEFORE_DEATH, codePointCount, noteThreadSlotGone, threadSlotOfWorker } from './chunk-BDOSMEEP.mjs';
1
+ import { MAX_DOCUMENT_ENCODING_DEPTH, singleFoldTable, appendFoldedCodePoint, compareCodePoints, EARLIER_RELEASE_MIN_M, MIN_M, MAX_M, DOCUMENT_ENCODER_RETAINED_BUFFER_BYTES, MAX_FILE_BYTES, detectRuntime, splitWorkerBudget, resolveWorkerCount, CHECKSUM_YIELD_CHUNK_BYTES, resolveWorkerEntry, missingWorkerEntry, DEFAULT_REQUEST_TIMEOUT_MS, toReducedSortValue, resolveRequestThreadCount, defaultSortMode, holdsUnpairedSurrogate, compareComparableValues, readSortField, exceedsCodePoints, toComparableSortValue, SORT_VALUE_MAX_CODE_POINTS, compareComparableKeys, truncateSortString, sortModeOf, isSortMode, SORT_MODES, SHUTDOWN_TIMEOUT_MS, MIN_OVERSAMPLE, MAX_RENUMBERED_SEARCH_ATTEMPTS, compareSortValues, DEFAULT_BACKPRESSURE_LIMIT, CONSECUTIVE_TIMEOUTS_BEFORE_DEATH, codePointCount, noteThreadSlotGone, threadSlotOfWorker } from './chunk-6DHYBN7M.mjs';
2
2
  import { DEFAULT_MAX_RERANK_WINDOW, DEFAULT_RERANK_TIMEOUT_MS } from './chunk-JPTQZWJQ.mjs';
3
3
  import { ErrorCodes, NarsilError, createNarsilError, ABSOLUTE_WINDOWS_PATH_PATTERN, MODULE_URL_SCHEME_PATTERN, MAX_SWEEP_INTERVAL_MS, MIN_SWEEP_INTERVAL_MS, STATISTICS_BROADCAST_INTERVAL_MS, MAX_INDEX_NAME_LENGTH, INDEX_NAME_PATTERN, MAX_EXPORT_LINE_BYTES, IMPORT_BATCH_DOCUMENTS, MAX_SUGGEST_LIMIT, MAX_INDEX_CONFIGURATION_BYTES, FOREIGN_STATS_TTL_MS, HEAP_PRESSURE_WARNING_FRACTION, MAX_IMPORT_REFUSALS_REPORTED, DEFAULT_SUGGEST_LIMIT, DEFAULT_FUZZY_PREFIX_LENGTH, MAX_CURSOR_LENGTH, MAX_CURSOR_ANCHOR_CODE_POINTS, MAX_SORT_FIELDS, MAX_SORT_FIELD_NAME_LENGTH, RESULT_WINDOW, DEFAULT_LIMIT, DEFAULT_OFFSET, DEFAULT_LINEAR_ALPHA, MIN_LINEAR_ALPHA, MAX_LINEAR_ALPHA, DEFAULT_RANK_CONSTANT, MIN_RANK_CONSTANT, MIN_DOCUMENTS_FOR_SEGMENTS, DEFAULT_PAGE_SIZE, DEFAULT_MAX_PER_GROUP, PREFIX_MAX_EXPANSIONS, HEAP_PRESSURE_REARM_FRACTION, MAX_TOLERANCE, MAX_PREFIX_LENGTH, BATCH_CHUNK_SIZE, MAX_DOC_ID_LENGTH } from './chunk-RHG4O77A.mjs';
4
4
  import { Encoder, Decoder, decode, encode } from '@msgpack/msgpack';
@@ -14949,7 +14949,7 @@ function requireLoadedVectorCode() {
14949
14949
  function loadVectorCode() {
14950
14950
  if (loaded !== null) return Promise.resolve(loaded);
14951
14951
  if (loading === null) {
14952
- loading = import('./module-CBB2ETYP.mjs').then(
14952
+ loading = import('./module-QJ55JCJ6.mjs').then(
14953
14953
  (code) => {
14954
14954
  loaded = code;
14955
14955
  return code;
@@ -19037,7 +19037,7 @@ async function createEngineCore(config, hooks, capacityScope = "index") {
19037
19037
  if (config?.lifecycle !== void 0 && durabilityTier === null) {
19038
19038
  throw new NarsilError(ErrorCodes.CONFIG_INVALID, "Index lifecycle settings require durability");
19039
19039
  }
19040
- const durabilityWiring = durabilityTier === null ? null : await import('./durability-wiring-SRUYT3VV.mjs');
19040
+ const durabilityWiring = durabilityTier === null ? null : await import('./durability-wiring-SGY7CZHD.mjs');
19041
19041
  const filesystemDurability = durabilityTier?.kind === "wal";
19042
19042
  const executor = createDirectExecutor({
19043
19043
  vectorWorkerCopies: vectorCopyPolicy,
@@ -22470,14 +22470,14 @@ function portabilityOperations(core, config, engine) {
22470
22470
  return {
22471
22471
  snapshot(indexName) {
22472
22472
  return withOpenIndex(indexName, async () => {
22473
- const { createSnapshot } = await import('./snapshot-OAAA5UJ7.mjs');
22473
+ const { createSnapshot } = await import('./snapshot-R7GY6PAG.mjs');
22474
22474
  return createSnapshot(snapshotDepsOf(indexName));
22475
22475
  });
22476
22476
  },
22477
22477
  async restore(indexName, data) {
22478
22478
  core.guardShutdown();
22479
22479
  validateIndexName(indexName);
22480
- const restored = import('./restore-queue-EEZQO6RF.mjs').then(
22480
+ const restored = import('./restore-queue-LPKB6QJR.mjs').then(
22481
22481
  ({ queueRestore }) => queueRestore(core, restoreHost, restoresInFlight, indexName, data)
22482
22482
  );
22483
22483
  await emitWriteEventAfter(core, indexName, restored);
@@ -22486,8 +22486,8 @@ function portabilityOperations(core, config, engine) {
22486
22486
  exportDocuments(indexName) {
22487
22487
  return withOpenIndex(indexName, async () => {
22488
22488
  const [{ checkpointForArchive }, { documentExportStream }] = await Promise.all([
22489
- import('./snapshot-OAAA5UJ7.mjs'),
22490
- import('./write-7D6VIK6O.mjs')
22489
+ import('./snapshot-R7GY6PAG.mjs'),
22490
+ import('./write-GFFRUCJD.mjs')
22491
22491
  ]);
22492
22492
  const header = indexConfigurationOf(core.requireIndex(indexName));
22493
22493
  return documentExportStream(header, await checkpointForArchive(snapshotDepsOf(indexName)));
@@ -1,9 +1,9 @@
1
1
  import { nodeThreadId, spawnNodeWorker } from './chunk-HOZW3PKP.mjs';
2
- import { DEFAULT_SEGMENT_MAX_BYTES, DEFAULT_CHECKPOINT_INTERVAL_MS, DEFAULT_CHECKPOINT_MUTATION_THRESHOLD, DEFAULT_COMPACTION_THRESHOLD, DEFAULT_ASYNC_FLUSH_INTERVAL_MS, WRITES_STALL_ABOVE_UNCHECKPOINTED_BYTES, directoryCheckpointStore, manifestKey, decodeSegmentManifest, readListedFile, adapterCheckpointStore, SINGLE_NODE_PRIMARY_TERM, readMetadataEnvelope, writeMetadataEnvelope, metadataFromConfig, DIRECTORY_LOCK_ATTEMPTS, createSeqOwner, readSegmentManifest, snapshotBundleKey, reclaimUnlistedKeys, manifestReferencedKeys, loadSegmentedCheckpoint, checkpointLastSeqNo, manifestFileRefs, DIRECTORY_LOCK_SETTLE_MS, readSegmentFile, isRecord, invalidManifest, deserializePayloadV2, unpackEnvelopeBytes, checkpointPrimaryTerm, frameRecord, isId, isUint32, isSequenceNumber, writeCheckpointSegments, partitionContentsOf, writeLiveVectors, commitCheckpointManifest, removeCheckpointGarbage, readWalSegments, durableRecordMissing, MAX_SEGMENTS_PER_PARTITION, growPartitionsTo, writeSegmentHeader, VECTOR_FILE_ENVELOPE_VERSION, SEGMENT_HEADER_SIZE, documentsOfPayloadV2, readCommitMarker, nextMarkerSlot, encodeMarkerSlot, markerSlotOffset, DIRECTORY_IDENTITY_CHECK_INTERVAL_MS, metadataConfigOf, buildEntry, readCurrentManifest, WHOLE_PARTITION_LARGEST_DOCUMENT_COUNT, WHOLE_PARTITION_MIN_CHANGED_SHARE, captureWholePartition, CHECKPOINT_TIMEOUT_RECOVERY_BACKOFF_MS, CHECKPOINT_WORKER_TIMEOUT_MS, CHECKPOINT_WORKER_IDLE_MS, LOG_RECORDS_PER_CHECKPOINT } from './chunk-PGIM3HIM.mjs';
3
- import { applyDeleteEntry, applyIndexEntry } from './chunk-EJDUFWSO.mjs';
4
- import { encodeDocument, fnv1a, requireValidFieldTypes, openChecksummedEnvelope, HEADER_SIZE, buildSegmentPayload, resolvePartitionInsertOptions, freezeSegmentShared, createSharedFrozenSegment } from './chunk-KPJMDPHG.mjs';
5
- import { decodeVectorIndexParts, VECTOR_FILE_MAX_VECTORS, deadBytesFor, countDead, decodeVectorFilePayload, decodeVectorGraphPayload, graphPartsOfEarlierPayload } from './chunk-RIJSLY2I.mjs';
6
- import { compareCodePoints, MIN_M, MAX_FILE_BYTES, detectRuntime, resolveWorkerEntry } from './chunk-BDOSMEEP.mjs';
2
+ import { DEFAULT_SEGMENT_MAX_BYTES, DEFAULT_CHECKPOINT_INTERVAL_MS, DEFAULT_CHECKPOINT_MUTATION_THRESHOLD, DEFAULT_COMPACTION_THRESHOLD, DEFAULT_ASYNC_FLUSH_INTERVAL_MS, WRITES_STALL_ABOVE_UNCHECKPOINTED_BYTES, directoryCheckpointStore, manifestKey, decodeSegmentManifest, readListedFile, adapterCheckpointStore, SINGLE_NODE_PRIMARY_TERM, readMetadataEnvelope, writeMetadataEnvelope, metadataFromConfig, DIRECTORY_LOCK_ATTEMPTS, createSeqOwner, readSegmentManifest, snapshotBundleKey, reclaimUnlistedKeys, manifestReferencedKeys, loadSegmentedCheckpoint, checkpointLastSeqNo, manifestFileRefs, DIRECTORY_LOCK_SETTLE_MS, readSegmentFile, isRecord, invalidManifest, deserializePayloadV2, unpackEnvelopeBytes, checkpointPrimaryTerm, frameRecord, isId, isUint32, isSequenceNumber, writeCheckpointSegments, partitionContentsOf, writeLiveVectors, commitCheckpointManifest, removeCheckpointGarbage, readWalSegments, durableRecordMissing, MAX_SEGMENTS_PER_PARTITION, growPartitionsTo, writeSegmentHeader, VECTOR_FILE_ENVELOPE_VERSION, SEGMENT_HEADER_SIZE, documentsOfPayloadV2, readCommitMarker, nextMarkerSlot, encodeMarkerSlot, markerSlotOffset, DIRECTORY_IDENTITY_CHECK_INTERVAL_MS, metadataConfigOf, buildEntry, readCurrentManifest, WHOLE_PARTITION_LARGEST_DOCUMENT_COUNT, WHOLE_PARTITION_MIN_CHANGED_SHARE, captureWholePartition, CHECKPOINT_TIMEOUT_RECOVERY_BACKOFF_MS, CHECKPOINT_WORKER_TIMEOUT_MS, CHECKPOINT_WORKER_IDLE_MS, LOG_RECORDS_PER_CHECKPOINT } from './chunk-CRNQAT2Q.mjs';
3
+ import { applyDeleteEntry, applyIndexEntry } from './chunk-74OXU3R2.mjs';
4
+ import { encodeDocument, fnv1a, requireValidFieldTypes, openChecksummedEnvelope, HEADER_SIZE, buildSegmentPayload, resolvePartitionInsertOptions, freezeSegmentShared, createSharedFrozenSegment } from './chunk-YMDH3JID.mjs';
5
+ import { decodeVectorIndexParts, VECTOR_FILE_MAX_VECTORS, deadBytesFor, countDead, decodeVectorFilePayload, decodeVectorGraphPayload, graphPartsOfEarlierPayload } from './chunk-AQZDOKDT.mjs';
6
+ import { compareCodePoints, MIN_M, MAX_FILE_BYTES, detectRuntime, resolveWorkerEntry } from './chunk-6DHYBN7M.mjs';
7
7
  import './chunk-JPTQZWJQ.mjs';
8
8
  import { NarsilError, ErrorCodes, MAX_INDEX_NAME_LENGTH, INDEX_NAME_PATTERN } from './chunk-RHG4O77A.mjs';
9
9
  import { decode } from '@msgpack/msgpack';
@@ -1,8 +1,8 @@
1
1
  import { spawnNodeWorker } from './chunk-HOZW3PKP.mjs';
2
- import { VECTOR_WORKER_COPIES_ALLOWED, openSharedQuantizer, STORE_ORDINAL_LAYOUT_GENERATION, searchOrdinals, insertNode, GRAPH_RETIRED, nodeCountOf, tombstoneCountOf, DEFAULT_PROMOTION_THRESHOLD, DEFAULT_FILTER_THRESHOLD, osqBitsOf, noBuildHistory, createOsqQuantizer, recordCheckpoint, planCheckpoint, deserialize, assignStorePartitions, liveSize, ordinalFilterForSubsets, ordinalFilterValues, handOverBuildTurns, threadsHoldCurrentLayout, filterForOptions, openGraphState, STORE_UNPLACED_COUNT, STORE_LIVE_COUNT, STORE_REMOVED_COUNT, fixedView, OSQ4_MIN_DIMENSION, sharedVectorStoreBytes, STORE_SLOTS, IN_MEMORY, resetStoreHeader, STORE_RELEASED_VECTORS_TO_DISK, magnitude, emptyFieldBeforeRestore, ESTIMATED_MS_PER_TOMBSTONE, graphNeedsRebuild, ESTIMATED_MS_PER_VECTOR_REBUILD, releaseReplacedVectors, yieldBuildTurn, createOrdinalFilter, addToOrdinalFilter, nativeScoresOf, toScore, ordinalFilterHas, WORKER_COPY_MIN_VECTORS, allLiveDocIds, openVectorBlock, NOTHING_STAGED, arenaFloat32Distance, slotByteOffset, detachNativeStore, STORE_BLOCK_COUNT, STORE_CODE_BLOCK_COUNT, createSharedVectorStoreHandles, BLOCK_MAX_BYTES, growBufferTo, unplacedChunkCount, STORE_DOC_ID_BYTES, recalibrateFromStore, signatureOf, nativeStoreScratchBytes, noteFallback, toDistance, euclideanDistance, dotProduct, cosineSimilarityWithMagnitudes, QUERY_STAGED, createVectorBlock, ensureBlockSlots, createHNSWIndex, adoptGraph, topLayerInParts, BUILD_RETRY_MAX_DELAY_MS, BUILD_RETRY_FIRST_DELAY_MS, fieldHandlesOf, sharedMemoryAvailable, requireWholeNeighbourLists, shuffleInPlace, createCentroidSums, liveOrdinals, RECALIBRATION_CHUNK_VECTORS, BUILD_CHUNK_SIZE, centroidOfCentroidSums, meanOfCentroidSums, countOfCentroidSums, squaredLengthsOfCentroidSums, releaseLocksHeldBy, DRIFT_CHECK_GROWTH_FACTOR, DISK_ADOPTION_YIELD_INTERVAL, adoptLoadedCalibration, RECALIBRATION_DRIFT_RATIO } from './chunk-JOVZ6HMT.mjs';
3
- export { releaseLocksHeldBy } from './chunk-JOVZ6HMT.mjs';
4
- import { isDead, NO_LIVE_VECTOR_AT_POSITION, bytesToVectors } from './chunk-RIJSLY2I.mjs';
5
- import { MAX_RENUMBERED_SEARCH_ATTEMPTS, DISK_STORAGE_BLOCK_BYTES, compareCodePoints, UNPLACED_FLAG_CHUNK_ORDINALS, MAX_VECTOR_ORDINALS, GRAPH_BUILD_CHUNKS_IN_FLIGHT_PER_WORKER, GRAPH_BUILD_DISPATCH_CHUNK, resolveWorkerCount, resolveWorkerEntry, detectRuntime, noteThreadSlotLive, noteThreadSlotGone, WORKER_YOUNG_GENERATION_MB, VECTOR_SEARCH_TIMEOUT_MS, VECTOR_SEARCH_LOAD_TIMEOUT_MS, VECTOR_SCRATCH_SLOTS, VECTOR_INSERT_TIMEOUT_MS } from './chunk-BDOSMEEP.mjs';
2
+ import { VECTOR_WORKER_COPIES_ALLOWED, openSharedQuantizer, STORE_ORDINAL_LAYOUT_GENERATION, searchOrdinals, insertNode, GRAPH_RETIRED, nodeCountOf, tombstoneCountOf, DEFAULT_PROMOTION_THRESHOLD, DEFAULT_FILTER_THRESHOLD, osqBitsOf, noBuildHistory, createOsqQuantizer, recordCheckpoint, planCheckpoint, deserialize, assignStorePartitions, liveSize, ordinalFilterForSubsets, ordinalFilterValues, handOverBuildTurns, threadsHoldCurrentLayout, filterForOptions, openGraphState, STORE_UNPLACED_COUNT, STORE_LIVE_COUNT, STORE_REMOVED_COUNT, fixedView, OSQ4_MIN_DIMENSION, sharedVectorStoreBytes, STORE_SLOTS, IN_MEMORY, resetStoreHeader, STORE_RELEASED_VECTORS_TO_DISK, magnitude, emptyFieldBeforeRestore, ESTIMATED_MS_PER_TOMBSTONE, graphNeedsRebuild, ESTIMATED_MS_PER_VECTOR_REBUILD, releaseReplacedVectors, yieldBuildTurn, createOrdinalFilter, addToOrdinalFilter, nativeScoresOf, toScore, ordinalFilterHas, WORKER_COPY_MIN_VECTORS, allLiveDocIds, openVectorBlock, NOTHING_STAGED, arenaFloat32Distance, slotByteOffset, detachNativeStore, STORE_BLOCK_COUNT, STORE_CODE_BLOCK_COUNT, createSharedVectorStoreHandles, BLOCK_MAX_BYTES, growBufferTo, unplacedChunkCount, STORE_DOC_ID_BYTES, recalibrateFromStore, signatureOf, nativeStoreScratchBytes, noteFallback, toDistance, euclideanDistance, dotProduct, cosineSimilarityWithMagnitudes, QUERY_STAGED, createVectorBlock, ensureBlockSlots, createHNSWIndex, adoptGraph, topLayerInParts, BUILD_RETRY_MAX_DELAY_MS, BUILD_RETRY_FIRST_DELAY_MS, fieldHandlesOf, sharedMemoryAvailable, requireWholeNeighbourLists, shuffleInPlace, createCentroidSums, liveOrdinals, RECALIBRATION_CHUNK_VECTORS, BUILD_CHUNK_SIZE, centroidOfCentroidSums, meanOfCentroidSums, countOfCentroidSums, squaredLengthsOfCentroidSums, releaseLocksHeldBy, DRIFT_CHECK_GROWTH_FACTOR, DISK_ADOPTION_YIELD_INTERVAL, adoptLoadedCalibration, RECALIBRATION_DRIFT_RATIO } from './chunk-MM7WIDI5.mjs';
3
+ export { releaseLocksHeldBy } from './chunk-MM7WIDI5.mjs';
4
+ import { isDead, NO_LIVE_VECTOR_AT_POSITION, bytesToVectors } from './chunk-AQZDOKDT.mjs';
5
+ import { MAX_RENUMBERED_SEARCH_ATTEMPTS, DISK_STORAGE_BLOCK_BYTES, compareCodePoints, UNPLACED_FLAG_CHUNK_ORDINALS, MAX_VECTOR_ORDINALS, GRAPH_BUILD_CHUNKS_IN_FLIGHT_PER_WORKER, GRAPH_BUILD_DISPATCH_CHUNK, resolveWorkerCount, resolveWorkerEntry, detectRuntime, noteThreadSlotLive, noteThreadSlotGone, WORKER_YOUNG_GENERATION_MB, VECTOR_SEARCH_TIMEOUT_MS, VECTOR_SEARCH_LOAD_TIMEOUT_MS, VECTOR_SCRATCH_SLOTS, VECTOR_INSERT_TIMEOUT_MS } from './chunk-6DHYBN7M.mjs';
6
6
  import { NarsilError, ErrorCodes, isNarsilError } from './chunk-RHG4O77A.mjs';
7
7
 
8
8
  // src/core/heap.ts
@@ -18,7 +18,7 @@ function restoreDepsOf(core, host) {
18
18
  function queueRestore(core, host, restoresInFlight, indexName, data) {
19
19
  const previous = restoresInFlight.get(indexName) ?? Promise.resolve();
20
20
  const restored = previous.then(async () => {
21
- const { restoreFromSnapshot } = await import('./snapshot-OAAA5UJ7.mjs');
21
+ const { restoreFromSnapshot } = await import('./snapshot-R7GY6PAG.mjs');
22
22
  await restoreFromSnapshot(indexName, data, restoreDepsOf(core, host));
23
23
  });
24
24
  const settled = restored.then(
@@ -1,9 +1,9 @@
1
- import { vectorsPerFile } from './chunk-JOVZ6HMT.mjs';
2
- import { indexMetadataOf, writeCheckpointSegments, DEFAULT_COMPACTION_THRESHOLD, writeLiveVectors, commitCheckpointManifest, manifestKey, decodeSegmentManifest, SINGLE_NODE_PRIMARY_TERM, partitionContentsOf, manifestFileRefs, unpackIndexSnapshotEnvelope, encodeSegmentManifest, loadSegmentedCheckpoint, writeMetadataEnvelope, openManifestPayload, listedKeysOf, decodeManifestPayload, readSegmentFile, readVectorFile, readGraphParts, documentsOfPayloadV2, deserializePayloadV1 } from './chunk-PGIM3HIM.mjs';
3
- import './chunk-EJDUFWSO.mjs';
4
- import { encodeIndexConfiguration, createByteReader, hasNrslMagic, HEADER_SIZE, readHeader, raiseEarlierReleaseGraphSetting, restoredConfigFields, restoredEmbedding, getLanguage, validateSchema, validatePatternValueLimit, requireSurfaceFormsForPartialFields, validateVectorPromotion, validateVectorStorage, validateRequiredFieldsInSchema, resolveIndexAnalysis, validateEmbeddingConfig, prepareStoredSynonyms, rejectSnapshot, readHeapStatistics, readResidentMemory, extractVectorFieldsFromSchema, loadVectorCodeFor, decodeEveryStoredDocument, parseVectorDimension, insertDocumentVectors, decodeIndexConfiguration, flattenSchema } from './chunk-KPJMDPHG.mjs';
5
- import { decodeVectorIndexParts, vectorsToBytes, VECTOR_FILE_PAYLOAD_VERSION, bytesToVectors } from './chunk-RIJSLY2I.mjs';
6
- import { MAX_FILE_BYTES } from './chunk-BDOSMEEP.mjs';
1
+ import { vectorsPerFile } from './chunk-MM7WIDI5.mjs';
2
+ import { indexMetadataOf, writeCheckpointSegments, DEFAULT_COMPACTION_THRESHOLD, writeLiveVectors, commitCheckpointManifest, manifestKey, decodeSegmentManifest, SINGLE_NODE_PRIMARY_TERM, partitionContentsOf, manifestFileRefs, unpackIndexSnapshotEnvelope, encodeSegmentManifest, loadSegmentedCheckpoint, writeMetadataEnvelope, openManifestPayload, listedKeysOf, decodeManifestPayload, readSegmentFile, readVectorFile, readGraphParts, documentsOfPayloadV2, deserializePayloadV1 } from './chunk-CRNQAT2Q.mjs';
3
+ import './chunk-74OXU3R2.mjs';
4
+ import { encodeIndexConfiguration, createByteReader, hasNrslMagic, HEADER_SIZE, readHeader, raiseEarlierReleaseGraphSetting, restoredConfigFields, restoredEmbedding, getLanguage, validateSchema, validatePatternValueLimit, requireSurfaceFormsForPartialFields, validateVectorPromotion, validateVectorStorage, validateRequiredFieldsInSchema, resolveIndexAnalysis, validateEmbeddingConfig, prepareStoredSynonyms, rejectSnapshot, readHeapStatistics, readResidentMemory, extractVectorFieldsFromSchema, loadVectorCodeFor, decodeEveryStoredDocument, parseVectorDimension, insertDocumentVectors, decodeIndexConfiguration, flattenSchema } from './chunk-YMDH3JID.mjs';
5
+ import { decodeVectorIndexParts, vectorsToBytes, VECTOR_FILE_PAYLOAD_VERSION, bytesToVectors } from './chunk-AQZDOKDT.mjs';
6
+ import { MAX_FILE_BYTES } from './chunk-6DHYBN7M.mjs';
7
7
  import './chunk-JPTQZWJQ.mjs';
8
8
  import { NarsilError, ErrorCodes } from './chunk-RHG4O77A.mjs';
9
9
  import { decode } from '@msgpack/msgpack';
@@ -1,7 +1,7 @@
1
- import { setNestedValue, KEYWORD_SEGMENT_ENVELOPE_VERSION, decodeKeywordSegment } from './chunk-EJDUFWSO.mjs';
2
- import { decodeStoredDocument, openChecksummedEnvelope, NUMBER_TAG, DATE_TAG, BYTES_TAG, encodeBase64, startsWithTagPrefix, OBJECT_TAG, MILLISECONDS_PER_SECOND, NANOSECONDS_PER_MILLISECOND, DOCUMENT_EXPORT_VERSION, DOCUMENT_EXPORT_FORMAT } from './chunk-KPJMDPHG.mjs';
3
- import { decodeVectorFilePayload, isDead, bytesToVectors } from './chunk-RIJSLY2I.mjs';
4
- import './chunk-BDOSMEEP.mjs';
1
+ import { setNestedValue, KEYWORD_SEGMENT_ENVELOPE_VERSION, decodeKeywordSegment } from './chunk-74OXU3R2.mjs';
2
+ import { decodeStoredDocument, openChecksummedEnvelope, NUMBER_TAG, DATE_TAG, BYTES_TAG, encodeBase64, startsWithTagPrefix, OBJECT_TAG, MILLISECONDS_PER_SECOND, NANOSECONDS_PER_MILLISECOND, DOCUMENT_EXPORT_VERSION, DOCUMENT_EXPORT_FORMAT } from './chunk-YMDH3JID.mjs';
3
+ import { decodeVectorFilePayload, isDead, bytesToVectors } from './chunk-AQZDOKDT.mjs';
4
+ import './chunk-6DHYBN7M.mjs';
5
5
  import './chunk-JPTQZWJQ.mjs';
6
6
  import { EXPORT_CHUNK_BYTES, NarsilError, ErrorCodes } from './chunk-RHG4O77A.mjs';
7
7
  import { decode } from '@msgpack/msgpack';
@@ -1,4 +1,4 @@
1
- import { SCRATCH_SLOTS_PER_THREAD_POOL } from './chunk-GBEEG5AN.mjs';
1
+ import { SCRATCH_SLOTS_PER_THREAD_POOL } from './chunk-QSK35UC2.mjs';
2
2
  import { NarsilError, ErrorCodes } from './chunk-BWJVNZPR.mjs';
3
3
 
4
4
  // src/workers/constants.ts
@@ -1,6 +1,6 @@
1
1
  import { nodeThreadId } from './chunk-C7SLA6CM.mjs';
2
2
  import { getFs, getPath } from './chunk-HLPRHOSO.mjs';
3
- import { DIRECTORY_LOCK_ATTEMPTS, DIRECTORY_LOCK_SETTLE_MS, DIRECTORY_LOCK_PROCESS_START_TOLERANCE_MS } from './chunk-J5QP52HA.mjs';
3
+ import { DIRECTORY_LOCK_ATTEMPTS, DIRECTORY_LOCK_SETTLE_MS, DIRECTORY_LOCK_PROCESS_START_TOLERANCE_MS } from './chunk-SM7S3HAP.mjs';
4
4
  import { compareCodePoints } from './chunk-YTJCGKM4.mjs';
5
5
  import { NarsilError, ErrorCodes } from './chunk-BWJVNZPR.mjs';
6
6
  import { openSync, close, readFileSync } from 'fs';
@@ -1,8 +1,8 @@
1
- import { vectorsPerFile } from './chunk-S7GNDRPS.mjs';
2
- import { writeLiveVectors, decodeSegmentManifest, openManifestPayload, listedKeysOf, decodeManifestPayload, SINGLE_NODE_PRIMARY_TERM } from './chunk-PNFKUCG3.mjs';
1
+ import { vectorsPerFile } from './chunk-TZRWRIZ6.mjs';
2
+ import { writeLiveVectors, decodeSegmentManifest, openManifestPayload, listedKeysOf, decodeManifestPayload, SINGLE_NODE_PRIMARY_TERM } from './chunk-HMPYTBBN.mjs';
3
3
  import { vectorsToBytes, VECTOR_FILE_PAYLOAD_VERSION } from './chunk-YYQIODMF.mjs';
4
- import { writeCheckpointSegments, DEFAULT_COMPACTION_THRESHOLD, commitCheckpointManifest, manifestKey, manifestFileRefs, partitionContentsOf } from './chunk-J5QP52HA.mjs';
5
- import { HEADER_SIZE } from './chunk-WVCOCKBU.mjs';
4
+ import { writeCheckpointSegments, DEFAULT_COMPACTION_THRESHOLD, commitCheckpointManifest, manifestKey, manifestFileRefs, partitionContentsOf } from './chunk-SM7S3HAP.mjs';
5
+ import { HEADER_SIZE } from './chunk-YVDYMXR2.mjs';
6
6
  import { MAX_FILE_BYTES } from './chunk-U476IXKQ.mjs';
7
7
  import { NarsilError, ErrorCodes } from './chunk-BWJVNZPR.mjs';
8
8
 
@@ -1,7 +1,7 @@
1
1
  import { stopUsingTheNativeSearchCore, noteFallback, nativeSearchCoreIsEnabled } from './chunk-DJHHF2L5.mjs';
2
2
  import { unpackLevels, readTrailer, stageQueryLevels, osqCodeBytes, osqStagedQueryBytes, osqRecordBytes, writeRecord } from './chunk-37CD3OKS.mjs';
3
3
  import { markSimdUnavailable } from './chunk-KOKM4PQN.mjs';
4
- import { MAX_WASM_PAGES, WASM_PAGE_BYTES, VECTOR_SCRATCH_SLOTS, UNPLACED_FLAG_CHUNK_ORDINALS, OSQ_STEPS, OSQ_GRID, VECTOR_BLOCK_INITIAL_SLOTS, MAX_VECTOR_ORDINALS, VECTOR_STORE_INITIAL_CAPACITY, LOCK_SPIN_ITERATIONS, LOCK_WAIT_SLICE_MS, OSQ_REFINE_ROUNDS, OSQ_REFINE_TOLERANCE, OSQ_PLACEMENT_QUERY_BITS, GRAPH_EXCLUSIVE_WAIT_DEADLINE_MS, OSQ_QUERY_BITS, NATIVE_ATTACH_RETRY_MS, OSQ_LAMBDA, GRAPH_LOCK_WAIT_SLICE_MS, MAX_DOC_ID_TABLE_BYTES } from './chunk-GBEEG5AN.mjs';
4
+ import { MAX_WASM_PAGES, WASM_PAGE_BYTES, VECTOR_SCRATCH_SLOTS, UNPLACED_FLAG_CHUNK_ORDINALS, OSQ_STEPS, OSQ_GRID, VECTOR_BLOCK_INITIAL_SLOTS, MAX_VECTOR_ORDINALS, VECTOR_STORE_INITIAL_CAPACITY, LOCK_SPIN_ITERATIONS, LOCK_WAIT_SLICE_MS, OSQ_REFINE_ROUNDS, OSQ_REFINE_TOLERANCE, OSQ_PLACEMENT_QUERY_BITS, GRAPH_LOCK_WAIT_SLICE_MS, OSQ_QUERY_BITS, NATIVE_ATTACH_RETRY_MS, GRAPH_LOCK_WAIT_DEADLINE_MS, OSQ_LAMBDA, MAX_DOC_ID_TABLE_BYTES } from './chunk-QSK35UC2.mjs';
5
5
  import { loadNativeCore } from './chunk-JZVARCRZ.mjs';
6
6
  import { COMPACTION_TOMBSTONE_RATIO, COMPACTION_ABSOLUTE_THRESHOLD, PLACEMENT_ROOM_REQUESTS, MAX_LAYER_CAP, INITIAL_LIST_CAPACITY, INITIAL_UPPER_SLOTS, DEFAULT_EF_SEARCH, FARTHEST_REJECTED_LINKS_KEPT } from './chunk-HMFNFVP7.mjs';
7
7
  import { compareCodePoints } from './chunk-YTJCGKM4.mjs';
@@ -81,6 +81,7 @@ var HELD_WRITE_VERSION = 1;
81
81
  var HELD_GRAPH = 2;
82
82
  var HELD_FENCE = 3;
83
83
  var HELD_GRAPH_WAITING = 4;
84
+ var HELD_ENTRY = 5;
84
85
  var HELD_WORDS_PER_THREAD = 32;
85
86
  var METRIC_CODES = ["cosine", "dotProduct", "euclidean"];
86
87
  function perOrdinal(bytesPerOrdinal, initialOrdinals) {
@@ -168,33 +169,16 @@ function waitOn(words, index, seen, sliceMs = LOCK_WAIT_SLICE_MS) {
168
169
  function heldIndex(locks, kind) {
169
170
  return locks.threadSlot * HELD_WORDS_PER_THREAD + kind;
170
171
  }
171
- function acquireExclusive(words, index) {
172
- let spins = 0;
173
- for (; ; ) {
174
- const seen = Atomics.compareExchange(words, index, FREE, EXCLUSIVE);
175
- if (seen === FREE) return;
176
- if (spins < LOCK_SPIN_ITERATIONS) {
177
- spins += 1;
178
- continue;
179
- }
180
- waitOn(words, index, seen, GRAPH_LOCK_WAIT_SLICE_MS);
181
- }
182
- }
183
- function acquireExclusiveWithin(words, index, deadlineMs) {
184
- let spins = 0;
185
- let deadline = Number.NaN;
186
- for (; ; ) {
187
- const seen = Atomics.compareExchange(words, index, FREE, EXCLUSIVE);
188
- if (seen === FREE) return true;
189
- if (spins < LOCK_SPIN_ITERATIONS) {
190
- spins += 1;
191
- continue;
192
- }
193
- const now = performance.now();
194
- if (Number.isNaN(deadline)) deadline = now + deadlineMs;
195
- else if (now >= deadline) return false;
196
- waitOn(words, index, seen, GRAPH_LOCK_WAIT_SLICE_MS);
197
- }
172
+ function waitedSince(locks, startedAt, lock) {
173
+ const now = performance.now();
174
+ if (Number.isNaN(startedAt)) return now;
175
+ if (now - startedAt < GRAPH_LOCK_WAIT_DEADLINE_MS) return startedAt;
176
+ if (releaseGoneThreads(locks) > 0) return now;
177
+ throw new NarsilError(
178
+ ErrorCodes.WORKER_TIMEOUT,
179
+ `Another thread held a lock on the vector graph for ${GRAPH_LOCK_WAIT_DEADLINE_MS} ms, so this thread stopped waiting for it`,
180
+ { waitedMs: GRAPH_LOCK_WAIT_DEADLINE_MS, threadSlot: locks.threadSlot, lock }
181
+ );
198
182
  }
199
183
  function releaseExclusive(words, index) {
200
184
  Atomics.store(words, index, FREE);
@@ -205,9 +189,22 @@ var WRITER_WAITING = 2;
205
189
  var VERSION_STEP = 4;
206
190
  function beginNodeRead(locks, ord) {
207
191
  const words = locks.words(ord);
192
+ const seen = Atomics.load(words, ord);
193
+ if ((seen & WRITE_HELD) === 0) return seen;
194
+ return waitForNodeRead(locks, words, ord);
195
+ }
196
+ function waitForNodeRead(locks, words, ord) {
197
+ let spins = 0;
198
+ let startedAt = Number.NaN;
208
199
  for (; ; ) {
209
200
  const seen = Atomics.load(words, ord);
210
201
  if ((seen & WRITE_HELD) === 0) return seen;
202
+ if (spins < LOCK_SPIN_ITERATIONS) {
203
+ spins += 1;
204
+ continue;
205
+ }
206
+ spins = 0;
207
+ startedAt = waitedSince(locks, startedAt, "node");
211
208
  }
212
209
  }
213
210
  function nodeReadHeld(locks, ord, version) {
@@ -217,6 +214,7 @@ function nodeReadHeld(locks, ord, version) {
217
214
  function lockNodeWrite(locks, ord) {
218
215
  const words = locks.words(ord);
219
216
  let spins = 0;
217
+ let startedAt = Number.NaN;
220
218
  for (; ; ) {
221
219
  const seen = Atomics.load(words, ord);
222
220
  if ((seen & WRITE_HELD) === 0) {
@@ -232,6 +230,7 @@ function lockNodeWrite(locks, ord) {
232
230
  spins += 1;
233
231
  continue;
234
232
  }
233
+ startedAt = waitedSince(locks, startedAt, "node");
235
234
  const waiting = seen | WRITER_WAITING;
236
235
  if (waiting === seen || Atomics.compareExchange(words, ord, seen, waiting) === seen) {
237
236
  waitOn(words, ord, waiting);
@@ -250,6 +249,7 @@ function unlockNodeWrite(locks, ord) {
250
249
  function lockGraphShared(locks) {
251
250
  const { header } = locks;
252
251
  let spins = 0;
252
+ let startedAt = Number.NaN;
253
253
  for (; ; ) {
254
254
  const seen = Atomics.load(header, GRAPH_LOCK);
255
255
  if (seen >= FREE && Atomics.load(header, GRAPH_WRITERS_WAITING) === 0) {
@@ -263,6 +263,7 @@ function lockGraphShared(locks) {
263
263
  spins += 1;
264
264
  continue;
265
265
  }
266
+ startedAt = waitedSince(locks, startedAt, "graph");
266
267
  waitOn(header, GRAPH_LOCK, seen, GRAPH_LOCK_WAIT_SLICE_MS);
267
268
  }
268
269
  }
@@ -272,17 +273,22 @@ function unlockGraphShared(locks) {
272
273
  if (Atomics.sub(header, GRAPH_LOCK, 1) === 1 && canWait(header)) Atomics.notify(header, GRAPH_LOCK);
273
274
  }
274
275
  function lockGraphExclusive(locks) {
276
+ const { header } = locks;
275
277
  Atomics.store(locks.held, heldIndex(locks, HELD_GRAPH_WAITING), 1);
276
- Atomics.add(locks.header, GRAPH_WRITERS_WAITING, 1);
278
+ Atomics.add(header, GRAPH_WRITERS_WAITING, 1);
277
279
  try {
278
- if (acquireExclusiveWithin(locks.header, GRAPH_LOCK, GRAPH_EXCLUSIVE_WAIT_DEADLINE_MS)) return;
279
- const released = releaseGoneThreads(locks);
280
- if (released > 0 && acquireExclusiveWithin(locks.header, GRAPH_LOCK, GRAPH_EXCLUSIVE_WAIT_DEADLINE_MS)) return;
281
- throw new NarsilError(
282
- ErrorCodes.WORKER_TIMEOUT,
283
- `Another thread held the vector graph for ${GRAPH_EXCLUSIVE_WAIT_DEADLINE_MS} ms, so this change to the graph gave up`,
284
- { waitedMs: GRAPH_EXCLUSIVE_WAIT_DEADLINE_MS, threadSlot: locks.threadSlot }
285
- );
280
+ let spins = 0;
281
+ let startedAt = Number.NaN;
282
+ for (; ; ) {
283
+ const seen = Atomics.compareExchange(header, GRAPH_LOCK, FREE, EXCLUSIVE);
284
+ if (seen === FREE) return;
285
+ if (spins < LOCK_SPIN_ITERATIONS) {
286
+ spins += 1;
287
+ continue;
288
+ }
289
+ startedAt = waitedSince(locks, startedAt, "graphAlone");
290
+ waitOn(header, GRAPH_LOCK, seen, GRAPH_LOCK_WAIT_SLICE_MS);
291
+ }
286
292
  } finally {
287
293
  Atomics.sub(locks.header, GRAPH_WRITERS_WAITING, 1);
288
294
  Atomics.store(locks.held, heldIndex(locks, HELD_GRAPH_WAITING), 0);
@@ -292,9 +298,25 @@ function unlockGraphExclusive(locks) {
292
298
  releaseExclusive(locks.header, GRAPH_LOCK);
293
299
  }
294
300
  function lockEntry(locks) {
295
- acquireExclusive(locks.header, GRAPH_ENTRY_LOCK);
301
+ const { header } = locks;
302
+ let spins = 0;
303
+ let startedAt = Number.NaN;
304
+ for (; ; ) {
305
+ const seen = Atomics.compareExchange(header, GRAPH_ENTRY_LOCK, FREE, EXCLUSIVE);
306
+ if (seen === FREE) {
307
+ Atomics.store(locks.held, heldIndex(locks, HELD_ENTRY), 1);
308
+ return;
309
+ }
310
+ if (spins < LOCK_SPIN_ITERATIONS) {
311
+ spins += 1;
312
+ continue;
313
+ }
314
+ startedAt = waitedSince(locks, startedAt, "entry");
315
+ waitOn(header, GRAPH_ENTRY_LOCK, seen, GRAPH_LOCK_WAIT_SLICE_MS);
316
+ }
296
317
  }
297
318
  function unlockEntry(locks) {
319
+ Atomics.store(locks.held, heldIndex(locks, HELD_ENTRY), 0);
298
320
  releaseExclusive(locks.header, GRAPH_ENTRY_LOCK);
299
321
  }
300
322
  function releaseGoneThreads(locks) {
@@ -306,7 +328,8 @@ function releaseGoneThreads(locks) {
306
328
  const writeOrd = Atomics.load(locks.held, base + HELD_WRITE) - 1;
307
329
  const holdsGraph = Atomics.load(locks.held, base + HELD_GRAPH) === 1;
308
330
  const waitsForGraph = Atomics.load(locks.held, base + HELD_GRAPH_WAITING) === 1;
309
- if (!holdsGraph && !waitsForGraph && writeOrd < 0) continue;
331
+ const holdsEntry = Atomics.load(locks.held, base + HELD_ENTRY) === 1;
332
+ if (!holdsGraph && !waitsForGraph && !holdsEntry && writeOrd < 0) continue;
310
333
  releaseSlot(locks.header, locks.held, writeOrd >= 0 ? locks.words(writeOrd) : null, slot);
311
334
  released += 1;
312
335
  }
@@ -320,6 +343,7 @@ function releaseSlot(header, held, words, threadSlot) {
320
343
  if (Atomics.exchange(held, base + HELD_GRAPH_WAITING, 0) === 1) {
321
344
  Atomics.sub(header, GRAPH_WRITERS_WAITING, 1);
322
345
  }
346
+ if (Atomics.exchange(held, base + HELD_ENTRY, 0) === 1) releaseExclusive(header, GRAPH_ENTRY_LOCK);
323
347
  const writeOrd = Atomics.exchange(held, base + HELD_WRITE, 0) - 1;
324
348
  const writeVersion = Atomics.load(held, base + HELD_WRITE_VERSION);
325
349
  if (words !== null && writeOrd >= 0 && writeOrd < words.length) {
@@ -1,7 +1,7 @@
1
1
  import { decodeVectorGraphPartPayload, assembleGraphParts, decodeVectorFilePayload, countDead, VECTOR_FILE_MAX_VECTORS, deadBytesFor } from './chunk-YYQIODMF.mjs';
2
- import { MAX_SEGMENT_ID, MANIFEST_ENVELOPE_VERSION, EARLIER_SEGMENT_MANIFEST_VERSION, SEGMENT_MANIFEST_VERSION, MAX_SEGMENTS_PER_PARTITION, segmentKey, readSegmentFile, manifestKey, segmentsPrefix, readListedFile, requireListedChecksum, vectorFileKey, graphPartKey } from './chunk-J5QP52HA.mjs';
3
- import { VERSION, rulesOfStoredSynonyms, openChecksummedEnvelope, readHeader, HEADER_SIZE, crc32, engineVersionParts, writeHeader, packChecksummedEnvelope } from './chunk-WVCOCKBU.mjs';
4
- import { decodeEveryStoredDocument, createSharedFrozenSegment, shareSegmentArrays } from './chunk-SP3NM3ZG.mjs';
2
+ import { MAX_SEGMENT_ID, MANIFEST_ENVELOPE_VERSION, EARLIER_SEGMENT_MANIFEST_VERSION, SEGMENT_MANIFEST_VERSION, MAX_SEGMENTS_PER_PARTITION, segmentKey, readSegmentFile, manifestKey, segmentsPrefix, readListedFile, requireListedChecksum, vectorFileKey, graphPartKey } from './chunk-SM7S3HAP.mjs';
3
+ import { VERSION, rulesOfStoredSynonyms, openChecksummedEnvelope, readHeader, HEADER_SIZE, crc32, engineVersionParts, writeHeader, packChecksummedEnvelope } from './chunk-YVDYMXR2.mjs';
4
+ import { decodeEveryStoredDocument, createSharedFrozenSegment, shareSegmentArrays } from './chunk-JTNDFNDP.mjs';
5
5
  import { flattenSchema, requireValidFieldTypes, isQuantizationMode, isStorageMode } from './chunk-OEYI3KRB.mjs';
6
6
  import { MAX_FILE_BYTES, VALID_HNSW_METRICS } from './chunk-U476IXKQ.mjs';
7
7
  import { compareCodePoints } from './chunk-YTJCGKM4.mjs';