@delali/narsil 0.3.1-next.85 → 0.3.1-next.87

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 (82) hide show
  1. package/dist/browser/chunk-3BXQPIXK.mjs +602 -0
  2. package/dist/browser/chunk-3ZRMZIH4.mjs +3959 -0
  3. package/dist/browser/chunk-BBDAYUCO.mjs +2703 -0
  4. package/dist/browser/chunk-FHFFWLEK.mjs +669 -0
  5. package/dist/browser/chunk-HOZW3PKP.mjs +9 -0
  6. package/dist/browser/chunk-NQW2YXEX.mjs +346 -0
  7. package/dist/browser/chunk-TBMNPGFO.mjs +22910 -0
  8. package/dist/browser/durability-wiring-7RUN7LNS.mjs +3250 -0
  9. package/dist/browser/module-E25UDADM.mjs +2766 -0
  10. package/dist/browser/snapshot-A42DRERF.mjs +888 -0
  11. package/dist/browser/write-4U6Q26TJ.mjs +206 -0
  12. package/dist/{capabilities-CAdkp2P-.d.ts → capabilities-SJPttcgQ.d.ts} +2 -2
  13. package/dist/chunk-37CD3OKS.mjs +87 -0
  14. package/dist/chunk-AQU2QHSY.mjs +7247 -0
  15. package/dist/{chunk-OLXM65YH.mjs → chunk-AV4IJKD2.mjs} +1 -18
  16. package/dist/{chunk-4D6OH4EF.mjs → chunk-AXDAS2VA.mjs} +7 -5
  17. package/dist/{chunk-LS5IRM23.mjs → chunk-BVOJIYRV.mjs} +2 -25
  18. package/dist/chunk-C7SLA6CM.mjs +19 -0
  19. package/dist/{chunk-KJ7LB3TR.mjs → chunk-CVQWQVFX.mjs} +3 -22
  20. package/dist/chunk-DJHHF2L5.mjs +17 -0
  21. package/dist/chunk-FGMGUDHX.mjs +21 -0
  22. package/dist/chunk-IKST36MA.mjs +614 -0
  23. package/dist/{chunk-2453RJYK.mjs → chunk-J2BPXTD7.mjs} +167 -176
  24. package/dist/chunk-JFJBA3PD.mjs +522 -0
  25. package/dist/chunk-K4OWQ2M3.mjs +462 -0
  26. package/dist/chunk-L5ORED7V.mjs +25 -0
  27. package/dist/chunk-MKK4OZ5W.mjs +703 -0
  28. package/dist/chunk-MXS5HWIH.mjs +515 -0
  29. package/dist/chunk-P36MUFEJ.mjs +10 -0
  30. package/dist/chunk-PR4O7CAP.mjs +18 -0
  31. package/dist/{chunk-4VBG6PEH.mjs → chunk-PSUJCOSE.mjs} +3 -2
  32. package/dist/{chunk-ZCKPRCYI.mjs → chunk-Q5DC6WAB.mjs} +1 -1
  33. package/dist/{chunk-NFF5TDRG.mjs → chunk-QZN3MIJ3.mjs} +1 -16
  34. package/dist/chunk-R7OSDAFK.mjs +44 -0
  35. package/dist/chunk-RVM7AODE.mjs +73 -0
  36. package/dist/{chunk-XYDP7CCJ.mjs → chunk-SYRFSF6V.mjs} +6 -4
  37. package/dist/{chunk-SREPGC6O.mjs → chunk-T6CNO72J.mjs} +1 -1
  38. package/dist/chunk-T7DMUVTL.mjs +1714 -0
  39. package/dist/chunk-UKSUENHK.mjs +997 -0
  40. package/dist/{chunk-NIWDQTZB.mjs → chunk-ULRPNYAG.mjs} +1220 -2311
  41. package/dist/{chunk-GNYXCLJS.mjs → chunk-URGLSNKR.mjs} +4 -3
  42. package/dist/chunk-WQSHDZ7Z.mjs +631 -0
  43. package/dist/{chunk-RCSXJCI5.mjs → chunk-XBXKPWMR.mjs} +20 -2664
  44. package/dist/{chunk-RM6FRYEC.mjs → chunk-XSZVS4S3.mjs} +3 -2
  45. package/dist/chunk-Y2F66IQJ.mjs +74 -0
  46. package/dist/chunk-YCJLVNWR.mjs +262 -0
  47. package/dist/{client-CKUtkLz3.d.ts → client-BMK53IR2.d.ts} +3 -3
  48. package/dist/client.d.ts +8 -8
  49. package/dist/{config-CSDEPraV.d.ts → config-BUR-7eVQ.d.ts} +2 -2
  50. package/dist/{config-BuIkeM5C.d.ts → config-UJx1dyX1.d.ts} +2 -2
  51. package/dist/direct-executor-LD6JW57R.mjs +18 -0
  52. package/dist/distribution/coordinator/etcd.d.ts +2 -2
  53. package/dist/distribution/coordinator/in-memory.d.ts +2 -2
  54. package/dist/distribution.d.ts +8 -8
  55. package/dist/distribution.mjs +30 -15
  56. package/dist/durability-wiring-5S32KDDC.mjs +2797 -0
  57. package/dist/{engine-DMNZJAUq.d.ts → engine-9X6W5naj.d.ts} +2 -2
  58. package/dist/{index-DzONZUKE.d.ts → index-vCMu8OeQ.d.ts} +1 -1
  59. package/dist/index.browser.mjs +2 -38121
  60. package/dist/index.d.ts +23 -9
  61. package/dist/index.mjs +18 -14
  62. package/dist/{memory-BPKNx9Tl.d.ts → memory-CV9NAxLY.d.ts} +1 -1
  63. package/dist/module-WIDYIJLY.mjs +1819 -0
  64. package/dist/partial-words.mjs +5 -3
  65. package/dist/pattern.mjs +3 -2
  66. package/dist/persistence/durability/checkpoint-worker.d.ts +1 -1
  67. package/dist/persistence/durability/checkpoint-worker.mjs +23 -13
  68. package/dist/react.d.ts +7 -7
  69. package/dist/{schema-DgyDijhf.d.ts → schema-DtsgmNfU.d.ts} +1 -1
  70. package/dist/server.d.ts +10 -10
  71. package/dist/server.mjs +14 -9
  72. package/dist/snapshot-6BYSUPWL.mjs +469 -0
  73. package/dist/{tasks-DGyz586z.d.ts → tasks-BGaZJyoY.d.ts} +1 -1
  74. package/dist/{thread-EUUNJNKU.mjs → thread-GS65E6RM.mjs} +12 -9
  75. package/dist/vector/search-worker.d.ts +30 -3
  76. package/dist/vector/search-worker.mjs +6 -2
  77. package/dist/workers/entry.mjs +5 -3
  78. package/dist/write-HLEZTL2L.mjs +233 -0
  79. package/package.json +11 -7
  80. package/dist/chunk-67MQF5CV.mjs +0 -15198
  81. package/dist/direct-executor-NY7ZTZIH.mjs +0 -19
  82. package/dist/simd-DW5AtJ6B.d.ts +0 -41
