@delali/narsil 0.2.4-next.51 → 0.2.4-next.54

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 (64) hide show
  1. package/README.md +33 -27
  2. package/dist/adapters/filesystem.mjs +1 -1
  3. package/dist/adapters/indexeddb.mjs +1 -1
  4. package/dist/{capabilities-BWm4IITU.d.ts → capabilities-DlYw0Ov0.d.ts} +13 -2
  5. package/dist/{chunk-KMMJMDUA.mjs → chunk-3L4U6EJQ.mjs} +15 -10
  6. package/dist/chunk-4NVPQ6S5.mjs +366 -0
  7. package/dist/{chunk-CMVG2UEF.mjs → chunk-5T6AOR37.mjs} +56 -518
  8. package/dist/{chunk-ND34I3SV.mjs → chunk-BH5SYB5W.mjs} +3295 -2149
  9. package/dist/{chunk-XE6XR2OE.mjs → chunk-D2S642IV.mjs} +4 -2
  10. package/dist/{chunk-P4ELXVJQ.mjs → chunk-FRQVMFY7.mjs} +7 -1
  11. package/dist/chunk-IFBKLBGB.mjs +7 -0
  12. package/dist/chunk-L225SHNB.mjs +513 -0
  13. package/dist/{chunk-MHE7YWAU.mjs → chunk-NTZYA3SJ.mjs} +3 -3
  14. package/dist/{chunk-WYJXSLER.mjs → chunk-POWOTUKJ.mjs} +7 -1
  15. package/dist/{chunk-CV5H7XL7.mjs → chunk-RGS7FMCB.mjs} +53 -10
  16. package/dist/{chunk-ZHUQKZBE.mjs → chunk-TVT5V4E7.mjs} +101 -34
  17. package/dist/chunk-U2AL3SON.mjs +4198 -0
  18. package/dist/chunk-UTOFOJOR.mjs +135 -0
  19. package/dist/{chunk-BEIK3EOZ.mjs → chunk-XNQAIO74.mjs} +5523 -3847
  20. package/dist/chunk-Y3L5MDRV.mjs +96 -0
  21. package/dist/chunk-ZJ4CSAB2.mjs +13 -0
  22. package/dist/{client-B_X6_AbT.d.ts → client-CQUqt9Ir.d.ts} +13 -4
  23. package/dist/client.d.ts +8 -8
  24. package/dist/client.mjs +20 -14
  25. package/dist/{config-Czh2YNDi.d.ts → config-CNas6wJH.d.ts} +2 -2
  26. package/dist/{config-OON7IJ_B.d.ts → config-bXxnJrQc.d.ts} +80 -35
  27. package/dist/direct-executor-RBA5O7EN.mjs +12 -0
  28. package/dist/distribution/coordinator/etcd.d.ts +2 -2
  29. package/dist/distribution/coordinator/etcd.mjs +1 -1
  30. package/dist/distribution/coordinator/in-memory.d.ts +2 -2
  31. package/dist/distribution/transport/grpc.mjs +1 -1
  32. package/dist/distribution.d.ts +8 -8
  33. package/dist/distribution.mjs +32 -17
  34. package/dist/embeddings/openai.mjs +1 -1
  35. package/dist/{engine-9PtFY50q.d.ts → engine-Dj4I91Jv.d.ts} +21 -8
  36. package/dist/index.browser.mjs +12962 -7786
  37. package/dist/index.d.ts +9 -21
  38. package/dist/index.mjs +14 -13
  39. package/dist/{memory-Bzd5xcEW.d.ts → memory-xrXOZMbw.d.ts} +68 -13
  40. package/dist/persistence/durability/checkpoint-worker.d.ts +138 -3
  41. package/dist/persistence/durability/checkpoint-worker.mjs +32 -18
  42. package/dist/react.d.ts +11 -11
  43. package/dist/react.mjs +16 -4
  44. package/dist/{schema-BqRx9t4E.d.ts → schema-mLpXZBEh.d.ts} +43 -12
  45. package/dist/serialization/crc32-worker.mjs +2 -1
  46. package/dist/server.d.ts +13 -10
  47. package/dist/server.mjs +136 -47
  48. package/dist/simd-DW5AtJ6B.d.ts +41 -0
  49. package/dist/{tasks-DT7L1p6w.d.ts → tasks-Df73Tjgq.d.ts} +9 -5
  50. package/dist/{thread-PZLEO6JL.mjs → thread-5UP6MGED.mjs} +131 -43
  51. package/dist/{types-DXPxaXPO.d.ts → types-BTIVO8DI.d.ts} +1 -1
  52. package/dist/vector/search-worker.d.ts +292 -128
  53. package/dist/vector/search-worker.mjs +70 -54
  54. package/dist/workers/entry.mjs +30 -14
  55. package/package.json +52 -31
  56. package/dist/brute-force-DbHYCTc3.d.ts +0 -8
  57. package/dist/chunk-CBLS46IE.mjs +0 -10
  58. package/dist/chunk-PIWKZPP7.mjs +0 -64
  59. package/dist/chunk-PMBHH44R.mjs +0 -492
  60. package/dist/chunk-RP23PWMV.mjs +0 -11
  61. package/dist/chunk-X6YZO4MQ.mjs +0 -1572
  62. package/dist/direct-executor-OREXU72C.mjs +0 -12
  63. package/dist/vector/hnsw-build-worker.d.ts +0 -105
  64. package/dist/vector/hnsw-build-worker.mjs +0 -123
