ruvector 0.1.77 → 0.1.79

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.
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ /**
3
+ * Worker Benchmark Suite for RuVector
4
+ *
5
+ * Measures performance of:
6
+ * - ONNX embedding generation (single vs batch)
7
+ * - Vector storage and search
8
+ * - Phase execution times
9
+ * - Worker end-to-end throughput
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.benchmarkEmbeddings = benchmarkEmbeddings;
13
+ exports.benchmarkWorkers = benchmarkWorkers;
14
+ exports.benchmarkPhases = benchmarkPhases;
15
+ exports.formatBenchmarkResults = formatBenchmarkResults;
16
+ exports.runFullBenchmark = runFullBenchmark;
17
+ const perf_hooks_1 = require("perf_hooks");
18
+ const native_worker_1 = require("./native-worker");
19
+ const onnx_embedder_1 = require("../core/onnx-embedder");
20
+ /**
21
+ * Run a benchmark function multiple times and collect stats
22
+ */
23
+ async function runBenchmark(name, fn, iterations = 10, warmup = 2) {
24
+ // Warmup runs
25
+ for (let i = 0; i < warmup; i++) {
26
+ await fn();
27
+ }
28
+ // Actual benchmark runs
29
+ const times = [];
30
+ for (let i = 0; i < iterations; i++) {
31
+ const start = perf_hooks_1.performance.now();
32
+ await fn();
33
+ times.push(perf_hooks_1.performance.now() - start);
34
+ }
35
+ // Calculate statistics
36
+ times.sort((a, b) => a - b);
37
+ const sum = times.reduce((a, b) => a + b, 0);
38
+ return {
39
+ name,
40
+ iterations,
41
+ results: {
42
+ min: times[0],
43
+ max: times[times.length - 1],
44
+ avg: sum / times.length,
45
+ p50: times[Math.floor(times.length * 0.5)],
46
+ p95: times[Math.floor(times.length * 0.95)],
47
+ p99: times[Math.floor(times.length * 0.99)],
48
+ },
49
+ };
50
+ }
51
+ /**
52
+ * Benchmark ONNX embedding generation
53
+ */
54
+ async function benchmarkEmbeddings(iterations = 10) {
55
+ const results = [];
56
+ // Initialize embedder
57
+ await (0, onnx_embedder_1.initOnnxEmbedder)();
58
+ const stats = (0, onnx_embedder_1.getStats)();
59
+ console.log(`\nšŸ“Š ONNX Embedder: ${stats.dimension}d, SIMD: ${stats.simd}`);
60
+ // Single embedding benchmark
61
+ const singleResult = await runBenchmark('Single embedding (short text)', async () => {
62
+ await (0, onnx_embedder_1.embed)('This is a test sentence for embedding.');
63
+ }, iterations);
64
+ results.push(singleResult);
65
+ // Single embedding - long text
66
+ const longText = 'This is a much longer text that contains more content. '.repeat(20);
67
+ const singleLongResult = await runBenchmark('Single embedding (long text)', async () => {
68
+ await (0, onnx_embedder_1.embed)(longText);
69
+ }, iterations);
70
+ results.push(singleLongResult);
71
+ // Batch embedding - small batch
72
+ const smallBatch = Array(4).fill(0).map((_, i) => `Test sentence number ${i}`);
73
+ const batchSmallResult = await runBenchmark('Batch embedding (4 texts)', async () => {
74
+ await (0, onnx_embedder_1.embedBatch)(smallBatch);
75
+ }, iterations);
76
+ batchSmallResult.throughput = {
77
+ itemsPerSecond: (4 * 1000) / batchSmallResult.results.avg,
78
+ };
79
+ results.push(batchSmallResult);
80
+ // Batch embedding - medium batch
81
+ const mediumBatch = Array(16).fill(0).map((_, i) => `Test sentence number ${i} with some content`);
82
+ const batchMediumResult = await runBenchmark('Batch embedding (16 texts)', async () => {
83
+ await (0, onnx_embedder_1.embedBatch)(mediumBatch);
84
+ }, iterations);
85
+ batchMediumResult.throughput = {
86
+ itemsPerSecond: (16 * 1000) / batchMediumResult.results.avg,
87
+ };
88
+ results.push(batchMediumResult);
89
+ // Batch embedding - large batch
90
+ const largeBatch = Array(64).fill(0).map((_, i) => `Test sentence number ${i} with additional content here`);
91
+ const batchLargeResult = await runBenchmark('Batch embedding (64 texts)', async () => {
92
+ await (0, onnx_embedder_1.embedBatch)(largeBatch);
93
+ }, Math.min(iterations, 5) // Fewer iterations for large batches
94
+ );
95
+ batchLargeResult.throughput = {
96
+ itemsPerSecond: (64 * 1000) / batchLargeResult.results.avg,
97
+ };
98
+ results.push(batchLargeResult);
99
+ return results;
100
+ }
101
+ /**
102
+ * Benchmark worker execution
103
+ */
104
+ async function benchmarkWorkers(targetPath = '.') {
105
+ const results = [];
106
+ // Security worker (no embeddings - fastest)
107
+ const securityWorker = (0, native_worker_1.createSecurityWorker)();
108
+ const securityResult = await runBenchmark('Security worker (no embeddings)', async () => {
109
+ await securityWorker.run(targetPath);
110
+ }, 5, 1);
111
+ results.push(securityResult);
112
+ // Analysis worker (with embeddings)
113
+ const analysisWorker = (0, native_worker_1.createAnalysisWorker)();
114
+ const analysisResult = await runBenchmark('Analysis worker (with embeddings)', async () => {
115
+ await analysisWorker.run(targetPath);
116
+ }, 3, 1);
117
+ results.push(analysisResult);
118
+ return results;
119
+ }
120
+ /**
121
+ * Benchmark individual phases
122
+ */
123
+ async function benchmarkPhases(targetPath = '.') {
124
+ const results = [];
125
+ // File discovery phase only
126
+ const discoveryWorker = new native_worker_1.NativeWorker({
127
+ name: 'discovery-only',
128
+ phases: [{ type: 'file-discovery' }],
129
+ capabilities: {},
130
+ });
131
+ const discoveryResult = await runBenchmark('Phase: file-discovery', async () => {
132
+ await discoveryWorker.run(targetPath);
133
+ }, 10);
134
+ results.push(discoveryResult);
135
+ // Pattern extraction phase
136
+ const patternWorker = new native_worker_1.NativeWorker({
137
+ name: 'pattern-only',
138
+ phases: [{ type: 'file-discovery' }, { type: 'pattern-extraction' }],
139
+ capabilities: {},
140
+ });
141
+ const patternResult = await runBenchmark('Phase: pattern-extraction', async () => {
142
+ await patternWorker.run(targetPath);
143
+ }, 5);
144
+ results.push(patternResult);
145
+ // Embedding generation phase
146
+ const embeddingWorker = new native_worker_1.NativeWorker({
147
+ name: 'embedding-only',
148
+ phases: [
149
+ { type: 'file-discovery', config: { patterns: ['**/*.ts'], exclude: ['**/node_modules/**'] } },
150
+ { type: 'pattern-extraction' },
151
+ { type: 'embedding-generation' },
152
+ ],
153
+ capabilities: { onnxEmbeddings: true },
154
+ });
155
+ const embeddingResult = await runBenchmark('Phase: embedding-generation', async () => {
156
+ await embeddingWorker.run(targetPath);
157
+ }, 3, 1);
158
+ results.push(embeddingResult);
159
+ return results;
160
+ }
161
+ /**
162
+ * Format benchmark results as table
163
+ */
164
+ function formatBenchmarkResults(results) {
165
+ const lines = [];
166
+ lines.push('');
167
+ lines.push('ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”');
168
+ lines.push('│ Benchmark │ Min (ms) │ Avg (ms) │ P95 (ms) │ Max (ms) │ Throughput │');
169
+ lines.push('ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤');
170
+ for (const result of results) {
171
+ const name = result.name.padEnd(35).slice(0, 35);
172
+ const min = result.results.min.toFixed(1).padStart(8);
173
+ const avg = result.results.avg.toFixed(1).padStart(8);
174
+ const p95 = result.results.p95.toFixed(1).padStart(8);
175
+ const max = result.results.max.toFixed(1).padStart(8);
176
+ const throughput = result.throughput
177
+ ? `${result.throughput.itemsPerSecond.toFixed(1)}/s`.padStart(12)
178
+ : ' -';
179
+ lines.push(`│ ${name} │ ${min} │ ${avg} │ ${p95} │ ${max} │ ${throughput} │`);
180
+ }
181
+ lines.push('ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜');
182
+ lines.push('');
183
+ return lines.join('\n');
184
+ }
185
+ /**
186
+ * Run full benchmark suite
187
+ */
188
+ async function runFullBenchmark(targetPath = '.') {
189
+ console.log('šŸš€ RuVector Native Worker Benchmark Suite\n');
190
+ console.log('='.repeat(60));
191
+ // Embeddings benchmark
192
+ console.log('\nšŸ“Š Benchmarking ONNX Embeddings...');
193
+ const embeddings = await benchmarkEmbeddings(10);
194
+ console.log(formatBenchmarkResults(embeddings));
195
+ // Phases benchmark
196
+ console.log('\n⚔ Benchmarking Individual Phases...');
197
+ const phases = await benchmarkPhases(targetPath);
198
+ console.log(formatBenchmarkResults(phases));
199
+ // Workers benchmark
200
+ console.log('\nšŸ”§ Benchmarking Full Workers...');
201
+ const workers = await benchmarkWorkers(targetPath);
202
+ console.log(formatBenchmarkResults(workers));
203
+ // Summary
204
+ const stats = (0, onnx_embedder_1.getStats)();
205
+ const summary = `
206
+ RuVector Native Worker Benchmark Summary
207
+ ========================================
208
+ ONNX Model: all-MiniLM-L6-v2 (${stats.dimension}d)
209
+ SIMD: ${stats.simd ? 'Enabled āœ“' : 'Disabled'}
210
+ Parallel Workers: ${stats.parallel ? `${stats.parallelWorkers} workers` : 'Disabled'}
211
+
212
+ Embedding Performance:
213
+ Single: ${embeddings[0].results.avg.toFixed(1)}ms avg
214
+ Batch (16): ${embeddings[3].results.avg.toFixed(1)}ms avg (${embeddings[3].throughput?.itemsPerSecond.toFixed(0)}/s)
215
+ Batch (64): ${embeddings[4].results.avg.toFixed(1)}ms avg (${embeddings[4].throughput?.itemsPerSecond.toFixed(0)}/s)
216
+
217
+ Worker Performance:
218
+ Security scan: ${workers[0].results.avg.toFixed(0)}ms avg
219
+ Full analysis: ${workers[1].results.avg.toFixed(0)}ms avg
220
+ `;
221
+ console.log(summary);
222
+ return { embeddings, phases, workers, summary };
223
+ }
224
+ exports.default = {
225
+ benchmarkEmbeddings,
226
+ benchmarkWorkers,
227
+ benchmarkPhases,
228
+ runFullBenchmark,
229
+ formatBenchmarkResults,
230
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * RuVector Native Workers
3
+ *
4
+ * Deep integration with ONNX embeddings, VectorDB, and intelligence engine.
5
+ * No external dependencies - pure ruvector execution.
6
+ */
7
+ export * from './types';
8
+ export * from './native-worker';
9
+ export * from './benchmark';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workers/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * RuVector Native Workers
4
+ *
5
+ * Deep integration with ONNX embeddings, VectorDB, and intelligence engine.
6
+ * No external dependencies - pure ruvector execution.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ __exportStar(require("./types"), exports);
24
+ __exportStar(require("./native-worker"), exports);
25
+ __exportStar(require("./benchmark"), exports);
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Native Worker Runner for RuVector
3
+ *
4
+ * Direct integration with:
5
+ * - ONNX embedder (384d, SIMD-accelerated)
6
+ * - VectorDB (HNSW indexing)
7
+ * - Intelligence engine (Q-learning, memory)
8
+ *
9
+ * No delegation to external tools - pure ruvector execution.
10
+ */
11
+ import { WorkerConfig, WorkerResult } from './types';
12
+ /**
13
+ * Native Worker Runner
14
+ */
15
+ export declare class NativeWorker {
16
+ private config;
17
+ private vectorDb;
18
+ private findings;
19
+ private stats;
20
+ constructor(config: WorkerConfig);
21
+ /**
22
+ * Initialize worker with capabilities
23
+ */
24
+ init(): Promise<void>;
25
+ /**
26
+ * Run all phases in sequence
27
+ */
28
+ run(targetPath?: string): Promise<WorkerResult>;
29
+ /**
30
+ * Execute a single phase
31
+ */
32
+ private executePhase;
33
+ /**
34
+ * Phase: File Discovery
35
+ */
36
+ private phaseFileDiscovery;
37
+ /**
38
+ * Phase: Pattern Extraction
39
+ */
40
+ private phasePatternExtraction;
41
+ /**
42
+ * Phase: Embedding Generation (ONNX)
43
+ */
44
+ private phaseEmbeddingGeneration;
45
+ /**
46
+ * Phase: Vector Storage
47
+ */
48
+ private phaseVectorStorage;
49
+ /**
50
+ * Phase: Similarity Search
51
+ */
52
+ private phaseSimilaritySearch;
53
+ /**
54
+ * Phase: Security Scan
55
+ */
56
+ private phaseSecurityScan;
57
+ /**
58
+ * Phase: Complexity Analysis
59
+ */
60
+ private phaseComplexityAnalysis;
61
+ /**
62
+ * Phase: Summarization
63
+ */
64
+ private phaseSummarization;
65
+ /**
66
+ * Summarize phase data for results
67
+ */
68
+ private summarizePhaseData;
69
+ }
70
+ /**
71
+ * Quick worker factory functions
72
+ */
73
+ export declare function createSecurityWorker(name?: string): NativeWorker;
74
+ export declare function createAnalysisWorker(name?: string): NativeWorker;
75
+ export declare function createLearningWorker(name?: string): NativeWorker;
76
+ //# sourceMappingURL=native-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-worker.d.ts","sourceRoot":"","sources":["../../src/workers/native-worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,EACL,YAAY,EACZ,YAAY,EAKb,MAAM,SAAS,CAAC;AAuBjB;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,KAAK,CAKX;gBAEU,MAAM,EAAE,YAAY;IAIhC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAmB3B;;OAEG;IACG,GAAG,CAAC,UAAU,GAAE,MAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAiD1D;;OAEG;YACW,YAAY;IAmC1B;;OAEG;YACW,kBAAkB;IAqBhC;;OAEG;YACW,sBAAsB;IAoDpC;;OAEG;YACW,wBAAwB;IAgDtC;;OAEG;YACW,kBAAkB;IA8BhC;;OAEG;YACW,qBAAqB;IAoBnC;;OAEG;YACW,iBAAiB;IAyC/B;;OAEG;YACW,uBAAuB;IA0CrC;;OAEG;YACW,kBAAkB;IAqBhC;;OAEG;IACH,OAAO,CAAC,kBAAkB;CAsB3B;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,SAAqB,GAAG,YAAY,CAW5E;AAED,wBAAgB,oBAAoB,CAAC,IAAI,SAAkB,GAAG,YAAY,CAczE;AAED,wBAAgB,oBAAoB,CAAC,IAAI,SAAoB,GAAG,YAAY,CAa3E"}