@ruvector/ruvllm 4.0.0 → 4.1.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.
Files changed (171) hide show
  1. package/README.md +449 -158
  2. package/bin/cli.js +1066 -0
  3. package/bin/gpu-delegate.js +67 -0
  4. package/bin/ruvllm-adapters.js +5 -0
  5. package/bin/ruvllm-gpu-loop.js +5 -0
  6. package/bin/serve.js +265 -0
  7. package/dist/cjs/benchmarks/embedding-benchmark.d.ts +102 -0
  8. package/dist/cjs/benchmarks/embedding-benchmark.d.ts.map +1 -0
  9. package/dist/cjs/benchmarks/embedding-benchmark.js +436 -0
  10. package/dist/cjs/benchmarks/index.d.ts +34 -0
  11. package/dist/cjs/benchmarks/index.d.ts.map +1 -0
  12. package/dist/cjs/benchmarks/index.js +132 -0
  13. package/dist/cjs/benchmarks/model-comparison.d.ts +71 -0
  14. package/dist/cjs/benchmarks/model-comparison.d.ts.map +1 -0
  15. package/dist/cjs/benchmarks/model-comparison.js +476 -0
  16. package/dist/cjs/benchmarks/routing-benchmark.d.ts +70 -0
  17. package/dist/cjs/benchmarks/routing-benchmark.d.ts.map +1 -0
  18. package/dist/cjs/benchmarks/routing-benchmark.js +289 -0
  19. package/dist/cjs/contrastive.d.ts +229 -0
  20. package/dist/cjs/contrastive.d.ts.map +1 -0
  21. package/dist/cjs/contrastive.js +589 -0
  22. package/dist/cjs/engine.d.ts +160 -0
  23. package/dist/cjs/engine.d.ts.map +1 -0
  24. package/dist/cjs/engine.js +552 -0
  25. package/dist/cjs/export.d.ts +182 -0
  26. package/dist/cjs/export.d.ts.map +1 -0
  27. package/dist/cjs/export.js +422 -0
  28. package/dist/cjs/federated.d.ts +233 -0
  29. package/dist/cjs/federated.d.ts.map +1 -0
  30. package/dist/cjs/federated.js +525 -0
  31. package/dist/cjs/index.d.ts +68 -0
  32. package/dist/cjs/index.d.ts.map +1 -0
  33. package/dist/cjs/index.js +104 -0
  34. package/dist/cjs/intelligence.d.ts +136 -0
  35. package/dist/cjs/intelligence.d.ts.map +1 -0
  36. package/dist/cjs/intelligence.js +226 -0
  37. package/dist/cjs/lora.d.ts +251 -0
  38. package/dist/cjs/lora.d.ts.map +1 -0
  39. package/dist/cjs/lora.js +509 -0
  40. package/dist/cjs/models.d.ts +129 -0
  41. package/dist/cjs/models.d.ts.map +1 -0
  42. package/dist/cjs/models.js +323 -0
  43. package/dist/cjs/native.d.ts +140 -0
  44. package/dist/cjs/native.d.ts.map +1 -0
  45. package/dist/cjs/native.js +98 -0
  46. package/dist/cjs/session.d.ts +80 -0
  47. package/dist/cjs/session.d.ts.map +1 -0
  48. package/dist/cjs/session.js +203 -0
  49. package/dist/cjs/simd.d.ts +90 -0
  50. package/dist/cjs/simd.d.ts.map +1 -0
  51. package/dist/cjs/simd.js +209 -0
  52. package/dist/cjs/sona.d.ts +223 -0
  53. package/dist/cjs/sona.d.ts.map +1 -0
  54. package/dist/cjs/sona.js +562 -0
  55. package/dist/cjs/streaming.d.ts +55 -0
  56. package/dist/cjs/streaming.d.ts.map +1 -0
  57. package/dist/cjs/streaming.js +131 -0
  58. package/dist/cjs/training.d.ts +312 -0
  59. package/dist/cjs/training.d.ts.map +1 -0
  60. package/dist/cjs/training.js +610 -0
  61. package/dist/cjs/types.d.ts +696 -0
  62. package/dist/cjs/types.d.ts.map +1 -0
  63. package/dist/cjs/types.js +6 -0
  64. package/dist/esm/benchmarks/embedding-benchmark.d.ts +102 -0
  65. package/dist/esm/benchmarks/embedding-benchmark.d.ts.map +1 -0
  66. package/dist/esm/benchmarks/embedding-benchmark.js +427 -0
  67. package/dist/esm/benchmarks/index.d.ts +34 -0
  68. package/dist/esm/benchmarks/index.d.ts.map +1 -0
  69. package/dist/esm/benchmarks/index.js +110 -0
  70. package/dist/esm/benchmarks/model-comparison.d.ts +71 -0
  71. package/dist/esm/benchmarks/model-comparison.d.ts.map +1 -0
  72. package/dist/esm/benchmarks/model-comparison.js +434 -0
  73. package/dist/esm/benchmarks/routing-benchmark.d.ts +70 -0
  74. package/dist/esm/benchmarks/routing-benchmark.d.ts.map +1 -0
  75. package/dist/esm/benchmarks/routing-benchmark.js +283 -0
  76. package/dist/esm/contrastive.d.ts +229 -0
  77. package/dist/esm/contrastive.d.ts.map +1 -0
  78. package/dist/esm/contrastive.js +578 -0
  79. package/dist/esm/engine.d.ts +160 -0
  80. package/dist/esm/engine.d.ts.map +1 -0
  81. package/dist/esm/engine.js +548 -0
  82. package/dist/esm/export.d.ts +182 -0
  83. package/dist/esm/export.d.ts.map +1 -0
  84. package/dist/esm/export.js +414 -0
  85. package/dist/esm/federated.d.ts +233 -0
  86. package/dist/esm/federated.d.ts.map +1 -0
  87. package/dist/esm/federated.js +520 -0
  88. package/dist/esm/index.d.ts +68 -0
  89. package/dist/esm/index.d.ts.map +1 -0
  90. package/dist/esm/index.js +84 -0
  91. package/dist/esm/intelligence.d.ts +136 -0
  92. package/dist/esm/intelligence.d.ts.map +1 -0
  93. package/dist/esm/intelligence.js +188 -0
  94. package/dist/esm/lora.d.ts +251 -0
  95. package/dist/esm/lora.d.ts.map +1 -0
  96. package/dist/esm/lora.js +504 -0
  97. package/dist/esm/models.d.ts +129 -0
  98. package/dist/esm/models.d.ts.map +1 -0
  99. package/dist/esm/models.js +282 -0
  100. package/dist/esm/native.d.ts +140 -0
  101. package/dist/esm/native.d.ts.map +1 -0
  102. package/dist/esm/native.js +100 -0
  103. package/dist/esm/session.d.ts +80 -0
  104. package/dist/esm/session.d.ts.map +1 -0
  105. package/dist/esm/session.js +199 -0
  106. package/dist/esm/simd.d.ts +90 -0
  107. package/dist/esm/simd.d.ts.map +1 -0
  108. package/dist/esm/simd.js +205 -0
  109. package/dist/esm/sona.d.ts +223 -0
  110. package/dist/esm/sona.d.ts.map +1 -0
  111. package/dist/esm/sona.js +556 -0
  112. package/dist/esm/streaming.d.ts +55 -0
  113. package/dist/esm/streaming.d.ts.map +1 -0
  114. package/dist/esm/streaming.js +126 -0
  115. package/dist/esm/training.d.ts +312 -0
  116. package/dist/esm/training.d.ts.map +1 -0
  117. package/dist/esm/training.js +603 -0
  118. package/dist/esm/types.d.ts +696 -0
  119. package/dist/esm/types.d.ts.map +1 -0
  120. package/dist/esm/types.js +5 -0
  121. package/gpu/_load.cjs +38 -0
  122. package/gpu/_load.mjs +33 -0
  123. package/gpu/adapters.cjs +3 -0
  124. package/gpu/adapters.mjs +5 -0
  125. package/gpu/engine.cjs +3 -0
  126. package/gpu/engine.mjs +5 -0
  127. package/gpu/fixture.cjs +3 -0
  128. package/gpu/fixture.mjs +5 -0
  129. package/gpu/gpu-host.cjs +3 -0
  130. package/gpu/gpu-host.mjs +5 -0
  131. package/gpu/gpu-loop.cjs +3 -0
  132. package/gpu/gpu-loop.mjs +5 -0
  133. package/gpu/gpu-spool-adapter.cjs +3 -0
  134. package/gpu/gpu-spool-adapter.mjs +5 -0
  135. package/gpu/vast-host-adapter.cjs +3 -0
  136. package/gpu/vast-host-adapter.mjs +5 -0
  137. package/package.json +159 -49
  138. package/scripts/ensemble-model-compare.js +287 -0
  139. package/scripts/fix-esm-extensions.mjs +220 -0
  140. package/scripts/huggingface/README.md +537 -0
  141. package/scripts/huggingface/publish.sh +112 -0
  142. package/scripts/hybrid-model-compare.js +373 -0
  143. package/scripts/improved-model-compare.js +288 -0
  144. package/scripts/optimized-model-compare.js +364 -0
  145. package/scripts/real-model-compare.js +280 -0
  146. package/scripts/smoke-esm.mjs +82 -0
  147. package/scripts/training/agentic-flow-capabilities.json +329 -0
  148. package/scripts/training/claude-code-synth.js +505 -0
  149. package/scripts/training/claude-flow-capabilities.json +1322 -0
  150. package/scripts/training/claude-hard-negatives.js +222 -0
  151. package/scripts/training/contrastive-finetune.js +517 -0
  152. package/scripts/training/ecosystem-triplets.jsonl +1467 -0
  153. package/scripts/training/generate-ecosystem-triplets.js +1324 -0
  154. package/scripts/training/routing-dataset.js +634 -0
  155. package/scripts/training/ruvector-capabilities.json +798 -0
  156. package/scripts/training/validate-ecosystem.js +381 -0
  157. package/scripts/training/validation-results.json +23 -0
  158. package/GPU-LOOP.md +0 -229
  159. package/LICENSE +0 -201
  160. package/NOTICE +0 -9
  161. package/examples/gpu-loop.example.json +0 -26
  162. package/src/adapters-cli.mjs +0 -23
  163. package/src/adapters.mjs +0 -91
  164. package/src/cli.mjs +0 -30
  165. package/src/engine.mjs +0 -238
  166. package/src/fixture.mjs +0 -38
  167. package/src/gpu-host.mjs +0 -47
  168. package/src/gpu-loop-cli.mjs +0 -67
  169. package/src/gpu-loop.mjs +0 -184
  170. package/src/gpu-spool-adapter.mjs +0 -80
  171. package/src/vast-host-adapter.mjs +0 -274
