@ruvector/ruvllm 2.5.6 → 2.5.7
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 +282 -282
- package/bin/cli.js +1020 -1020
- package/dist/cjs/benchmarks/embedding-benchmark.js +8 -8
- package/dist/cjs/benchmarks/index.js +5 -5
- package/dist/cjs/benchmarks/model-comparison.js +15 -25
- package/dist/cjs/benchmarks/routing-benchmark.js +5 -5
- package/dist/cjs/contrastive.js +78 -78
- package/dist/cjs/engine.js +13 -13
- package/dist/cjs/export.js +31 -31
- package/dist/cjs/federated.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/intelligence.js +8 -18
- package/dist/cjs/lora.js +1 -1
- package/dist/cjs/models.js +13 -23
- package/dist/cjs/native.js +5 -4
- package/dist/cjs/session.js +1 -1
- package/dist/cjs/simd.js +1 -1
- package/dist/cjs/sona.js +1 -1
- package/dist/cjs/streaming.d.ts +1 -0
- package/dist/cjs/streaming.d.ts.map +1 -1
- package/dist/cjs/streaming.js +3 -3
- package/dist/cjs/training.d.ts +32 -4
- package/dist/cjs/training.d.ts.map +1 -1
- package/dist/cjs/training.js +59 -9
- package/dist/cjs/types.js +1 -1
- package/dist/esm/benchmarks/embedding-benchmark.js +1 -1
- package/dist/esm/benchmarks/index.js +1 -1
- package/dist/esm/benchmarks/model-comparison.js +1 -1
- package/dist/esm/benchmarks/routing-benchmark.js +1 -1
- package/dist/esm/contrastive.js +70 -70
- package/dist/esm/engine.js +13 -13
- package/dist/esm/export.js +31 -31
- package/dist/esm/federated.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/intelligence.js +1 -1
- package/dist/esm/lora.js +1 -1
- package/dist/esm/models.js +1 -1
- package/dist/esm/native.js +1 -1
- package/dist/esm/session.js +1 -1
- package/dist/esm/simd.js +1 -1
- package/dist/esm/sona.js +1 -1
- package/dist/esm/streaming.d.ts +1 -0
- package/dist/esm/streaming.d.ts.map +1 -1
- package/dist/esm/streaming.js +1 -1
- package/dist/esm/training.d.ts +32 -4
- package/dist/esm/training.d.ts.map +1 -1
- package/dist/esm/training.js +59 -9
- package/dist/esm/types.js +1 -1
- package/package.json +133 -133
- package/scripts/ensemble-model-compare.js +287 -287
- package/scripts/huggingface/README.md +537 -537
- package/scripts/huggingface/publish.sh +112 -112
- package/scripts/hybrid-model-compare.js +373 -373
- package/scripts/improved-model-compare.js +288 -288
- package/scripts/optimized-model-compare.js +364 -364
- package/scripts/real-model-compare.js +280 -280
- package/scripts/training/agentic-flow-capabilities.json +329 -329
- package/scripts/training/claude-code-synth.js +505 -505
- package/scripts/training/claude-flow-capabilities.json +1322 -1322
- package/scripts/training/claude-hard-negatives.js +222 -222
- package/scripts/training/contrastive-finetune.js +517 -517
- package/scripts/training/ecosystem-triplets.jsonl +1466 -1466
- package/scripts/training/generate-ecosystem-triplets.js +1324 -1324
- package/scripts/training/routing-dataset.js +634 -634
- package/scripts/training/ruvector-capabilities.json +798 -798
- package/scripts/training/validate-ecosystem.js +381 -381
- package/scripts/training/validation-results.json +22 -22
|
@@ -1,280 +1,280 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Real Model Comparison - Qwen 0.5B vs RuvLTRA Claude Code
|
|
4
|
-
*
|
|
5
|
-
* Uses llama-embedding for actual model inference.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const { execSync } = require('child_process');
|
|
9
|
-
const { existsSync } = require('fs');
|
|
10
|
-
const { join } = require('path');
|
|
11
|
-
const { homedir } = require('os');
|
|
12
|
-
|
|
13
|
-
// Model paths
|
|
14
|
-
const MODELS_DIR = join(homedir(), '.ruvllm', 'models');
|
|
15
|
-
const QWEN_MODEL = join(MODELS_DIR, 'qwen2.5-0.5b-instruct-q4_k_m.gguf');
|
|
16
|
-
const RUVLTRA_MODEL = join(MODELS_DIR, 'ruvltra-claude-code-0.5b-q4_k_m.gguf');
|
|
17
|
-
|
|
18
|
-
// Agent descriptions for routing
|
|
19
|
-
const AGENT_DESCRIPTIONS = {
|
|
20
|
-
coder: 'implement create write build add code function class component feature',
|
|
21
|
-
researcher: 'research find investigate analyze explore search discover examine',
|
|
22
|
-
reviewer: 'review check evaluate assess inspect examine code quality',
|
|
23
|
-
tester: 'test unit integration e2e coverage mock assertion spec',
|
|
24
|
-
architect: 'design architecture schema system structure plan database',
|
|
25
|
-
'security-architect': 'security vulnerability xss injection audit cve authentication',
|
|
26
|
-
debugger: 'debug fix bug error issue broken crash exception trace',
|
|
27
|
-
documenter: 'document readme jsdoc comment explain describe documentation',
|
|
28
|
-
refactorer: 'refactor extract rename consolidate clean restructure simplify',
|
|
29
|
-
optimizer: 'optimize performance slow fast cache speed memory latency',
|
|
30
|
-
devops: 'deploy ci cd kubernetes docker pipeline container infrastructure',
|
|
31
|
-
'api-docs': 'openapi swagger api documentation graphql schema endpoint',
|
|
32
|
-
planner: 'plan estimate prioritize sprint roadmap schedule milestone',
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// Test cases for routing
|
|
36
|
-
const ROUTING_TESTS = [
|
|
37
|
-
{ task: 'Implement a binary search function in TypeScript', expected: 'coder' },
|
|
38
|
-
{ task: 'Write unit tests for the authentication module', expected: 'tester' },
|
|
39
|
-
{ task: 'Review the pull request for security vulnerabilities', expected: 'reviewer' },
|
|
40
|
-
{ task: 'Research best practices for React state management', expected: 'researcher' },
|
|
41
|
-
{ task: 'Design the database schema for user profiles', expected: 'architect' },
|
|
42
|
-
{ task: 'Fix the null pointer exception in the login handler', expected: 'debugger' },
|
|
43
|
-
{ task: 'Audit the API endpoints for XSS vulnerabilities', expected: 'security-architect' },
|
|
44
|
-
{ task: 'Write JSDoc comments for the utility functions', expected: 'documenter' },
|
|
45
|
-
{ task: 'Refactor the payment module to use async/await', expected: 'refactorer' },
|
|
46
|
-
{ task: 'Optimize the database queries for the dashboard', expected: 'optimizer' },
|
|
47
|
-
{ task: 'Set up the CI/CD pipeline for the microservices', expected: 'devops' },
|
|
48
|
-
{ task: 'Generate OpenAPI documentation for the REST API', expected: 'api-docs' },
|
|
49
|
-
{ task: 'Create a sprint plan for the next two weeks', expected: 'planner' },
|
|
50
|
-
{ task: 'Build a React component for user registration', expected: 'coder' },
|
|
51
|
-
{ task: 'Debug memory leak in the WebSocket handler', expected: 'debugger' },
|
|
52
|
-
{ task: 'Investigate slow API response times', expected: 'researcher' },
|
|
53
|
-
{ task: 'Check code for potential race conditions', expected: 'reviewer' },
|
|
54
|
-
{ task: 'Add integration tests for the payment gateway', expected: 'tester' },
|
|
55
|
-
{ task: 'Plan the architecture for real-time notifications', expected: 'architect' },
|
|
56
|
-
{ task: 'Cache the frequently accessed user data', expected: 'optimizer' },
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
// Similarity test pairs
|
|
60
|
-
const SIMILARITY_TESTS = [
|
|
61
|
-
{ text1: 'implement user authentication', text2: 'create login functionality', expected: 'high' },
|
|
62
|
-
{ text1: 'write unit tests', text2: 'fix database bug', expected: 'low' },
|
|
63
|
-
{ text1: 'optimize query performance', text2: 'improve database speed', expected: 'high' },
|
|
64
|
-
{ text1: 'design system architecture', text2: 'plan software structure', expected: 'high' },
|
|
65
|
-
{ text1: 'deploy to kubernetes', text2: 'analyze user behavior', expected: 'low' },
|
|
66
|
-
{ text1: 'refactor legacy code', text2: 'restructure old module', expected: 'high' },
|
|
67
|
-
{ text1: 'debug memory leak', text2: 'fix memory consumption issue', expected: 'high' },
|
|
68
|
-
{ text1: 'document api endpoints', text2: 'write openapi spec', expected: 'high' },
|
|
69
|
-
];
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Get embedding from model using llama-embedding
|
|
73
|
-
*/
|
|
74
|
-
function getEmbedding(modelPath, text) {
|
|
75
|
-
try {
|
|
76
|
-
const sanitized = text.replace(/"/g, '\\"').replace(/\n/g, ' ');
|
|
77
|
-
const result = execSync(
|
|
78
|
-
`llama-embedding -m "${modelPath}" -p "${sanitized}" --embd-output-format json 2>/dev/null`,
|
|
79
|
-
{ encoding: 'utf-8', maxBuffer: 10 * 1024 * 1024 }
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const json = JSON.parse(result);
|
|
83
|
-
// Return the last embedding (the full prompt embedding)
|
|
84
|
-
return json.data[json.data.length - 1].embedding;
|
|
85
|
-
} catch (err) {
|
|
86
|
-
console.error(`Error getting embedding: ${err.message}`);
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Compute cosine similarity
|
|
93
|
-
*/
|
|
94
|
-
function cosineSimilarity(a, b) {
|
|
95
|
-
if (!a || !b || a.length !== b.length) return 0;
|
|
96
|
-
|
|
97
|
-
let dot = 0, normA = 0, normB = 0;
|
|
98
|
-
for (let i = 0; i < a.length; i++) {
|
|
99
|
-
dot += a[i] * b[i];
|
|
100
|
-
normA += a[i] * a[i];
|
|
101
|
-
normB += b[i] * b[i];
|
|
102
|
-
}
|
|
103
|
-
return dot / (Math.sqrt(normA) * Math.sqrt(normB) || 1);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Route task to agent using embedding similarity
|
|
108
|
-
*/
|
|
109
|
-
function routeTask(taskEmbedding, agentEmbeddings) {
|
|
110
|
-
let bestAgent = 'coder';
|
|
111
|
-
let bestSimilarity = -1;
|
|
112
|
-
|
|
113
|
-
for (const [agent, embedding] of Object.entries(agentEmbeddings)) {
|
|
114
|
-
const sim = cosineSimilarity(taskEmbedding, embedding);
|
|
115
|
-
if (sim > bestSimilarity) {
|
|
116
|
-
bestSimilarity = sim;
|
|
117
|
-
bestAgent = agent;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return { agent: bestAgent, confidence: bestSimilarity };
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Run routing benchmark for a model
|
|
126
|
-
*/
|
|
127
|
-
function runRoutingBenchmark(modelPath, modelName) {
|
|
128
|
-
console.log(`\n Computing agent embeddings for ${modelName}...`);
|
|
129
|
-
|
|
130
|
-
// Pre-compute agent embeddings
|
|
131
|
-
const agentEmbeddings = {};
|
|
132
|
-
for (const [agent, description] of Object.entries(AGENT_DESCRIPTIONS)) {
|
|
133
|
-
process.stdout.write(` ${agent}... `);
|
|
134
|
-
agentEmbeddings[agent] = getEmbedding(modelPath, description);
|
|
135
|
-
console.log('done');
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
console.log(` Running routing tests...`);
|
|
139
|
-
let correct = 0;
|
|
140
|
-
const results = [];
|
|
141
|
-
|
|
142
|
-
for (const test of ROUTING_TESTS) {
|
|
143
|
-
process.stdout.write(` "${test.task.slice(0, 40)}..." `);
|
|
144
|
-
const taskEmbedding = getEmbedding(modelPath, test.task);
|
|
145
|
-
const { agent, confidence } = routeTask(taskEmbedding, agentEmbeddings);
|
|
146
|
-
const isCorrect = agent === test.expected;
|
|
147
|
-
if (isCorrect) correct++;
|
|
148
|
-
console.log(`${agent} (expected: ${test.expected}) ${isCorrect ? '✓' : '✗'}`);
|
|
149
|
-
results.push({ task: test.task, expected: test.expected, actual: agent, correct: isCorrect, confidence });
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const accuracy = correct / ROUTING_TESTS.length;
|
|
153
|
-
return { accuracy, correct, total: ROUTING_TESTS.length, results };
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Run similarity benchmark for a model
|
|
158
|
-
*/
|
|
159
|
-
function runSimilarityBenchmark(modelPath, modelName) {
|
|
160
|
-
console.log(`\n Running similarity tests for ${modelName}...`);
|
|
161
|
-
|
|
162
|
-
let correct = 0;
|
|
163
|
-
const results = [];
|
|
164
|
-
|
|
165
|
-
for (const test of SIMILARITY_TESTS) {
|
|
166
|
-
process.stdout.write(` "${test.text1}" vs "${test.text2}"... `);
|
|
167
|
-
|
|
168
|
-
const emb1 = getEmbedding(modelPath, test.text1);
|
|
169
|
-
const emb2 = getEmbedding(modelPath, test.text2);
|
|
170
|
-
const similarity = cosineSimilarity(emb1, emb2);
|
|
171
|
-
|
|
172
|
-
// Threshold: > 0.7 is high, < 0.5 is low
|
|
173
|
-
const predicted = similarity > 0.6 ? 'high' : 'low';
|
|
174
|
-
const isCorrect = predicted === test.expected;
|
|
175
|
-
if (isCorrect) correct++;
|
|
176
|
-
|
|
177
|
-
console.log(`${(similarity * 100).toFixed(1)}% (${predicted}, expected: ${test.expected}) ${isCorrect ? '✓' : '✗'}`);
|
|
178
|
-
results.push({ text1: test.text1, text2: test.text2, similarity, predicted, expected: test.expected, correct: isCorrect });
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const accuracy = correct / SIMILARITY_TESTS.length;
|
|
182
|
-
return { accuracy, correct, total: SIMILARITY_TESTS.length, results };
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Main comparison
|
|
187
|
-
*/
|
|
188
|
-
async function main() {
|
|
189
|
-
console.log('\n╔═══════════════════════════════════════════════════════════════════════════════════╗');
|
|
190
|
-
console.log('║ REAL MODEL COMPARISON: Qwen 0.5B vs RuvLTRA Claude Code ║');
|
|
191
|
-
console.log('║ Using llama-embedding inference ║');
|
|
192
|
-
console.log('╚═══════════════════════════════════════════════════════════════════════════════════╝\n');
|
|
193
|
-
|
|
194
|
-
// Check models exist
|
|
195
|
-
if (!existsSync(QWEN_MODEL)) {
|
|
196
|
-
console.error(`Qwen model not found at: ${QWEN_MODEL}`);
|
|
197
|
-
console.error('Download with: curl -L -o ~/.ruvllm/models/qwen2.5-0.5b-instruct-q4_k_m.gguf "https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf"');
|
|
198
|
-
process.exit(1);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (!existsSync(RUVLTRA_MODEL)) {
|
|
202
|
-
console.error(`RuvLTRA model not found at: ${RUVLTRA_MODEL}`);
|
|
203
|
-
console.error('Download with: ruvllm models download claude-code');
|
|
204
|
-
process.exit(1);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
console.log('Models found:');
|
|
208
|
-
console.log(` Qwen: ${QWEN_MODEL}`);
|
|
209
|
-
console.log(` RuvLTRA: ${RUVLTRA_MODEL}`);
|
|
210
|
-
|
|
211
|
-
// Run benchmarks for both models
|
|
212
|
-
console.log('\n─────────────────────────────────────────────────────────────────');
|
|
213
|
-
console.log(' QWEN 0.5B BASE MODEL');
|
|
214
|
-
console.log('─────────────────────────────────────────────────────────────────');
|
|
215
|
-
|
|
216
|
-
const qwenRouting = runRoutingBenchmark(QWEN_MODEL, 'Qwen 0.5B');
|
|
217
|
-
const qwenSimilarity = runSimilarityBenchmark(QWEN_MODEL, 'Qwen 0.5B');
|
|
218
|
-
|
|
219
|
-
console.log('\n─────────────────────────────────────────────────────────────────');
|
|
220
|
-
console.log(' RUVLTRA CLAUDE CODE MODEL');
|
|
221
|
-
console.log('─────────────────────────────────────────────────────────────────');
|
|
222
|
-
|
|
223
|
-
const ruvltraRouting = runRoutingBenchmark(RUVLTRA_MODEL, 'RuvLTRA Claude Code');
|
|
224
|
-
const ruvltraSimilarity = runSimilarityBenchmark(RUVLTRA_MODEL, 'RuvLTRA Claude Code');
|
|
225
|
-
|
|
226
|
-
// Results summary
|
|
227
|
-
console.log('\n═══════════════════════════════════════════════════════════════════════════════════');
|
|
228
|
-
console.log(' COMPARISON RESULTS');
|
|
229
|
-
console.log('═══════════════════════════════════════════════════════════════════════════════════\n');
|
|
230
|
-
|
|
231
|
-
console.log('┌─────────────────────────────┬───────────────┬───────────────┐');
|
|
232
|
-
console.log('│ Metric │ Qwen Base │ RuvLTRA │');
|
|
233
|
-
console.log('├─────────────────────────────┼───────────────┼───────────────┤');
|
|
234
|
-
|
|
235
|
-
const qwenRoutingPct = `${(qwenRouting.accuracy * 100).toFixed(1)}%`;
|
|
236
|
-
const ruvltraRoutingPct = `${(ruvltraRouting.accuracy * 100).toFixed(1)}%`;
|
|
237
|
-
const routingWinner = ruvltraRouting.accuracy > qwenRouting.accuracy ? '✓' : ' ';
|
|
238
|
-
const routingLoser = qwenRouting.accuracy > ruvltraRouting.accuracy ? '✓' : ' ';
|
|
239
|
-
console.log(`│ Routing Accuracy │${routingLoser}${qwenRoutingPct.padStart(12)} │${routingWinner}${ruvltraRoutingPct.padStart(12)} │`);
|
|
240
|
-
|
|
241
|
-
const qwenSimPct = `${(qwenSimilarity.accuracy * 100).toFixed(1)}%`;
|
|
242
|
-
const ruvltraSimPct = `${(ruvltraSimilarity.accuracy * 100).toFixed(1)}%`;
|
|
243
|
-
const simWinner = ruvltraSimilarity.accuracy > qwenSimilarity.accuracy ? '✓' : ' ';
|
|
244
|
-
const simLoser = qwenSimilarity.accuracy > ruvltraSimilarity.accuracy ? '✓' : ' ';
|
|
245
|
-
console.log(`│ Similarity Detection │${simLoser}${qwenSimPct.padStart(12)} │${simWinner}${ruvltraSimPct.padStart(12)} │`);
|
|
246
|
-
|
|
247
|
-
// Overall score
|
|
248
|
-
const qwenOverall = (qwenRouting.accuracy * 0.6 + qwenSimilarity.accuracy * 0.4);
|
|
249
|
-
const ruvltraOverall = (ruvltraRouting.accuracy * 0.6 + ruvltraSimilarity.accuracy * 0.4);
|
|
250
|
-
const qwenOverallPct = `${(qwenOverall * 100).toFixed(1)}%`;
|
|
251
|
-
const ruvltraOverallPct = `${(ruvltraOverall * 100).toFixed(1)}%`;
|
|
252
|
-
const overallWinner = ruvltraOverall > qwenOverall ? '✓' : ' ';
|
|
253
|
-
const overallLoser = qwenOverall > ruvltraOverall ? '✓' : ' ';
|
|
254
|
-
console.log('├─────────────────────────────┼───────────────┼───────────────┤');
|
|
255
|
-
console.log(`│ Overall Score (60/40) │${overallLoser}${qwenOverallPct.padStart(12)} │${overallWinner}${ruvltraOverallPct.padStart(12)} │`);
|
|
256
|
-
|
|
257
|
-
console.log('└─────────────────────────────┴───────────────┴───────────────┘');
|
|
258
|
-
|
|
259
|
-
// Winner announcement
|
|
260
|
-
const winner = ruvltraOverall > qwenOverall ? 'RuvLTRA Claude Code' : 'Qwen 0.5B Base';
|
|
261
|
-
const improvement = Math.abs(ruvltraOverall - qwenOverall) * 100;
|
|
262
|
-
|
|
263
|
-
console.log('\n═══════════════════════════════════════════════════════════════════════════════════');
|
|
264
|
-
console.log(` WINNER: ${winner}`);
|
|
265
|
-
console.log('═══════════════════════════════════════════════════════════════════════════════════');
|
|
266
|
-
|
|
267
|
-
if (ruvltraOverall > qwenOverall) {
|
|
268
|
-
console.log(`\n RuvLTRA outperforms Qwen base by ${improvement.toFixed(1)} percentage points.`);
|
|
269
|
-
console.log(' Fine-tuning for Claude Code workflows provides measurable improvements.');
|
|
270
|
-
} else if (qwenOverall > ruvltraOverall) {
|
|
271
|
-
console.log(`\n Qwen base outperforms RuvLTRA by ${improvement.toFixed(1)} percentage points.`);
|
|
272
|
-
console.log(' Consider additional fine-tuning or different training approach.');
|
|
273
|
-
} else {
|
|
274
|
-
console.log('\n Both models perform equally. Fine-tuning may need adjustment.');
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
console.log('\n');
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
main().catch(console.error);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Real Model Comparison - Qwen 0.5B vs RuvLTRA Claude Code
|
|
4
|
+
*
|
|
5
|
+
* Uses llama-embedding for actual model inference.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { execSync } = require('child_process');
|
|
9
|
+
const { existsSync } = require('fs');
|
|
10
|
+
const { join } = require('path');
|
|
11
|
+
const { homedir } = require('os');
|
|
12
|
+
|
|
13
|
+
// Model paths
|
|
14
|
+
const MODELS_DIR = join(homedir(), '.ruvllm', 'models');
|
|
15
|
+
const QWEN_MODEL = join(MODELS_DIR, 'qwen2.5-0.5b-instruct-q4_k_m.gguf');
|
|
16
|
+
const RUVLTRA_MODEL = join(MODELS_DIR, 'ruvltra-claude-code-0.5b-q4_k_m.gguf');
|
|
17
|
+
|
|
18
|
+
// Agent descriptions for routing
|
|
19
|
+
const AGENT_DESCRIPTIONS = {
|
|
20
|
+
coder: 'implement create write build add code function class component feature',
|
|
21
|
+
researcher: 'research find investigate analyze explore search discover examine',
|
|
22
|
+
reviewer: 'review check evaluate assess inspect examine code quality',
|
|
23
|
+
tester: 'test unit integration e2e coverage mock assertion spec',
|
|
24
|
+
architect: 'design architecture schema system structure plan database',
|
|
25
|
+
'security-architect': 'security vulnerability xss injection audit cve authentication',
|
|
26
|
+
debugger: 'debug fix bug error issue broken crash exception trace',
|
|
27
|
+
documenter: 'document readme jsdoc comment explain describe documentation',
|
|
28
|
+
refactorer: 'refactor extract rename consolidate clean restructure simplify',
|
|
29
|
+
optimizer: 'optimize performance slow fast cache speed memory latency',
|
|
30
|
+
devops: 'deploy ci cd kubernetes docker pipeline container infrastructure',
|
|
31
|
+
'api-docs': 'openapi swagger api documentation graphql schema endpoint',
|
|
32
|
+
planner: 'plan estimate prioritize sprint roadmap schedule milestone',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Test cases for routing
|
|
36
|
+
const ROUTING_TESTS = [
|
|
37
|
+
{ task: 'Implement a binary search function in TypeScript', expected: 'coder' },
|
|
38
|
+
{ task: 'Write unit tests for the authentication module', expected: 'tester' },
|
|
39
|
+
{ task: 'Review the pull request for security vulnerabilities', expected: 'reviewer' },
|
|
40
|
+
{ task: 'Research best practices for React state management', expected: 'researcher' },
|
|
41
|
+
{ task: 'Design the database schema for user profiles', expected: 'architect' },
|
|
42
|
+
{ task: 'Fix the null pointer exception in the login handler', expected: 'debugger' },
|
|
43
|
+
{ task: 'Audit the API endpoints for XSS vulnerabilities', expected: 'security-architect' },
|
|
44
|
+
{ task: 'Write JSDoc comments for the utility functions', expected: 'documenter' },
|
|
45
|
+
{ task: 'Refactor the payment module to use async/await', expected: 'refactorer' },
|
|
46
|
+
{ task: 'Optimize the database queries for the dashboard', expected: 'optimizer' },
|
|
47
|
+
{ task: 'Set up the CI/CD pipeline for the microservices', expected: 'devops' },
|
|
48
|
+
{ task: 'Generate OpenAPI documentation for the REST API', expected: 'api-docs' },
|
|
49
|
+
{ task: 'Create a sprint plan for the next two weeks', expected: 'planner' },
|
|
50
|
+
{ task: 'Build a React component for user registration', expected: 'coder' },
|
|
51
|
+
{ task: 'Debug memory leak in the WebSocket handler', expected: 'debugger' },
|
|
52
|
+
{ task: 'Investigate slow API response times', expected: 'researcher' },
|
|
53
|
+
{ task: 'Check code for potential race conditions', expected: 'reviewer' },
|
|
54
|
+
{ task: 'Add integration tests for the payment gateway', expected: 'tester' },
|
|
55
|
+
{ task: 'Plan the architecture for real-time notifications', expected: 'architect' },
|
|
56
|
+
{ task: 'Cache the frequently accessed user data', expected: 'optimizer' },
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
// Similarity test pairs
|
|
60
|
+
const SIMILARITY_TESTS = [
|
|
61
|
+
{ text1: 'implement user authentication', text2: 'create login functionality', expected: 'high' },
|
|
62
|
+
{ text1: 'write unit tests', text2: 'fix database bug', expected: 'low' },
|
|
63
|
+
{ text1: 'optimize query performance', text2: 'improve database speed', expected: 'high' },
|
|
64
|
+
{ text1: 'design system architecture', text2: 'plan software structure', expected: 'high' },
|
|
65
|
+
{ text1: 'deploy to kubernetes', text2: 'analyze user behavior', expected: 'low' },
|
|
66
|
+
{ text1: 'refactor legacy code', text2: 'restructure old module', expected: 'high' },
|
|
67
|
+
{ text1: 'debug memory leak', text2: 'fix memory consumption issue', expected: 'high' },
|
|
68
|
+
{ text1: 'document api endpoints', text2: 'write openapi spec', expected: 'high' },
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Get embedding from model using llama-embedding
|
|
73
|
+
*/
|
|
74
|
+
function getEmbedding(modelPath, text) {
|
|
75
|
+
try {
|
|
76
|
+
const sanitized = text.replace(/"/g, '\\"').replace(/\n/g, ' ');
|
|
77
|
+
const result = execSync(
|
|
78
|
+
`llama-embedding -m "${modelPath}" -p "${sanitized}" --embd-output-format json 2>/dev/null`,
|
|
79
|
+
{ encoding: 'utf-8', maxBuffer: 10 * 1024 * 1024 }
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const json = JSON.parse(result);
|
|
83
|
+
// Return the last embedding (the full prompt embedding)
|
|
84
|
+
return json.data[json.data.length - 1].embedding;
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.error(`Error getting embedding: ${err.message}`);
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Compute cosine similarity
|
|
93
|
+
*/
|
|
94
|
+
function cosineSimilarity(a, b) {
|
|
95
|
+
if (!a || !b || a.length !== b.length) return 0;
|
|
96
|
+
|
|
97
|
+
let dot = 0, normA = 0, normB = 0;
|
|
98
|
+
for (let i = 0; i < a.length; i++) {
|
|
99
|
+
dot += a[i] * b[i];
|
|
100
|
+
normA += a[i] * a[i];
|
|
101
|
+
normB += b[i] * b[i];
|
|
102
|
+
}
|
|
103
|
+
return dot / (Math.sqrt(normA) * Math.sqrt(normB) || 1);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Route task to agent using embedding similarity
|
|
108
|
+
*/
|
|
109
|
+
function routeTask(taskEmbedding, agentEmbeddings) {
|
|
110
|
+
let bestAgent = 'coder';
|
|
111
|
+
let bestSimilarity = -1;
|
|
112
|
+
|
|
113
|
+
for (const [agent, embedding] of Object.entries(agentEmbeddings)) {
|
|
114
|
+
const sim = cosineSimilarity(taskEmbedding, embedding);
|
|
115
|
+
if (sim > bestSimilarity) {
|
|
116
|
+
bestSimilarity = sim;
|
|
117
|
+
bestAgent = agent;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return { agent: bestAgent, confidence: bestSimilarity };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Run routing benchmark for a model
|
|
126
|
+
*/
|
|
127
|
+
function runRoutingBenchmark(modelPath, modelName) {
|
|
128
|
+
console.log(`\n Computing agent embeddings for ${modelName}...`);
|
|
129
|
+
|
|
130
|
+
// Pre-compute agent embeddings
|
|
131
|
+
const agentEmbeddings = {};
|
|
132
|
+
for (const [agent, description] of Object.entries(AGENT_DESCRIPTIONS)) {
|
|
133
|
+
process.stdout.write(` ${agent}... `);
|
|
134
|
+
agentEmbeddings[agent] = getEmbedding(modelPath, description);
|
|
135
|
+
console.log('done');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
console.log(` Running routing tests...`);
|
|
139
|
+
let correct = 0;
|
|
140
|
+
const results = [];
|
|
141
|
+
|
|
142
|
+
for (const test of ROUTING_TESTS) {
|
|
143
|
+
process.stdout.write(` "${test.task.slice(0, 40)}..." `);
|
|
144
|
+
const taskEmbedding = getEmbedding(modelPath, test.task);
|
|
145
|
+
const { agent, confidence } = routeTask(taskEmbedding, agentEmbeddings);
|
|
146
|
+
const isCorrect = agent === test.expected;
|
|
147
|
+
if (isCorrect) correct++;
|
|
148
|
+
console.log(`${agent} (expected: ${test.expected}) ${isCorrect ? '✓' : '✗'}`);
|
|
149
|
+
results.push({ task: test.task, expected: test.expected, actual: agent, correct: isCorrect, confidence });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const accuracy = correct / ROUTING_TESTS.length;
|
|
153
|
+
return { accuracy, correct, total: ROUTING_TESTS.length, results };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Run similarity benchmark for a model
|
|
158
|
+
*/
|
|
159
|
+
function runSimilarityBenchmark(modelPath, modelName) {
|
|
160
|
+
console.log(`\n Running similarity tests for ${modelName}...`);
|
|
161
|
+
|
|
162
|
+
let correct = 0;
|
|
163
|
+
const results = [];
|
|
164
|
+
|
|
165
|
+
for (const test of SIMILARITY_TESTS) {
|
|
166
|
+
process.stdout.write(` "${test.text1}" vs "${test.text2}"... `);
|
|
167
|
+
|
|
168
|
+
const emb1 = getEmbedding(modelPath, test.text1);
|
|
169
|
+
const emb2 = getEmbedding(modelPath, test.text2);
|
|
170
|
+
const similarity = cosineSimilarity(emb1, emb2);
|
|
171
|
+
|
|
172
|
+
// Threshold: > 0.7 is high, < 0.5 is low
|
|
173
|
+
const predicted = similarity > 0.6 ? 'high' : 'low';
|
|
174
|
+
const isCorrect = predicted === test.expected;
|
|
175
|
+
if (isCorrect) correct++;
|
|
176
|
+
|
|
177
|
+
console.log(`${(similarity * 100).toFixed(1)}% (${predicted}, expected: ${test.expected}) ${isCorrect ? '✓' : '✗'}`);
|
|
178
|
+
results.push({ text1: test.text1, text2: test.text2, similarity, predicted, expected: test.expected, correct: isCorrect });
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const accuracy = correct / SIMILARITY_TESTS.length;
|
|
182
|
+
return { accuracy, correct, total: SIMILARITY_TESTS.length, results };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Main comparison
|
|
187
|
+
*/
|
|
188
|
+
async function main() {
|
|
189
|
+
console.log('\n╔═══════════════════════════════════════════════════════════════════════════════════╗');
|
|
190
|
+
console.log('║ REAL MODEL COMPARISON: Qwen 0.5B vs RuvLTRA Claude Code ║');
|
|
191
|
+
console.log('║ Using llama-embedding inference ║');
|
|
192
|
+
console.log('╚═══════════════════════════════════════════════════════════════════════════════════╝\n');
|
|
193
|
+
|
|
194
|
+
// Check models exist
|
|
195
|
+
if (!existsSync(QWEN_MODEL)) {
|
|
196
|
+
console.error(`Qwen model not found at: ${QWEN_MODEL}`);
|
|
197
|
+
console.error('Download with: curl -L -o ~/.ruvllm/models/qwen2.5-0.5b-instruct-q4_k_m.gguf "https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf"');
|
|
198
|
+
process.exit(1);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (!existsSync(RUVLTRA_MODEL)) {
|
|
202
|
+
console.error(`RuvLTRA model not found at: ${RUVLTRA_MODEL}`);
|
|
203
|
+
console.error('Download with: ruvllm models download claude-code');
|
|
204
|
+
process.exit(1);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
console.log('Models found:');
|
|
208
|
+
console.log(` Qwen: ${QWEN_MODEL}`);
|
|
209
|
+
console.log(` RuvLTRA: ${RUVLTRA_MODEL}`);
|
|
210
|
+
|
|
211
|
+
// Run benchmarks for both models
|
|
212
|
+
console.log('\n─────────────────────────────────────────────────────────────────');
|
|
213
|
+
console.log(' QWEN 0.5B BASE MODEL');
|
|
214
|
+
console.log('─────────────────────────────────────────────────────────────────');
|
|
215
|
+
|
|
216
|
+
const qwenRouting = runRoutingBenchmark(QWEN_MODEL, 'Qwen 0.5B');
|
|
217
|
+
const qwenSimilarity = runSimilarityBenchmark(QWEN_MODEL, 'Qwen 0.5B');
|
|
218
|
+
|
|
219
|
+
console.log('\n─────────────────────────────────────────────────────────────────');
|
|
220
|
+
console.log(' RUVLTRA CLAUDE CODE MODEL');
|
|
221
|
+
console.log('─────────────────────────────────────────────────────────────────');
|
|
222
|
+
|
|
223
|
+
const ruvltraRouting = runRoutingBenchmark(RUVLTRA_MODEL, 'RuvLTRA Claude Code');
|
|
224
|
+
const ruvltraSimilarity = runSimilarityBenchmark(RUVLTRA_MODEL, 'RuvLTRA Claude Code');
|
|
225
|
+
|
|
226
|
+
// Results summary
|
|
227
|
+
console.log('\n═══════════════════════════════════════════════════════════════════════════════════');
|
|
228
|
+
console.log(' COMPARISON RESULTS');
|
|
229
|
+
console.log('═══════════════════════════════════════════════════════════════════════════════════\n');
|
|
230
|
+
|
|
231
|
+
console.log('┌─────────────────────────────┬───────────────┬───────────────┐');
|
|
232
|
+
console.log('│ Metric │ Qwen Base │ RuvLTRA │');
|
|
233
|
+
console.log('├─────────────────────────────┼───────────────┼───────────────┤');
|
|
234
|
+
|
|
235
|
+
const qwenRoutingPct = `${(qwenRouting.accuracy * 100).toFixed(1)}%`;
|
|
236
|
+
const ruvltraRoutingPct = `${(ruvltraRouting.accuracy * 100).toFixed(1)}%`;
|
|
237
|
+
const routingWinner = ruvltraRouting.accuracy > qwenRouting.accuracy ? '✓' : ' ';
|
|
238
|
+
const routingLoser = qwenRouting.accuracy > ruvltraRouting.accuracy ? '✓' : ' ';
|
|
239
|
+
console.log(`│ Routing Accuracy │${routingLoser}${qwenRoutingPct.padStart(12)} │${routingWinner}${ruvltraRoutingPct.padStart(12)} │`);
|
|
240
|
+
|
|
241
|
+
const qwenSimPct = `${(qwenSimilarity.accuracy * 100).toFixed(1)}%`;
|
|
242
|
+
const ruvltraSimPct = `${(ruvltraSimilarity.accuracy * 100).toFixed(1)}%`;
|
|
243
|
+
const simWinner = ruvltraSimilarity.accuracy > qwenSimilarity.accuracy ? '✓' : ' ';
|
|
244
|
+
const simLoser = qwenSimilarity.accuracy > ruvltraSimilarity.accuracy ? '✓' : ' ';
|
|
245
|
+
console.log(`│ Similarity Detection │${simLoser}${qwenSimPct.padStart(12)} │${simWinner}${ruvltraSimPct.padStart(12)} │`);
|
|
246
|
+
|
|
247
|
+
// Overall score
|
|
248
|
+
const qwenOverall = (qwenRouting.accuracy * 0.6 + qwenSimilarity.accuracy * 0.4);
|
|
249
|
+
const ruvltraOverall = (ruvltraRouting.accuracy * 0.6 + ruvltraSimilarity.accuracy * 0.4);
|
|
250
|
+
const qwenOverallPct = `${(qwenOverall * 100).toFixed(1)}%`;
|
|
251
|
+
const ruvltraOverallPct = `${(ruvltraOverall * 100).toFixed(1)}%`;
|
|
252
|
+
const overallWinner = ruvltraOverall > qwenOverall ? '✓' : ' ';
|
|
253
|
+
const overallLoser = qwenOverall > ruvltraOverall ? '✓' : ' ';
|
|
254
|
+
console.log('├─────────────────────────────┼───────────────┼───────────────┤');
|
|
255
|
+
console.log(`│ Overall Score (60/40) │${overallLoser}${qwenOverallPct.padStart(12)} │${overallWinner}${ruvltraOverallPct.padStart(12)} │`);
|
|
256
|
+
|
|
257
|
+
console.log('└─────────────────────────────┴───────────────┴───────────────┘');
|
|
258
|
+
|
|
259
|
+
// Winner announcement
|
|
260
|
+
const winner = ruvltraOverall > qwenOverall ? 'RuvLTRA Claude Code' : 'Qwen 0.5B Base';
|
|
261
|
+
const improvement = Math.abs(ruvltraOverall - qwenOverall) * 100;
|
|
262
|
+
|
|
263
|
+
console.log('\n═══════════════════════════════════════════════════════════════════════════════════');
|
|
264
|
+
console.log(` WINNER: ${winner}`);
|
|
265
|
+
console.log('═══════════════════════════════════════════════════════════════════════════════════');
|
|
266
|
+
|
|
267
|
+
if (ruvltraOverall > qwenOverall) {
|
|
268
|
+
console.log(`\n RuvLTRA outperforms Qwen base by ${improvement.toFixed(1)} percentage points.`);
|
|
269
|
+
console.log(' Fine-tuning for Claude Code workflows provides measurable improvements.');
|
|
270
|
+
} else if (qwenOverall > ruvltraOverall) {
|
|
271
|
+
console.log(`\n Qwen base outperforms RuvLTRA by ${improvement.toFixed(1)} percentage points.`);
|
|
272
|
+
console.log(' Consider additional fine-tuning or different training approach.');
|
|
273
|
+
} else {
|
|
274
|
+
console.log('\n Both models perform equally. Fine-tuning may need adjustment.');
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
console.log('\n');
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
main().catch(console.error);
|