@@ -0,0 +1,669 @@
1
+ // src/errors.ts
2
+ var NARSIL_ERROR_MARKER = /* @__PURE__ */ Symbol.for("@delali/narsil.NarsilError");
3
+ var ErrorCodes = {
4
+ SCHEMA_INVALID_TYPE: "SCHEMA_INVALID_TYPE",
5
+ SCHEMA_DEPTH_EXCEEDED: "SCHEMA_DEPTH_EXCEEDED",
6
+ SCHEMA_INVALID_VECTOR_DIMENSION: "SCHEMA_INVALID_VECTOR_DIMENSION",
7
+ SCHEMA_INVALID_GEOPOINT: "SCHEMA_INVALID_GEOPOINT",
8
+ DOC_NOT_FOUND: "DOC_NOT_FOUND",
9
+ DOC_ALREADY_EXISTS: "DOC_ALREADY_EXISTS",
10
+ DOC_VALIDATION_FAILED: "DOC_VALIDATION_FAILED",
11
+ INDEX_NOT_FOUND: "INDEX_NOT_FOUND",
12
+ INDEX_ALREADY_EXISTS: "INDEX_ALREADY_EXISTS",
13
+ INDEX_ORPHANED: "INDEX_ORPHANED",
14
+ INDEX_REOPEN_CAPACITY_EXHAUSTED: "INDEX_REOPEN_CAPACITY_EXHAUSTED",
15
+ INSTANCE_SHUT_DOWN: "INSTANCE_SHUT_DOWN",
16
+ PARTITION_CORRUPTED: "PARTITION_CORRUPTED",
17
+ PARTITION_REBALANCING_BACKPRESSURE: "PARTITION_REBALANCING_BACKPRESSURE",
18
+ WORKER_CRASHED: "WORKER_CRASHED",
19
+ WORKER_BUSY: "WORKER_BUSY",
20
+ WORKER_TIMEOUT: "WORKER_TIMEOUT",
21
+ WORKER_ACTION_FAILED: "WORKER_ACTION_FAILED",
22
+ PERSISTENCE_SAVE_FAILED: "PERSISTENCE_SAVE_FAILED",
23
+ PERSISTENCE_LOAD_FAILED: "PERSISTENCE_LOAD_FAILED",
24
+ PERSISTENCE_DELETE_FAILED: "PERSISTENCE_DELETE_FAILED",
25
+ PERSISTENCE_CRC_MISMATCH: "PERSISTENCE_CRC_MISMATCH",
26
+ PERSISTENCE_WAL_CORRUPT: "PERSISTENCE_WAL_CORRUPT",
27
+ PERSISTENCE_FSYNC_FAILED: "PERSISTENCE_FSYNC_FAILED",
28
+ SEARCH_INVALID_FIELD: "SEARCH_INVALID_FIELD",
29
+ VECTOR_DIMENSION_MISMATCH: "VECTOR_DIMENSION_MISMATCH",
30
+ SEARCH_INVALID_FILTER: "SEARCH_INVALID_FILTER",
31
+ SEARCH_INVALID_MODE: "SEARCH_INVALID_MODE",
32
+ SEARCH_INVALID_CURSOR: "SEARCH_INVALID_CURSOR",
33
+ SEARCH_RESULT_WINDOW_EXCEEDED: "SEARCH_RESULT_WINDOW_EXCEEDED",
34
+ SEARCH_WORK_CAP_EXCEEDED: "SEARCH_WORK_CAP_EXCEEDED",
35
+ LANGUAGE_NOT_SUPPORTED: "LANGUAGE_NOT_SUPPORTED",
36
+ ENVELOPE_VERSION_MISMATCH: "ENVELOPE_VERSION_MISMATCH",
37
+ ENVELOPE_INVALID_MAGIC: "ENVELOPE_INVALID_MAGIC",
38
+ PARTITION_CAPACITY_EXCEEDED: "PARTITION_CAPACITY_EXCEEDED",
39
+ EMBEDDING_FAILED: "EMBEDDING_FAILED",
40
+ EMBEDDING_DIMENSION_MISMATCH: "EMBEDDING_DIMENSION_MISMATCH",
41
+ EMBEDDING_NO_SOURCE: "EMBEDDING_NO_SOURCE",
42
+ EMBEDDING_CONFIG_INVALID: "EMBEDDING_CONFIG_INVALID",
43
+ DOC_MISSING_REQUIRED_FIELD: "DOC_MISSING_REQUIRED_FIELD",
44
+ CONFIG_INVALID: "CONFIG_INVALID",
45
+ QUERY_ROUTING_FAILED: "QUERY_ROUTING_FAILED",
46
+ QUERY_PARTIAL_FAILURE: "QUERY_PARTIAL_FAILURE",
47
+ QUERY_NODE_TIMEOUT: "QUERY_NODE_TIMEOUT",
48
+ QUERY_NO_ACTIVE_REPLICA: "QUERY_NO_ACTIVE_REPLICA",
49
+ CLUSTER_OPERATION_UNSUPPORTED: "CLUSTER_OPERATION_UNSUPPORTED",
50
+ CLUSTER_WRITE_BLOCKED: "CLUSTER_WRITE_BLOCKED",
51
+ ALLOCATION_NO_DATA_NODES: "ALLOCATION_NO_DATA_NODES",
52
+ ALLOCATION_INVALID_CONFIG: "ALLOCATION_INVALID_CONFIG",
53
+ ALLOCATION_FAILED: "ALLOCATION_FAILED",
54
+ CONTROLLER_METADATA_INVALID: "CONTROLLER_METADATA_INVALID",
55
+ NODE_BOOTSTRAP_FAILED: "NODE_BOOTSTRAP_FAILED",
56
+ NODE_ALREADY_JOINED: "NODE_ALREADY_JOINED",
57
+ NODE_NOT_JOINED: "NODE_NOT_JOINED",
58
+ NODE_NOT_READY: "NODE_NOT_READY",
59
+ NODE_NOT_CONTROLLER: "NODE_NOT_CONTROLLER",
60
+ COORDINATOR_DEPENDENCY_MISSING: "COORDINATOR_DEPENDENCY_MISSING",
61
+ TRANSPORT_DEPENDENCY_MISSING: "TRANSPORT_DEPENDENCY_MISSING",
62
+ REPLICATION_ENTRY_INVALID: "REPLICATION_ENTRY_INVALID",
63
+ REPLICATION_INSYNC_REMOVAL_FAILED: "REPLICATION_INSYNC_REMOVAL_FAILED",
64
+ REPLICATION_ROLLBACK_FAILED: "REPLICATION_ROLLBACK_FAILED",
65
+ REPLICATION_LOG_FULL: "REPLICATION_LOG_FULL",
66
+ REPLICATION_ENTRY_CORRUPT: "REPLICATION_ENTRY_CORRUPT",
67
+ REPLICATION_SNAPSHOT_CORRUPT: "REPLICATION_SNAPSHOT_CORRUPT",
68
+ REPLICATION_TERM_MISMATCH: "REPLICATION_TERM_MISMATCH",
69
+ REPLICATION_SYNC_FAILED: "REPLICATION_SYNC_FAILED",
70
+ PARTITION_NOT_PRIMARY: "PARTITION_NOT_PRIMARY",
71
+ PARTITION_UNASSIGNED: "PARTITION_UNASSIGNED",
72
+ INSUFFICIENT_REPLICAS: "INSUFFICIENT_REPLICAS",
73
+ SNAPSHOT_SYNC_UNAUTHORIZED: "SNAPSHOT_SYNC_UNAUTHORIZED",
74
+ SNAPSHOT_SYNC_REQUEST_INVALID: "SNAPSHOT_SYNC_REQUEST_INVALID",
75
+ SNAPSHOT_SYNC_INDEX_NOT_FOUND: "SNAPSHOT_SYNC_INDEX_NOT_FOUND",
76
+ SNAPSHOT_SYNC_CAPACITY_EXHAUSTED: "SNAPSHOT_SYNC_CAPACITY_EXHAUSTED",
77
+ SNAPSHOT_SYNC_SNAPSHOT_FAILED: "SNAPSHOT_SYNC_SNAPSHOT_FAILED",
78
+ SNAPSHOT_SYNC_DECODE_FAILED: "SNAPSHOT_SYNC_DECODE_FAILED",
79
+ SNAPSHOT_SYNC_FRAME_INVALID: "SNAPSHOT_SYNC_FRAME_INVALID",
80
+ SNAPSHOT_SYNC_HEADER_INVALID: "SNAPSHOT_SYNC_HEADER_INVALID",
81
+ SNAPSHOT_SYNC_HEADER_MISMATCH: "SNAPSHOT_SYNC_HEADER_MISMATCH",
82
+ SNAPSHOT_SYNC_CHUNK_OUT_OF_ORDER: "SNAPSHOT_SYNC_CHUNK_OUT_OF_ORDER",
83
+ SNAPSHOT_SYNC_CHUNK_OVERFLOW: "SNAPSHOT_SYNC_CHUNK_OVERFLOW",
84
+ SNAPSHOT_SYNC_CHUNK_SIZE_EXCEEDED: "SNAPSHOT_SYNC_CHUNK_SIZE_EXCEEDED",
85
+ SNAPSHOT_SYNC_CHUNK_MISSING: "SNAPSHOT_SYNC_CHUNK_MISSING",
86
+ SNAPSHOT_SYNC_END_MISSING: "SNAPSHOT_SYNC_END_MISSING",
87
+ SNAPSHOT_SYNC_CHECKSUM_MISMATCH: "SNAPSHOT_SYNC_CHECKSUM_MISMATCH",
88
+ SNAPSHOT_SYNC_PRIMARY_ERROR: "SNAPSHOT_SYNC_PRIMARY_ERROR",
89
+ SNAPSHOT_SYNC_NO_TARGETS: "SNAPSHOT_SYNC_NO_TARGETS",
90
+ SNAPSHOT_SYNC_TRANSPORT_FAILED: "SNAPSHOT_SYNC_TRANSPORT_FAILED",
91
+ SNAPSHOT_SYNC_SCHEMA_UNAVAILABLE: "SNAPSHOT_SYNC_SCHEMA_UNAVAILABLE",
92
+ SNAPSHOT_SYNC_RESTORE_FAILED: "SNAPSHOT_SYNC_RESTORE_FAILED",
93
+ SNAPSHOT_SYNC_RESTORE_CLEANUP_FAILED: "SNAPSHOT_SYNC_RESTORE_CLEANUP_FAILED",
94
+ SNAPSHOT_SYNC_TIMEOUT: "SNAPSHOT_SYNC_TIMEOUT",
95
+ SNAPSHOT_SYNC_ALLOCATION_UNAVAILABLE: "SNAPSHOT_SYNC_ALLOCATION_UNAVAILABLE",
96
+ SNAPSHOT_SYNC_NOT_ASSIGNED: "SNAPSHOT_SYNC_NOT_ASSIGNED",
97
+ SNAPSHOT_SYNC_ABORTED: "SNAPSHOT_SYNC_ABORTED"
98
+ };
99
+ var ServerErrorCodes = {
100
+ INVALID_REQUEST: "INVALID_REQUEST",
101
+ INVALID_JSON: "INVALID_JSON",
102
+ EMPTY_BODY: "EMPTY_BODY",
103
+ PAYLOAD_TOO_LARGE: "PAYLOAD_TOO_LARGE",
104
+ NOT_FOUND: "NOT_FOUND",
105
+ TASK_NOT_FOUND: "TASK_NOT_FOUND",
106
+ TASK_NOT_CANCELLABLE: "TASK_NOT_CANCELLABLE",
107
+ TASK_OWNED_BY_ANOTHER_INSTANCE: "TASK_OWNED_BY_ANOTHER_INSTANCE",
108
+ TASK_INTERRUPTED: "TASK_INTERRUPTED",
109
+ TOO_MANY_REQUESTS: "TOO_MANY_REQUESTS",
110
+ HOOK_ERROR: "HOOK_ERROR",
111
+ INTERNAL_ERROR: "INTERNAL_ERROR"
112
+ };
113
+ var ClientErrorCodes = {
114
+ CLIENT_CONNECTION_FAILED: "CLIENT_CONNECTION_FAILED",
115
+ CLIENT_REQUEST_TIMEOUT: "CLIENT_REQUEST_TIMEOUT",
116
+ CLIENT_REQUEST_ABORTED: "CLIENT_REQUEST_ABORTED",
117
+ CLIENT_INVALID_RESPONSE: "CLIENT_INVALID_RESPONSE",
118
+ CLIENT_TASK_TIMEOUT: "CLIENT_TASK_TIMEOUT",
119
+ CLIENT_UNEXPECTED_ERROR: "CLIENT_UNEXPECTED_ERROR"
120
+ };
121
+ var NarsilError = class extends Error {
122
+ /** This says which failure it is. */
123
+ code;
124
+ /** This carries the values behind the failure, such as the field, index, or limit involved. It is empty when the code says everything. */
125
+ details;
126
+ /**
127
+ * Builds an error carrying a code the caller can branch on.
128
+ *
129
+ * @param code - The failure this error reports, from {@link ErrorCodes} for
130
+ * an engine failure, {@link ServerErrorCodes} for one the HTTP layer raised,
131
+ * or {@link ClientErrorCodes} for one that stopped a request from reaching a
132
+ * server.
133
+ * @param message - Plain description, for a log or a person.
134
+ * @param details - Values behind the failure, which reach
135
+ * {@link NarsilError.details}.
136
+ */
137
+ constructor(code, message, details) {
138
+ super(message);
139
+ this.name = "NarsilError";
140
+ this.code = code;
141
+ this.details = details ?? {};
142
+ Object.defineProperty(this, NARSIL_ERROR_MARKER, { value: true });
143
+ }
144
+ };
145
+ function isNarsilError(value) {
146
+ return typeof value === "object" && value !== null && NARSIL_ERROR_MARKER in value;
147
+ }
148
+ function createNarsilError(code, message, details) {
149
+ return new NarsilError(code, message, details);
150
+ }
151
+
152
+ // src/runtime/simd-support.ts
153
+ var SIMD_PROBE_MODULE = new Uint8Array([
154
+ 0,
155
+ 97,
156
+ 115,
157
+ 109,
158
+ 1,
159
+ 0,
160
+ 0,
161
+ 0,
162
+ 1,
163
+ 5,
164
+ 1,
165
+ 96,
166
+ 0,
167
+ 1,
168
+ 123,
169
+ 3,
170
+ 2,
171
+ 1,
172
+ 0,
173
+ 10,
174
+ 10,
175
+ 1,
176
+ 8,
177
+ 0,
178
+ 65,
179
+ 0,
180
+ 253,
181
+ 15,
182
+ 253,
183
+ 98,
184
+ 11
185
+ ]);
186
+ function runtimeStartsSimdModule() {
187
+ try {
188
+ if (typeof WebAssembly === "undefined") return false;
189
+ new WebAssembly.Instance(new WebAssembly.Module(SIMD_PROBE_MODULE));
190
+ return true;
191
+ } catch {
192
+ return false;
193
+ }
194
+ }
195
+ var simdAvailable = runtimeStartsSimdModule();
196
+ function isSimdAvailable() {
197
+ return simdAvailable;
198
+ }
199
+ function markSimdUnavailable() {
200
+ simdAvailable = false;
201
+ }
202
+
203
+ // src/search/constants.ts
204
+ var RESULT_WINDOW = 1e4;
205
+ var DEFAULT_PAGE_SIZE = 10;
206
+ var MAX_CURSOR_LENGTH = 40960;
207
+ var MAX_SORT_FIELDS = 8;
208
+ var MAX_SORT_FIELD_NAME_LENGTH = 255;
209
+ var MAX_CURSOR_ANCHOR_CODE_POINTS = 512;
210
+ var PREFIX_MAX_EXPANSIONS = 50;
211
+ var DEFAULT_FUZZY_PREFIX_LENGTH = 2;
212
+ var MAX_TOLERANCE = 10;
213
+ var MAX_PREFIX_LENGTH = 1024;
214
+ var DEFAULT_MAX_PER_GROUP = 1;
215
+ var DEFAULT_RANK_CONSTANT = 60;
216
+ var MIN_RANK_CONSTANT = 1;
217
+ var DEFAULT_LINEAR_ALPHA = 0.5;
218
+ var MIN_LINEAR_ALPHA = 0;
219
+ var MAX_LINEAR_ALPHA = 1;
220
+
221
+ // src/engine/constants.ts
222
+ var MIN_DOCUMENTS_FOR_SEGMENTS = 64;
223
+ var BATCH_CHUNK_SIZE = 1e3;
224
+ var DEFAULT_LIMIT = DEFAULT_PAGE_SIZE;
225
+ var DEFAULT_OFFSET = 0;
226
+ var INDEX_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
227
+ var ABSOLUTE_WINDOWS_PATH_PATTERN = /^[a-zA-Z]:[\\/]/;
228
+ var MODULE_URL_SCHEME_PATTERN = /^(file|https?|data|node):/;
229
+ var MAX_INDEX_NAME_LENGTH = 255;
230
+ var MAX_DOC_ID_LENGTH = 512;
231
+ var EXPORT_CHUNK_BYTES = 1048576;
232
+ var MAX_EXPORT_LINE_BYTES = 117443592;
233
+ var MAX_INDEX_CONFIGURATION_BYTES = 16777216;
234
+ var IMPORT_BATCH_DOCUMENTS = 1e3;
235
+ var MAX_IMPORT_REFUSALS_REPORTED = 1e3;
236
+ var MIN_SWEEP_INTERVAL_MS = 100;
237
+ var MAX_SWEEP_INTERVAL_MS = 6e4;
238
+ var HEAP_PRESSURE_WARNING_FRACTION = 0.9;
239
+ var HEAP_PRESSURE_REARM_FRACTION = 0.8;
240
+ var STATISTICS_BROADCAST_INTERVAL_MS = 5e3;
241
+ var FOREIGN_STATS_TTL_MS = 6e4;
242
+ var DEFAULT_SUGGEST_LIMIT = 10;
243
+ var MAX_SUGGEST_LIMIT = 100;
244
+ var SUGGEST_OVERSAMPLE_FACTOR = 1.5;
245
+ var SUGGEST_OVERSAMPLE_PADDING = 10;
246
+ var MAX_SUGGEST_SCATTER_LIMIT = Math.ceil(MAX_SUGGEST_LIMIT * SUGGEST_OVERSAMPLE_FACTOR) + SUGGEST_OVERSAMPLE_PADDING;
247
+
248
+ // src/serialization/constants.ts
249
+ var CHECKSUM_YIELD_CHUNK_BYTES = 4 * 1024 * 1024;
250
+ var NATIVE_CRC32_MIN_BYTES = 16;
251
+ var MAX_FILE_BYTES = 2147483647;
252
+ var VALID_HNSW_METRICS = /* @__PURE__ */ new Set(["cosine", "dotProduct", "euclidean"]);
253
+
254
+ // src/core/ordering/code-points.ts
255
+ function exceedsCodePoints(value, maximum) {
256
+ if (value.length <= maximum) return false;
257
+ let counted = 0;
258
+ let i = 0;
259
+ while (i < value.length) {
260
+ const unit = value.charCodeAt(i);
261
+ if (unit >= 55296 && unit < 56320 && i + 1 < value.length) {
262
+ const low = value.charCodeAt(i + 1);
263
+ if (low >= 56320 && low < 57344) i++;
264
+ }
265
+ i++;
266
+ counted++;
267
+ if (counted > maximum) return true;
268
+ }
269
+ return false;
270
+ }
271
+ var SURROGATE_UNIT = /[\ud800-\udfff]/;
272
+ function holdsUnpairedSurrogate(value) {
273
+ if (!SURROGATE_UNIT.test(value)) return false;
274
+ for (let i = 0; i < value.length; i++) {
275
+ const unit = value.charCodeAt(i);
276
+ if (unit < 55296 || unit >= 57344) continue;
277
+ if (unit >= 56320) return true;
278
+ const low = value.charCodeAt(i + 1);
279
+ if (!(low >= 56320 && low < 57344)) return true;
280
+ i++;
281
+ }
282
+ return false;
283
+ }
284
+ function codePointCount(value) {
285
+ let counted = 0;
286
+ for (let i = 0; i < value.length; i++) {
287
+ const unit = value.charCodeAt(i);
288
+ if (unit >= 55296 && unit < 56320 && i + 1 < value.length) {
289
+ const low = value.charCodeAt(i + 1);
290
+ if (low >= 56320 && low < 57344) i++;
291
+ }
292
+ counted++;
293
+ }
294
+ return counted;
295
+ }
296
+ function adjustUtf16Unit(unit) {
297
+ if (unit < 55296) return unit;
298
+ if (unit < 57344) return unit + 8192;
299
+ return unit - 2048;
300
+ }
301
+ function compareCodePoints(a, b) {
302
+ const shorter = a.length < b.length ? a.length : b.length;
303
+ let i = 0;
304
+ while (i < shorter && a.charCodeAt(i) === b.charCodeAt(i)) i++;
305
+ if (i === shorter) return a.length - b.length;
306
+ return adjustUtf16Unit(a.charCodeAt(i)) - adjustUtf16Unit(b.charCodeAt(i));
307
+ }
308
+
309
+ // src/core/ordering/fold-table.ts
310
+ var SINGLE_FOLDS = "1t,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;2j,lj;b,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;2,w;1,w;1,w;1,w;1,w;1,w;1,w;y,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;4,1;2,1;2,1;3,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;3,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,-3d;1,1;2,1;2,1;2,-7g;2,5u;1,1;2,1;2,5q;1,1;2,5p;1,5p;1,1;3,27;1,5m;1,5n;1,1;2,5p;1,5r;2,5v;1,5t;1,1;4,5v;1,5x;2,5y;1,1;2,1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y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;";
311
+ var MULTI_FOLDS = "67,37,37;29,2x,lj;p,jg,32;4n,2y,lo;bk,qh,lk,ld;w,qt,lk,ld;d3,12d,136;4y7,2w,mp;1,38,lk;1,3b,lm;1,3d,lm;1,2p,ji;4,37,37;4y,qt,lv;2,qt,lv,lc;2,qt,lv,ld;2,qt,lv,n6;16,64g,qh;1,64h,qh;1,64i,qh;1,64j,qh;1,64k,qh;1,64l,qh;1,64m,qh;1,64n,qh;1,64g,qh;1,64h,qh;1,64i,qh;1,64j,qh;1,64k,qh;1,64l,qh;1,64m,qh;1,64n,qh;1,65c,qh;1,65d,qh;1,65e,qh;1,65f,qh;1,65g,qh;1,65h,qh;1,65i,qh;1,65j,qh;1,65c,qh;1,65d,qh;1,65e,qh;1,65f,qh;1,65g,qh;1,65h,qh;1,65i,qh;1,65j,qh;1,674,qh;1,675,qh;1,676,qh;1,677,qh;1,678,qh;1,679,qh;1,67a,qh;1,67b,qh;1,674,qh;1,675,qh;1,676,qh;1,677,qh;1,678,qh;1,679,qh;1,67a,qh;1,67b,qh;3,67k,qh;1,q9,qh;1,q4,qh;2,q9,n6;1,q9,n6,qh;5,q9,qh;6,67o,qh;1,qf,qh;1,q6,qh;2,qf,n6;1,qf,n6,qh;5,qf,qh;6,qh,lk,lc;1,qh,lk,ld;3,qh,n6;1,qh,lk,n6;b,qt,lk,lc;1,qt,lk,ld;1,qp,lv;2,qt,n6;1,qt,lk,n6;b,67w,qh;1,qx,qh;1,r2,qh;2,qx,n6;1,qx,n6,qh;5,qx,qh;179g,2u,2u;1,2u,2x;1,2u,30;1,2u,2u,2x;1,2u,2u,30;1,37,38;1,37,38;d,12s,12u;1,12s,12d;1,12s,12j;1,132,12u;1,12s,12l;";
312
+ var singleTable = null;
313
+ var multiTable = null;
314
+ function singleFoldTable() {
315
+ if (singleTable === null) {
316
+ singleTable = /* @__PURE__ */ new Map();
317
+ let source = 0;
318
+ for (const entry of SINGLE_FOLDS.split(";")) {
319
+ if (entry.length === 0) continue;
320
+ const [delta, offset] = entry.split(",");
321
+ source += Number.parseInt(delta, 36);
322
+ singleTable.set(source, source + Number.parseInt(offset, 36));
323
+ }
324
+ }
325
+ return singleTable;
326
+ }
327
+ function multiFoldTable() {
328
+ if (multiTable === null) {
329
+ multiTable = /* @__PURE__ */ new Map();
330
+ let source = 0;
331
+ for (const entry of MULTI_FOLDS.split(";")) {
332
+ if (entry.length === 0) continue;
333
+ const parts = entry.split(",");
334
+ source += Number.parseInt(parts[0], 36);
335
+ multiTable.set(
336
+ source,
337
+ parts.slice(1).map((cp) => Number.parseInt(cp, 36))
338
+ );
339
+ }
340
+ }
341
+ return multiTable;
342
+ }
343
+
344
+ // src/core/ordering/fold-compare.ts
345
+ var EXHAUSTED = -1;
346
+ function foldOf(codePoint, single, multi) {
347
+ if (codePoint < 128) return codePoint >= 65 && codePoint <= 90 ? codePoint + 32 : codePoint;
348
+ return single.get(codePoint) ?? multi.get(codePoint) ?? codePoint;
349
+ }
350
+ function nextFoldedCodePoint(text, cursor, single, multi) {
351
+ if (cursor.pending !== null) {
352
+ const cp2 = cursor.pending[cursor.pendingIndex];
353
+ cursor.pendingIndex++;
354
+ if (cursor.pendingIndex === cursor.pending.length) {
355
+ cursor.pending = null;
356
+ cursor.pendingIndex = 0;
357
+ }
358
+ return cp2;
359
+ }
360
+ if (cursor.index >= text.length) return EXHAUSTED;
361
+ let cp = text.charCodeAt(cursor.index);
362
+ cursor.index++;
363
+ if (cp >= 55296 && cp < 56320 && cursor.index < text.length) {
364
+ const low = text.charCodeAt(cursor.index);
365
+ if (low >= 56320 && low < 57344) {
366
+ cp = 65536 + (cp - 55296 << 10) + (low - 56320);
367
+ cursor.index++;
368
+ }
369
+ }
370
+ const folded = foldOf(cp, single, multi);
371
+ if (typeof folded === "number") return folded;
372
+ if (folded.length > 1) {
373
+ cursor.pending = folded;
374
+ cursor.pendingIndex = 1;
375
+ }
376
+ return folded[0];
377
+ }
378
+ function compareCaseFolded(a, b) {
379
+ const shorter = a.length < b.length ? a.length : b.length;
380
+ let start = 0;
381
+ while (start < shorter && a.charCodeAt(start) === b.charCodeAt(start)) start++;
382
+ if (start === a.length && start === b.length) return 0;
383
+ if (start > 0) {
384
+ const previous = a.charCodeAt(start - 1);
385
+ if (previous >= 55296 && previous < 56320) start--;
386
+ }
387
+ const single = singleFoldTable();
388
+ const multi = multiFoldTable();
389
+ const aCursor = { index: start, pending: null, pendingIndex: 0 };
390
+ const bCursor = { index: start, pending: null, pendingIndex: 0 };
391
+ for (; ; ) {
392
+ const aCp = nextFoldedCodePoint(a, aCursor, single, multi);
393
+ const bCp = nextFoldedCodePoint(b, bCursor, single, multi);
394
+ if (aCp !== bCp) return aCp - bCp;
395
+ if (aCp === EXHAUSTED) return 0;
396
+ }
397
+ }
398
+ function compareSortStrings(a, b) {
399
+ const folded = compareCaseFolded(a, b);
400
+ if (folded !== 0) return folded;
401
+ return compareCodePoints(a, b);
402
+ }
403
+ function appendFoldedCodePoint(codePoint, out) {
404
+ const folded = foldOf(codePoint, singleFoldTable(), multiFoldTable());
405
+ if (typeof folded === "number") {
406
+ out.push(folded);
407
+ return;
408
+ }
409
+ for (const foldedCodePoint of folded) out.push(foldedCodePoint);
410
+ }
411
+
412
+ // src/core/ordering/constants.ts
413
+ var SORT_VALUE_MAX_CODE_POINTS = 512;
414
+
415
+ // src/core/ordering/sort-values.ts
416
+ var SORT_MODES = ["min", "max", "avg", "median"];
417
+ function isSortMode(value) {
418
+ return value === "min" || value === "max" || value === "avg" || value === "median";
419
+ }
420
+ function defaultSortMode(direction) {
421
+ return direction === "desc" ? "max" : "min";
422
+ }
423
+ function sortModeOf(entry) {
424
+ return entry.mode ?? defaultSortMode(entry.direction);
425
+ }
426
+ function truncateSortString(value) {
427
+ if (value.length <= SORT_VALUE_MAX_CODE_POINTS) return value;
428
+ let index = 0;
429
+ let counted = 0;
430
+ while (index < value.length && counted < SORT_VALUE_MAX_CODE_POINTS) {
431
+ const unit = value.charCodeAt(index);
432
+ if (unit >= 55296 && unit < 56320 && index + 1 < value.length) {
433
+ const low = value.charCodeAt(index + 1);
434
+ if (low >= 56320 && low < 57344) index++;
435
+ }
436
+ index++;
437
+ counted++;
438
+ }
439
+ return value.slice(0, index);
440
+ }
441
+ function toComparableSortValue(value) {
442
+ if (typeof value === "string") return truncateSortString(value);
443
+ if (typeof value === "number") return Number.isFinite(value) ? value : null;
444
+ if (typeof value === "boolean") return value;
445
+ return null;
446
+ }
447
+ function numericReduction(values, mode) {
448
+ const numbers = [];
449
+ for (const element of values) {
450
+ if (typeof element === "number" && Number.isFinite(element)) numbers.push(element);
451
+ }
452
+ if (numbers.length === 0) return null;
453
+ if (mode === "avg") {
454
+ let mean = 0;
455
+ for (let index = 0; index < numbers.length; index++) {
456
+ mean += (numbers[index] - mean) / (index + 1);
457
+ }
458
+ return mean;
459
+ }
460
+ numbers.sort((a, b) => a - b);
461
+ const middle = numbers.length >> 1;
462
+ if (numbers.length % 2 === 1) return numbers[middle];
463
+ return numbers[middle - 1] / 2 + numbers[middle] / 2;
464
+ }
465
+ function toReducedSortValue(value, mode) {
466
+ if (!Array.isArray(value)) return toComparableSortValue(value);
467
+ if (mode === "avg" || mode === "median") return numericReduction(value, mode);
468
+ let chosen = null;
469
+ for (const element of value) {
470
+ const comparable = toComparableSortValue(element);
471
+ if (comparable === null) continue;
472
+ if (chosen === null) {
473
+ chosen = comparable;
474
+ continue;
475
+ }
476
+ const comparison = comparePresentValues(comparable, chosen);
477
+ if (mode === "min" ? comparison < 0 : comparison > 0) chosen = comparable;
478
+ }
479
+ return chosen;
480
+ }
481
+ function readSortField(document, path) {
482
+ const segments = path.split(".");
483
+ let current = document;
484
+ for (const segment of segments) {
485
+ if (current === null || current === void 0 || typeof current !== "object") return void 0;
486
+ if (!Object.hasOwn(current, segment)) return void 0;
487
+ current = current[segment];
488
+ }
489
+ return current;
490
+ }
491
+ function typeRank(value) {
492
+ if (typeof value === "number") return 0;
493
+ if (typeof value === "string") return 1;
494
+ return 2;
495
+ }
496
+ function comparePresentValues(a, b) {
497
+ const rankDifference = typeRank(a) - typeRank(b);
498
+ if (rankDifference !== 0) return rankDifference;
499
+ if (typeof a === "number" && typeof b === "number") return a - b;
500
+ if (typeof a === "string" && typeof b === "string") return compareSortStrings(a, b);
501
+ if (a === b) return 0;
502
+ return a ? 1 : -1;
503
+ }
504
+ function compareComparableValues(a, b, direction) {
505
+ if (a === null && b === null) return 0;
506
+ if (a === null) return 1;
507
+ if (b === null) return -1;
508
+ const comparison = comparePresentValues(a, b);
509
+ if (comparison === 0) return 0;
510
+ return direction === "desc" ? -comparison : comparison;
511
+ }
512
+ function compareComparableKeys(aKey, bKey, directions) {
513
+ for (let i = 0; i < directions.length; i++) {
514
+ const comparison = compareComparableValues(aKey[i] ?? null, bKey[i] ?? null, directions[i]);
515
+ if (comparison !== 0) return comparison;
516
+ }
517
+ return 0;
518
+ }
519
+ function compareSortValues(aValues, bValues, directions) {
520
+ for (let i = 0; i < directions.length; i++) {
521
+ const a = toComparableSortValue(aValues[i]);
522
+ const b = toComparableSortValue(bValues[i]);
523
+ if (a === null && b === null) continue;
524
+ if (a === null) return 1;
525
+ if (b === null) return -1;
526
+ const comparison = comparePresentValues(a, b);
527
+ if (comparison !== 0) return directions[i] === "desc" ? -comparison : comparison;
528
+ }
529
+ return 0;
530
+ }
531
+
532
+ // src/vector/hnsw/constants.ts
533
+ var MAX_LAYER_CAP = 32;
534
+ var MAX_M = 512;
535
+ var MIN_M = 2;
536
+ var EARLIER_RELEASE_MIN_M = 1;
537
+ var INITIAL_UPPER_SLOTS = 64;
538
+ var INITIAL_LIST_CAPACITY = 64;
539
+ var PLACEMENT_ROOM_REQUESTS = 8;
540
+ var COMPACTION_TOMBSTONE_RATIO = 0.1;
541
+ var COMPACTION_ABSOLUTE_THRESHOLD = 1e3;
542
+ var DEFAULT_EF_SEARCH = 50;
543
+
544
+ // src/vector/constants.ts
545
+ var WASM_PAGE_BYTES = 65536;
546
+ var MAX_WASM_PAGES = 65536;
547
+ var VECTOR_STORE_INITIAL_CAPACITY = 16;
548
+ var VECTOR_BLOCK_INITIAL_SLOTS = 256;
549
+ var DISK_STORAGE_BLOCK_BYTES = 67108864;
550
+ var MAX_VECTOR_ORDINALS = 16777216;
551
+ var UNPLACED_FLAG_CHUNK_ORDINALS = 1024;
552
+ var VECTOR_SCRATCH_SLOTS = 64;
553
+ var SCRATCH_SLOTS_PER_THREAD_POOL = 31;
554
+ var MAX_DOC_ID_TABLE_BYTES = 1073741824;
555
+ var VECTOR_SEARCH_TIMEOUT_MS = 3e4;
556
+ var VECTOR_SEARCH_LOAD_TIMEOUT_MS = 3e5;
557
+ var VECTOR_INSERT_TIMEOUT_MS = 6e5;
558
+ var NATIVE_ATTACH_RETRY_MS = 1e3;
559
+ var LOCK_SPIN_ITERATIONS = 128;
560
+ var LOCK_WAIT_SLICE_MS = 20;
561
+ var GRAPH_LOCK_WAIT_SLICE_MS = 1;
562
+ var GRAPH_BUILD_DISPATCH_CHUNK = 64;
563
+ var GRAPH_BUILD_CHUNKS_IN_FLIGHT_PER_WORKER = 2;
564
+
565
+ // src/vector/osq/constants.ts
566
+ var OSQ_GRID = { 1: 0.798, 2: 1.493, 4: 2.514, 8: 3.922 };
567
+ var OSQ_STEPS = { 1: 1, 2: 3, 4: 15, 8: 255 };
568
+ var OSQ_QUERY_BITS = { 1: 4, 2: 4, 4: 4, 8: 8 };
569
+ var OSQ_LAMBDA = 0.1;
570
+ var OSQ_REFINE_ROUNDS = 5;
571
+ var OSQ_REFINE_TOLERANCE = 1e-8;
572
+ var DEFAULT_OVERSAMPLE_BY_BITS = { 1: 3, 2: 3, 4: 2, 8: 2 };
573
+ var DEFAULT_OSQ4_NARROW_OVERSAMPLE = 5;
574
+ var OSQ4_NARROW_DIMENSION_LIMIT = 1024;
575
+ var MIN_OVERSAMPLE = 1;
576
+
577
+ // src/workers/constants.ts
578
+ var WORKER_YOUNG_GENERATION_MB = 24;
579
+ var MIN_WORKER_COUNT = 2;
580
+ var MAX_WORKER_COUNT = 8;
581
+ var FALLBACK_CPU_COUNT = 4;
582
+ var MIN_CORES_FOR_SEVERAL_REQUEST_THREADS = 3;
583
+ var DEFAULT_BACKPRESSURE_LIMIT = 100;
584
+ var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
585
+ var SHUTDOWN_TIMEOUT_MS = 5e3;
586
+ var CONSECUTIVE_TIMEOUTS_BEFORE_DEATH = 3;
587
+
588
+ // src/workers/worker-count.ts
589
+ function detectCpuCount() {
590
+ try {
591
+ if (navigator?.hardwareConcurrency) {
592
+ return navigator.hardwareConcurrency;
593
+ }
594
+ if (typeof process !== "undefined") {
595
+ const ap = process.availableParallelism;
596
+ if (typeof ap === "function") {
597
+ return ap();
598
+ }
599
+ }
600
+ } catch {
601
+ return FALLBACK_CPU_COUNT;
602
+ }
603
+ return FALLBACK_CPU_COUNT;
604
+ }
605
+ function resolveWorkerCount(requested) {
606
+ if (requested !== void 0 && requested > 0) {
607
+ return Math.min(requested, SCRATCH_SLOTS_PER_THREAD_POOL);
608
+ }
609
+ return Math.max(MIN_WORKER_COUNT, Math.min(MAX_WORKER_COUNT, detectCpuCount() - 1));
610
+ }
611
+ function resolveRequestThreadCount(requested) {
612
+ if (detectCpuCount() < MIN_CORES_FOR_SEVERAL_REQUEST_THREADS) return 1;
613
+ return resolveWorkerCount(requested);
614
+ }
615
+ function splitWorkerBudget(total) {
616
+ const keyword = Math.ceil(total / 2);
617
+ return { keyword, vector: total - keyword };
618
+ }
619
+
620
+ // src/runtime/detect.ts
621
+ function detectRuntimeName() {
622
+ if ("Bun" in globalThis) {
623
+ return "bun";
624
+ }
625
+ if ("Deno" in globalThis) {
626
+ return "deno";
627
+ }
628
+ const proc = globalThis.process;
629
+ if (typeof proc === "object" && proc !== null && typeof proc.versions === "object" && typeof proc.versions?.node === "string") {
630
+ return "node";
631
+ }
632
+ return "browser";
633
+ }
634
+ function getCpuCount() {
635
+ const nav = globalThis.navigator;
636
+ if (nav && typeof nav.hardwareConcurrency === "number" && nav.hardwareConcurrency >= 1) {
637
+ return nav.hardwareConcurrency;
638
+ }
639
+ return 1;
640
+ }
641
+ function detectRuntime() {
642
+ const runtime = detectRuntimeName();
643
+ return {
644
+ runtime,
645
+ cpuCount: getCpuCount(),
646
+ supportsWorkerThreads: runtime === "node" || runtime === "bun",
647
+ supportsWebWorkers: runtime === "browser" || runtime === "deno" || runtime === "bun",
648
+ supportsFileSystem: runtime === "node" || runtime === "bun" || runtime === "deno",
649
+ supportsIndexedDB: runtime === "browser" || "indexedDB" in globalThis,
650
+ supportsBroadcastChannel: "BroadcastChannel" in globalThis
651
+ };
652
+ }
653
+
654
+ // src/workers/entry-point.ts
655
+ var DIST_SEGMENT = "/dist/";
656
+ function resolveWorkerEntry(moduleUrl, sourceDirectory, distEntry) {
657
+ const distIndex = moduleUrl.lastIndexOf(DIST_SEGMENT);
658
+ const entry = distIndex !== -1 ? new URL(distEntry, moduleUrl.slice(0, distIndex + DIST_SEGMENT.length)).href : sourceDirectory.test(moduleUrl) ? moduleUrl.replace(sourceDirectory, `${DIST_SEGMENT}${distEntry}`) : null;
659
+ return entry === moduleUrl ? null : entry;
660
+ }
661
+ function missingWorkerEntry(moduleUrl) {
662
+ return new NarsilError(
663
+ ErrorCodes.CONFIG_INVALID,
664
+ `The engine finds no worker entry beside its own module at "${moduleUrl}", which happens where a bundler folds @delali/narsil into an application bundle. Keep @delali/narsil outside the bundle, or set workers.enabled to false`,
665
+ { moduleUrl }
666
+ );
667
+ }
668
+
669
+ export { ABSOLUTE_WINDOWS_PATH_PATTERN, BATCH_CHUNK_SIZE, CHECKSUM_YIELD_CHUNK_BYTES, COMPACTION_ABSOLUTE_THRESHOLD, COMPACTION_TOMBSTONE_RATIO, CONSECUTIVE_TIMEOUTS_BEFORE_DEATH, ClientErrorCodes, DEFAULT_BACKPRESSURE_LIMIT, DEFAULT_EF_SEARCH, DEFAULT_FUZZY_PREFIX_LENGTH, DEFAULT_LIMIT, DEFAULT_LINEAR_ALPHA, DEFAULT_MAX_PER_GROUP, DEFAULT_OFFSET, DEFAULT_OSQ4_NARROW_OVERSAMPLE, DEFAULT_OVERSAMPLE_BY_BITS, DEFAULT_PAGE_SIZE, DEFAULT_RANK_CONSTANT, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_SUGGEST_LIMIT, DISK_STORAGE_BLOCK_BYTES, EARLIER_RELEASE_MIN_M, EXPORT_CHUNK_BYTES, ErrorCodes, FOREIGN_STATS_TTL_MS, GRAPH_BUILD_CHUNKS_IN_FLIGHT_PER_WORKER, GRAPH_BUILD_DISPATCH_CHUNK, GRAPH_LOCK_WAIT_SLICE_MS, HEAP_PRESSURE_REARM_FRACTION, HEAP_PRESSURE_WARNING_FRACTION, IMPORT_BATCH_DOCUMENTS, INDEX_NAME_PATTERN, INITIAL_LIST_CAPACITY, INITIAL_UPPER_SLOTS, LOCK_SPIN_ITERATIONS, LOCK_WAIT_SLICE_MS, MAX_CURSOR_ANCHOR_CODE_POINTS, MAX_CURSOR_LENGTH, MAX_DOC_ID_LENGTH, MAX_DOC_ID_TABLE_BYTES, MAX_EXPORT_LINE_BYTES, MAX_FILE_BYTES, MAX_IMPORT_REFUSALS_REPORTED, MAX_INDEX_CONFIGURATION_BYTES, MAX_INDEX_NAME_LENGTH, MAX_LAYER_CAP, MAX_LINEAR_ALPHA, MAX_M, MAX_PREFIX_LENGTH, MAX_SORT_FIELDS, MAX_SORT_FIELD_NAME_LENGTH, MAX_SUGGEST_LIMIT, MAX_SUGGEST_SCATTER_LIMIT, MAX_SWEEP_INTERVAL_MS, MAX_TOLERANCE, MAX_VECTOR_ORDINALS, MAX_WASM_PAGES, MIN_DOCUMENTS_FOR_SEGMENTS, MIN_LINEAR_ALPHA, MIN_M, MIN_OVERSAMPLE, MIN_RANK_CONSTANT, MIN_SWEEP_INTERVAL_MS, MODULE_URL_SCHEME_PATTERN, NATIVE_ATTACH_RETRY_MS, NATIVE_CRC32_MIN_BYTES, NarsilError, OSQ4_NARROW_DIMENSION_LIMIT, OSQ_GRID, OSQ_LAMBDA, OSQ_QUERY_BITS, OSQ_REFINE_ROUNDS, OSQ_REFINE_TOLERANCE, OSQ_STEPS, PLACEMENT_ROOM_REQUESTS, PREFIX_MAX_EXPANSIONS, RESULT_WINDOW, SHUTDOWN_TIMEOUT_MS, SORT_MODES, SORT_VALUE_MAX_CODE_POINTS, STATISTICS_BROADCAST_INTERVAL_MS, ServerErrorCodes, 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, createNarsilError, defaultSortMode, detectRuntime, exceedsCodePoints, holdsUnpairedSurrogate, isNarsilError, isSimdAvailable, isSortMode, markSimdUnavailable, missingWorkerEntry, readSortField, resolveRequestThreadCount, resolveWorkerCount, resolveWorkerEntry, singleFoldTable, sortModeOf, splitWorkerBudget, toComparableSortValue, toReducedSortValue, truncateSortString };
@@ -0,0 +1,9 @@
1
+ // src/workers/node-worker.browser.ts
2
+ async function spawnNodeWorker(_entryPoint, _resourceLimits) {
3
+ return null;
4
+ }
5
+ async function nodeThreadId() {
6
+ return 0;
7
+ }
8
+
9
+ export { nodeThreadId, spawnNodeWorker };