@@ -0,0 +1,222 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Claude-Powered Hard Negative Generator for SOTA Agent Routing
4
+ *
5
+ * Uses Claude Opus 4.5 to generate high-quality confusing triplets
6
+ * that push embedding-only accuracy toward 100%.
7
+ */
8
+
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+ require('dotenv').config({ path: path.resolve(__dirname, '../../../../../.env') });
12
+
13
+ const ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY;
14
+ if (!ANTHROPIC_API_KEY) {
15
+ console.error('Error: ANTHROPIC_API_KEY not found in .env');
16
+ process.exit(1);
17
+ }
18
+
19
+ // Agent types and their descriptions
20
+ const AGENTS = {
21
+ coder: 'Implements code, builds features, writes functions',
22
+ researcher: 'Investigates problems, explores documentation, gathers information',
23
+ reviewer: 'Reviews pull requests, checks code quality, suggests improvements',
24
+ tester: 'Writes tests, validates behavior, ensures coverage',
25
+ architect: 'Designs systems, creates schemas, plans architecture',
26
+ 'security-architect': 'Audits for vulnerabilities, checks security, reviews auth',
27
+ debugger: 'Fixes bugs, traces errors, diagnoses issues',
28
+ documenter: 'Writes documentation, adds comments, creates READMEs',
29
+ refactorer: 'Refactors code, modernizes patterns, improves structure',
30
+ optimizer: 'Optimizes performance, adds caching, improves speed',
31
+ devops: 'Deploys apps, sets up CI/CD, manages infrastructure',
32
+ 'api-docs': 'Generates OpenAPI specs, documents endpoints, creates Swagger',
33
+ planner: 'Creates sprint plans, estimates timelines, prioritizes tasks'
34
+ };
35
+
36
+ // Confusing pairs - agent types that are easily mixed up
37
+ const CONFUSING_PAIRS = [
38
+ ['coder', 'refactorer'], // Both modify code
39
+ ['researcher', 'architect'], // Both do analysis
40
+ ['reviewer', 'tester'], // Both validate
41
+ ['debugger', 'optimizer'], // Both fix issues
42
+ ['documenter', 'api-docs'], // Both write docs
43
+ ['architect', 'planner'], // Both plan
44
+ ['security-architect', 'reviewer'], // Both check code
45
+ ['coder', 'debugger'], // Both write/fix code
46
+ ['tester', 'debugger'], // Both find problems
47
+ ['optimizer', 'architect'] // Both improve systems
48
+ ];
49
+
50
+ async function callClaude(prompt) {
51
+ const response = await fetch('https://api.anthropic.com/v1/messages', {
52
+ method: 'POST',
53
+ headers: {
54
+ 'Content-Type': 'application/json',
55
+ 'x-api-key': ANTHROPIC_API_KEY,
56
+ 'anthropic-version': '2023-06-01'
57
+ },
58
+ body: JSON.stringify({
59
+ model: 'claude-opus-4-5-20251101',
60
+ max_tokens: 4096,
61
+ messages: [{
62
+ role: 'user',
63
+ content: prompt
64
+ }]
65
+ })
66
+ });
67
+
68
+ if (!response.ok) {
69
+ const error = await response.text();
70
+ throw new Error(`Claude API error: ${response.status} - ${error}`);
71
+ }
72
+
73
+ const data = await response.json();
74
+ return data.content[0].text;
75
+ }
76
+
77
+ async function generateHardNegatives(pair, count = 10) {
78
+ const [agent1, agent2] = pair;
79
+
80
+ const prompt = `You are helping train an AI routing model. Generate ${count} task descriptions that are AMBIGUOUS between "${agent1}" and "${agent2}" agents.
81
+
82
+ Agent descriptions:
83
+ - ${agent1}: ${AGENTS[agent1]}
84
+ - ${agent2}: ${AGENTS[agent2]}
85
+
86
+ Generate tasks that could reasonably be assigned to either agent but have a subtle preference for one.
87
+
88
+ Format each line as JSON:
89
+ {"anchor": "task description", "positive": "correct_agent", "negative": "wrong_agent", "isHard": true, "reason": "why this is confusing"}
90
+
91
+ Requirements:
92
+ 1. Tasks should be realistic software development scenarios
93
+ 2. The distinction should be subtle but learnable
94
+ 3. Include edge cases and ambiguous wording
95
+ 4. Mix which agent is the positive/negative
96
+
97
+ Generate exactly ${count} examples, one per line:`;
98
+
99
+ const response = await callClaude(prompt);
100
+
101
+ // Parse response - extract JSON lines
102
+ const lines = response.split('\n').filter(line => line.trim().startsWith('{'));
103
+ const triplets = [];
104
+
105
+ for (const line of lines) {
106
+ try {
107
+ const triplet = JSON.parse(line);
108
+ if (triplet.anchor && triplet.positive && triplet.negative) {
109
+ triplets.push({
110
+ anchor: triplet.anchor,
111
+ positive: triplet.positive,
112
+ negative: triplet.negative,
113
+ isHard: true
114
+ });
115
+ }
116
+ } catch (e) {
117
+ // Skip malformed JSON
118
+ }
119
+ }
120
+
121
+ return triplets;
122
+ }
123
+
124
+ async function evaluateWithGRPO(triplets, model = 'keyword-first') {
125
+ // GRPO-style evaluation: Use Claude to judge if predictions are correct
126
+ const prompt = `You are evaluating an AI agent router. For each task, determine which agent should handle it.
127
+
128
+ Agents: ${Object.keys(AGENTS).join(', ')}
129
+
130
+ Tasks to evaluate:
131
+ ${triplets.slice(0, 10).map((t, i) => `${i + 1}. "${t.anchor}"`).join('\n')}
132
+
133
+ For each task, respond with the agent name that should handle it and your confidence (0-1).
134
+ Format: 1. agent_name (0.95)`;
135
+
136
+ const response = await callClaude(prompt);
137
+ console.log('\nGRPO Evaluation (Claude as judge):');
138
+ console.log(response);
139
+
140
+ return response;
141
+ }
142
+
143
+ async function main() {
144
+ console.log('╔═══════════════════════════════════════════════════════════════════════════════════╗');
145
+ console.log('║ Claude-Powered Hard Negative Generator for SOTA Agent Routing ║');
146
+ console.log('╚═══════════════════════════════════════════════════════════════════════════════════╝\n');
147
+
148
+ const args = process.argv.slice(2);
149
+ const outputPath = args.find(a => a.startsWith('--output='))?.split('=')[1]
150
+ || path.join(process.env.HOME, '.ruvllm/training/claude-hard-negatives.jsonl');
151
+ const tripletCount = parseInt(args.find(a => a.startsWith('--count='))?.split('=')[1] || '5');
152
+ const doGRPO = args.includes('--grpo');
153
+
154
+ console.log(`Configuration:`);
155
+ console.log(` Output: ${outputPath}`);
156
+ console.log(` Triplets per pair: ${tripletCount}`);
157
+ console.log(` Confusing pairs: ${CONFUSING_PAIRS.length}`);
158
+ console.log(` Total expected: ~${CONFUSING_PAIRS.length * tripletCount} triplets`);
159
+ console.log(` GRPO evaluation: ${doGRPO}`);
160
+ console.log();
161
+
162
+ const allTriplets = [];
163
+
164
+ console.log('Generating hard negatives using Claude Opus 4.5...\n');
165
+
166
+ for (const pair of CONFUSING_PAIRS) {
167
+ console.log(` Generating for ${pair[0]} vs ${pair[1]}...`);
168
+ try {
169
+ const triplets = await generateHardNegatives(pair, tripletCount);
170
+ allTriplets.push(...triplets);
171
+ console.log(` ✓ Generated ${triplets.length} triplets`);
172
+ } catch (error) {
173
+ console.log(` ✗ Error: ${error.message}`);
174
+ }
175
+
176
+ // Rate limiting - wait between requests
177
+ await new Promise(resolve => setTimeout(resolve, 1000));
178
+ }
179
+
180
+ console.log(`\nTotal triplets generated: ${allTriplets.length}`);
181
+
182
+ // Save triplets
183
+ const dir = path.dirname(outputPath);
184
+ if (!fs.existsSync(dir)) {
185
+ fs.mkdirSync(dir, { recursive: true });
186
+ }
187
+
188
+ const jsonl = allTriplets.map(t => JSON.stringify(t)).join('\n');
189
+ fs.writeFileSync(outputPath, jsonl);
190
+ console.log(`Saved to: ${outputPath}`);
191
+
192
+ // Optional GRPO evaluation
193
+ if (doGRPO && allTriplets.length > 0) {
194
+ console.log('\n─────────────────────────────────────────────────────────────────');
195
+ console.log(' GRPO EVALUATION');
196
+ console.log('─────────────────────────────────────────────────────────────────\n');
197
+ await evaluateWithGRPO(allTriplets);
198
+ }
199
+
200
+ // Show sample
201
+ console.log('\n─────────────────────────────────────────────────────────────────');
202
+ console.log(' SAMPLE TRIPLETS');
203
+ console.log('─────────────────────────────────────────────────────────────────\n');
204
+
205
+ for (const triplet of allTriplets.slice(0, 5)) {
206
+ console.log(` Task: "${triplet.anchor}"`);
207
+ console.log(` → Correct: ${triplet.positive}, Wrong: ${triplet.negative}`);
208
+ console.log();
209
+ }
210
+
211
+ console.log('═══════════════════════════════════════════════════════════════════════════════════');
212
+ console.log(' NEXT STEPS');
213
+ console.log('═══════════════════════════════════════════════════════════════════════════════════\n');
214
+ console.log('1. Merge with existing triplets:');
215
+ console.log(` cat ~/.ruvllm/training/ruvltra-finetuned/triplets.jsonl ${outputPath} > combined.jsonl`);
216
+ console.log('\n2. Run training with enhanced data:');
217
+ console.log(' cargo run --example train_contrastive --release -- --triplets combined.jsonl --epochs 30');
218
+ console.log('\n3. Benchmark embedding-only accuracy improvement');
219
+ console.log();
220
+ }
221
+
222
+ main().catch(console.error);