ruvector/crates/ruvector-attention-node
github-actions[bot] cf074121e5
Some checks failed
ruvector-verified CI / check (--features coherence-proofs) (push) Has been cancelled
ruvector-verified CI / check (--features hnsw-proofs) (push) Has been cancelled
ruvector-verified CI / check (--features rvf-proofs) (push) Has been cancelled
ruvector-verified CI / check (--features serde) (push) Has been cancelled
ruvector-verified CI / check (--features ultra) (push) Has been cancelled
ruvector-verified CI / clippy (push) Has been cancelled
Clippy + fmt / Clippy (deny warnings) (push) Has been cancelled
Clippy + fmt / Rustfmt (push) Has been cancelled
Benchmarks / Rust Benchmarks (push) Has been cancelled
Benchmarks / SQL Benchmarks (push) Has been cancelled
Build Attention Native Modules / Build darwin-arm64 (push) Has been cancelled
Build Attention Native Modules / Build darwin-x64 (push) Has been cancelled
Build Attention Native Modules / Build linux-arm64-gnu (push) Has been cancelled
Build Attention Native Modules / Build linux-x64-gnu (push) Has been cancelled
Build Attention Native Modules / Build win32-x64-msvc (push) Has been cancelled
ruvector-verified CI / check () (push) Has been cancelled
ruvector-verified CI / check (--all-features) (push) Has been cancelled
ruvector-verified CI / check (--features all-proofs) (push) Has been cancelled
supply-chain / dependency-review (PRs only) (push) Has been cancelled
supply-chain / cargo audit (RustSec advisories) (push) Has been cancelled
supply-chain / cargo deny (license + source + ban policy) (push) Has been cancelled
supply-chain / npm audit (npm/ workspace) (push) Has been cancelled
RuvLLM Benchmarks / macOS ARM64 Benchmarks (M-series) (push) Has been cancelled
supply-chain / lockfile integrity (Cargo.lock) (push) Has been cancelled
Build DiskANN Native Modules / Build DiskANN linux-arm64-gnu (push) Has been cancelled
Build DiskANN Native Modules / Build DiskANN linux-x64-gnu (push) Has been cancelled
Build DiskANN Native Modules / Build DiskANN win32-x64-msvc (push) Has been cancelled
Workspace CI / Security audit (push) Has been cancelled
Build GNN Native Modules / Build GNN darwin-arm64 (push) Has been cancelled
Build GNN Native Modules / Build GNN darwin-x64 (push) Has been cancelled
Build GNN Native Modules / Build GNN linux-arm64-gnu (push) Has been cancelled
Build GNN Native Modules / Build GNN linux-x64-gnu (push) Has been cancelled
RuvLTRA-Small Tests / Test Coverage (push) Has been cancelled
Build GNN Native Modules / Build GNN linux-x64-musl (push) Has been cancelled
Build GNN Native Modules / Build GNN win32-x64-msvc (push) Has been cancelled
Build Graph Node Native Modules / Build Graph darwin-arm64 (push) Has been cancelled
Build Graph Node Native Modules / Build Graph darwin-x64 (push) Has been cancelled
Build Graph Node Native Modules / Build Graph linux-arm64-gnu (push) Has been cancelled
Build Graph Node Native Modules / Build Graph linux-x64-gnu (push) Has been cancelled
Build Graph Node Native Modules / Build Graph win32-x64-msvc (push) Has been cancelled
Build Graph Transformer Native Modules / Build darwin-arm64 (push) Has been cancelled
Build Graph Transformer Native Modules / Build linux-x64-musl (push) Has been cancelled
Build Graph Transformer Native Modules / Build win32-x64-msvc (push) Has been cancelled
Build Graph Transformer Native Modules / Build WASM (push) Has been cancelled
Build Attention Native Modules / Build WASM (push) Has been cancelled
Build DiskANN Native Modules / Build DiskANN darwin-arm64 (push) Has been cancelled
Build DiskANN Native Modules / Build DiskANN darwin-x64 (push) Has been cancelled
Build Graph Transformer Native Modules / Build darwin-x64 (push) Has been cancelled
Build Graph Transformer Native Modules / Build linux-arm64-gnu (push) Has been cancelled
Build Graph Transformer Native Modules / Build linux-arm64-musl (push) Has been cancelled
Build Graph Transformer Native Modules / Build linux-x64-gnu (push) Has been cancelled
Workspace CI / Tests (ruqu-quantum) (push) Has been cancelled
Workspace CI / Tests (ruvix) (push) Has been cancelled
Workspace CI / Tests (rvagent) (push) Has been cancelled
Workspace CI / Tests (vector-index) (push) Has been cancelled
RuvLTRA-Small Tests / Apple Silicon Tests (push) Has been cancelled
regression-guard / reentrant-rwlock-double-write (push) Has been cancelled
regression-guard / case-insensitive-collisions (push) Has been cancelled
regression-guard / ruvector-core-no-avx512-builds-on-stable (push) Has been cancelled
RuvLTRA-Small Tests / Quantization Accuracy (push) Has been cancelled
regression-guard / hnsw-recall-at-1 (push) Has been cancelled
regression-guard / vector-db-rebuilds-index-on-open (push) Has been cancelled
regression-guard / npm-publish-pipeline (npm/packages/pi-brain) (push) Has been cancelled
regression-guard / npm-publish-pipeline (npm/packages/ruvector) (push) Has been cancelled
regression-guard / npm-publish-pipeline (npm/packages/rvf-wasm) (push) Has been cancelled
regression-guard / no-npx-execSync-in-route-enhanced (push) Has been cancelled
regression-guard / shell-injection-in-mcp-server (push) Has been cancelled
regression-guard / no-systemtime-in-wasm-crates (push) Has been cancelled
regression-guard / brain-hydration-counters-present (push) Has been cancelled
regression-guard / optional-deps-resolvable-on-npm (push) Has been cancelled
RuvLLM Benchmarks / Linux Benchmarks (NEON baseline) (push) Has been cancelled
RuvLTRA-Small Tests / Unit Tests (ubuntu-latest) (push) Has been cancelled
Build Native Modules / Build darwin-arm64 (push) Has been cancelled
Build Native Modules / Build linux-arm64-gnu (push) Has been cancelled
Build Native Modules / Build darwin-x64 (push) Has been cancelled
Build Native Modules / Build win32-x64-msvc (push) Has been cancelled
Build Native Modules / Build linux-x64-gnu (push) Has been cancelled
Build Router Native Modules / Build Router darwin-arm64 (push) Has been cancelled
Build Router Native Modules / Build Router darwin-x64 (push) Has been cancelled
Build Router Native Modules / Build Router linux-arm64-gnu (push) Has been cancelled
Build Router Native Modules / Build Router linux-x64-gnu (push) Has been cancelled
Build Router Native Modules / Build Router win32-x64-msvc (push) Has been cancelled
Build Tiny Dancer Native Modules / Build Tiny Dancer darwin-arm64 (push) Has been cancelled
Build Tiny Dancer Native Modules / Build Tiny Dancer darwin-x64 (push) Has been cancelled
Build Tiny Dancer Native Modules / Build Tiny Dancer linux-arm64-gnu (push) Has been cancelled
Build Tiny Dancer Native Modules / Build Tiny Dancer linux-x64-gnu (push) Has been cancelled
Build Tiny Dancer Native Modules / Build Tiny Dancer win32-x64-msvc (push) Has been cancelled
Workspace CI / Rustfmt (push) Has been cancelled
Workspace CI / Cargo check (push) Has been cancelled
Workspace CI / Clippy (push) Has been cancelled
Workspace CI / Tests (core-and-rest) (push) Has been cancelled
Workspace CI / Tests (core-and-rest-heavy) (push) Has been cancelled
Workspace CI / Tests (core-and-rest-wasm) (push) Has been cancelled
Workspace CI / Tests (ml-research-heavy) (push) Has been cancelled
regression-guard / no-hardcoded-workspaces-paths (push) Has been cancelled
Workspace CI / Tests (ml-research-rest) (push) Has been cancelled
regression-guard / hnsw-insert-beam-no-m2-clamp (push) Has been cancelled
regression-guard / hnsw-distance-based-neighbor-pruning (push) Has been cancelled
RuvLTRA-Small Tests / Performance Benchmarks (push) Has been cancelled
RuvLTRA-Small Tests / Stress Tests (push) Has been cancelled
RuvLTRA-Small Tests / Code Quality (push) Has been cancelled
RuvLTRA-Small Tests / Unit Tests (windows-latest) (push) Has been cancelled
RuvLTRA-Small Tests / Unit Tests (macos-latest) (push) Has been cancelled
RuvLTRA-Small Tests / E2E Tests (macos-latest) (push) Has been cancelled
RuvLTRA-Small Tests / E2E Tests (ubuntu-latest) (push) Has been cancelled
RuvLTRA-Small Tests / Thread Safety (push) Has been cancelled
Benchmarks / Compare with Baseline (push) Has been cancelled
Build Attention Native Modules / Commit Built Binaries (push) Has been cancelled
Build Attention Native Modules / Publish Attention Platform Packages (push) Has been cancelled
Build Graph Node Native Modules / Publish Graph Node Platform Packages (push) Has been cancelled
Build DiskANN Native Modules / Publish DiskANN Platform Packages (push) Has been cancelled
Build GNN Native Modules / Commit Built GNN Binaries (push) Has been cancelled
Build GNN Native Modules / Publish GNN Platform Packages (push) Has been cancelled
RuvLTRA-Small Tests / Test Summary (push) Has been cancelled
Build Graph Transformer Native Modules / Commit Built Binaries (push) Has been cancelled
Build Graph Transformer Native Modules / Publish Platform Packages (push) Has been cancelled
Build Native Modules / Commit Built Binaries (push) Has been cancelled
Build Router Native Modules / Publish Router Platform Packages (push) Has been cancelled
Build Tiny Dancer Native Modules / Publish Tiny Dancer Platform Packages (push) Has been cancelled
RuvLLM Benchmarks / Compare Benchmarks (push) Has been cancelled
thermorust CI / Test (macos-latest) (push) Has been cancelled
thermorust CI / Test (ubuntu-latest) (push) Has been cancelled
thermorust CI / Test (windows-latest) (push) Has been cancelled
thermorust CI / Benchmarks compile (push) Has been cancelled
WASM Dedup Check / check-wasm-dedup (push) Has been cancelled
ruvector-verified CI / test (push) Has been cancelled
ruvector-verified CI / bench (push) Has been cancelled
chore: Update attention NAPI-RS binaries for all platforms
Built from commit eafba64fa5

  Platforms updated:
  - linux-x64-gnu
  - linux-arm64-gnu
  - darwin-x64
  - darwin-arm64
  - win32-x64-msvc
  - wasm

  🤖 Generated by GitHub Actions
