npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ruvector/learning-wasm

v0.1.30

Published

Ultra-fast MicroLoRA adaptation for WASM - rank-2 LoRA with <100us latency for per-operator learning

Readme

@ruvector/learning-wasm - Ultra-Fast MicroLoRA for WebAssembly

npm version License: MIT OR Apache-2.0 Bundle Size WebAssembly

Ultra-fast Low-Rank Adaptation (LoRA) for WebAssembly with sub-100 microsecond adaptation latency. Designed for real-time per-operator-type learning in query optimization systems, edge AI, and browser-based machine learning applications.

Key Features

  • Rank-2 LoRA Architecture: Minimal parameter count (2d parameters per adapter) for efficient edge deployment
  • Sub-100us Adaptation Latency: Instant weight updates enabling real-time learning
  • Per-Operator Scoping: Separate adapters for 17 different operator types (scan, filter, join, aggregate, etc.)
  • Zero-Allocation Forward Pass: Direct memory access for maximum performance
  • Trajectory Buffer: Track learning history with success rate analytics
  • WASM-Optimized: no_std compatible with minimal allocations

Installation

npm install @ruvector/learning-wasm
# or
yarn add @ruvector/learning-wasm
# or
pnpm add @ruvector/learning-wasm

Quick Start

Runs in browsers and Node.js (tested on Node.js 22); WebAssembly, no native build. In a browser call await init(); in Node pass the .wasm bytes to init():

import { readFileSync } from 'node:fs';
import { createRequire } from 'node:module';
import init, { WasmMicroLoRA } from '@ruvector/learning-wasm';

const require = createRequire(import.meta.url);
await init({ module_or_path: readFileSync(require.resolve('@ruvector/learning-wasm/ruvector_learning_wasm_bg.wasm')) });

// A MicroLoRA engine for 256-dim embeddings
const lora = new WasmMicroLoRA(256, 0.1, 0.01);
const input = new Float32Array(256).fill(0.1);
const before = lora.forward_array(input);

lora.adapt_array(new Float32Array(256).fill(0.05)); // adapt from a gradient
lora.adapt_with_reward(0.15);                        // or from a reward (15% improvement)

const after = lora.forward_array(input);
console.log('adaptations:', Number(lora.adapt_count()));
console.log('output changed:', before.some((v, i) => v !== after[i]));

Expected output:

adaptations: 2
output changed: true

Zero-Allocation Forward Pass

For maximum performance, use direct memory access:

// Get buffer pointers
const inputPtr = lora.get_input_ptr();
const outputPtr = lora.get_output_ptr();

// Write directly to WASM memory
const memory = new Float32Array(wasmInstance.memory.buffer, inputPtr, 256);
memory.set(inputData);

// Execute forward pass (zero allocation)
lora.forward();

// Read output directly from WASM memory
const result = new Float32Array(wasmInstance.memory.buffer, outputPtr, 256);

Per-Operator Scoped LoRA

import { WasmScopedLoRA } from '@ruvector/learning-wasm';

const scopedLora = new WasmScopedLoRA(256, 0.1, 0.01);

// Operator types: 0=Scan, 1=Filter, 2=Join, 3=Aggregate, 4=Project, 5=Sort, ...
const SCAN_OP = 0;
const JOIN_OP = 2;

// Forward pass for specific operator
const scanOutput = scopedLora.forward_array(SCAN_OP, input);

// Adapt specific operator based on improvement
scopedLora.adapt_with_reward(JOIN_OP, 0.25);

// Get operator name
console.log(WasmScopedLoRA.scope_name(SCAN_OP)); // "Scan"

// Check per-operator statistics
console.log(`Scan adaptations: ${scopedLora.adapt_count(SCAN_OP)}`);
console.log(`Total adaptations: ${scopedLora.total_adapt_count()}`);

Trajectory Tracking

import { WasmTrajectoryBuffer } from '@ruvector/learning-wasm';

