agentdb 2.0.0-alpha.2.15 → 2.0.0-alpha.2.16
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.
- package/dist/agentdb.browser.js +197 -4
- package/dist/agentdb.browser.js.map +4 -4
- package/dist/agentdb.browser.min.js +2 -2
- package/dist/agentdb.browser.min.js.map +4 -4
- package/dist/src/services/federated-learning.d.ts +172 -0
- package/dist/src/services/federated-learning.d.ts.map +1 -0
- package/dist/src/services/federated-learning.js +342 -0
- package/dist/src/services/federated-learning.js.map +1 -0
- package/examples/federated-learning-example.ts +285 -0
- package/package.json +2 -2
- package/src/services/federated-learning.ts +436 -0
package/dist/agentdb.browser.js
CHANGED
|
@@ -1,4 +1,197 @@
|
|
|
1
|
-
/*! AgentDB Browser Bundle v2.0.0-alpha.2.
|
|
1
|
+
/*! AgentDB Browser Bundle v2.0.0-alpha.2.16 | MIT License | https://agentdb.ruv.io */
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __esm = (fn, res) => function __init() {
|
|
5
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
+
};
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// dist/agentdb.wasm-loader.js
|
|
13
|
+
var agentdb_wasm_loader_exports = {};
|
|
14
|
+
__export(agentdb_wasm_loader_exports, {
|
|
15
|
+
initWASM: () => initWASM,
|
|
16
|
+
wasmLoadError: () => wasmLoadError,
|
|
17
|
+
wasmModule: () => wasmModule
|
|
18
|
+
});
|
|
19
|
+
async function initWASM() {
|
|
20
|
+
if (wasmModule) return wasmModule;
|
|
21
|
+
if (wasmLoading) return wasmLoading;
|
|
22
|
+
wasmLoading = (async () => {
|
|
23
|
+
try {
|
|
24
|
+
if (typeof WebAssembly === "undefined") {
|
|
25
|
+
throw new Error("WebAssembly not supported in this browser");
|
|
26
|
+
}
|
|
27
|
+
const simdSupported = await detectWasmSIMD();
|
|
28
|
+
console.log(`WASM SIMD support: ${simdSupported}`);
|
|
29
|
+
wasmModule = {
|
|
30
|
+
flashAttention: createFlashAttentionMock(),
|
|
31
|
+
hyperbolicAttention: createHyperbolicAttentionMock(),
|
|
32
|
+
memoryConsolidation: createMemoryConsolidationMock(),
|
|
33
|
+
simdSupported
|
|
34
|
+
};
|
|
35
|
+
console.log("\u2705 WASM attention module loaded");
|
|
36
|
+
return wasmModule;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
wasmLoadError = error;
|
|
39
|
+
console.warn("\u26A0\uFE0F WASM loading failed, using fallback:", error.message);
|
|
40
|
+
wasmModule = {
|
|
41
|
+
flashAttention: createFlashAttentionMock(),
|
|
42
|
+
hyperbolicAttention: createHyperbolicAttentionMock(),
|
|
43
|
+
memoryConsolidation: createMemoryConsolidationMock(),
|
|
44
|
+
simdSupported: false
|
|
45
|
+
};
|
|
46
|
+
return wasmModule;
|
|
47
|
+
} finally {
|
|
48
|
+
wasmLoading = null;
|
|
49
|
+
}
|
|
50
|
+
})();
|
|
51
|
+
return wasmLoading;
|
|
52
|
+
}
|
|
53
|
+
async function detectWasmSIMD() {
|
|
54
|
+
try {
|
|
55
|
+
const simdTest = new Uint8Array([
|
|
56
|
+
0,
|
|
57
|
+
97,
|
|
58
|
+
115,
|
|
59
|
+
109,
|
|
60
|
+
1,
|
|
61
|
+
0,
|
|
62
|
+
0,
|
|
63
|
+
0,
|
|
64
|
+
1,
|
|
65
|
+
5,
|
|
66
|
+
1,
|
|
67
|
+
96,
|
|
68
|
+
0,
|
|
69
|
+
1,
|
|
70
|
+
123,
|
|
71
|
+
3,
|
|
72
|
+
2,
|
|
73
|
+
1,
|
|
74
|
+
0,
|
|
75
|
+
10,
|
|
76
|
+
10,
|
|
77
|
+
1,
|
|
78
|
+
8,
|
|
79
|
+
0,
|
|
80
|
+
253,
|
|
81
|
+
12,
|
|
82
|
+
253,
|
|
83
|
+
12,
|
|
84
|
+
253,
|
|
85
|
+
84,
|
|
86
|
+
11
|
|
87
|
+
]);
|
|
88
|
+
const module = await WebAssembly.instantiate(simdTest);
|
|
89
|
+
return module instanceof WebAssembly.Instance;
|
|
90
|
+
} catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function createFlashAttentionMock() {
|
|
95
|
+
return (query, keys, values, options = {}) => {
|
|
96
|
+
const { dim = 384, numHeads = 4, blockSize = 64 } = options;
|
|
97
|
+
const seqLen = keys.length / dim;
|
|
98
|
+
const output = new Float32Array(query.length);
|
|
99
|
+
for (let i = 0; i < query.length; i += dim) {
|
|
100
|
+
const q = query.slice(i, i + dim);
|
|
101
|
+
let sumWeights = 0;
|
|
102
|
+
const weights = new Float32Array(seqLen);
|
|
103
|
+
for (let j = 0; j < seqLen; j++) {
|
|
104
|
+
const k = keys.slice(j * dim, (j + 1) * dim);
|
|
105
|
+
let dot = 0;
|
|
106
|
+
for (let d = 0; d < dim; d++) {
|
|
107
|
+
dot += q[d] * k[d];
|
|
108
|
+
}
|
|
109
|
+
weights[j] = Math.exp(dot / Math.sqrt(dim));
|
|
110
|
+
sumWeights += weights[j];
|
|
111
|
+
}
|
|
112
|
+
for (let j = 0; j < seqLen; j++) {
|
|
113
|
+
weights[j] /= sumWeights;
|
|
114
|
+
const v = values.slice(j * dim, (j + 1) * dim);
|
|
115
|
+
for (let d = 0; d < dim; d++) {
|
|
116
|
+
output[i + d] += weights[j] * v[d];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return output;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function createHyperbolicAttentionMock() {
|
|
124
|
+
return (query, keys, options = {}) => {
|
|
125
|
+
const { curvature = -1 } = options;
|
|
126
|
+
const k = Math.abs(curvature);
|
|
127
|
+
const similarities = new Float32Array(keys.length / query.length);
|
|
128
|
+
for (let i = 0; i < similarities.length; i++) {
|
|
129
|
+
const offset = i * query.length;
|
|
130
|
+
let dotProduct = 0;
|
|
131
|
+
let normQ = 0;
|
|
132
|
+
let normK = 0;
|
|
133
|
+
for (let j = 0; j < query.length; j++) {
|
|
134
|
+
dotProduct += query[j] * keys[offset + j];
|
|
135
|
+
normQ += query[j] * query[j];
|
|
136
|
+
normK += keys[offset + j] * keys[offset + j];
|
|
137
|
+
}
|
|
138
|
+
const euclidean = Math.sqrt(normQ + normK - 2 * dotProduct);
|
|
139
|
+
const poincare = Math.acosh(1 + 2 * k * euclidean * euclidean);
|
|
140
|
+
similarities[i] = 1 / (1 + poincare);
|
|
141
|
+
}
|
|
142
|
+
return similarities;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function createMemoryConsolidationMock() {
|
|
146
|
+
return (memories, options = {}) => {
|
|
147
|
+
const { threshold = 0.8, maxClusters = 10 } = options;
|
|
148
|
+
const consolidated = [];
|
|
149
|
+
const used = /* @__PURE__ */ new Set();
|
|
150
|
+
for (let i = 0; i < memories.length; i++) {
|
|
151
|
+
if (used.has(i)) continue;
|
|
152
|
+
const cluster = [memories[i]];
|
|
153
|
+
used.add(i);
|
|
154
|
+
for (let j = i + 1; j < memories.length; j++) {
|
|
155
|
+
if (used.has(j)) continue;
|
|
156
|
+
let dot = 0;
|
|
157
|
+
let norm1 = 0;
|
|
158
|
+
let norm2 = 0;
|
|
159
|
+
for (let k = 0; k < memories[i].length; k++) {
|
|
160
|
+
dot += memories[i][k] * memories[j][k];
|
|
161
|
+
norm1 += memories[i][k] * memories[i][k];
|
|
162
|
+
norm2 += memories[j][k] * memories[j][k];
|
|
163
|
+
}
|
|
164
|
+
const similarity = dot / (Math.sqrt(norm1 * norm2) || 1);
|
|
165
|
+
if (similarity > threshold) {
|
|
166
|
+
cluster.push(memories[j]);
|
|
167
|
+
used.add(j);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const avg = new Float32Array(memories[i].length);
|
|
171
|
+
for (const mem of cluster) {
|
|
172
|
+
for (let k = 0; k < avg.length; k++) {
|
|
173
|
+
avg[k] += mem[k] / cluster.length;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
consolidated.push({
|
|
177
|
+
memory: avg,
|
|
178
|
+
count: cluster.size,
|
|
179
|
+
members: cluster
|
|
180
|
+
});
|
|
181
|
+
if (consolidated.length >= maxClusters) break;
|
|
182
|
+
}
|
|
183
|
+
return consolidated;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
var wasmModule, wasmLoading, wasmLoadError;
|
|
187
|
+
var init_agentdb_wasm_loader = __esm({
|
|
188
|
+
"dist/agentdb.wasm-loader.js"() {
|
|
189
|
+
"use strict";
|
|
190
|
+
wasmModule = null;
|
|
191
|
+
wasmLoading = null;
|
|
192
|
+
wasmLoadError = null;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
2
195
|
|
|
3
196
|
// src/browser/ProductQuantization.ts
|
|
4
197
|
var ProductQuantization = class {
|
|
@@ -1068,7 +1261,7 @@ var AttentionBrowser = class {
|
|
|
1068
1261
|
this.loadingState = "loaded";
|
|
1069
1262
|
return;
|
|
1070
1263
|
}
|
|
1071
|
-
const wasmLoader = await
|
|
1264
|
+
const wasmLoader = await Promise.resolve().then(() => (init_agentdb_wasm_loader(), agentdb_wasm_loader_exports));
|
|
1072
1265
|
this.wasmModule = await wasmLoader.initWASM();
|
|
1073
1266
|
this.loadingState = "loaded";
|
|
1074
1267
|
} catch (error) {
|
|
@@ -1283,11 +1476,11 @@ function detectFeatures() {
|
|
|
1283
1476
|
indexedDB: "indexedDB" in globalThis,
|
|
1284
1477
|
broadcastChannel: "BroadcastChannel" in globalThis,
|
|
1285
1478
|
webWorkers: typeof globalThis.Worker !== "undefined",
|
|
1286
|
-
wasmSIMD:
|
|
1479
|
+
wasmSIMD: detectWasmSIMD2(),
|
|
1287
1480
|
sharedArrayBuffer: typeof SharedArrayBuffer !== "undefined"
|
|
1288
1481
|
};
|
|
1289
1482
|
}
|
|
1290
|
-
async function
|
|
1483
|
+
async function detectWasmSIMD2() {
|
|
1291
1484
|
try {
|
|
1292
1485
|
if (typeof globalThis.WebAssembly === "undefined") {
|
|
1293
1486
|
return false;
|