@delali/narsil 0.2.4-next.50 → 0.2.4-next.52

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 (55) hide show
  1. package/README.md +27 -25
  2. package/dist/{capabilities-JrVQOwi4.d.ts → capabilities-CuTSXvbN.d.ts} +2 -2
  3. package/dist/{chunk-BEIK3EOZ.mjs → chunk-2FO7KZ6K.mjs} +5468 -3837
  4. package/dist/{chunk-XE6XR2OE.mjs → chunk-3GWP2TO6.mjs} +1 -1
  5. package/dist/{chunk-KMMJMDUA.mjs → chunk-3L4U6EJQ.mjs} +15 -10
  6. package/dist/{chunk-MHE7YWAU.mjs → chunk-72AXTIBW.mjs} +2 -2
  7. package/dist/{chunk-CV5H7XL7.mjs → chunk-EY2ULUMT.mjs} +30 -7
  8. package/dist/chunk-IFBKLBGB.mjs +7 -0
  9. package/dist/{chunk-WYJXSLER.mjs → chunk-POWOTUKJ.mjs} +7 -1
  10. package/dist/chunk-T62YOSGS.mjs +4280 -0
  11. package/dist/chunk-U36IDJN7.mjs +366 -0
  12. package/dist/{chunk-ND34I3SV.mjs → chunk-ULJ36FK4.mjs} +3502 -2383
  13. package/dist/{chunk-RP23PWMV.mjs → chunk-WFKIGEBY.mjs} +3 -3
  14. package/dist/{chunk-CMVG2UEF.mjs → chunk-WM7IS45M.mjs} +55 -517
  15. package/dist/chunk-Y3L5MDRV.mjs +96 -0
  16. package/dist/{chunk-ZHUQKZBE.mjs → chunk-YPYULM5E.mjs} +20 -4
  17. package/dist/chunk-ZJ4CSAB2.mjs +13 -0
  18. package/dist/chunk-ZT5BRDFW.mjs +513 -0
  19. package/dist/{client-CBOVHdjp.d.ts → client-BMJWVxOP.d.ts} +5 -5
  20. package/dist/client.d.ts +8 -8
  21. package/dist/{config-OON7IJ_B.d.ts → config-BcYZkdMw.d.ts} +2 -2
  22. package/dist/{config-Czh2YNDi.d.ts → config-qMLpi5T4.d.ts} +2 -2
  23. package/dist/direct-executor-UJC36S2D.mjs +12 -0
  24. package/dist/distribution/coordinator/etcd.d.ts +2 -2
  25. package/dist/distribution/coordinator/in-memory.d.ts +2 -2
  26. package/dist/distribution.d.ts +8 -8
  27. package/dist/distribution.mjs +30 -15
  28. package/dist/{engine-9PtFY50q.d.ts → engine-zhms1qId.d.ts} +2 -2
  29. package/dist/index.browser.mjs +12845 -7766
  30. package/dist/index.d.ts +9 -21
  31. package/dist/index.mjs +13 -12
  32. package/dist/{memory-Bzd5xcEW.d.ts → memory-OmgkX_Z2.d.ts} +11 -1
  33. package/dist/persistence/durability/checkpoint-worker.d.ts +138 -3
  34. package/dist/persistence/durability/checkpoint-worker.mjs +31 -17
  35. package/dist/react.d.ts +6 -6
  36. package/dist/{schema-BqRx9t4E.d.ts → schema-OSWaaZzx.d.ts} +30 -6
  37. package/dist/serialization/crc32-worker.mjs +2 -1
  38. package/dist/server.d.ts +10 -10
  39. package/dist/server.mjs +80 -36
  40. package/dist/simd-DW5AtJ6B.d.ts +41 -0
  41. package/dist/{tasks-Bn4R1NPN.d.ts → tasks-DiF1c9v2.d.ts} +20 -1
  42. package/dist/{thread-PZLEO6JL.mjs → thread-TLCX43WV.mjs} +129 -41
  43. package/dist/{types-DXPxaXPO.d.ts → types-LEzMyjVX.d.ts} +1 -1
  44. package/dist/vector/search-worker.d.ts +292 -128
  45. package/dist/vector/search-worker.mjs +70 -54
  46. package/dist/workers/entry.mjs +10 -7
  47. package/package.json +52 -31
  48. package/dist/brute-force-DbHYCTc3.d.ts +0 -8
  49. package/dist/chunk-CBLS46IE.mjs +0 -10
  50. package/dist/chunk-PIWKZPP7.mjs +0 -64
  51. package/dist/chunk-PMBHH44R.mjs +0 -492
  52. package/dist/chunk-X6YZO4MQ.mjs +0 -1572
  53. package/dist/direct-executor-OREXU72C.mjs +0 -12
  54. package/dist/vector/hnsw-build-worker.d.ts +0 -105
  55. package/dist/vector/hnsw-build-worker.mjs +0 -123