2026-05-23 10:52:21 +00:00
..
npm chore: Update attention NAPI-RS binaries for all platforms 2026-05-23 10:52:21 +00:00
src chore(workspace): clippy-clean every crate under -D warnings + fmt + repair pre-existing broken benches 2026-04-25 17:00:20 -04:00
.npmignore fix: Fix PQ integration test failures and add v0.1.18 release 2025-11-30 20:45:43 +00:00
build.rs fix: Fix PQ integration test failures and add v0.1.18 release 2025-11-30 20:45:43 +00:00
Cargo.toml fix(security): RUSTSEC advisories + clippy hardening in RuVector (#504) 2026-05-23 05:40:24 -04:00
LICENSE feat: Export all 39 attention mechanisms and utilities 2025-11-30 22:23:21 +00:00
package.json feat(training): RuvLTRA v2.4 Ecosystem Edition - 100% routing accuracy (#123) 2026-01-20 20:08:30 -05:00
README.md fix: Fix PQ integration test failures and add v0.1.18 release 2025-11-30 20:45:43 +00:00

@ruvector/attention

High-performance attention mechanisms for Node.js, powered by Rust.

Features

  • Scaled Dot-Product Attention: Classic attention mechanism with optional scaling
  • Multi-Head Attention: Parallel attention heads for richer representations
  • Flash Attention: Memory-efficient attention with block-wise computation
  • Linear Attention: O(N) complexity attention using kernel approximations
  • Hyperbolic Attention: Attention in hyperbolic space for hierarchical data
  • Mixture-of-Experts (MoE) Attention: Dynamic expert routing for specialized attention

Installation

npm install @ruvector/attention

Usage

Basic Dot-Product Attention

const { DotProductAttention } = require('@ruvector/attention');

const attention = new DotProductAttention(512, 1.0);
const query = new Float32Array([/* ... */]);
const keys = [new Float32Array([/* ... */])];
const values = [new Float32Array([/* ... */])];

const output = attention.compute(query, keys, values);

Multi-Head Attention

const { MultiHeadAttention } = require('@ruvector/attention');

const mha = new MultiHeadAttention(512, 8); // 512 dim, 8 heads
const output = mha.compute(query, keys, values);

// Async version for large computations
const outputAsync = await mha.computeAsync(query, keys, values);

Flash Attention

const { FlashAttention } = require('@ruvector/attention');

const flash = new FlashAttention(512, 64); // 512 dim, 64 block size
const output = flash.compute(query, keys, values);

Hyperbolic Attention

const { HyperbolicAttention } = require('@ruvector/attention');

const hyperbolic = new HyperbolicAttention(512, -1.0); // negative curvature
const output = hyperbolic.compute(query, keys, values);

Mixture-of-Experts Attention

const { MoEAttention } = require('@ruvector/attention');

const moe = new MoEAttention({
  dim: 512,
  numExperts: 8,
  topK: 2,
  expertCapacity: 1.25
});

const output = moe.compute(query, keys, values);
const expertUsage = moe.getExpertUsage();

Training

const { Trainer, AdamOptimizer } = require('@ruvector/attention');

// Configure training
const trainer = new Trainer({
  learningRate: 0.001,
  batchSize: 32,
  numEpochs: 100,
  weightDecay: 0.01,
  gradientClip: 1.0,
  warmupSteps: 1000
});

// Training step
const loss = trainer.trainStep(inputs, targets);

// Get metrics
const metrics = trainer.getMetrics();
console.log(`Loss: ${metrics.loss}, LR: ${metrics.learningRate}`);

// Custom optimizer
const optimizer = new AdamOptimizer(0.001, 0.9, 0.999, 1e-8);
const updatedParams = optimizer.step(gradients);

Batch Processing

const { BatchProcessor, parallelAttentionCompute } = require('@ruvector/attention');

// Batch processor for efficient batching
const processor = new BatchProcessor({
  batchSize: 32,
  numWorkers: 4,
  prefetch: true
});

const results = await processor.processBatch(queries, keys, values);
const throughput = processor.getThroughput();

// Parallel computation with automatic worker management
const results = await parallelAttentionCompute(
  'multi-head',
  queries,
  keys,
  values,
  4 // number of workers
);

API Reference

Classes

DotProductAttention

  • constructor(dim: number, scale?: number)
  • compute(query: Float32Array, keys: Float32Array[], values: Float32Array[]): Float32Array

MultiHeadAttention

  • constructor(dim: number, numHeads: number)
  • compute(query: Float32Array, keys: Float32Array[], values: Float32Array[]): Float32Array
  • computeAsync(query: Float32Array, keys: Float32Array[], values: Float32Array[]): Promise<Float32Array>

FlashAttention

  • constructor(dim: number, blockSize: number)
  • compute(query: Float32Array, keys: Float32Array[], values: Float32Array[]): Float32Array

LinearAttention

  • constructor(dim: number, numFeatures: number)
  • compute(query: Float32Array, keys: Float32Array[], values: Float32Array[]): Float32Array

HyperbolicAttention

  • constructor(dim: number, curvature: number)
  • compute(query: Float32Array, keys: Float32Array[], values: Float32Array[]): Float32Array

MoEAttention

  • constructor(config: MoEConfig)
  • compute(query: Float32Array, keys: Float32Array[], values: Float32Array[]): Float32Array
  • getExpertUsage(): number[]

Trainer

  • constructor(config: TrainingConfig)
  • trainStep(inputs: Float32Array[], targets: Float32Array[]): number
  • trainStepAsync(inputs: Float32Array[], targets: Float32Array[]): Promise<number>
  • getMetrics(): TrainingMetrics

AdamOptimizer

  • constructor(learningRate: number, beta1?: number, beta2?: number, epsilon?: number)
  • step(gradients: Float32Array[]): Float32Array[]
  • getLearningRate(): number
  • setLearningRate(lr: number): void

BatchProcessor

  • constructor(config: BatchConfig)
  • processBatch(queries: Float32Array[], keys: Float32Array[][], values: Float32Array[][]): Promise<Float32Array[]>
  • getThroughput(): number

Functions

parallelAttentionCompute

function parallelAttentionCompute(
  attentionType: string,
  queries: Float32Array[],
  keys: Float32Array[][],
  values: Float32Array[][],
  numWorkers?: number
): Promise<Float32Array[]>

version

Returns the package version string.

Performance

This package uses Rust under the hood for optimal performance:

  • Zero-copy data transfer where possible
  • SIMD optimizations for vector operations
  • Multi-threaded batch processing
  • Memory-efficient attention mechanisms

Platform Support

Pre-built binaries are provided for:

  • macOS (x64, ARM64)
  • Linux (x64, ARM64, musl)
  • Windows (x64, ARM64)

License

MIT OR Apache-2.0