@ruvector/ruvllm 0.2.3 → 2.4.0
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/README.md +379 -739
- package/bin/cli.js +619 -2
- package/dist/cjs/benchmarks/embedding-benchmark.d.ts +102 -0
- package/dist/cjs/benchmarks/embedding-benchmark.d.ts.map +1 -0
- package/dist/cjs/benchmarks/embedding-benchmark.js +436 -0
- package/dist/cjs/benchmarks/index.d.ts +34 -0
- package/dist/cjs/benchmarks/index.d.ts.map +1 -0
- package/dist/cjs/benchmarks/index.js +132 -0
- package/dist/cjs/benchmarks/model-comparison.d.ts +71 -0
- package/dist/cjs/benchmarks/model-comparison.d.ts.map +1 -0
- package/dist/cjs/benchmarks/model-comparison.js +476 -0
- package/dist/cjs/benchmarks/routing-benchmark.d.ts +70 -0
- package/dist/cjs/benchmarks/routing-benchmark.d.ts.map +1 -0
- package/dist/cjs/benchmarks/routing-benchmark.js +289 -0
- package/dist/cjs/contrastive.d.ts +229 -0
- package/dist/cjs/contrastive.d.ts.map +1 -0
- package/dist/cjs/contrastive.js +589 -0
- package/dist/cjs/engine.d.ts +3 -0
- package/dist/cjs/engine.d.ts.map +1 -1
- package/dist/cjs/engine.js +29 -9
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +9 -1
- package/dist/cjs/models.d.ts +129 -0
- package/dist/cjs/models.d.ts.map +1 -0
- package/dist/cjs/models.js +323 -0
- package/dist/cjs/rlm/controller.d.ts +245 -0
- package/dist/cjs/rlm/controller.d.ts.map +1 -0
- package/dist/cjs/rlm/controller.js +554 -0
- package/dist/cjs/rlm/index.d.ts +62 -0
- package/dist/cjs/rlm/index.d.ts.map +1 -0
- package/dist/cjs/rlm/index.js +97 -0
- package/dist/cjs/rlm/training.d.ts +333 -0
- package/dist/cjs/rlm/training.d.ts.map +1 -0
- package/dist/cjs/rlm/training.js +680 -0
- package/dist/cjs/rlm/types.d.ts +189 -0
- package/dist/cjs/rlm/types.d.ts.map +1 -0
- package/dist/cjs/rlm/types.js +10 -0
- package/dist/esm/benchmarks/embedding-benchmark.d.ts +102 -0
- package/dist/esm/benchmarks/embedding-benchmark.d.ts.map +1 -0
- package/dist/esm/benchmarks/embedding-benchmark.js +427 -0
- package/dist/esm/benchmarks/index.d.ts +34 -0
- package/dist/esm/benchmarks/index.d.ts.map +1 -0
- package/dist/esm/benchmarks/index.js +110 -0
- package/dist/esm/benchmarks/model-comparison.d.ts +71 -0
- package/dist/esm/benchmarks/model-comparison.d.ts.map +1 -0
- package/dist/esm/benchmarks/model-comparison.js +434 -0
- package/dist/esm/benchmarks/routing-benchmark.d.ts +70 -0
- package/dist/esm/benchmarks/routing-benchmark.d.ts.map +1 -0
- package/dist/esm/benchmarks/routing-benchmark.js +283 -0
- package/dist/esm/contrastive.d.ts +229 -0
- package/dist/esm/contrastive.d.ts.map +1 -0
- package/dist/esm/contrastive.js +578 -0
- package/dist/esm/engine.d.ts +3 -0
- package/dist/esm/engine.d.ts.map +1 -1
- package/dist/esm/engine.js +29 -9
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +9 -1
- package/dist/esm/models.d.ts +129 -0
- package/dist/esm/models.d.ts.map +1 -0
- package/dist/esm/models.js +282 -0
- package/dist/esm/rlm/controller.d.ts +245 -0
- package/dist/esm/rlm/controller.d.ts.map +1 -0
- package/dist/esm/rlm/controller.js +550 -0
- package/dist/esm/rlm/index.d.ts +62 -0
- package/dist/esm/rlm/index.d.ts.map +1 -0
- package/dist/esm/rlm/index.js +71 -0
- package/dist/esm/rlm/training.d.ts +333 -0
- package/dist/esm/rlm/training.d.ts.map +1 -0
- package/dist/esm/rlm/training.js +672 -0
- package/dist/esm/rlm/types.d.ts +189 -0
- package/dist/esm/rlm/types.d.ts.map +1 -0
- package/dist/esm/rlm/types.js +9 -0
- package/package.json +13 -11
- package/scripts/ensemble-model-compare.js +287 -0
- package/scripts/huggingface/README.md +537 -0
- package/scripts/huggingface/publish.sh +112 -0
- package/scripts/hybrid-model-compare.js +373 -0
- package/scripts/improved-model-compare.js +288 -0
- package/scripts/optimized-model-compare.js +364 -0
- package/scripts/real-model-compare.js +280 -0
- package/scripts/training/agentic-flow-capabilities.json +329 -0
- package/scripts/training/claude-code-synth.js +505 -0
- package/scripts/training/claude-flow-capabilities.json +1322 -0
- package/scripts/training/claude-hard-negatives.js +222 -0
- package/scripts/training/contrastive-finetune.js +517 -0
- package/scripts/training/ecosystem-triplets.jsonl +1467 -0
- package/scripts/training/generate-ecosystem-triplets.js +1324 -0
- package/scripts/training/rlm-dataset.js +671 -0
- package/scripts/training/routing-dataset.js +634 -0
- package/scripts/training/ruvector-capabilities.json +798 -0
- package/scripts/training/validate-ecosystem.js +381 -0
- package/scripts/training/validation-results.json +23 -0
package/README.md
CHANGED
|
@@ -1,886 +1,526 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ruvector/ruvllm v2.4
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](LICENSE)
|
|
5
|
-
[](#testing)
|
|
6
|
-
[](#architecture)
|
|
7
|
-
[](#huggingface-export)
|
|
8
|
-
[](https://www.npmjs.com/package/@ruvector/ruvllm)
|
|
9
|
-
[](#trm-tiny-recursive-models)
|
|
3
|
+
Self-learning LLM orchestration with SONA adaptive learning, HNSW memory, RLM recursive retrieval, and SIMD inference for Node.js.
|
|
10
4
|
|
|
11
|
-
|
|
5
|
+
## Installation
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## What is RuvLLM?
|
|
18
|
-
|
|
19
|
-
RuvLLM is a **self-learning language model orchestration system** that combines frozen foundation models with adaptive memory and intelligent routing. Unlike traditional LLMs that rely solely on static parameters, RuvLLM continuously improves from every interaction through three temporal learning loops.
|
|
20
|
-
|
|
21
|
-
**Key Innovation**: RuvLLM doesn't replace your LLM—it makes any LLM smarter over time by learning from experience, routing intelligently, and preventing catastrophic forgetting.
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
┌─────────────────────────────────────────────────────────────────────────┐
|
|
25
|
-
│ RuvLLM Architecture │
|
|
26
|
-
├─────────────────────────────────────────────────────────────────────────┤
|
|
27
|
-
│ │
|
|
28
|
-
│ Query ──► Embedding ──► Memory Search ──► Router Decision │
|
|
29
|
-
│ │ │ │
|
|
30
|
-
│ ▼ ▼ │
|
|
31
|
-
│ Graph Attention Model Selection │
|
|
32
|
-
│ │ │ │
|
|
33
|
-
│ └────────┬───────────┘ │
|
|
34
|
-
│ ▼ │
|
|
35
|
-
│ ┌─────────────────────┐ │
|
|
36
|
-
│ │ LLM Inference │ │
|
|
37
|
-
│ │ (Any LLM Backend) │ │
|
|
38
|
-
│ └─────────────────────┘ │
|
|
39
|
-
│ │ │
|
|
40
|
-
│ ▼ │
|
|
41
|
-
│ ┌───────────────────────────────────┐ │
|
|
42
|
-
│ │ SONA Learning (3 Temporal Loops) │ │
|
|
43
|
-
│ │ • Instant: Per-request MicroLoRA │ │
|
|
44
|
-
│ │ • Background: Hourly patterns │ │
|
|
45
|
-
│ │ • Deep: Weekly EWC++ updates │ │
|
|
46
|
-
│ └───────────────────────────────────┘ │
|
|
47
|
-
│ │
|
|
48
|
-
└─────────────────────────────────────────────────────────────────────────┘
|
|
7
|
+
```bash
|
|
8
|
+
npm install @ruvector/ruvllm
|
|
49
9
|
```
|
|
50
10
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
## Features
|
|
54
|
-
|
|
55
|
-
### Core Components
|
|
56
|
-
|
|
57
|
-
| Component | Description | Implementation |
|
|
58
|
-
|-----------|-------------|----------------|
|
|
59
|
-
| **LFM2 Cortex** | Frozen reasoning engine (135M-2.6B params) | Mock, Candle, or external (llama.cpp/vLLM) |
|
|
60
|
-
| **Ruvector Memory** | Adaptive synaptic mesh with HNSW indexing | Full CPU implementation with graph expansion |
|
|
61
|
-
| **FastGRNN Router** | Intelligent model selection circuit | Sparse + low-rank matrices with EWC learning |
|
|
62
|
-
| **Graph Attention** | Multi-head attention with edge features | 8-head attention, layer normalization |
|
|
63
|
-
| **SONA Engine** | Self-optimizing neural architecture | LoRA + EWC++ + ReasoningBank |
|
|
64
|
-
| **TRM Engine** | Tiny Recursive Models (7M params) | Recursive latent refinement with SONA bridge |
|
|
65
|
-
|
|
66
|
-
### TRM (Tiny Recursive Models)
|
|
67
|
-
|
|
68
|
-
RuvLLM v0.2.3 introduces **TRM** - Samsung SAIL Montreal's parameter-efficient recursive reasoning approach. TRM achieves strong reasoning performance with only **7M parameters** through iterative latent refinement.
|
|
11
|
+
## Quick Start
|
|
69
12
|
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
│ TRM Architecture │
|
|
73
|
-
├─────────────────────────────────────────────────────────────────────────┤
|
|
74
|
-
│ │
|
|
75
|
-
│ Question ──┬► Latent Update (n times) ──► Answer Refine ──┐ │
|
|
76
|
-
│ │ │ │
|
|
77
|
-
│ └───────────────────────────────────────────────┘ │
|
|
78
|
-
│ (repeat K times) │
|
|
79
|
-
│ │
|
|
80
|
-
│ Components: │
|
|
81
|
-
│ • MLP Latent Updater - Fast feed-forward updates │
|
|
82
|
-
│ • Attention Latent Updater - Multi-head attention refinement │
|
|
83
|
-
│ • Confidence Scorer - Early stopping based on convergence │
|
|
84
|
-
│ • Answer Refiner - Residual-based answer improvement │
|
|
85
|
-
│ • SONA Bridge - Integration with learning loops │
|
|
86
|
-
│ │
|
|
87
|
-
└─────────────────────────────────────────────────────────────────────────┘
|
|
88
|
-
```
|
|
13
|
+
```typescript
|
|
14
|
+
import { RuvLLM, RuvLLMConfig } from '@ruvector/ruvllm';
|
|
89
15
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
- **Recursive refinement** - Iteratively improves answers through K iterations
|
|
93
|
-
- **Adaptive K** - SONA routing determines optimal iteration count
|
|
94
|
-
- **Early stopping** - Confidence-based termination for efficiency
|
|
95
|
-
- **NaN-safe** - Robust numerical guards prevent gradient explosions
|
|
96
|
-
- **Buffer reuse** - Optimized memory allocation for production use
|
|
16
|
+
// Initialize with default configuration
|
|
17
|
+
const llm = new RuvLLM();
|
|
97
18
|
|
|
98
|
-
|
|
19
|
+
// Or with custom configuration
|
|
20
|
+
const llm = new RuvLLM({
|
|
21
|
+
modelPath: './models/ruvltra-small-q4km.gguf',
|
|
22
|
+
sonaEnabled: true,
|
|
23
|
+
flashAttention: true,
|
|
24
|
+
maxTokens: 256,
|
|
25
|
+
});
|
|
99
26
|
|
|
100
|
-
|
|
27
|
+
// Generate text
|
|
28
|
+
const response = await llm.query('Explain quantum computing');
|
|
29
|
+
console.log(response.text);
|
|
101
30
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
│ • Records query trajectories with activation patterns │
|
|
107
|
-
│ • MicroLoRA adaptation (rank 1-2) for immediate improvement │
|
|
108
|
-
│ • SIMD-optimized: 2,236 ops/sec throughput │
|
|
109
|
-
├──────────────────────────────────────────────────────────────────────────┤
|
|
110
|
-
│ Loop B: Background (Hourly) │
|
|
111
|
-
│ ───────────────────────────── │
|
|
112
|
-
│ • K-means++ clustering extracts patterns (100 clusters = 1.3ms search) │
|
|
113
|
-
│ • Base LoRA updates (rank 4-16) from successful patterns │
|
|
114
|
-
│ • ReasoningBank stores learned strategies │
|
|
115
|
-
├──────────────────────────────────────────────────────────────────────────┤
|
|
116
|
-
│ Loop C: Deep (Weekly) │
|
|
117
|
-
│ ───────────────────── │
|
|
118
|
-
│ • Dream consolidation across all memory │
|
|
119
|
-
│ • EWC++ prevents catastrophic forgetting (λ=2000 optimal) │
|
|
120
|
-
│ • Concept hierarchies created, old nodes archived │
|
|
121
|
-
└──────────────────────────────────────────────────────────────────────────┘
|
|
31
|
+
// Stream generation
|
|
32
|
+
for await (const token of llm.stream('Write a haiku about Rust')) {
|
|
33
|
+
process.stdout.write(token);
|
|
34
|
+
}
|
|
122
35
|
```
|
|
123
36
|
|
|
124
|
-
|
|
37
|
+
## What's New in v2.4
|
|
125
38
|
|
|
126
39
|
| Feature | Description |
|
|
127
40
|
|---------|-------------|
|
|
128
|
-
| **
|
|
129
|
-
| **
|
|
130
|
-
| **
|
|
131
|
-
| **
|
|
132
|
-
| **
|
|
133
|
-
| **HuggingFace
|
|
134
|
-
| **Real Inference** | Candle-based inference with HuggingFace model support |
|
|
135
|
-
| **Multi-Model Routing** | Automatic selection between SmolLM, Qwen2, TinyLlama |
|
|
136
|
-
| **Federated Learning** | Distributed learning across ephemeral agents with central coordinator |
|
|
137
|
-
| **WASM Support** | Run SONA in browsers and edge devices |
|
|
138
|
-
| **Training Pipelines** | Templated training for code, chat, reasoning, and custom agents |
|
|
139
|
-
| **Agent Factory** | Create and manage multiple specialized learning agents |
|
|
140
|
-
| **TRM Reasoning** | Recursive reasoning with only 7M parameters (83% GSM8K) |
|
|
141
|
-
| **Adaptive K Routing** | SONA-driven iteration count for optimal compute |
|
|
142
|
-
| **NaN Guards** | Robust numerical stability for production deployment |
|
|
143
|
-
|
|
144
|
-
### Federated Learning Architecture
|
|
145
|
-
|
|
146
|
-
RuvLLM supports **federated learning** where ephemeral agents collect trajectories and export to a central coordinator:
|
|
147
|
-
|
|
148
|
-
```
|
|
149
|
-
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
|
|
150
|
-
│ Agent A │ │ Agent B │ │ Agent C │
|
|
151
|
-
│ (ephemeral) │ │ (ephemeral) │ │ (ephemeral) │
|
|
152
|
-
└──────┬──────┘ └──────┬──────┘ └──────┬──────┘
|
|
153
|
-
│ │ │
|
|
154
|
-
│ export() │ export() │ export()
|
|
155
|
-
▼ ▼ ▼
|
|
156
|
-
┌────────────────────────────────────────────────┐
|
|
157
|
-
│ Federated Coordinator │
|
|
158
|
-
│ (persistent, large capacity) │
|
|
159
|
-
│ • Aggregates trajectories from all agents │
|
|
160
|
-
│ • Quality-filtered acceptance (threshold) │
|
|
161
|
-
│ • Auto-consolidation every N agents │
|
|
162
|
-
│ • Shares patterns with new agents │
|
|
163
|
-
└────────────────────────────────────────────────┘
|
|
164
|
-
```
|
|
41
|
+
| **RLM (Recursive Language Model)** | Query decomposition with recursive retrieval and synthesis |
|
|
42
|
+
| **100% Routing Accuracy** | Hybrid keyword-first strategy achieves 100% on Claude Code tasks |
|
|
43
|
+
| **145 Tests Passing** | Comprehensive test coverage across all modules |
|
|
44
|
+
| **Contrastive Fine-tuning** | LoRA-based training with 793 contrastive pairs |
|
|
45
|
+
| **Training Scripts** | Generate routing datasets and fine-tune models |
|
|
46
|
+
| **HuggingFace Models** | Pre-trained RuvLTRA models available |
|
|
165
47
|
|
|
166
|
-
|
|
167
|
-
- **EphemeralAgent**: Short-lived agents that process tasks and export learned state
|
|
168
|
-
- **FederatedCoordinator**: Central aggregator with 50K trajectory capacity
|
|
169
|
-
- **AgentExport**: Serializable state containing trajectories, stats, and patterns
|
|
170
|
-
- **Quality Filtering**: Only high-quality trajectories (>0.4 score) are aggregated
|
|
48
|
+
## RLM (Recursive Language Model)
|
|
171
49
|
|
|
172
|
-
|
|
50
|
+
RLM provides recursive retrieval-augmented generation that breaks down complex queries into sub-queries and synthesizes answers from retrieved context.
|
|
173
51
|
|
|
174
|
-
|
|
52
|
+
### Basic Usage
|
|
175
53
|
|
|
176
|
-
|
|
54
|
+
```typescript
|
|
55
|
+
import { RlmController } from '@ruvector/ruvllm';
|
|
177
56
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
| **Throughput** | ~38,000 q/s | 8 concurrent queries |
|
|
184
|
-
| **Memory Footprint** | ~50MB | Base system |
|
|
57
|
+
const rlm = new RlmController({
|
|
58
|
+
maxDepth: 5,
|
|
59
|
+
retrievalTopK: 10,
|
|
60
|
+
enableCache: true,
|
|
61
|
+
});
|
|
185
62
|
|
|
186
|
-
|
|
63
|
+
// Add knowledge to memory
|
|
64
|
+
await rlm.addMemory('TypeScript adds static typing to JavaScript.');
|
|
65
|
+
await rlm.addMemory('React is a library for building user interfaces.');
|
|
187
66
|
|
|
67
|
+
// Query with recursive retrieval
|
|
68
|
+
const answer = await rlm.query('What are causes and solutions for type errors in React?');
|
|
69
|
+
console.log(answer.text);
|
|
70
|
+
console.log('Sources:', answer.sources);
|
|
71
|
+
console.log('Quality Score:', answer.qualityScore);
|
|
72
|
+
console.log('Confidence:', answer.confidence);
|
|
188
73
|
```
|
|
189
|
-
Embedding: ~0.02ms ████░░░░░░ (20%)
|
|
190
|
-
Retrieval: ~0.01ms ██░░░░░░░░ (10%)
|
|
191
|
-
Routing: ~0.01ms ██░░░░░░░░ (10%)
|
|
192
|
-
Attention: ~0.02ms ████░░░░░░ (20%)
|
|
193
|
-
Generation: ~0.04ms ████████░░ (40%)
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
### SONA Learning Performance
|
|
197
|
-
|
|
198
|
-
| Component | Metric | Value |
|
|
199
|
-
|-----------|--------|-------|
|
|
200
|
-
| MicroLoRA | Throughput | 2,236 ops/sec |
|
|
201
|
-
| MicroLoRA | Batch-32 Latency | 0.447ms |
|
|
202
|
-
| ReasoningBank | Pattern Search | 1.3ms (100 clusters) |
|
|
203
|
-
| EWC++ | Fisher Update | <1ms |
|
|
204
|
-
|
|
205
|
-
### Comparison with Traditional Systems
|
|
206
|
-
|
|
207
|
-
| System | P50 (ms) | P95 (ms) | vs GPT-4o |
|
|
208
|
-
|--------|----------|----------|-----------|
|
|
209
|
-
| GPT-4o (API) | 450.00 | 585.00 | 1.0x (baseline) |
|
|
210
|
-
| Claude 3.5 Sonnet | 380.00 | 456.00 | 1.2x |
|
|
211
|
-
| Gemini 2.0 Flash | 180.00 | 234.00 | 2.5x |
|
|
212
|
-
| Llama 3.3 70B (vLLM) | 120.00 | 168.00 | 3.8x |
|
|
213
|
-
| **RuvLLM Orchestration** | **0.06** | **0.08** | **~7,500x** |
|
|
214
|
-
|
|
215
|
-
> **Note**: RuvLLM orchestration latency measures memory retrieval, routing, and context preparation—NOT LLM generation. Actual response quality depends on your LLM backend.
|
|
216
|
-
|
|
217
|
-
---
|
|
218
|
-
|
|
219
|
-
## Feature Comparison
|
|
220
|
-
|
|
221
|
-
| Feature | GPT-4o | Claude | RAG | vLLM | RuvLLM |
|
|
222
|
-
|---------|--------|--------|-----|------|--------|
|
|
223
|
-
| On-device Inference | ✗ | ✗ | ✗ | ✓ | ✓ |
|
|
224
|
-
| Continuous Learning | ✗ | ✗ | ✗ | ✗ | ✓ |
|
|
225
|
-
| Graph-based Memory | ✗ | ✗ | △ | ✗ | ✓ |
|
|
226
|
-
| Adaptive Model Routing | ✗ | ✗ | ✗ | ✗ | ✓ |
|
|
227
|
-
| EWC Anti-Forgetting | ✗ | ✗ | ✗ | ✗ | ✓ |
|
|
228
|
-
| LoRA Adaptation | ✗ | ✗ | ✗ | ✗ | ✓ |
|
|
229
|
-
| Pattern Extraction | ✗ | ✗ | ✗ | ✗ | ✓ |
|
|
230
|
-
| HuggingFace Export | ✗ | ✗ | ✗ | ✗ | ✓ |
|
|
231
|
-
| SIMD Optimization | ✗ | ✗ | ✗ | △ | ✓ |
|
|
232
|
-
| Sub-ms Orchestration | ✗ | ✗ | ✗ | ✗ | ✓ |
|
|
233
|
-
| Federated Learning | ✗ | ✗ | ✗ | ✗ | ✓ |
|
|
234
|
-
| WASM/Browser Support | ✗ | ✗ | ✗ | ✗ | ✓ |
|
|
235
|
-
| Training Pipelines | ✗ | ✗ | ✗ | ✗ | ✓ |
|
|
236
|
-
| Works with ANY LLM | ✗ | ✗ | ✓ | ✗ | ✓ |
|
|
237
|
-
| **TRM Recursive Reasoning** | ✗ | ✗ | ✗ | ✗ | ✓ |
|
|
238
|
-
| **7M Param Efficiency** | ✗ | ✗ | ✗ | ✗ | ✓ |
|
|
239
|
-
|
|
240
|
-
*Legend: ✓ = Full Support, △ = Partial, ✗ = Not Supported*
|
|
241
|
-
|
|
242
|
-
---
|
|
243
|
-
|
|
244
|
-
## Quick Start
|
|
245
74
|
|
|
246
|
-
###
|
|
75
|
+
### Streaming
|
|
247
76
|
|
|
248
|
-
|
|
249
|
-
|
|
77
|
+
```typescript
|
|
78
|
+
import { RlmController } from '@ruvector/ruvllm';
|
|
250
79
|
|
|
251
|
-
|
|
80
|
+
const rlm = new RlmController();
|
|
252
81
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
82
|
+
for await (const event of rlm.queryStream('Explain machine learning')) {
|
|
83
|
+
if (event.type === 'token') {
|
|
84
|
+
process.stdout.write(event.text);
|
|
85
|
+
} else {
|
|
86
|
+
console.log('\n\nQuality:', event.answer.qualityScore);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
260
89
|
```
|
|
261
90
|
|
|
262
|
-
###
|
|
263
|
-
|
|
264
|
-
```bash
|
|
265
|
-
# Interactive demo with mock inference
|
|
266
|
-
cargo run --bin ruvllm-demo --release
|
|
267
|
-
|
|
268
|
-
# SIMD capabilities demo
|
|
269
|
-
cargo run --bin ruvllm-simd-demo --release
|
|
270
|
-
|
|
271
|
-
# Quick benchmark
|
|
272
|
-
cargo run --bin ruvllm-bench --release
|
|
273
|
-
|
|
274
|
-
# Full benchmark suite
|
|
275
|
-
cargo run --bin ruvllm-benchmark-suite --release
|
|
91
|
+
### With Reflection
|
|
276
92
|
|
|
277
|
-
|
|
278
|
-
|
|
93
|
+
```typescript
|
|
94
|
+
import { RlmController } from '@ruvector/ruvllm';
|
|
279
95
|
|
|
280
|
-
|
|
281
|
-
|
|
96
|
+
const rlm = new RlmController({
|
|
97
|
+
enableReflection: true,
|
|
98
|
+
maxReflectionIterations: 2,
|
|
99
|
+
minQualityScore: 0.8,
|
|
100
|
+
});
|
|
282
101
|
|
|
283
|
-
|
|
284
|
-
|
|
102
|
+
// Answers will be iteratively refined until quality >= 0.8
|
|
103
|
+
const answer = await rlm.query('Complex multi-part technical question...');
|
|
285
104
|
```
|
|
286
105
|
|
|
287
|
-
###
|
|
106
|
+
### RLM Configuration
|
|
288
107
|
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
// Initialize
|
|
303
|
-
let llm = RuvLLM::new(config).await?;
|
|
108
|
+
```typescript
|
|
109
|
+
interface RlmConfig {
|
|
110
|
+
maxDepth?: number; // Max recursion depth (default: 3)
|
|
111
|
+
maxSubQueries?: number; // Max sub-queries per level (default: 5)
|
|
112
|
+
tokenBudget?: number; // Token budget (default: 4096)
|
|
113
|
+
enableCache?: boolean; // Enable caching (default: true)
|
|
114
|
+
cacheTtl?: number; // Cache TTL in ms (default: 300000)
|
|
115
|
+
retrievalTopK?: number; // Memory spans to retrieve (default: 10)
|
|
116
|
+
minQualityScore?: number; // Min quality threshold (default: 0.7)
|
|
117
|
+
enableReflection?: boolean; // Enable self-reflection (default: false)
|
|
118
|
+
maxReflectionIterations?: number; // Max reflection loops (default: 2)
|
|
119
|
+
}
|
|
120
|
+
```
|
|
304
121
|
|
|
305
|
-
|
|
306
|
-
let session = llm.new_session();
|
|
122
|
+
## Exports
|
|
307
123
|
|
|
308
|
-
|
|
309
|
-
|
|
124
|
+
```typescript
|
|
125
|
+
import {
|
|
126
|
+
// Core
|
|
127
|
+
RuvLLM,
|
|
128
|
+
RuvLLMConfig,
|
|
310
129
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
130
|
+
// RLM - Recursive Language Model
|
|
131
|
+
RlmController,
|
|
132
|
+
RlmConfig,
|
|
133
|
+
RlmAnswer,
|
|
134
|
+
MemorySpan,
|
|
135
|
+
StreamToken,
|
|
314
136
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
137
|
+
// RLM Training
|
|
138
|
+
RlmTrainer,
|
|
139
|
+
RlmTrainingConfig,
|
|
140
|
+
RlmTrainingExample,
|
|
141
|
+
createRlmTrainer,
|
|
142
|
+
DEFAULT_RLM_CONFIG,
|
|
143
|
+
FAST_RLM_CONFIG,
|
|
144
|
+
THOROUGH_RLM_CONFIG,
|
|
145
|
+
ROUTING_FOCUSED_CONFIG,
|
|
322
146
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
147
|
+
// SONA Learning
|
|
148
|
+
SonaCoordinator,
|
|
149
|
+
TrajectoryBuilder,
|
|
326
150
|
|
|
327
|
-
|
|
151
|
+
// Federated Learning
|
|
152
|
+
EphemeralAgent,
|
|
153
|
+
FederatedCoordinator,
|
|
328
154
|
|
|
329
|
-
|
|
330
|
-
|
|
155
|
+
// LoRA Adapters
|
|
156
|
+
LoraAdapter,
|
|
157
|
+
LoraManager,
|
|
331
158
|
|
|
332
|
-
//
|
|
333
|
-
|
|
159
|
+
// Sessions
|
|
160
|
+
SessionManager,
|
|
334
161
|
|
|
335
|
-
//
|
|
336
|
-
|
|
337
|
-
max_tokens: 50,
|
|
338
|
-
temperature: 0.7,
|
|
339
|
-
top_p: 0.9,
|
|
340
|
-
..Default::default()
|
|
341
|
-
};
|
|
162
|
+
// Contrastive Training
|
|
163
|
+
ContrastiveTrainer,
|
|
342
164
|
|
|
343
|
-
//
|
|
344
|
-
|
|
165
|
+
// Benchmarks
|
|
166
|
+
ModelComparisonBenchmark,
|
|
167
|
+
RoutingBenchmark,
|
|
168
|
+
EmbeddingBenchmark,
|
|
169
|
+
} from '@ruvector/ruvllm';
|
|
345
170
|
```
|
|
346
171
|
|
|
347
|
-
|
|
172
|
+
## Performance
|
|
348
173
|
|
|
349
|
-
|
|
350
|
-
use ruvllm::sona::{LoopCoordinator, SonaConfig, InstantLoop, BackgroundLoop};
|
|
174
|
+
### Test Results
|
|
351
175
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
176
|
+
```
|
|
177
|
+
145 tests passing
|
|
178
|
+
- RLM Controller: 24 tests
|
|
179
|
+
- Routing Accuracy: 18 tests
|
|
180
|
+
- Contrastive Training: 15 tests
|
|
181
|
+
- SIMD Operations: 22 tests
|
|
182
|
+
- SONA Learning: 19 tests
|
|
183
|
+
- Memory/HNSW: 21 tests
|
|
184
|
+
- Benchmarks: 26 tests
|
|
185
|
+
```
|
|
361
186
|
|
|
362
|
-
|
|
363
|
-
coordinator.instant_loop().record_trajectory(query, response, quality);
|
|
187
|
+
### Routing Accuracy (Claude Code Tasks)
|
|
364
188
|
|
|
365
|
-
|
|
366
|
-
|
|
189
|
+
| Strategy | RuvLTRA | Qwen Base |
|
|
190
|
+
|----------|---------|-----------|
|
|
191
|
+
| Embedding Only | 45% | 40% |
|
|
192
|
+
| Keyword-First (Hybrid) | **100%** | 95% |
|
|
367
193
|
|
|
368
|
-
|
|
369
|
-
coordinator.deep_consolidation().await;
|
|
370
|
-
```
|
|
194
|
+
### Inference Performance (M4 Pro)
|
|
371
195
|
|
|
372
|
-
|
|
196
|
+
| Operation | Performance |
|
|
197
|
+
|-----------|-------------|
|
|
198
|
+
| Inference | 88-135 tok/s |
|
|
199
|
+
| Flash Attention | 320us (seq=2048) |
|
|
200
|
+
| HNSW Search | 17-62us |
|
|
201
|
+
| SONA Adapt | <1ms |
|
|
202
|
+
| RLM Query | 50-200ms |
|
|
373
203
|
|
|
374
|
-
|
|
375
|
-
use ruvllm::trm::{TrmEngine, TrmEngineBuilder, TrmConfig, RecursiveReasoner};
|
|
204
|
+
### SIMD Optimizations
|
|
376
205
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
.embedding_dim(256)
|
|
381
|
-
.default_k(10) // Default K iterations
|
|
382
|
-
.n_inner(4) // Inner latent updates per K
|
|
383
|
-
.confidence_threshold(0.95) // Early stopping threshold
|
|
384
|
-
.build()
|
|
385
|
-
.unwrap();
|
|
206
|
+
- AVX2/AVX-512 on x86_64
|
|
207
|
+
- NEON on ARM64
|
|
208
|
+
- 4-8x speedup on vector operations
|
|
386
209
|
|
|
387
|
-
|
|
388
|
-
let question = vec![0.5; 256]; // Question embedding
|
|
389
|
-
let mut answer = vec![0.1; 256]; // Initial answer (refined in-place)
|
|
210
|
+
## CLI Usage
|
|
390
211
|
|
|
391
|
-
|
|
392
|
-
|
|
212
|
+
```bash
|
|
213
|
+
# Query a model
|
|
214
|
+
ruvllm query "What is machine learning?"
|
|
393
215
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
println!("Early stopped: {}", result.early_stopped);
|
|
216
|
+
# Stream output
|
|
217
|
+
ruvllm query --stream "Write a poem"
|
|
397
218
|
|
|
398
|
-
|
|
399
|
-
|
|
219
|
+
# Download a model
|
|
220
|
+
ruvllm download ruvector/ruvltra-small-q4km
|
|
400
221
|
|
|
401
|
-
|
|
402
|
-
|
|
222
|
+
# Benchmark
|
|
223
|
+
ruvllm bench ./models/model.gguf
|
|
403
224
|
|
|
404
|
-
|
|
405
|
-
|
|
225
|
+
# Run evaluation (SWE-Bench)
|
|
226
|
+
ruvllm eval --model ./models/model.gguf --subset lite --max-tasks 50
|
|
406
227
|
```
|
|
407
228
|
|
|
408
|
-
|
|
229
|
+
## Training
|
|
409
230
|
|
|
410
|
-
|
|
411
|
-
use ruvector_sona::training::{EphemeralAgent, FederatedCoordinator, SonaConfig};
|
|
231
|
+
### Routing Dataset Generation
|
|
412
232
|
|
|
413
|
-
|
|
414
|
-
let mut coordinator = FederatedCoordinator::default_coordinator("main", 3072);
|
|
415
|
-
coordinator.set_quality_threshold(0.4); // Only accept high-quality trajectories
|
|
416
|
-
coordinator.set_consolidation_interval(50); // Auto-consolidate every 50 agents
|
|
233
|
+
Generate training data for agent routing:
|
|
417
234
|
|
|
418
|
-
|
|
419
|
-
|
|
235
|
+
```bash
|
|
236
|
+
# Generate routing dataset
|
|
237
|
+
node scripts/training/routing-dataset.js
|
|
420
238
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
embedding, // Query embedding
|
|
424
|
-
activations, // Hidden state activations
|
|
425
|
-
quality, // Quality score [0.0, 1.0]
|
|
426
|
-
Some("gpt-4".to_string()), // Model route
|
|
427
|
-
vec!["code".to_string()], // Context tags
|
|
428
|
-
);
|
|
239
|
+
# Output: 381 examples, 793 contrastive pairs
|
|
240
|
+
```
|
|
429
241
|
|
|
430
|
-
|
|
431
|
-
let export = agent.export_state();
|
|
432
|
-
println!("Agent exported {} trajectories", export.trajectories.len());
|
|
242
|
+
### Contrastive Fine-tuning
|
|
433
243
|
|
|
434
|
-
|
|
435
|
-
let result = coordinator.aggregate(export);
|
|
436
|
-
println!("Accepted: {}, Rejected: {}",
|
|
437
|
-
result.trajectories_accepted,
|
|
438
|
-
result.trajectories_rejected
|
|
439
|
-
);
|
|
244
|
+
Fine-tune models with LoRA adapters:
|
|
440
245
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
```
|
|
246
|
+
```typescript
|
|
247
|
+
import { ContrastiveTrainer, ContrastivePair } from '@ruvector/ruvllm';
|
|
444
248
|
|
|
445
|
-
|
|
249
|
+
const trainer = new ContrastiveTrainer({
|
|
250
|
+
modelPath: './models/base.gguf',
|
|
251
|
+
loraRank: 8,
|
|
252
|
+
loraAlpha: 16,
|
|
253
|
+
learningRate: 1e-4,
|
|
254
|
+
});
|
|
446
255
|
|
|
447
|
-
|
|
256
|
+
// Training pairs from routing dataset
|
|
257
|
+
const pairs: ContrastivePair[] = [
|
|
258
|
+
{
|
|
259
|
+
anchor: 'Fix the authentication bug in login.ts',
|
|
260
|
+
positive: 'coder',
|
|
261
|
+
negative: 'researcher',
|
|
262
|
+
},
|
|
263
|
+
// ... more pairs
|
|
264
|
+
];
|
|
448
265
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
cd crates/sona
|
|
452
|
-
wasm-pack build --target web --features wasm
|
|
266
|
+
await trainer.train(pairs, { epochs: 10, batchSize: 32 });
|
|
267
|
+
await trainer.save('./adapters/routing-lora');
|
|
453
268
|
```
|
|
454
269
|
|
|
455
|
-
|
|
270
|
+
### Training Scripts
|
|
456
271
|
|
|
457
|
-
|
|
458
|
-
import init, { WasmSonaEngine } from './pkg/sona.js';
|
|
272
|
+
Located in `scripts/training/`:
|
|
459
273
|
|
|
460
|
-
|
|
461
|
-
|
|
274
|
+
| Script | Description |
|
|
275
|
+
|--------|-------------|
|
|
276
|
+
| `routing-dataset.js` | Generate 381 routing examples |
|
|
277
|
+
| `claude-code-synth.js` | Synthetic data generation |
|
|
278
|
+
| `contrastive-finetune.js` | LoRA fine-tuning pipeline |
|
|
462
279
|
|
|
463
|
-
|
|
464
|
-
const engine = new WasmSonaEngine(256); // hidden_dim = 256
|
|
280
|
+
## Model Links
|
|
465
281
|
|
|
466
|
-
|
|
467
|
-
const engineCustom = WasmSonaEngine.withConfig({
|
|
468
|
-
hidden_dim: 256,
|
|
469
|
-
embedding_dim: 256,
|
|
470
|
-
micro_lora_rank: 2,
|
|
471
|
-
base_lora_rank: 16,
|
|
472
|
-
ewc_lambda: 1000.0,
|
|
473
|
-
pattern_clusters: 128,
|
|
474
|
-
});
|
|
282
|
+
### HuggingFace Repository
|
|
475
283
|
|
|
476
|
-
|
|
477
|
-
const embedding = new Float32Array(256).fill(0.1);
|
|
478
|
-
const trajectoryId = engine.startTrajectory(embedding);
|
|
284
|
+
**URL**: [https://huggingface.co/ruv/ruvltra](https://huggingface.co/ruv/ruvltra)
|
|
479
285
|
|
|
480
|
-
|
|
481
|
-
engine.recordStep(trajectoryId, 42, 0.8, 1000);
|
|
286
|
+
### Available Models
|
|
482
287
|
|
|
483
|
-
|
|
484
|
-
|
|
288
|
+
| Model | File | Size | Purpose |
|
|
289
|
+
|-------|------|------|---------|
|
|
290
|
+
| RuvLTRA Claude Code 0.5B | `ruvltra-claude-code-0.5b-q4_k_m.gguf` | ~400MB | Agent routing (100% with hybrid) |
|
|
291
|
+
| RuvLTRA Small 0.5B | `ruvltra-0.5b-q4_k_m.gguf` | ~400MB | General embeddings |
|
|
292
|
+
| RuvLTRA Medium 3B | `ruvltra-3b-q4_k_m.gguf` | ~2GB | Full LLM inference |
|
|
485
293
|
|
|
486
|
-
|
|
487
|
-
const input = new Float32Array(256).fill(1.0);
|
|
488
|
-
const output = engine.applyLora(input);
|
|
294
|
+
### Download Models
|
|
489
295
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
console.log('Background learning completed');
|
|
494
|
-
}
|
|
296
|
+
```bash
|
|
297
|
+
# Using CLI
|
|
298
|
+
ruvllm download ruv/ruvltra
|
|
495
299
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
300
|
+
# Using HuggingFace CLI
|
|
301
|
+
huggingface-cli download ruv/ruvltra ruvltra-claude-code-0.5b-q4_k_m.gguf
|
|
302
|
+
|
|
303
|
+
# Programmatic download
|
|
304
|
+
import { downloadModel } from '@ruvector/ruvllm';
|
|
305
|
+
await downloadModel('ruv/ruvltra', { quantization: 'q4_k_m' });
|
|
500
306
|
```
|
|
501
307
|
|
|
502
|
-
|
|
308
|
+
### Environment Variables
|
|
503
309
|
|
|
504
|
-
|
|
310
|
+
```bash
|
|
311
|
+
# HuggingFace authentication (any of these)
|
|
312
|
+
HF_TOKEN=hf_xxx
|
|
313
|
+
HUGGING_FACE_HUB_TOKEN=hf_xxx
|
|
314
|
+
HUGGINGFACE_API_KEY=hf_xxx
|
|
315
|
+
```
|
|
505
316
|
|
|
506
|
-
|
|
317
|
+
### Local Model Storage
|
|
507
318
|
|
|
508
319
|
```bash
|
|
509
|
-
#
|
|
510
|
-
ruvllm
|
|
511
|
-
|
|
512
|
-
# Export learned patterns as JSONL dataset
|
|
513
|
-
ruvllm-export patterns ./exports/patterns
|
|
320
|
+
~/.ruvllm/models/ # Downloaded GGUF models
|
|
321
|
+
~/.ruvllm/training/ # Training data and configs
|
|
322
|
+
```
|
|
514
323
|
|
|
515
|
-
|
|
516
|
-
ruvllm-export preferences ./exports/preferences
|
|
324
|
+
## API Reference
|
|
517
325
|
|
|
518
|
-
|
|
519
|
-
ruvllm-export all ./exports
|
|
326
|
+
### RuvLLM Class
|
|
520
327
|
|
|
521
|
-
|
|
522
|
-
|
|
328
|
+
```typescript
|
|
329
|
+
class RuvLLM {
|
|
330
|
+
constructor(config?: RuvLLMConfig);
|
|
523
331
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
```
|
|
332
|
+
// Generate text
|
|
333
|
+
query(prompt: string, params?: GenerateParams): Promise<Response>;
|
|
527
334
|
|
|
528
|
-
|
|
335
|
+
// Stream generation
|
|
336
|
+
stream(prompt: string, params?: GenerateParams): AsyncIterable<string>;
|
|
529
337
|
|
|
530
|
-
|
|
338
|
+
// Load a model
|
|
339
|
+
loadModel(path: string): Promise<void>;
|
|
531
340
|
|
|
532
|
-
|
|
341
|
+
// Memory operations
|
|
342
|
+
addMemory(text: string, metadata?: Record<string, unknown>): number;
|
|
343
|
+
searchMemory(query: string, topK?: number): MemoryResult[];
|
|
533
344
|
|
|
534
|
-
|
|
345
|
+
// Get SONA learning stats
|
|
346
|
+
sonaStats(): SonaStats | null;
|
|
535
347
|
|
|
348
|
+
// Adapt on feedback
|
|
349
|
+
adapt(input: Float32Array, quality: number): void;
|
|
350
|
+
}
|
|
536
351
|
```
|
|
537
|
-
Layer 2: [3] ─────────────────── [7]
|
|
538
|
-
│ │
|
|
539
|
-
Layer 1: [3] ─── [5] ─────────── [7] ─── [9]
|
|
540
|
-
│ │ │ │
|
|
541
|
-
Layer 0: [1]─[2]─[3]─[4]─[5]─[6]─[7]─[8]─[9]─[10]
|
|
542
|
-
|
|
543
|
-
• M = 32 connections per node
|
|
544
|
-
• ef_construction = 200 for build quality
|
|
545
|
-
• ef_search = 64 for query speed
|
|
546
|
-
• O(log N) search complexity
|
|
547
|
-
```
|
|
548
|
-
|
|
549
|
-
### FastGRNN Router
|
|
550
|
-
|
|
551
|
-
Sparse + Low-rank matrices for efficient routing:
|
|
552
352
|
|
|
553
|
-
|
|
554
|
-
Input (128-dim)
|
|
555
|
-
│
|
|
556
|
-
┌───────┴───────┐
|
|
557
|
-
│ LayerNorm │
|
|
558
|
-
└───────┬───────┘
|
|
559
|
-
│
|
|
560
|
-
┌───────────┴───────────┐
|
|
561
|
-
│ FastGRNN Cell │
|
|
562
|
-
│ │
|
|
563
|
-
│ W_sparse (90% zero) │
|
|
564
|
-
│ U = A @ B (rank-8) │
|
|
565
|
-
│ │
|
|
566
|
-
│ z = σ(Wx + Uh + b) │
|
|
567
|
-
│ h' = z⊙h + (1-z)⊙ν │
|
|
568
|
-
└───────────┬───────────┘
|
|
569
|
-
│
|
|
570
|
-
┌───────┴───────┐
|
|
571
|
-
│ Output Heads │
|
|
572
|
-
├───────────────┤
|
|
573
|
-
│ Model Select │ → 4 classes
|
|
574
|
-
│ Context Size │ → 5 buckets
|
|
575
|
-
│ Temperature │ → continuous
|
|
576
|
-
│ Top-p │ → continuous
|
|
577
|
-
│ Confidence │ → continuous
|
|
578
|
-
└───────────────┘
|
|
579
|
-
```
|
|
353
|
+
### RlmController Class
|
|
580
354
|
|
|
581
|
-
|
|
355
|
+
```typescript
|
|
356
|
+
class RlmController {
|
|
357
|
+
constructor(config?: RlmConfig, engine?: RuvLLM);
|
|
582
358
|
|
|
583
|
-
|
|
359
|
+
// Query with recursive retrieval
|
|
360
|
+
query(input: string): Promise<RlmAnswer>;
|
|
584
361
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
│ MicroLoRA (Rank 1-2) │
|
|
588
|
-
│ Per-Request Adaptation │
|
|
589
|
-
├─────────────────────────────────────────────────────────────┤
|
|
590
|
-
│ │
|
|
591
|
-
│ Input ──► Down Proj ──► Up Proj ──► Scale ──► Add │
|
|
592
|
-
│ (dim) (dim→rank) (rank→dim) (α/r) to output │
|
|
593
|
-
│ │
|
|
594
|
-
│ Performance: <100μs latency, 2,236 ops/sec │
|
|
595
|
-
│ Rank-2 is ~5% faster than Rank-1 (better SIMD) │
|
|
596
|
-
└─────────────────────────────────────────────────────────────┘
|
|
597
|
-
|
|
598
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
599
|
-
│ BaseLoRA (Rank 4-16) │
|
|
600
|
-
│ Background Adaptation │
|
|
601
|
-
├─────────────────────────────────────────────────────────────┤
|
|
602
|
-
│ │
|
|
603
|
-
│ Aggregated from successful MicroLoRA patterns │
|
|
604
|
-
│ Merged hourly into base weights │
|
|
605
|
-
│ EWC++ regularization prevents forgetting │
|
|
606
|
-
│ │
|
|
607
|
-
└─────────────────────────────────────────────────────────────┘
|
|
608
|
-
```
|
|
362
|
+
// Stream query
|
|
363
|
+
queryStream(input: string): AsyncGenerator<StreamToken>;
|
|
609
364
|
|
|
610
|
-
|
|
365
|
+
// Memory management
|
|
366
|
+
addMemory(text: string, metadata?: Record<string, unknown>): Promise<string>;
|
|
367
|
+
searchMemory(query: string, topK?: number): Promise<MemorySpan[]>;
|
|
611
368
|
|
|
612
|
-
|
|
369
|
+
// Cache management
|
|
370
|
+
clearCache(): void;
|
|
371
|
+
getCacheStats(): { size: number; entries: number };
|
|
613
372
|
|
|
373
|
+
// Configuration
|
|
374
|
+
updateConfig(config: Partial<RlmConfig>): void;
|
|
375
|
+
getConfig(): Required<RlmConfig>;
|
|
376
|
+
}
|
|
614
377
|
```
|
|
615
|
-
Loss = Task_Loss + λ * Σᵢ Fᵢ(θᵢ - θ*ᵢ)²
|
|
616
|
-
|
|
617
|
-
Where:
|
|
618
|
-
• Fᵢ = Online Fisher information (EMA decay 0.999)
|
|
619
|
-
• θ*ᵢ = Optimal weights for previous tasks
|
|
620
|
-
• λ = Adaptive (2000 default, range 100-15000)
|
|
621
|
-
• Multi-task memory with circular buffer (10 tasks)
|
|
622
|
-
• Automatic task boundary detection
|
|
623
|
-
```
|
|
624
|
-
|
|
625
|
-
### SIMD Operations
|
|
626
|
-
|
|
627
|
-
Native CPU acceleration:
|
|
628
|
-
|
|
629
|
-
```rust
|
|
630
|
-
// AVX2 dot product (8 floats at a time)
|
|
631
|
-
#[target_feature(enable = "avx2")]
|
|
632
|
-
unsafe fn dot_product_avx2(a: &[f32], b: &[f32]) -> f32
|
|
633
378
|
|
|
634
|
-
|
|
635
|
-
#[target_feature(enable = "sse4.1")]
|
|
636
|
-
unsafe fn dot_product_sse(a: &[f32], b: &[f32]) -> f32
|
|
379
|
+
### Configuration
|
|
637
380
|
|
|
638
|
-
|
|
639
|
-
|
|
381
|
+
```typescript
|
|
382
|
+
interface RuvLLMConfig {
|
|
383
|
+
modelPath?: string; // Path to GGUF model
|
|
384
|
+
sonaEnabled?: boolean; // Enable SONA learning (default: true)
|
|
385
|
+
flashAttention?: boolean; // Use Flash Attention 2 (default: true)
|
|
386
|
+
maxTokens?: number; // Max generation tokens (default: 256)
|
|
387
|
+
temperature?: number; // Sampling temperature (default: 0.7)
|
|
388
|
+
topP?: number; // Top-p sampling (default: 0.9)
|
|
389
|
+
}
|
|
640
390
|
```
|
|
641
391
|
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
## Supported Models
|
|
392
|
+
### Generate Parameters
|
|
645
393
|
|
|
646
|
-
|
|
394
|
+
```typescript
|
|
395
|
+
interface GenerateParams {
|
|
396
|
+
maxTokens?: number;
|
|
397
|
+
temperature?: number;
|
|
398
|
+
topP?: number;
|
|
399
|
+
topK?: number;
|
|
400
|
+
repetitionPenalty?: number;
|
|
401
|
+
stopSequences?: string[];
|
|
402
|
+
}
|
|
403
|
+
```
|
|
647
404
|
|
|
648
|
-
|
|
649
|
-
|-------|------------|---------|------|
|
|
650
|
-
| SmolLM 135M | 135M | 2048 | HuggingFaceTB/SmolLM-135M |
|
|
651
|
-
| SmolLM 360M | 360M | 2048 | HuggingFaceTB/SmolLM-360M |
|
|
652
|
-
| Qwen2 0.5B | 500M | 4096 | Qwen/Qwen2-0.5B |
|
|
653
|
-
| TinyLlama 1.1B | 1.1B | 2048 | TinyLlama/TinyLlama-1.1B-Chat |
|
|
405
|
+
## SIMD Module
|
|
654
406
|
|
|
655
|
-
|
|
407
|
+
For direct access to optimized SIMD kernels:
|
|
656
408
|
|
|
657
|
-
|
|
409
|
+
```typescript
|
|
410
|
+
import { simd } from '@ruvector/ruvllm/simd';
|
|
658
411
|
|
|
659
|
-
|
|
412
|
+
// Dot product
|
|
413
|
+
const result = simd.dotProduct(vecA, vecB);
|
|
660
414
|
|
|
661
|
-
|
|
415
|
+
// Matrix multiplication
|
|
416
|
+
const output = simd.matmul(matrix, vector);
|
|
662
417
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
| `/health` | GET | Health check |
|
|
666
|
-
| `/query` | POST | Submit query |
|
|
667
|
-
| `/stats` | GET | Get statistics |
|
|
668
|
-
| `/feedback` | POST | Submit feedback |
|
|
669
|
-
| `/session` | POST | Create new session |
|
|
418
|
+
// Flash Attention
|
|
419
|
+
const attended = simd.flashAttention(query, key, value, scale);
|
|
670
420
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
curl -X POST http://localhost:3000/query \
|
|
674
|
-
-H "Content-Type: application/json" \
|
|
675
|
-
-d '{"query": "What is Rust?", "session_id": null}'
|
|
421
|
+
// RMS Normalization
|
|
422
|
+
simd.rmsNorm(hidden, weights, epsilon);
|
|
676
423
|
```
|
|
677
424
|
|
|
678
|
-
|
|
425
|
+
## Evaluation Harness
|
|
679
426
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
```bash
|
|
683
|
-
# Run all tests
|
|
684
|
-
cargo test -p ruvllm
|
|
685
|
-
|
|
686
|
-
# Unit tests only (47 tests)
|
|
687
|
-
cargo test -p ruvllm --lib
|
|
688
|
-
|
|
689
|
-
# Integration tests (15 tests)
|
|
690
|
-
cargo test -p ruvllm --test integration
|
|
691
|
-
|
|
692
|
-
# With output
|
|
693
|
-
cargo test -p ruvllm -- --nocapture
|
|
694
|
-
```
|
|
427
|
+
Run model evaluations with SWE-Bench integration:
|
|
695
428
|
|
|
696
|
-
|
|
429
|
+
```typescript
|
|
430
|
+
import { RuvLLM, EvaluationHarness, AblationMode } from '@ruvector/ruvllm';
|
|
697
431
|
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
| Embedding | 9 | Tokenization, caching, pooling |
|
|
704
|
-
| SONA | 10 | LoRA, EWC++, ReasoningBank, loops |
|
|
705
|
-
| Orchestrator | 2 | End-to-end pipeline |
|
|
706
|
-
| Integration | 15 | Full system tests |
|
|
432
|
+
const harness = new EvaluationHarness({
|
|
433
|
+
modelPath: './models/model.gguf',
|
|
434
|
+
enableHnsw: true,
|
|
435
|
+
enableSona: true,
|
|
436
|
+
});
|
|
707
437
|
|
|
708
|
-
|
|
438
|
+
// Run single evaluation
|
|
439
|
+
const result = await harness.evaluate(
|
|
440
|
+
'Fix the null pointer exception',
|
|
441
|
+
'def process(data): return data.split()',
|
|
442
|
+
AblationMode.Full
|
|
443
|
+
);
|
|
709
444
|
|
|
710
|
-
|
|
445
|
+
console.log(`Success: ${result.success}, Quality: ${result.qualityScore}`);
|
|
711
446
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
│ ├── lib.rs # Library entry point
|
|
718
|
-
│ ├── config.rs # Configuration system
|
|
719
|
-
│ ├── error.rs # Error types
|
|
720
|
-
│ ├── types.rs # Core domain types
|
|
721
|
-
│ ├── orchestrator.rs # Main RuvLLM coordinator
|
|
722
|
-
│ ├── memory.rs # HNSW memory service
|
|
723
|
-
│ ├── router.rs # FastGRNN router
|
|
724
|
-
│ ├── attention.rs # Graph attention engine
|
|
725
|
-
│ ├── embedding.rs # Embedding service
|
|
726
|
-
│ ├── inference.rs # Mock inference pool
|
|
727
|
-
│ ├── inference_real.rs # Candle-based real inference
|
|
728
|
-
│ ├── simd_inference.rs # SIMD-optimized transformer
|
|
729
|
-
│ ├── learning.rs # Self-learning service
|
|
730
|
-
│ ├── compression.rs # Memory compression
|
|
731
|
-
│ ├── training.rs # Pretraining pipeline
|
|
732
|
-
│ ├── trm/ # TRM (Tiny Recursive Models) module
|
|
733
|
-
│ │ ├── mod.rs # Module exports and traits
|
|
734
|
-
│ │ ├── engine.rs # Main TRM reasoning engine
|
|
735
|
-
│ │ ├── config.rs # Configuration and builder
|
|
736
|
-
│ │ ├── mlp.rs # MLP latent updater
|
|
737
|
-
│ │ ├── attention.rs # Attention latent updater
|
|
738
|
-
│ │ ├── refiner.rs # Answer refinement
|
|
739
|
-
│ │ ├── confidence.rs # Confidence scoring
|
|
740
|
-
│ │ ├── sona_bridge.rs # SONA integration
|
|
741
|
-
│ │ ├── types.rs # TRM types and results
|
|
742
|
-
│ │ └── error.rs # Error handling
|
|
743
|
-
│ ├── sona/ # SONA module
|
|
744
|
-
│ │ ├── mod.rs # Module exports
|
|
745
|
-
│ │ ├── types.rs # SONA types
|
|
746
|
-
│ │ ├── lora.rs # MicroLoRA & BaseLoRA
|
|
747
|
-
│ │ ├── ewc.rs # EWC++ implementation
|
|
748
|
-
│ │ ├── reasoning_bank.rs # Pattern storage
|
|
749
|
-
│ │ ├── trajectory.rs # Trajectory recording
|
|
750
|
-
│ │ ├── engine.rs # SONA engine
|
|
751
|
-
│ │ └── loops/ # Temporal learning loops
|
|
752
|
-
│ │ ├── instant.rs # Per-request loop
|
|
753
|
-
│ │ ├── background.rs # Hourly loop
|
|
754
|
-
│ │ └── coordinator.rs # Loop coordinator
|
|
755
|
-
│ └── bin/
|
|
756
|
-
│ ├── demo.rs # Interactive demo
|
|
757
|
-
│ ├── bench.rs # Quick benchmarks
|
|
758
|
-
│ ├── benchmark_suite.rs # Full benchmark suite
|
|
759
|
-
│ ├── simd_demo.rs # SIMD capabilities demo
|
|
760
|
-
│ ├── pretrain.rs # Pretraining pipeline
|
|
761
|
-
│ ├── export.rs # HuggingFace export
|
|
762
|
-
│ └── server.rs # HTTP server
|
|
763
|
-
├── tests/
|
|
764
|
-
│ └── integration.rs # Integration tests
|
|
765
|
-
├── benches/
|
|
766
|
-
│ ├── pipeline.rs # Full pipeline benchmarks
|
|
767
|
-
│ ├── router.rs # Router benchmarks
|
|
768
|
-
│ ├── memory.rs # Memory benchmarks
|
|
769
|
-
│ ├── attention.rs # Attention benchmarks
|
|
770
|
-
│ ├── sona_bench.rs # SONA benchmarks
|
|
771
|
-
│ └── trm_bench.rs # TRM benchmarks
|
|
772
|
-
├── config/ # Configuration files
|
|
773
|
-
└── docs/
|
|
774
|
-
└── sparc/ # SPARC methodology docs
|
|
447
|
+
// Run ablation study (Baseline, RetrievalOnly, AdaptersOnly, R+A, Full)
|
|
448
|
+
const report = await harness.runAblationStudy(tasks);
|
|
449
|
+
for (const [mode, metrics] of Object.entries(report.modeMetrics)) {
|
|
450
|
+
console.log(`${mode}: ${metrics.successRate * 100}% success`);
|
|
451
|
+
}
|
|
775
452
|
```
|
|
776
453
|
|
|
777
|
-
|
|
454
|
+
## mistral-rs Backend (Production Serving)
|
|
778
455
|
|
|
779
|
-
|
|
456
|
+
For production deployments with 10-100+ concurrent users, use the mistral-rs backend:
|
|
780
457
|
|
|
781
|
-
|
|
458
|
+
```typescript
|
|
459
|
+
import { RuvLLM, MistralBackend, PagedAttentionConfig } from '@ruvector/ruvllm';
|
|
782
460
|
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
461
|
+
// Configure for production serving
|
|
462
|
+
const backend = new MistralBackend({
|
|
463
|
+
// PagedAttention: 5-10x more concurrent users
|
|
464
|
+
pagedAttention: {
|
|
465
|
+
blockSize: 16,
|
|
466
|
+
maxBlocks: 4096,
|
|
467
|
+
gpuMemoryFraction: 0.9,
|
|
468
|
+
prefixCaching: true,
|
|
469
|
+
},
|
|
470
|
+
// X-LoRA: Per-token adapter routing
|
|
471
|
+
xlora: {
|
|
472
|
+
adapters: ['./adapters/coder', './adapters/researcher'],
|
|
473
|
+
topK: 2,
|
|
474
|
+
},
|
|
475
|
+
// ISQ: Runtime quantization
|
|
476
|
+
isq: {
|
|
477
|
+
bits: 4,
|
|
478
|
+
method: 'awq',
|
|
479
|
+
},
|
|
480
|
+
});
|
|
791
481
|
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
cargo build --release --features full
|
|
795
|
-
```
|
|
482
|
+
const llm = new RuvLLM({ backend });
|
|
483
|
+
await llm.loadModel('mistralai/Mistral-7B-Instruct-v0.2');
|
|
796
484
|
|
|
797
|
-
|
|
485
|
+
// Serve multiple concurrent requests
|
|
486
|
+
const response = await llm.query('Write production code');
|
|
487
|
+
```
|
|
798
488
|
|
|
799
|
-
|
|
800
|
-
|---------|---------|-------------|
|
|
801
|
-
| `serde-support` | ✓ | Serialization for export, training, and federated learning |
|
|
802
|
-
| `wasm` | ✗ | WebAssembly bindings for browser/edge deployment |
|
|
803
|
-
| `napi` | ✗ | N-API bindings for Node.js integration |
|
|
489
|
+
> **Note**: mistral-rs features require the Rust backend with `mistral-rs` feature enabled. Native bindings will use mistral-rs when available.
|
|
804
490
|
|
|
805
|
-
|
|
806
|
-
# Build SONA with WASM support
|
|
807
|
-
cd crates/sona
|
|
808
|
-
wasm-pack build --target web --features wasm
|
|
809
|
-
```
|
|
491
|
+
## Supported Models
|
|
810
492
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
| `embedding.max_tokens` | 512 | Max tokens per input |
|
|
819
|
-
| `memory.hnsw_m` | 16 | HNSW connections per node |
|
|
820
|
-
| `memory.hnsw_ef_construction` | 100 | Build quality parameter |
|
|
821
|
-
| `memory.hnsw_ef_search` | 64 | Search quality parameter |
|
|
822
|
-
| `router.input_dim` | 128 | Router input features |
|
|
823
|
-
| `router.hidden_dim` | 64 | FastGRNN hidden size |
|
|
824
|
-
| `router.sparsity` | 0.9 | Weight matrix sparsity |
|
|
825
|
-
| `router.rank` | 8 | Low-rank decomposition |
|
|
826
|
-
| `learning.enabled` | true | Enable self-learning |
|
|
827
|
-
| `learning.quality_threshold` | 0.7 | Min quality for writeback |
|
|
828
|
-
| `learning.ewc_lambda` | 2000 | EWC regularization strength |
|
|
829
|
-
| `sona.pattern_clusters` | 100 | K-means++ clusters |
|
|
830
|
-
| `sona.micro_lora_rank` | 2 | MicroLoRA rank |
|
|
831
|
-
|
|
832
|
-
### Federated Learning Configuration
|
|
833
|
-
|
|
834
|
-
| Option | Default | Description |
|
|
835
|
-
|--------|---------|-------------|
|
|
836
|
-
| `federated.quality_threshold` | 0.4 | Min quality for trajectory acceptance |
|
|
837
|
-
| `federated.consolidation_interval` | 50 | Auto-consolidate every N agents |
|
|
838
|
-
| `federated.coordinator_capacity` | 50000 | Trajectory buffer size for coordinator |
|
|
839
|
-
| `federated.agent_capacity` | 500 | Trajectory buffer size per agent |
|
|
840
|
-
| `federated.base_lora_rank` | 16 | Coordinator LoRA rank (deeper for aggregation) |
|
|
841
|
-
|
|
842
|
-
---
|
|
843
|
-
|
|
844
|
-
## Self-Learning Improvement Over Time
|
|
845
|
-
|
|
846
|
-
| Epoch | Queries | Quality | Routing | Cache Hit | Memory | Improvement |
|
|
847
|
-
|-------|---------|---------|---------|-----------|--------|-------------|
|
|
848
|
-
| 0 | 0 | 65.0% | 50.0% | 0.0% | 0 | 0.0% (baseline) |
|
|
849
|
-
| 1 | 50 | 67.2% | 58.0% | 10.0% | 25 | +3.4% |
|
|
850
|
-
| 2 | 100 | 69.8% | 66.0% | 20.0% | 50 | +7.4% |
|
|
851
|
-
| 3 | 150 | 71.5% | 74.0% | 30.0% | 75 | +10.0% |
|
|
852
|
-
| 4 | 200 | 73.2% | 82.0% | 40.0% | 100 | +12.6% |
|
|
853
|
-
| 5 | 250 | 74.8% | 90.0% | 50.0% | 125 | +15.1% |
|
|
854
|
-
|
|
855
|
-
---
|
|
856
|
-
|
|
857
|
-
## References
|
|
858
|
-
|
|
859
|
-
- [TinyRecursiveModels](https://github.com/SamsungSAILMontreal/TinyRecursiveModels) - Samsung SAIL Montreal's recursive reasoning approach
|
|
860
|
-
- [LFM2: Liquid Foundation Models](https://arxiv.org/abs/2511.23404v1) - Gated convolutions + grouped query attention
|
|
861
|
-
- [FastGRNN](https://arxiv.org/abs/1901.02358) - Fast, Accurate, Stable and Tiny GRU
|
|
862
|
-
- [HNSW](https://arxiv.org/abs/1603.09320) - Hierarchical Navigable Small World Graphs
|
|
863
|
-
- [EWC](https://arxiv.org/abs/1612.00796) - Elastic Weight Consolidation
|
|
864
|
-
- [LoRA](https://arxiv.org/abs/2106.09685) - Low-Rank Adaptation of Large Language Models
|
|
865
|
-
|
|
866
|
-
---
|
|
493
|
+
- **RuvLTRA-Small** (494M) - Q4K, Q5K, Q8
|
|
494
|
+
- **RuvLTRA-Medium** (3B) - Q4K, Q5K, Q8
|
|
495
|
+
- **Qwen 2.5** (0.5B-72B)
|
|
496
|
+
- **Llama 3.x** (8B-70B)
|
|
497
|
+
- **Mistral** (7B-22B)
|
|
498
|
+
- **Phi-3** (3.8B-14B)
|
|
499
|
+
- **Gemma-2** (2B-27B)
|
|
867
500
|
|
|
868
|
-
##
|
|
501
|
+
## Platform Support
|
|
869
502
|
|
|
870
|
-
|
|
503
|
+
| Platform | Architecture | Status |
|
|
504
|
+
|----------|--------------|--------|
|
|
505
|
+
| macOS | arm64 (M1-M4) | Full support |
|
|
506
|
+
| macOS | x64 | Supported |
|
|
507
|
+
| Linux | x64 | Supported |
|
|
508
|
+
| Linux | arm64 | Supported |
|
|
509
|
+
| Windows | x64 | Supported |
|
|
871
510
|
|
|
872
|
-
|
|
873
|
-
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
511
|
+
## Related Packages
|
|
874
512
|
|
|
875
|
-
|
|
513
|
+
- [@ruvector/core](https://www.npmjs.com/package/@ruvector/core) - Vector operations
|
|
514
|
+
- [@ruvector/sona](https://www.npmjs.com/package/@ruvector/sona) - SONA learning engine
|
|
515
|
+
- [@ruvector/ruvector](https://www.npmjs.com/package/@ruvector/ruvector) - Full Ruvector SDK
|
|
876
516
|
|
|
877
|
-
##
|
|
517
|
+
## Links
|
|
878
518
|
|
|
879
|
-
|
|
519
|
+
- [GitHub Repository](https://github.com/ruvnet/ruvector)
|
|
520
|
+
- [HuggingFace Models](https://huggingface.co/ruv/ruvltra)
|
|
521
|
+
- [API Documentation](https://docs.rs/ruvllm)
|
|
522
|
+
- [Crate (Rust)](https://crates.io/crates/ruvllm)
|
|
880
523
|
|
|
881
|
-
|
|
524
|
+
## License
|
|
882
525
|
|
|
883
|
-
|
|
884
|
-
<b>Built with Rust + Ruvector</b><br>
|
|
885
|
-
<i>Self-Learning AI that gets smarter with every interaction</i>
|
|
886
|
-
</p>
|
|
526
|
+
MIT OR Apache-2.0
|