@@ -1,12 +0,0 @@
1
- export { createDirectExecutor } from './chunk-BEIK3EOZ.mjs';
2
- import './chunk-CMVG2UEF.mjs';
3
- import './chunk-AV4IJKD2.mjs';
4
- import './chunk-CBLS46IE.mjs';
5
- import './chunk-TGP5M5R7.mjs';
6
- import './chunk-PMBHH44R.mjs';
7
- import './chunk-X6YZO4MQ.mjs';
8
- import './chunk-RP23PWMV.mjs';
9
- import './chunk-U2BKYEC7.mjs';
10
- import './chunk-2GWVQWGA.mjs';
11
- import './chunk-WYJXSLER.mjs';
12
- import './chunk-P4ELXVJQ.mjs';
@@ -1,105 +0,0 @@
1
- import { V as VectorMetric } from '../brute-force-DbHYCTc3.js';
2
-
3
- /**
4
- * How an HNSW graph is built.
5
- *
6
- * @internal
7
- */
8
- interface HNSWConfig {
9
- /** Each node keeps this many neighbours per layer. */
10
- m?: number;
11
- /** The builder explores this many candidates while placing each node. */
12
- efConstruction?: number;
13
- /** The graph ranks by this metric. */
14
- metric?: VectorMetric;
15
- }
16
- /**
17
- * An HNSW graph in the form the engine passes between threads.
18
- *
19
- * @internal
20
- */
21
- interface SerializedHNSWGraph {
22
- /** Every search starts at this node, and it is `null` while the graph is empty. */
23
- entryPoint: string | null;
24
- /** The graph reaches this many layers. */
25
- maxLayer: number;
26
- /** Each node keeps this many neighbours per layer. */
27
- m: number;
28
- /** The builder explored this many candidates while placing each node. */
29
- efConstruction: number;
30
- /** The graph ranks by this metric. */
31
- metric?: VectorMetric;
32
- /** Each entry holds a document id, its top layer, and its neighbours per layer. */
33
- nodes: Array<[string, number, Array<[number, string[]]>]>;
34
- }
35
-
36
- /**
37
- * Asks the build worker to construct a graph from vectors sent as arrays.
38
- *
39
- * This module is the worker's own entry point, and the engine posts these
40
- * messages to it. It exists so that a bundler can resolve the worker file, and
41
- * nothing here is part of the engine's supported surface.
42
- *
43
- * @internal
44
- */
45
- interface HNSWBuildRequest {
46
- /** This marks the message as an array-form build request. */
47
- type: 'build';
48
- /** The worker indexes these vectors, each carrying the document id it belongs to. */
49
- vectors: Array<{
50
- docId: string;
51
- values: number[];
52
- }>;
53
- /** Each vector carries this many components. */
54
- dimension: number;
55
- /** The worker builds to this graph shape, clamped to safe bounds first. */
56
- config: HNSWConfig;
57
- }
58
- /**
59
- * Asks the build worker to construct a graph from vectors packed into one
60
- * transferable buffer, which is what the engine sends for a large field.
61
- *
62
- * @internal
63
- */
64
- interface HNSWBuildRequestBinary {
65
- /** This marks the message as a packed-buffer build request. */
66
- type: 'build-binary';
67
- /** These document ids run in the order their vectors appear in the buffer. */
68
- docIds: string[];
69
- /** This holds every vector end to end, `docIds.length * dimension` components long. */
70
- vectorData: Float32Array;
71
- /** Each vector carries this many components. */
72
- dimension: number;
73
- /** The worker builds to this graph shape, clamped to safe bounds first. */
74
- config: HNSWConfig;
75
- }
76
- /**
77
- * What the build worker returns once a graph is built.
78
- *
79
- * @internal
80
- */
81
- interface HNSWBuildResponse {
82
- /** This marks the message as a completed build. */
83
- type: 'success';
84
- /** This graph is ready for the engine to adopt. */
85
- graph: SerializedHNSWGraph;
86
- }
87
- /**
88
- * What the build worker returns when a build fails.
89
- *
90
- * @internal
91
- */
92
- interface HNSWBuildError {
93
- /** This marks the message as a failed build. */
94
- type: 'error';
95
- /** This says why the build failed. */
96
- message: string;
97
- }
98
- /**
99
- * Either message the build worker posts back.
100
- *
101
- * @internal
102
- */
103
- type HNSWWorkerMessage = HNSWBuildResponse | HNSWBuildError;
104
-
105
- export { type HNSWBuildError, type HNSWBuildRequest, type HNSWBuildRequestBinary, type HNSWBuildResponse, type HNSWConfig, type HNSWWorkerMessage, type SerializedHNSWGraph, VectorMetric };
@@ -1,123 +0,0 @@
1
- import { createVectorStore, createHNSWIndex, MAX_WORKER_DIMENSION, MAX_WORKER_VECTORS } from '../chunk-X6YZO4MQ.mjs';
2
- import '../chunk-RP23PWMV.mjs';
3
- import '../chunk-2GWVQWGA.mjs';
4
-
5
- // src/vector/hnsw-build-worker.ts
6
- function validateBuildRequest(request) {
7
- if (typeof request.dimension !== "number" || request.dimension <= 0 || request.dimension > MAX_WORKER_DIMENSION) {
8
- throw new Error(`Invalid dimension: ${request.dimension} (must be 1..${MAX_WORKER_DIMENSION})`);
9
- }
10
- if (!Array.isArray(request.vectors)) {
11
- throw new Error("vectors must be an array");
12
- }
13
- if (request.vectors.length > MAX_WORKER_VECTORS) {
14
- throw new Error(`Too many vectors: ${request.vectors.length} (max ${MAX_WORKER_VECTORS})`);
15
- }
16
- for (let i = 0; i < request.vectors.length; i++) {
17
- const entry = request.vectors[i];
18
- if (typeof entry.docId !== "string" || !Array.isArray(entry.values)) {
19
- throw new Error(`Invalid vector entry at index ${i}`);
20
- }
21
- if (entry.values.length !== request.dimension) {
22
- throw new Error(`Vector at index ${i} has ${entry.values.length} elements, expected ${request.dimension}`);
23
- }
24
- }
25
- }
26
- function clampHNSWConfig(config) {
27
- return {
28
- ...config,
29
- m: config.m != null ? Math.max(2, Math.min(64, config.m)) : void 0,
30
- efConstruction: config.efConstruction != null ? Math.max(10, Math.min(1e3, config.efConstruction)) : void 0
31
- };
32
- }
33
- function handleBuildRequest(request) {
34
- validateBuildRequest(request);
35
- const safeConfig = clampHNSWConfig(request.config);
36
- const store = createVectorStore();
37
- for (const entry of request.vectors) {
38
- store.insert(entry.docId, new Float32Array(entry.values));
39
- }
40
- const hnsw = createHNSWIndex(request.dimension, store, safeConfig);
41
- for (const entry of request.vectors) {
42
- hnsw.insertNode(entry.docId);
43
- }
44
- return hnsw.serialize();
45
- }
46
- function handleBuildRequestBinary(request) {
47
- const { docIds, vectorData, dimension, config } = request;
48
- if (!Number.isInteger(dimension) || dimension <= 0 || dimension > MAX_WORKER_DIMENSION) {
49
- throw new Error(`Invalid dimension: ${dimension} (must be 1..${MAX_WORKER_DIMENSION})`);
50
- }
51
- if (docIds.length > MAX_WORKER_VECTORS) {
52
- throw new Error(`Too many vectors: ${docIds.length} (max ${MAX_WORKER_VECTORS})`);
53
- }
54
- const expectedLength = docIds.length * dimension;
55
- if (vectorData.length !== expectedLength) {
56
- throw new Error(
57
- `vectorData length ${vectorData.length} does not match ${docIds.length} * ${dimension} = ${expectedLength}`
58
- );
59
- }
60
- const safeConfig = clampHNSWConfig(config);
61
- const store = createVectorStore();
62
- for (let i = 0; i < docIds.length; i++) {
63
- const offset = i * dimension;
64
- const vec = vectorData.subarray(offset, offset + dimension);
65
- store.insert(docIds[i], new Float32Array(vec));
66
- }
67
- const hnsw = createHNSWIndex(dimension, store, safeConfig);
68
- for (const docId of docIds) {
69
- hnsw.insertNode(docId);
70
- }
71
- return hnsw.serialize();
72
- }
73
- function handleAnyRequest(raw) {
74
- const request = raw;
75
- if (request.type === "build") {
76
- return handleBuildRequest(raw);
77
- }
78
- if (request.type === "build-binary") {
79
- return handleBuildRequestBinary(raw);
80
- }
81
- throw new Error(`Unknown request type: ${request.type}`);
82
- }
83
- function setupWorker() {
84
- setupAsync().catch((err) => {
85
- console.error("HNSW build worker setup failed:", err);
86
- });
87
- }
88
- async function setupAsync() {
89
- let parentPort = null;
90
- try {
91
- const workerThreads = await import('worker_threads');
92
- parentPort = workerThreads.parentPort ?? null;
93
- } catch {
94
- parentPort = null;
95
- }
96
- if (parentPort) {
97
- const port = parentPort;
98
- port.on("message", (raw) => {
99
- try {
100
- const graph = handleAnyRequest(raw);
101
- port.postMessage({ type: "success", graph });
102
- } catch (err) {
103
- const message = err instanceof Error ? err.message : String(err);
104
- port.postMessage({ type: "error", message });
105
- }
106
- });
107
- return;
108
- }
109
- const globalSelf = typeof self !== "undefined" ? self : void 0;
110
- if (globalSelf && typeof globalSelf.postMessage === "function") {
111
- const webSelf = globalSelf;
112
- webSelf.onmessage = (event) => {
113
- try {
114
- const graph = handleAnyRequest(event.data);
115
- webSelf.postMessage({ type: "success", graph });
116
- } catch (err) {
117
- const message = err instanceof Error ? err.message : String(err);
118
- webSelf.postMessage({ type: "error", message });
119
- }
120
- };
121
- }
122
- }
123
- setupWorker();