const buffer = new WasmTrajectoryBuffer(1000, 256);

// Record trajectories
buffer.record(
  embedding,      // Float32Array
  2,              // operator type (JOIN)
  5,              // attention mechanism used
  45.2,           // actual execution time (ms)
  120.5           // baseline execution time (ms)
);

// Analyze learning progress
console.log(`Success rate: ${(buffer.success_rate() * 100).toFixed(1)}%`);
console.log(`Best improvement: ${buffer.best_improvement()}x`);
console.log(`Mean improvement: ${buffer.mean_improvement()}x`);
console.log(`Best attention mechanism: ${buffer.best_attention()}`);

// Filter high-quality trajectories
const topTrajectories = buffer.high_quality_count(0.5); // >50% improvement

Architecture

Input Embedding (d-dim)
       |
       v
  +---------+
  | A: d x 2 |  Down projection (d -> 2)
  +---------+
       |
       v
  +---------+
  | B: 2 x d |  Up projection (2 -> d)
  +---------+
       |
       v
Delta W = alpha * (A @ B)
       |
       v
Output = Input + Delta W

Performance Benchmarks

| Operation | Latency | Throughput | |-----------|---------|------------| | Forward (256-dim) | ~15us | 66K ops/sec | | Adapt (gradient) | ~25us | 40K ops/sec | | Forward (zero-alloc) | ~8us | 125K ops/sec | | Scoped forward | ~20us | 50K ops/sec | | Trajectory record | ~5us | 200K ops/sec |

Tested on Chrome 120+ / Node.js 20+ with WASM SIMD support.

API Reference

WasmMicroLoRA

| Method | Description | |--------|-------------| | new(dim?, alpha?, learning_rate?) | Create engine (defaults: 256, 0.1, 0.01) | | forward_array(input) | Forward pass with Float32Array | | forward() | Zero-allocation forward using buffers | | adapt_array(gradient) | Adapt with gradient vector | | adapt_with_reward(improvement) | Reward-based adaptation | | delta_norm() | Get weight change magnitude | | adapt_count() | Number of adaptations | | reset() | Reset to initial state |

WasmScopedLoRA

| Method | Description | |--------|-------------| | new(dim?, alpha?, learning_rate?) | Create scoped manager | | forward_array(op_type, input) | Forward for operator | | adapt_with_reward(op_type, improvement) | Operator-specific adaptation | | scope_name(op_type) | Get operator name (static) | | total_adapt_count() | Total adaptations across all operators | | set_category_fallback(enabled) | Enable category fallback |

WasmTrajectoryBuffer

| Method | Description | |--------|-------------| | new(capacity?, embedding_dim?) | Create buffer | | record(embedding, op_type, attention_type, exec_ms, baseline_ms) | Record trajectory | | success_rate() | Get success rate (0.0-1.0) | | best_improvement() | Get best improvement ratio | | mean_improvement() | Get mean improvement ratio | | high_quality_count(threshold) | Count trajectories above threshold |

Use Cases

  • Query Optimization: Learn optimal attention mechanisms per SQL operator
  • Edge AI Personalization: Real-time model adaptation on user devices
  • Browser ML: In-browser fine-tuning without server round-trips
  • Federated Learning: Lightweight local adaptation for aggregation
  • Reinforcement Learning: Fast policy adaptation from rewards

Bundle Size

  • WASM binary: ~39KB (uncompressed)
  • Gzip compressed: ~15KB
  • JavaScript glue: ~5KB

Related Packages

License

MIT OR Apache-2.0

Links


Keywords: LoRA, Low-Rank Adaptation, machine learning, WASM, WebAssembly, neural network, edge AI, adaptation, fine-tuning, query optimization, real-time learning, micro LoRA, rank-2, browser ML

Works with / Used by

Part of the ruv.io open-source stack for WASM, LoRA, AI.