@@ -0,0 +1,135 @@
1
+ import { NarsilError, ErrorCodes } from './chunk-FRQVMFY7.mjs';
2
+ import { existsSync } from 'fs';
3
+ import { createRequire } from 'module';
4
+ import { join, dirname } from 'path';
5
+
6
+ // src/vector/hnsw/constants.ts
7
+ var MAX_LAYER_CAP = 32;
8
+ var MAX_M = 512;
9
+ var INITIAL_UPPER_SLOTS = 64;
10
+ var INITIAL_LIST_CAPACITY = 64;
11
+ var PLACEMENT_ROOM_REQUESTS = 8;
12
+ var COMPACTION_TOMBSTONE_RATIO = 0.1;
13
+ var COMPACTION_ABSOLUTE_THRESHOLD = 1e3;
14
+ var DEFAULT_EF_SEARCH = 50;
15
+
16
+ // src/vector/native/backend.ts
17
+ var nativeSearchCoreEnabled = true;
18
+ function nativeSearchCoreIsEnabled() {
19
+ return nativeSearchCoreEnabled;
20
+ }
21
+ function stopUsingTheNativeSearchCore(error) {
22
+ if (!nativeSearchCoreEnabled) return;
23
+ nativeSearchCoreEnabled = false;
24
+ console.warn(
25
+ "The native search core raised an error, so this thread searches through WebAssembly from now on:",
26
+ error instanceof Error ? error.message : String(error)
27
+ );
28
+ }
29
+ function noteFallback(operation) {
30
+ }
31
+ var NATIVE_CORE_ABI_VERSION = 2;
32
+ var BINARY_FILE_NAME = "narsil-core.node";
33
+ var MUSL_DIRECTORY = "musl";
34
+ var PLATFORMS_WITH_A_BINARY = /* @__PURE__ */ new Set([
35
+ "darwin-arm64",
36
+ "darwin-x64",
37
+ "linux-arm64",
38
+ "linux-x64",
39
+ "win32-arm64",
40
+ "win32-x64"
41
+ ]);
42
+ var loaded;
43
+ function usesMuslLibc() {
44
+ try {
45
+ const report = process.report.getReport();
46
+ return report.header?.glibcVersionRuntime === void 0;
47
+ } catch {
48
+ return false;
49
+ }
50
+ }
51
+ function isUnavailable(value) {
52
+ return "missing" in value;
53
+ }
54
+ function binaryFileSegments() {
55
+ return process.platform === "linux" && usesMuslLibc() ? [MUSL_DIRECTORY, BINARY_FILE_NAME] : [BINARY_FILE_NAME];
56
+ }
57
+ function publishedCoreLocation(target) {
58
+ const packageName = `@delali/narsil-native-${target}`;
59
+ let manifest;
60
+ try {
61
+ manifest = createRequire(import.meta.url).resolve(`${packageName}/package.json`);
62
+ } catch {
63
+ return { missing: `this installation has no "${packageName}" package` };
64
+ }
65
+ const path = join(dirname(manifest), ...binaryFileSegments());
66
+ if (!existsSync(path)) return { missing: `the "${packageName}" package has no search core at ${path}` };
67
+ return { path };
68
+ }
69
+ function coreLocation() {
70
+ const named = process.env.NARSIL_NATIVE_CORE_PATH;
71
+ if (named !== void 0 && named.length > 0) {
72
+ if (!existsSync(named)) {
73
+ return { missing: `this process sets NARSIL_NATIVE_CORE_PATH to ${named}, where no file exists` };
74
+ }
75
+ return { path: named };
76
+ }
77
+ const target = `${process.platform}-${process.arch}`;
78
+ if (!PLATFORMS_WITH_A_BINARY.has(target)) {
79
+ return { missing: `the Narsil release includes no search core for ${target}` };
80
+ }
81
+ return publishedCoreLocation(target);
82
+ }
83
+ function refuseToSearchWithoutTheCore(reason) {
84
+ throw new NarsilError(ErrorCodes.CONFIG_INVALID, `NARSIL_REQUIRE_NATIVE_CORE is 1, yet ${reason}`, {
85
+ platform: `${process.platform}-${process.arch}`
86
+ });
87
+ }
88
+ function requestedBackend() {
89
+ const raw = process.env.NARSIL_SEARCH_BACKEND;
90
+ if (raw === void 0 || raw.trim().length === 0) return null;
91
+ const named = raw.trim().toLowerCase();
92
+ if (named === "native" || named === "wasm") return named;
93
+ throw new NarsilError(
94
+ ErrorCodes.CONFIG_INVALID,
95
+ `NARSIL_SEARCH_BACKEND takes either "native" or "wasm", while this environment sets it to "${raw}"`,
96
+ { value: raw, backends: ["native", "wasm"] }
97
+ );
98
+ }
99
+ function reportMissingCore(reason, announce) {
100
+ if (process.env.NARSIL_REQUIRE_NATIVE_CORE === "1") refuseToSearchWithoutTheCore(reason);
101
+ loaded = null;
102
+ if (announce) console.warn(`Narsil searches through WebAssembly on this thread, because ${reason}.`);
103
+ return null;
104
+ }
105
+ function coreAt(path) {
106
+ let core;
107
+ try {
108
+ core = createRequire(import.meta.url)(path);
109
+ } catch (error) {
110
+ const message = error instanceof Error ? error.message : String(error);
111
+ return { missing: `node raised "${message}" while loading the search core at ${path}` };
112
+ }
113
+ if (typeof core.abiVersion !== "function") return { missing: `the file at ${path} is no Narsil search core` };
114
+ const reported = core.abiVersion();
115
+ if (reported !== NATIVE_CORE_ABI_VERSION) {
116
+ return {
117
+ missing: `the search core at ${path} reports ABI version ${reported}, while this build of Narsil needs ${NATIVE_CORE_ABI_VERSION}`
118
+ };
119
+ }
120
+ return core;
121
+ }
122
+ function loadNativeCore() {
123
+ if (loaded !== void 0) return loaded;
124
+ if (requestedBackend() === "wasm") {
125
+ return reportMissingCore("this process sets NARSIL_SEARCH_BACKEND to the WebAssembly search", false);
126
+ }
127
+ const location = coreLocation();
128
+ if (isUnavailable(location)) return reportMissingCore(location.missing, true);
129
+ const core = coreAt(location.path);
130
+ if (isUnavailable(core)) return reportMissingCore(core.missing, true);
131
+ loaded = core;
132
+ return loaded;
133
+ }
134
+
135
+ export { COMPACTION_ABSOLUTE_THRESHOLD, COMPACTION_TOMBSTONE_RATIO, DEFAULT_EF_SEARCH, INITIAL_LIST_CAPACITY, INITIAL_UPPER_SLOTS, MAX_LAYER_CAP, MAX_M, PLACEMENT_ROOM_REQUESTS, loadNativeCore, nativeSearchCoreIsEnabled, noteFallback, stopUsingTheNativeSearchCore };