ruvector 0.1.25 → 0.1.26

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.
@@ -1,7 +1,7 @@
1
1
  {
2
- "startTime": 1764542370768,
3
- "sessionId": "session-1764542370768",
4
- "lastActivity": 1764542370768,
2
+ "startTime": 1764543814799,
3
+ "sessionId": "session-1764543814799",
4
+ "lastActivity": 1764543814799,
5
5
  "sessionDuration": 0,
6
6
  "totalTasks": 1,
7
7
  "successfulTasks": 1,
@@ -1,10 +1,10 @@
1
1
  [
2
2
  {
3
- "id": "cmd-hooks-1764542370895",
3
+ "id": "cmd-hooks-1764543814926",
4
4
  "type": "hooks",
5
5
  "success": true,
6
- "duration": 15.263496999999973,
7
- "timestamp": 1764542370910,
6
+ "duration": 11.31845599999997,
7
+ "timestamp": 1764543814938,
8
8
  "metadata": {}
9
9
  }
10
10
  ]
package/README.md CHANGED
@@ -484,6 +484,119 @@ npx ruvector gnn search -q "[1.0,0.0,0.0]" -c candidates.json -k 5
484
484
  # -t, --temperature Softmax temperature (default: 1.0)
485
485
  ```
486
486
 
487
+ ### Attention Commands
488
+
489
+ Ruvector includes high-performance attention mechanisms for transformer-based operations, hyperbolic embeddings, and graph attention.
490
+
491
+ ```bash
492
+ # Install the attention module (optional)
493
+ npm install @ruvector/attention
494
+ ```
495
+
496
+ #### Attention Mechanisms Reference
497
+
498
+ | Mechanism | Type | Complexity | When to Use |
499
+ |-----------|------|------------|-------------|
500
+ | **DotProductAttention** | Core | O(n²) | Standard scaled dot-product attention for transformers |
501
+ | **MultiHeadAttention** | Core | O(n²) | Parallel attention heads for capturing different relationships |
502
+ | **FlashAttention** | Core | O(n²) IO-optimized | Memory-efficient attention for long sequences |
503
+ | **HyperbolicAttention** | Core | O(n²) | Hierarchical data, tree-like structures, taxonomies |
504
+ | **LinearAttention** | Core | O(n) | Very long sequences where O(n²) is prohibitive |
505
+ | **MoEAttention** | Core | O(n*k) | Mixture of Experts routing, specialized attention |
506
+ | **GraphRoPeAttention** | Graph | O(n²) | Graph data with rotary position embeddings |
507
+ | **EdgeFeaturedAttention** | Graph | O(n²) | Graphs with rich edge features/attributes |
508
+ | **DualSpaceAttention** | Graph | O(n²) | Combined Euclidean + hyperbolic representation |
509
+ | **LocalGlobalAttention** | Graph | O(n*k) | Large graphs with local + global context |
510
+
511
+ #### Attention Info
512
+
513
+ ```bash
514
+ # Show attention module information
515
+ npx ruvector attention info
516
+
517
+ # Output:
518
+ # Attention Module Information
519
+ # Status: Available
520
+ # Version: 0.1.0
521
+ # Platform: linux
522
+ # Architecture: x64
523
+ #
524
+ # Core Attention Mechanisms:
525
+ # • DotProductAttention - Scaled dot-product attention
526
+ # • MultiHeadAttention - Multi-head self-attention
527
+ # • FlashAttention - Memory-efficient IO-aware attention
528
+ # • HyperbolicAttention - Poincaré ball attention
529
+ # • LinearAttention - O(n) linear complexity attention
530
+ # • MoEAttention - Mixture of Experts attention
531
+ ```
532
+
533
+ #### Attention List
534
+
535
+ ```bash
536
+ # List all available attention mechanisms
537
+ npx ruvector attention list
538
+
539
+ # With verbose details
540
+ npx ruvector attention list -v
541
+ ```
542
+
543
+ #### Attention Benchmark
544
+
545
+ ```bash
546
+ # Benchmark attention mechanisms
547
+ npx ruvector attention benchmark -d 256 -n 100 -i 100
548
+
549
+ # Options:
550
+ # -d, --dimension Vector dimension (default: 256)
551
+ # -n, --num-vectors Number of vectors (default: 100)
552
+ # -i, --iterations Benchmark iterations (default: 100)
553
+ # -t, --types Attention types to benchmark (default: dot,flash,linear)
554
+
555
+ # Example output:
556
+ # Dimension: 256
557
+ # Vectors: 100
558
+ # Iterations: 100
559
+ #
560
+ # dot: 0.012ms/op (84,386 ops/sec)
561
+ # flash: 0.012ms/op (82,844 ops/sec)
562
+ # linear: 0.066ms/op (15,259 ops/sec)
563
+ ```
564
+
565
+ #### Hyperbolic Operations
566
+
567
+ ```bash
568
+ # Calculate Poincaré distance between two points
569
+ npx ruvector attention hyperbolic -a distance -v "[0.1,0.2,0.3]" -b "[0.4,0.5,0.6]"
570
+
571
+ # Project vector to Poincaré ball
572
+ npx ruvector attention hyperbolic -a project -v "[1.5,2.0,0.8]"
573
+
574
+ # Möbius addition in hyperbolic space
575
+ npx ruvector attention hyperbolic -a mobius-add -v "[0.1,0.2]" -b "[0.3,0.4]"
576
+
577
+ # Exponential map (tangent space → Poincaré ball)
578
+ npx ruvector attention hyperbolic -a exp-map -v "[0.1,0.2,0.3]"
579
+
580
+ # Options:
581
+ # -a, --action Action: distance|project|mobius-add|exp-map|log-map
582
+ # -v, --vector Input vector as JSON array (required)
583
+ # -b, --vector-b Second vector for binary operations
584
+ # -c, --curvature Poincaré ball curvature (default: 1.0)
585
+ ```
586
+
587
+ #### When to Use Each Attention Type
588
+
589
+ | Use Case | Recommended Attention | Reason |
590
+ |----------|----------------------|--------|
591
+ | **Standard NLP/Transformers** | MultiHeadAttention | Industry standard, well-tested |
592
+ | **Long Documents (>4K tokens)** | FlashAttention or LinearAttention | Memory efficient |
593
+ | **Hierarchical Classification** | HyperbolicAttention | Captures tree-like structures |
594
+ | **Knowledge Graphs** | GraphRoPeAttention | Position-aware graph attention |
595
+ | **Multi-Relational Graphs** | EdgeFeaturedAttention | Leverages edge attributes |
596
+ | **Taxonomy/Ontology Search** | DualSpaceAttention | Best of both Euclidean + hyperbolic |
597
+ | **Large-Scale Graphs** | LocalGlobalAttention | Efficient local + global context |
598
+ | **Model Routing/MoE** | MoEAttention | Expert selection and routing |
599
+
487
600
  ## 📊 Performance Benchmarks
488
601
 
489
602
  Tested on AMD Ryzen 9 5950X, 128-dimensional vectors:
package/bin/cli.js CHANGED
@@ -356,9 +356,10 @@ program
356
356
 
357
357
  // Try to load ruvector for implementation info
358
358
  if (loadRuvector()) {
359
- const info = getVersion();
360
- console.log(chalk.white(` Core Version: ${chalk.yellow(info.version)}`));
361
- console.log(chalk.white(` Implementation: ${chalk.yellow(info.implementation)}`));
359
+ const version = typeof getVersion === 'function' ? getVersion() : 'unknown';
360
+ const impl = typeof getImplementationType === 'function' ? getImplementationType() : 'native';
361
+ console.log(chalk.white(` Core Version: ${chalk.yellow(version)}`));
362
+ console.log(chalk.white(` Implementation: ${chalk.yellow(impl)}`));
362
363
  } else {
363
364
  console.log(chalk.white(` Core: ${chalk.gray('Not loaded (install @ruvector/core)')}`));
364
365
  }
@@ -1056,6 +1057,10 @@ attentionCmd
1056
1057
 
1057
1058
  const results = [];
1058
1059
 
1060
+ // Convert to Float32Arrays for compute()
1061
+ const queryF32 = new Float32Array(query);
1062
+ const keysF32 = keys.map(k => new Float32Array(k));
1063
+
1059
1064
  for (const type of types) {
1060
1065
  spinner.text = `Benchmarking ${type} attention...`;
1061
1066
  spinner.start();
@@ -1064,39 +1069,42 @@ attentionCmd
1064
1069
  try {
1065
1070
  switch (type) {
1066
1071
  case 'dot':
1067
- attn = new DotProductAttention();
1072
+ attn = new DotProductAttention(dim);
1068
1073
  break;
1069
1074
  case 'flash':
1070
- attn = new FlashAttention(dim);
1075
+ attn = new FlashAttention(dim, 64); // dim, block_size
1071
1076
  break;
1072
1077
  case 'linear':
1073
- attn = new LinearAttention(dim);
1078
+ attn = new LinearAttention(dim, 64); // dim, num_features
1074
1079
  break;
1075
1080
  case 'hyperbolic':
1076
1081
  attn = new HyperbolicAttention(dim, 1.0);
1077
1082
  break;
1078
1083
  case 'multi-head':
1079
- attn = new MultiHeadAttention(dim, 4, 64);
1084
+ attn = new MultiHeadAttention(dim, 4); // dim, num_heads
1080
1085
  break;
1081
1086
  default:
1082
1087
  console.log(chalk.yellow(` Skipping unknown type: ${type}`));
1083
1088
  continue;
1084
1089
  }
1085
1090
  } catch (e) {
1086
- console.log(chalk.yellow(` ${type}: not available`));
1091
+ console.log(chalk.yellow(` ${type}: not available (${e.message})`));
1087
1092
  continue;
1088
1093
  }
1089
1094
 
1090
1095
  // Warm up
1091
- const queryMat = [query];
1092
1096
  for (let i = 0; i < 5; i++) {
1093
- attn.forward(queryMat, keys, keys);
1097
+ try {
1098
+ attn.compute(queryF32, keysF32, keysF32);
1099
+ } catch (e) {
1100
+ // Some mechanisms may fail warmup
1101
+ }
1094
1102
  }
1095
1103
 
1096
1104
  // Benchmark
1097
1105
  const start = process.hrtime.bigint();
1098
1106
  for (let i = 0; i < iterations; i++) {
1099
- attn.forward(queryMat, keys, keys);
1107
+ attn.compute(queryF32, keysF32, keysF32);
1100
1108
  }
1101
1109
  const end = process.hrtime.bigint();
1102
1110
  const totalMs = Number(end - start) / 1_000_000;
@@ -1398,8 +1406,10 @@ program
1398
1406
 
1399
1407
  // Check if native binding works
1400
1408
  if (coreAvailable && loadRuvector()) {
1401
- const info = getVersion();
1402
- console.log(chalk.green(` ✓ Native binding working (${info.implementation})`));
1409
+ const version = typeof getVersion === 'function' ? getVersion() : null;
1410
+ const impl = typeof getImplementationType === 'function' ? getImplementationType() : 'native';
1411
+ const versionStr = version ? `, v${version}` : '';
1412
+ console.log(chalk.green(` ✓ Native binding working (${impl}${versionStr})`));
1403
1413
  } else if (coreAvailable) {
1404
1414
  console.log(chalk.yellow(` ! Native binding failed to load`));
1405
1415
  warnings++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ruvector",
3
- "version": "0.1.25",
3
+ "version": "0.1.26",
4
4
  "description": "High-performance vector database for Node.js with automatic native/WASM fallback",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -49,8 +49,8 @@
49
49
  "dependencies": {
50
50
  "@ruvector/core": "^0.1.16",
51
51
  "@ruvector/gnn": "^0.1.15",
52
- "commander": "^11.1.0",
53
52
  "chalk": "^4.1.2",
53
+ "commander": "^11.1.0",
54
54
  "ora": "^5.4.1"
55
55
  },
56
56
  "optionalDependencies": {