ruvector 0.1.62 → 0.1.64
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/core/attention-fallbacks.d.ts +100 -0
- package/dist/core/attention-fallbacks.d.ts.map +1 -1
- package/dist/core/attention-fallbacks.js +192 -1
- package/dist/core/cluster-wrapper.d.ts +148 -0
- package/dist/core/cluster-wrapper.d.ts.map +1 -0
- package/dist/core/cluster-wrapper.js +271 -0
- package/dist/core/graph-wrapper.d.ts +147 -0
- package/dist/core/graph-wrapper.d.ts.map +1 -0
- package/dist/core/graph-wrapper.js +299 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +13 -1
- package/dist/core/parallel-workers.d.ts +183 -0
- package/dist/core/parallel-workers.d.ts.map +1 -0
- package/dist/core/parallel-workers.js +671 -0
- package/dist/core/router-wrapper.d.ts +62 -0
- package/dist/core/router-wrapper.d.ts.map +1 -0
- package/dist/core/router-wrapper.js +209 -0
- package/package.json +1 -1
- package/ruvector.db +0 -0
|
@@ -202,13 +202,112 @@ export declare function isAttentionAvailable(): boolean;
|
|
|
202
202
|
* Get attention module version
|
|
203
203
|
*/
|
|
204
204
|
export declare function getAttentionVersion(): string | null;
|
|
205
|
+
/**
|
|
206
|
+
* Graph attention with Rotary Position Embeddings
|
|
207
|
+
* Excellent for code AST and dependency graphs
|
|
208
|
+
*/
|
|
209
|
+
export declare class GraphRoPeAttention {
|
|
210
|
+
private inner;
|
|
211
|
+
readonly dim: number;
|
|
212
|
+
readonly numHeads: number;
|
|
213
|
+
readonly maxSeqLen: number;
|
|
214
|
+
constructor(dim: number, numHeads?: number, maxSeqLen?: number);
|
|
215
|
+
compute(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[], positions?: number[]): AttentionOutput;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Edge-featured attention for graphs with edge attributes
|
|
219
|
+
* Useful for weighted dependency graphs
|
|
220
|
+
*/
|
|
221
|
+
export declare class EdgeFeaturedAttention {
|
|
222
|
+
private inner;
|
|
223
|
+
readonly dim: number;
|
|
224
|
+
readonly edgeDim: number;
|
|
225
|
+
constructor(dim: number, edgeDim?: number);
|
|
226
|
+
compute(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[], edgeFeatures?: (number[] | Float32Array)[]): AttentionOutput;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Dual-space attention (Euclidean + Hyperbolic)
|
|
230
|
+
* Best of both worlds for hierarchical + semantic similarity
|
|
231
|
+
*/
|
|
232
|
+
export declare class DualSpaceAttention {
|
|
233
|
+
private inner;
|
|
234
|
+
readonly dim: number;
|
|
235
|
+
readonly curvature: number;
|
|
236
|
+
readonly alpha: number;
|
|
237
|
+
constructor(dim: number, curvature?: number, alpha?: number);
|
|
238
|
+
compute(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[]): AttentionOutput;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Basic dot-product attention
|
|
242
|
+
*/
|
|
243
|
+
export declare class DotProductAttention {
|
|
244
|
+
private inner;
|
|
245
|
+
readonly dim: number;
|
|
246
|
+
constructor(dim: number);
|
|
247
|
+
compute(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[]): AttentionOutput;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Compute attention in parallel across multiple queries
|
|
251
|
+
*/
|
|
252
|
+
export declare function parallelAttentionCompute(queries: (number[] | Float32Array)[], keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[], attentionType?: 'dot' | 'multi-head' | 'flash' | 'hyperbolic' | 'linear'): Promise<number[][]>;
|
|
253
|
+
/**
|
|
254
|
+
* Batch attention compute for multiple query-key-value sets
|
|
255
|
+
*/
|
|
256
|
+
export declare function batchAttentionCompute(batches: Array<{
|
|
257
|
+
query: number[] | Float32Array;
|
|
258
|
+
keys: (number[] | Float32Array)[];
|
|
259
|
+
values: (number[] | Float32Array)[];
|
|
260
|
+
}>, attentionType?: 'dot' | 'multi-head' | 'flash' | 'hyperbolic' | 'linear'): Promise<number[][]>;
|
|
261
|
+
/**
|
|
262
|
+
* Async flash attention with callback
|
|
263
|
+
*/
|
|
264
|
+
export declare function computeFlashAttentionAsync(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[]): Promise<number[]>;
|
|
265
|
+
/**
|
|
266
|
+
* Async hyperbolic attention
|
|
267
|
+
*/
|
|
268
|
+
export declare function computeHyperbolicAttentionAsync(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[], curvature?: number): Promise<number[]>;
|
|
269
|
+
/**
|
|
270
|
+
* Adam optimizer for attention training
|
|
271
|
+
*/
|
|
272
|
+
export declare class AdamOptimizer {
|
|
273
|
+
private inner;
|
|
274
|
+
constructor(learningRate?: number, beta1?: number, beta2?: number);
|
|
275
|
+
step(gradients: number[] | Float32Array, params: number[] | Float32Array): number[];
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* InfoNCE contrastive loss
|
|
279
|
+
*/
|
|
280
|
+
export declare function infoNceLoss(anchor: number[] | Float32Array, positive: number[] | Float32Array, negatives: (number[] | Float32Array)[], temperature?: number): number;
|
|
281
|
+
/**
|
|
282
|
+
* Hard negative mining for contrastive learning
|
|
283
|
+
*/
|
|
284
|
+
export declare function mineHardNegatives(anchor: number[] | Float32Array, candidates: (number[] | Float32Array)[], topK?: number): number[][];
|
|
285
|
+
/**
|
|
286
|
+
* Benchmark attention implementations
|
|
287
|
+
*/
|
|
288
|
+
export declare function benchmarkAttention(dim: number, seqLen: number, iterations?: number): Promise<Record<string, {
|
|
289
|
+
avgMs: number;
|
|
290
|
+
minMs: number;
|
|
291
|
+
maxMs: number;
|
|
292
|
+
}>>;
|
|
205
293
|
declare const _default: {
|
|
294
|
+
DotProductAttention: typeof DotProductAttention;
|
|
206
295
|
MultiHeadAttention: typeof MultiHeadAttention;
|
|
207
296
|
FlashAttention: typeof FlashAttention;
|
|
208
297
|
HyperbolicAttention: typeof HyperbolicAttention;
|
|
209
298
|
LinearAttention: typeof LinearAttention;
|
|
210
299
|
LocalGlobalAttention: typeof LocalGlobalAttention;
|
|
211
300
|
MoEAttention: typeof MoEAttention;
|
|
301
|
+
GraphRoPeAttention: typeof GraphRoPeAttention;
|
|
302
|
+
EdgeFeaturedAttention: typeof EdgeFeaturedAttention;
|
|
303
|
+
DualSpaceAttention: typeof DualSpaceAttention;
|
|
304
|
+
parallelAttentionCompute: typeof parallelAttentionCompute;
|
|
305
|
+
batchAttentionCompute: typeof batchAttentionCompute;
|
|
306
|
+
computeFlashAttentionAsync: typeof computeFlashAttentionAsync;
|
|
307
|
+
computeHyperbolicAttentionAsync: typeof computeHyperbolicAttentionAsync;
|
|
308
|
+
AdamOptimizer: typeof AdamOptimizer;
|
|
309
|
+
infoNceLoss: typeof infoNceLoss;
|
|
310
|
+
mineHardNegatives: typeof mineHardNegatives;
|
|
212
311
|
projectToPoincareBall: typeof projectToPoincareBall;
|
|
213
312
|
poincareDistance: typeof poincareDistance;
|
|
214
313
|
mobiusAddition: typeof mobiusAddition;
|
|
@@ -216,6 +315,7 @@ declare const _default: {
|
|
|
216
315
|
logMap: typeof logMap;
|
|
217
316
|
isAttentionAvailable: typeof isAttentionAvailable;
|
|
218
317
|
getAttentionVersion: typeof getAttentionVersion;
|
|
318
|
+
benchmarkAttention: typeof benchmarkAttention;
|
|
219
319
|
};
|
|
220
320
|
export default _default;
|
|
221
321
|
//# sourceMappingURL=attention-fallbacks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attention-fallbacks.d.ts","sourceRoot":"","sources":["../../src/core/attention-fallbacks.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA8CH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,qCAAqC;IACr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EAAE,MAAM,EAAE,GAAG,YAAY,EAC/B,QAAQ,EAAE,MAAM,EAAE,GAAG,YAAY,EACjC,SAAS,EAAE,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,EAAE,EACtC,WAAW,GAAE,MAAa,GACzB,MAAM,CAQR;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EAAE,GAAG,YAAY,EAC/B,UAAU,EAAE,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,EAAE,EACvC,IAAI,GAAE,MAAU,GACf,MAAM,EAAE,EAAE,CAKZ;AAMD;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,UAAU,GAAE,MAAY,GACvB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAG1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAED,wBAqCE"}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* This wrapper handles the conversion automatically.
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.MoEAttention = exports.LocalGlobalAttention = exports.LinearAttention = exports.HyperbolicAttention = exports.FlashAttention = exports.MultiHeadAttention = void 0;
|
|
12
|
+
exports.AdamOptimizer = exports.DotProductAttention = exports.DualSpaceAttention = exports.EdgeFeaturedAttention = exports.GraphRoPeAttention = exports.MoEAttention = exports.LocalGlobalAttention = exports.LinearAttention = exports.HyperbolicAttention = exports.FlashAttention = exports.MultiHeadAttention = void 0;
|
|
13
13
|
exports.projectToPoincareBall = projectToPoincareBall;
|
|
14
14
|
exports.poincareDistance = poincareDistance;
|
|
15
15
|
exports.mobiusAddition = mobiusAddition;
|
|
@@ -17,6 +17,13 @@ exports.expMap = expMap;
|
|
|
17
17
|
exports.logMap = logMap;
|
|
18
18
|
exports.isAttentionAvailable = isAttentionAvailable;
|
|
19
19
|
exports.getAttentionVersion = getAttentionVersion;
|
|
20
|
+
exports.parallelAttentionCompute = parallelAttentionCompute;
|
|
21
|
+
exports.batchAttentionCompute = batchAttentionCompute;
|
|
22
|
+
exports.computeFlashAttentionAsync = computeFlashAttentionAsync;
|
|
23
|
+
exports.computeHyperbolicAttentionAsync = computeHyperbolicAttentionAsync;
|
|
24
|
+
exports.infoNceLoss = infoNceLoss;
|
|
25
|
+
exports.mineHardNegatives = mineHardNegatives;
|
|
26
|
+
exports.benchmarkAttention = benchmarkAttention;
|
|
20
27
|
// Lazy load to avoid import errors if not installed
|
|
21
28
|
let attentionModule = null;
|
|
22
29
|
let loadError = null;
|
|
@@ -344,18 +351,202 @@ function getAttentionVersion() {
|
|
|
344
351
|
return null;
|
|
345
352
|
}
|
|
346
353
|
}
|
|
354
|
+
// ============================================================================
|
|
355
|
+
// Graph-based Attention (for code structure)
|
|
356
|
+
// ============================================================================
|
|
357
|
+
/**
|
|
358
|
+
* Graph attention with Rotary Position Embeddings
|
|
359
|
+
* Excellent for code AST and dependency graphs
|
|
360
|
+
*/
|
|
361
|
+
class GraphRoPeAttention {
|
|
362
|
+
constructor(dim, numHeads = 4, maxSeqLen = 4096) {
|
|
363
|
+
const attention = getAttentionModule();
|
|
364
|
+
this.inner = new attention.GraphRoPeAttention(dim, numHeads, maxSeqLen);
|
|
365
|
+
this.dim = dim;
|
|
366
|
+
this.numHeads = numHeads;
|
|
367
|
+
this.maxSeqLen = maxSeqLen;
|
|
368
|
+
}
|
|
369
|
+
compute(query, keys, values, positions) {
|
|
370
|
+
const raw = this.inner.compute(toFloat32Array(query), toFloat32Arrays(keys), toFloat32Arrays(values), positions ? new Int32Array(positions) : undefined);
|
|
371
|
+
return { values: fromFloat32Array(raw), raw };
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
exports.GraphRoPeAttention = GraphRoPeAttention;
|
|
375
|
+
/**
|
|
376
|
+
* Edge-featured attention for graphs with edge attributes
|
|
377
|
+
* Useful for weighted dependency graphs
|
|
378
|
+
*/
|
|
379
|
+
class EdgeFeaturedAttention {
|
|
380
|
+
constructor(dim, edgeDim = 16) {
|
|
381
|
+
const attention = getAttentionModule();
|
|
382
|
+
this.inner = new attention.EdgeFeaturedAttention(dim, edgeDim);
|
|
383
|
+
this.dim = dim;
|
|
384
|
+
this.edgeDim = edgeDim;
|
|
385
|
+
}
|
|
386
|
+
compute(query, keys, values, edgeFeatures) {
|
|
387
|
+
const raw = this.inner.compute(toFloat32Array(query), toFloat32Arrays(keys), toFloat32Arrays(values), edgeFeatures ? toFloat32Arrays(edgeFeatures) : undefined);
|
|
388
|
+
return { values: fromFloat32Array(raw), raw };
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
exports.EdgeFeaturedAttention = EdgeFeaturedAttention;
|
|
392
|
+
/**
|
|
393
|
+
* Dual-space attention (Euclidean + Hyperbolic)
|
|
394
|
+
* Best of both worlds for hierarchical + semantic similarity
|
|
395
|
+
*/
|
|
396
|
+
class DualSpaceAttention {
|
|
397
|
+
constructor(dim, curvature = 1.0, alpha = 0.5) {
|
|
398
|
+
const attention = getAttentionModule();
|
|
399
|
+
this.inner = new attention.DualSpaceAttention(dim, curvature, alpha);
|
|
400
|
+
this.dim = dim;
|
|
401
|
+
this.curvature = curvature;
|
|
402
|
+
this.alpha = alpha;
|
|
403
|
+
}
|
|
404
|
+
compute(query, keys, values) {
|
|
405
|
+
const raw = this.inner.compute(toFloat32Array(query), toFloat32Arrays(keys), toFloat32Arrays(values));
|
|
406
|
+
return { values: fromFloat32Array(raw), raw };
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
exports.DualSpaceAttention = DualSpaceAttention;
|
|
410
|
+
/**
|
|
411
|
+
* Basic dot-product attention
|
|
412
|
+
*/
|
|
413
|
+
class DotProductAttention {
|
|
414
|
+
constructor(dim) {
|
|
415
|
+
const attention = getAttentionModule();
|
|
416
|
+
this.inner = new attention.DotProductAttention(dim);
|
|
417
|
+
this.dim = dim;
|
|
418
|
+
}
|
|
419
|
+
compute(query, keys, values) {
|
|
420
|
+
const raw = this.inner.compute(toFloat32Array(query), toFloat32Arrays(keys), toFloat32Arrays(values));
|
|
421
|
+
return { values: fromFloat32Array(raw), raw };
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
exports.DotProductAttention = DotProductAttention;
|
|
425
|
+
// ============================================================================
|
|
426
|
+
// Parallel/Batch Attention Compute
|
|
427
|
+
// ============================================================================
|
|
428
|
+
/**
|
|
429
|
+
* Compute attention in parallel across multiple queries
|
|
430
|
+
*/
|
|
431
|
+
async function parallelAttentionCompute(queries, keys, values, attentionType = 'multi-head') {
|
|
432
|
+
const attention = getAttentionModule();
|
|
433
|
+
const results = await attention.parallelAttentionCompute(toFloat32Arrays(queries), toFloat32Arrays(keys), toFloat32Arrays(values), attentionType);
|
|
434
|
+
return results.map((r) => fromFloat32Array(r));
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Batch attention compute for multiple query-key-value sets
|
|
438
|
+
*/
|
|
439
|
+
async function batchAttentionCompute(batches, attentionType = 'multi-head') {
|
|
440
|
+
const attention = getAttentionModule();
|
|
441
|
+
const nativeBatches = batches.map(b => ({
|
|
442
|
+
query: toFloat32Array(b.query),
|
|
443
|
+
keys: toFloat32Arrays(b.keys),
|
|
444
|
+
values: toFloat32Arrays(b.values),
|
|
445
|
+
}));
|
|
446
|
+
const results = await attention.batchAttentionCompute(nativeBatches, attentionType);
|
|
447
|
+
return results.map((r) => fromFloat32Array(r));
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Async flash attention with callback
|
|
451
|
+
*/
|
|
452
|
+
function computeFlashAttentionAsync(query, keys, values) {
|
|
453
|
+
const attention = getAttentionModule();
|
|
454
|
+
return new Promise((resolve, reject) => {
|
|
455
|
+
attention.computeFlashAttentionAsync(toFloat32Array(query), toFloat32Arrays(keys), toFloat32Arrays(values), (err, result) => {
|
|
456
|
+
if (err)
|
|
457
|
+
reject(err);
|
|
458
|
+
else
|
|
459
|
+
resolve(fromFloat32Array(result));
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Async hyperbolic attention
|
|
465
|
+
*/
|
|
466
|
+
function computeHyperbolicAttentionAsync(query, keys, values, curvature = 1.0) {
|
|
467
|
+
const attention = getAttentionModule();
|
|
468
|
+
return new Promise((resolve, reject) => {
|
|
469
|
+
attention.computeHyperbolicAttentionAsync(toFloat32Array(query), toFloat32Arrays(keys), toFloat32Arrays(values), curvature, (err, result) => {
|
|
470
|
+
if (err)
|
|
471
|
+
reject(err);
|
|
472
|
+
else
|
|
473
|
+
resolve(fromFloat32Array(result));
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
// ============================================================================
|
|
478
|
+
// Training Utilities (for SONA integration)
|
|
479
|
+
// ============================================================================
|
|
480
|
+
/**
|
|
481
|
+
* Adam optimizer for attention training
|
|
482
|
+
*/
|
|
483
|
+
class AdamOptimizer {
|
|
484
|
+
constructor(learningRate = 0.001, beta1 = 0.9, beta2 = 0.999) {
|
|
485
|
+
const attention = getAttentionModule();
|
|
486
|
+
this.inner = new attention.AdamOptimizer(learningRate, beta1, beta2);
|
|
487
|
+
}
|
|
488
|
+
step(gradients, params) {
|
|
489
|
+
const result = this.inner.step(toFloat32Array(gradients), toFloat32Array(params));
|
|
490
|
+
return fromFloat32Array(result);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
exports.AdamOptimizer = AdamOptimizer;
|
|
494
|
+
/**
|
|
495
|
+
* InfoNCE contrastive loss
|
|
496
|
+
*/
|
|
497
|
+
function infoNceLoss(anchor, positive, negatives, temperature = 0.07) {
|
|
498
|
+
const attention = getAttentionModule();
|
|
499
|
+
return attention.InfoNceLoss.compute(toFloat32Array(anchor), toFloat32Array(positive), toFloat32Arrays(negatives), temperature);
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Hard negative mining for contrastive learning
|
|
503
|
+
*/
|
|
504
|
+
function mineHardNegatives(anchor, candidates, topK = 5) {
|
|
505
|
+
const attention = getAttentionModule();
|
|
506
|
+
const miner = new attention.HardNegativeMiner(topK);
|
|
507
|
+
const results = miner.mine(toFloat32Array(anchor), toFloat32Arrays(candidates));
|
|
508
|
+
return results.map((r) => fromFloat32Array(r));
|
|
509
|
+
}
|
|
510
|
+
// ============================================================================
|
|
511
|
+
// Benchmarking
|
|
512
|
+
// ============================================================================
|
|
513
|
+
/**
|
|
514
|
+
* Benchmark attention implementations
|
|
515
|
+
*/
|
|
516
|
+
async function benchmarkAttention(dim, seqLen, iterations = 100) {
|
|
517
|
+
const attention = getAttentionModule();
|
|
518
|
+
return attention.benchmarkAttention(dim, seqLen, iterations);
|
|
519
|
+
}
|
|
347
520
|
exports.default = {
|
|
521
|
+
// Core attention types
|
|
522
|
+
DotProductAttention,
|
|
348
523
|
MultiHeadAttention,
|
|
349
524
|
FlashAttention,
|
|
350
525
|
HyperbolicAttention,
|
|
351
526
|
LinearAttention,
|
|
352
527
|
LocalGlobalAttention,
|
|
353
528
|
MoEAttention,
|
|
529
|
+
// Graph attention types
|
|
530
|
+
GraphRoPeAttention,
|
|
531
|
+
EdgeFeaturedAttention,
|
|
532
|
+
DualSpaceAttention,
|
|
533
|
+
// Parallel/batch compute
|
|
534
|
+
parallelAttentionCompute,
|
|
535
|
+
batchAttentionCompute,
|
|
536
|
+
computeFlashAttentionAsync,
|
|
537
|
+
computeHyperbolicAttentionAsync,
|
|
538
|
+
// Training utilities
|
|
539
|
+
AdamOptimizer,
|
|
540
|
+
infoNceLoss,
|
|
541
|
+
mineHardNegatives,
|
|
542
|
+
// Hyperbolic math
|
|
354
543
|
projectToPoincareBall,
|
|
355
544
|
poincareDistance,
|
|
356
545
|
mobiusAddition,
|
|
357
546
|
expMap,
|
|
358
547
|
logMap,
|
|
548
|
+
// Utilities
|
|
359
549
|
isAttentionAvailable,
|
|
360
550
|
getAttentionVersion,
|
|
551
|
+
benchmarkAttention,
|
|
361
552
|
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cluster Wrapper - Distributed coordination for multi-agent systems
|
|
3
|
+
*
|
|
4
|
+
* Wraps @ruvector/cluster for Raft consensus, auto-sharding,
|
|
5
|
+
* and distributed memory across agents.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isClusterAvailable(): boolean;
|
|
8
|
+
export interface ClusterNode {
|
|
9
|
+
id: string;
|
|
10
|
+
address: string;
|
|
11
|
+
role: 'leader' | 'follower' | 'candidate';
|
|
12
|
+
status: 'healthy' | 'unhealthy' | 'unknown';
|
|
13
|
+
lastHeartbeat: number;
|
|
14
|
+
}
|
|
15
|
+
export interface ShardInfo {
|
|
16
|
+
id: number;
|
|
17
|
+
range: [number, number];
|
|
18
|
+
node: string;
|
|
19
|
+
size: number;
|
|
20
|
+
status: 'active' | 'migrating' | 'offline';
|
|
21
|
+
}
|
|
22
|
+
export interface ClusterConfig {
|
|
23
|
+
nodeId: string;
|
|
24
|
+
address: string;
|
|
25
|
+
peers?: string[];
|
|
26
|
+
shards?: number;
|
|
27
|
+
replicationFactor?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Distributed cluster for multi-agent coordination
|
|
31
|
+
*/
|
|
32
|
+
export declare class RuvectorCluster {
|
|
33
|
+
private inner;
|
|
34
|
+
private nodeId;
|
|
35
|
+
private isLeader;
|
|
36
|
+
constructor(config: ClusterConfig);
|
|
37
|
+
/**
|
|
38
|
+
* Start the cluster node
|
|
39
|
+
*/
|
|
40
|
+
start(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Stop the cluster node gracefully
|
|
43
|
+
*/
|
|
44
|
+
stop(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Join an existing cluster
|
|
47
|
+
*/
|
|
48
|
+
join(peerAddress: string): Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Leave the cluster
|
|
51
|
+
*/
|
|
52
|
+
leave(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Get current node info
|
|
55
|
+
*/
|
|
56
|
+
getNodeInfo(): ClusterNode;
|
|
57
|
+
/**
|
|
58
|
+
* Get all cluster nodes
|
|
59
|
+
*/
|
|
60
|
+
getNodes(): ClusterNode[];
|
|
61
|
+
/**
|
|
62
|
+
* Check if this node is the leader
|
|
63
|
+
*/
|
|
64
|
+
isClusterLeader(): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Get the current leader
|
|
67
|
+
*/
|
|
68
|
+
getLeader(): ClusterNode | null;
|
|
69
|
+
/**
|
|
70
|
+
* Put a value in distributed storage
|
|
71
|
+
*/
|
|
72
|
+
put(key: string, value: any): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Get a value from distributed storage
|
|
75
|
+
*/
|
|
76
|
+
get(key: string): Promise<any | null>;
|
|
77
|
+
/**
|
|
78
|
+
* Delete a value from distributed storage
|
|
79
|
+
*/
|
|
80
|
+
delete(key: string): Promise<boolean>;
|
|
81
|
+
/**
|
|
82
|
+
* Atomic compare-and-swap
|
|
83
|
+
*/
|
|
84
|
+
compareAndSwap(key: string, expected: any, newValue: any): Promise<boolean>;
|
|
85
|
+
/**
|
|
86
|
+
* Get shard information
|
|
87
|
+
*/
|
|
88
|
+
getShards(): ShardInfo[];
|
|
89
|
+
/**
|
|
90
|
+
* Get the shard for a key
|
|
91
|
+
*/
|
|
92
|
+
getShardForKey(key: string): ShardInfo;
|
|
93
|
+
/**
|
|
94
|
+
* Trigger shard rebalancing
|
|
95
|
+
*/
|
|
96
|
+
rebalance(): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Acquire a distributed lock
|
|
99
|
+
*/
|
|
100
|
+
lock(name: string, timeout?: number): Promise<string | null>;
|
|
101
|
+
/**
|
|
102
|
+
* Release a distributed lock
|
|
103
|
+
*/
|
|
104
|
+
unlock(name: string, token: string): Promise<boolean>;
|
|
105
|
+
/**
|
|
106
|
+
* Extend a lock's TTL
|
|
107
|
+
*/
|
|
108
|
+
extendLock(name: string, token: string, extension?: number): Promise<boolean>;
|
|
109
|
+
/**
|
|
110
|
+
* Subscribe to a channel
|
|
111
|
+
*/
|
|
112
|
+
subscribe(channel: string, callback: (message: any) => void): () => void;
|
|
113
|
+
/**
|
|
114
|
+
* Publish to a channel
|
|
115
|
+
*/
|
|
116
|
+
publish(channel: string, message: any): Promise<number>;
|
|
117
|
+
/**
|
|
118
|
+
* Register an agent with the cluster
|
|
119
|
+
*/
|
|
120
|
+
registerAgent(agentId: string, capabilities: string[]): Promise<boolean>;
|
|
121
|
+
/**
|
|
122
|
+
* Find agents with a capability
|
|
123
|
+
*/
|
|
124
|
+
findAgents(capability: string): Promise<string[]>;
|
|
125
|
+
/**
|
|
126
|
+
* Assign a task to an agent
|
|
127
|
+
*/
|
|
128
|
+
assignTask(taskId: string, agentId: string, task: any): Promise<boolean>;
|
|
129
|
+
/**
|
|
130
|
+
* Complete a task
|
|
131
|
+
*/
|
|
132
|
+
completeTask(taskId: string, result: any): Promise<boolean>;
|
|
133
|
+
/**
|
|
134
|
+
* Get cluster statistics
|
|
135
|
+
*/
|
|
136
|
+
stats(): {
|
|
137
|
+
nodes: number;
|
|
138
|
+
shards: number;
|
|
139
|
+
leader: string | null;
|
|
140
|
+
healthy: boolean;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Create a cluster node for agent coordination
|
|
145
|
+
*/
|
|
146
|
+
export declare function createCluster(config: ClusterConfig): RuvectorCluster;
|
|
147
|
+
export default RuvectorCluster;
|
|
148
|
+
//# sourceMappingURL=cluster-wrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cluster-wrapper.d.ts","sourceRoot":"","sources":["../../src/core/cluster-wrapper.ts"],"names":[],"mappings":"AAAA;;;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