ruvector 0.1.61 → 0.1.62
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/bin/cli.js +3 -0
- package/bin/mcp-server.js +3 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +4 -1
- package/dist/core/intelligence-engine.d.ts +21 -0
- package/dist/core/intelligence-engine.d.ts.map +1 -1
- package/dist/core/intelligence-engine.js +49 -0
- package/dist/core/onnx-embedder.d.ts +6 -1
- package/dist/core/onnx-embedder.d.ts.map +1 -1
- package/dist/core/onnx-embedder.js +22 -2
- package/dist/core/parallel-intelligence.d.ts +109 -0
- package/dist/core/parallel-intelligence.d.ts.map +1 -0
- package/dist/core/parallel-intelligence.js +340 -0
- package/package.json +1 -1
- package/ruvector.db +0 -0
package/bin/cli.js
CHANGED
package/bin/mcp-server.js
CHANGED
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
* claude mcp add ruvector npx ruvector mcp start
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
// Signal that this is an MCP server (enables parallel workers for embeddings)
|
|
15
|
+
process.env.MCP_SERVER = '1';
|
|
16
|
+
|
|
14
17
|
const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
|
|
15
18
|
const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
|
|
16
19
|
const {
|
package/dist/core/index.d.ts
CHANGED
|
@@ -10,10 +10,12 @@ export * from './agentdb-fast';
|
|
|
10
10
|
export * from './sona-wrapper';
|
|
11
11
|
export * from './intelligence-engine';
|
|
12
12
|
export * from './onnx-embedder';
|
|
13
|
+
export * from './parallel-intelligence';
|
|
13
14
|
export { default as gnnWrapper } from './gnn-wrapper';
|
|
14
15
|
export { default as attentionFallbacks } from './attention-fallbacks';
|
|
15
16
|
export { default as agentdbFast } from './agentdb-fast';
|
|
16
17
|
export { default as Sona } from './sona-wrapper';
|
|
17
18
|
export { default as IntelligenceEngine } from './intelligence-engine';
|
|
18
19
|
export { default as OnnxEmbedder } from './onnx-embedder';
|
|
20
|
+
export { default as ParallelIntelligence } from './parallel-intelligence';
|
|
19
21
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AAGxC,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -23,13 +23,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.OnnxEmbedder = exports.IntelligenceEngine = exports.Sona = exports.agentdbFast = exports.attentionFallbacks = exports.gnnWrapper = void 0;
|
|
26
|
+
exports.ParallelIntelligence = exports.OnnxEmbedder = exports.IntelligenceEngine = exports.Sona = exports.agentdbFast = exports.attentionFallbacks = exports.gnnWrapper = void 0;
|
|
27
27
|
__exportStar(require("./gnn-wrapper"), exports);
|
|
28
28
|
__exportStar(require("./attention-fallbacks"), exports);
|
|
29
29
|
__exportStar(require("./agentdb-fast"), exports);
|
|
30
30
|
__exportStar(require("./sona-wrapper"), exports);
|
|
31
31
|
__exportStar(require("./intelligence-engine"), exports);
|
|
32
32
|
__exportStar(require("./onnx-embedder"), exports);
|
|
33
|
+
__exportStar(require("./parallel-intelligence"), exports);
|
|
33
34
|
// Re-export default objects for convenience
|
|
34
35
|
var gnn_wrapper_1 = require("./gnn-wrapper");
|
|
35
36
|
Object.defineProperty(exports, "gnnWrapper", { enumerable: true, get: function () { return __importDefault(gnn_wrapper_1).default; } });
|
|
@@ -43,3 +44,5 @@ var intelligence_engine_1 = require("./intelligence-engine");
|
|
|
43
44
|
Object.defineProperty(exports, "IntelligenceEngine", { enumerable: true, get: function () { return __importDefault(intelligence_engine_1).default; } });
|
|
44
45
|
var onnx_embedder_1 = require("./onnx-embedder");
|
|
45
46
|
Object.defineProperty(exports, "OnnxEmbedder", { enumerable: true, get: function () { return __importDefault(onnx_embedder_1).default; } });
|
|
47
|
+
var parallel_intelligence_1 = require("./parallel-intelligence");
|
|
48
|
+
Object.defineProperty(exports, "ParallelIntelligence", { enumerable: true, get: function () { return __importDefault(parallel_intelligence_1).default; } });
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { EpisodeSearchResult } from './agentdb-fast';
|
|
14
14
|
import { SonaConfig, LearnedPattern } from './sona-wrapper';
|
|
15
|
+
import { ParallelConfig, BatchEpisode } from './parallel-intelligence';
|
|
15
16
|
export interface MemoryEntry {
|
|
16
17
|
id: string;
|
|
17
18
|
content: string;
|
|
@@ -48,6 +49,10 @@ export interface LearningStats {
|
|
|
48
49
|
coEditPatterns: number;
|
|
49
50
|
attentionEnabled: boolean;
|
|
50
51
|
onnxEnabled: boolean;
|
|
52
|
+
parallelEnabled: boolean;
|
|
53
|
+
parallelWorkers: number;
|
|
54
|
+
parallelBusy: number;
|
|
55
|
+
parallelQueued: number;
|
|
51
56
|
}
|
|
52
57
|
export interface IntelligenceConfig {
|
|
53
58
|
/** Embedding dimension for vectors (default: 256, 384 for ONNX) */
|
|
@@ -68,6 +73,11 @@ export interface IntelligenceConfig {
|
|
|
68
73
|
storagePath?: string;
|
|
69
74
|
/** Learning rate for pattern updates (default: 0.1) */
|
|
70
75
|
learningRate?: number;
|
|
76
|
+
/**
|
|
77
|
+
* Enable parallel workers for batch operations
|
|
78
|
+
* Auto-enabled for MCP servers, disabled for CLI hooks
|
|
79
|
+
*/
|
|
80
|
+
parallelConfig?: Partial<ParallelConfig>;
|
|
71
81
|
}
|
|
72
82
|
/**
|
|
73
83
|
* Full-stack intelligence engine using all RuVector capabilities
|
|
@@ -80,6 +90,7 @@ export declare class IntelligenceEngine {
|
|
|
80
90
|
private attention;
|
|
81
91
|
private onnxEmbedder;
|
|
82
92
|
private onnxReady;
|
|
93
|
+
private parallel;
|
|
83
94
|
private memories;
|
|
84
95
|
private routingPatterns;
|
|
85
96
|
private errorPatterns;
|
|
@@ -88,9 +99,11 @@ export declare class IntelligenceEngine {
|
|
|
88
99
|
private currentTrajectoryId;
|
|
89
100
|
private sessionStart;
|
|
90
101
|
private learningEnabled;
|
|
102
|
+
private episodeBatchQueue;
|
|
91
103
|
constructor(config?: IntelligenceConfig);
|
|
92
104
|
private initOnnx;
|
|
93
105
|
private initVectorDb;
|
|
106
|
+
private initParallel;
|
|
94
107
|
/**
|
|
95
108
|
* Generate embedding using ONNX, attention, or hash (in order of preference)
|
|
96
109
|
*/
|
|
@@ -146,6 +159,14 @@ export declare class IntelligenceEngine {
|
|
|
146
159
|
* Record an episode for learning
|
|
147
160
|
*/
|
|
148
161
|
recordEpisode(state: string, action: string, reward: number, nextState: string, done: boolean, metadata?: Record<string, any>): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Queue episode for batch processing (3-4x faster with workers)
|
|
164
|
+
*/
|
|
165
|
+
queueEpisode(episode: BatchEpisode): void;
|
|
166
|
+
/**
|
|
167
|
+
* Process queued episodes in parallel batch
|
|
168
|
+
*/
|
|
169
|
+
flushEpisodeBatch(): Promise<number>;
|
|
149
170
|
/**
|
|
150
171
|
* Learn from similar past episodes
|
|
151
172
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intelligence-engine.d.ts","sourceRoot":"","sources":["../../src/core/intelligence-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAoC,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACvF,OAAO,EAAc,UAAU,EAAE,cAAc,EAA8B,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"intelligence-engine.d.ts","sourceRoot":"","sources":["../../src/core/intelligence-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAoC,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACvF,OAAO,EAAc,UAAU,EAAE,cAAc,EAA8B,MAAM,gBAAgB,CAAC;AAEpG,OAAO,EAAwB,cAAc,EAAE,YAAY,EAA2B,MAAM,yBAAyB,CAAC;AAMtH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;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gB,2BAA2B,IAAI,kBAAkB,CAchE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,kBAAkB,CAQ5D;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -19,6 +19,7 @@ exports.createLightweightEngine = createLightweightEngine;
|
|
|
19
19
|
const agentdb_fast_1 = require("./agentdb-fast");
|
|
20
20
|
const sona_wrapper_1 = require("./sona-wrapper");
|
|
21
21
|
const onnx_embedder_1 = require("./onnx-embedder");
|
|
22
|
+
const parallel_intelligence_1 = require("./parallel-intelligence");
|
|
22
23
|
// ============================================================================
|
|
23
24
|
// Lazy Loading
|
|
24
25
|
// ============================================================================
|
|
@@ -75,6 +76,7 @@ class IntelligenceEngine {
|
|
|
75
76
|
this.attention = null;
|
|
76
77
|
this.onnxEmbedder = null;
|
|
77
78
|
this.onnxReady = false;
|
|
79
|
+
this.parallel = null;
|
|
78
80
|
// In-memory data structures
|
|
79
81
|
this.memories = new Map();
|
|
80
82
|
this.routingPatterns = new Map(); // state -> action -> value
|
|
@@ -85,6 +87,7 @@ class IntelligenceEngine {
|
|
|
85
87
|
this.currentTrajectoryId = null;
|
|
86
88
|
this.sessionStart = Date.now();
|
|
87
89
|
this.learningEnabled = true;
|
|
90
|
+
this.episodeBatchQueue = [];
|
|
88
91
|
// If ONNX is enabled, use 384 dimensions (MiniLM default)
|
|
89
92
|
const useOnnx = !!(config.enableOnnx && (0, onnx_embedder_1.isOnnxAvailable)());
|
|
90
93
|
const embeddingDim = useOnnx ? 384 : (config.embeddingDim ?? 256);
|
|
@@ -98,7 +101,11 @@ class IntelligenceEngine {
|
|
|
98
101
|
sonaConfig: config.sonaConfig ?? {},
|
|
99
102
|
storagePath: config.storagePath ?? '',
|
|
100
103
|
learningRate: config.learningRate ?? 0.1,
|
|
104
|
+
parallelConfig: config.parallelConfig ?? {},
|
|
101
105
|
};
|
|
106
|
+
// Initialize parallel workers (auto-enabled for MCP, disabled for CLI)
|
|
107
|
+
this.parallel = (0, parallel_intelligence_1.getParallelIntelligence)(this.config.parallelConfig);
|
|
108
|
+
this.initParallel();
|
|
102
109
|
// Initialize FastAgentDB for episode storage
|
|
103
110
|
this.agentDb = new agentdb_fast_1.FastAgentDB(this.config.embeddingDim, this.config.maxEpisodes);
|
|
104
111
|
// Initialize ONNX embedder if enabled
|
|
@@ -155,6 +162,17 @@ class IntelligenceEngine {
|
|
|
155
162
|
// VectorDB not available, use fallback
|
|
156
163
|
}
|
|
157
164
|
}
|
|
165
|
+
async initParallel() {
|
|
166
|
+
if (this.parallel) {
|
|
167
|
+
try {
|
|
168
|
+
await this.parallel.init();
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
// Parallel not available, use sequential
|
|
172
|
+
this.parallel = null;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
158
176
|
// =========================================================================
|
|
159
177
|
// Embedding Generation
|
|
160
178
|
// =========================================================================
|
|
@@ -580,6 +598,32 @@ class IntelligenceEngine {
|
|
|
580
598
|
const newValue = oldValue + this.config.learningRate * (reward - oldValue);
|
|
581
599
|
patterns.set(action, newValue);
|
|
582
600
|
}
|
|
601
|
+
/**
|
|
602
|
+
* Queue episode for batch processing (3-4x faster with workers)
|
|
603
|
+
*/
|
|
604
|
+
queueEpisode(episode) {
|
|
605
|
+
this.episodeBatchQueue.push(episode);
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Process queued episodes in parallel batch
|
|
609
|
+
*/
|
|
610
|
+
async flushEpisodeBatch() {
|
|
611
|
+
if (this.episodeBatchQueue.length === 0)
|
|
612
|
+
return 0;
|
|
613
|
+
const count = this.episodeBatchQueue.length;
|
|
614
|
+
if (this.parallel) {
|
|
615
|
+
// Use parallel workers for batch processing
|
|
616
|
+
await this.parallel.recordEpisodesBatch(this.episodeBatchQueue);
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
// Sequential fallback
|
|
620
|
+
for (const ep of this.episodeBatchQueue) {
|
|
621
|
+
await this.recordEpisode(ep.state, ep.action, ep.reward, ep.nextState, ep.done, ep.metadata);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
this.episodeBatchQueue = [];
|
|
625
|
+
return count;
|
|
626
|
+
}
|
|
583
627
|
/**
|
|
584
628
|
* Learn from similar past episodes
|
|
585
629
|
*/
|
|
@@ -713,6 +757,7 @@ class IntelligenceEngine {
|
|
|
713
757
|
rewardCount++;
|
|
714
758
|
}
|
|
715
759
|
}
|
|
760
|
+
const parallelStats = this.parallel?.getStats() ?? { enabled: false, workers: 0, busy: 0, queued: 0 };
|
|
716
761
|
return {
|
|
717
762
|
totalMemories: this.memories.size,
|
|
718
763
|
memoryDimensions: this.config.embeddingDim,
|
|
@@ -730,6 +775,10 @@ class IntelligenceEngine {
|
|
|
730
775
|
coEditPatterns: this.coEditPatterns.size,
|
|
731
776
|
attentionEnabled: this.attention !== null,
|
|
732
777
|
onnxEnabled: this.onnxReady,
|
|
778
|
+
parallelEnabled: parallelStats.enabled,
|
|
779
|
+
parallelWorkers: parallelStats.workers,
|
|
780
|
+
parallelBusy: parallelStats.busy,
|
|
781
|
+
parallelQueued: parallelStats.queued,
|
|
733
782
|
};
|
|
734
783
|
}
|
|
735
784
|
// =========================================================================
|
|
@@ -18,7 +18,12 @@ export interface OnnxEmbedderConfig {
|
|
|
18
18
|
maxLength?: number;
|
|
19
19
|
normalize?: boolean;
|
|
20
20
|
cacheDir?: string;
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Enable parallel workers for batch operations
|
|
23
|
+
* - 'auto' (default): Enable for long-running processes, skip for CLI
|
|
24
|
+
* - true: Always enable workers
|
|
25
|
+
* - false: Never use workers
|
|
26
|
+
*/
|
|
22
27
|
enableParallel?: boolean | 'auto';
|
|
23
28
|
/** Number of worker threads (default: CPU cores - 1) */
|
|
24
29
|
numWorkers?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onnx-embedder.d.ts","sourceRoot":"","sources":["../../src/core/onnx-embedder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAWH,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB
|
|
1
|
+
{"version":3,"file":"onnx-embedder.d.ts","sourceRoot":"","sources":["../../src/core/onnx-embedder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAWH,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAClC,wDAAwD;IACxD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iEAAiE;IACjE,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAMD,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAeD;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAOzC;AA6DD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,GAAE,kBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC,CA+FxF;AAED;;GAEG;AACH,wBAAsB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAiBlE;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,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
|
|
201
201
|
detectSimd();
|
|
202
202
|
console.error(`ONNX embedder ready: ${embedder.dimension()}d, SIMD: ${simdAvailable}`);
|
|
203
203
|
isInitialized = true;
|
|
204
|
-
//
|
|
205
|
-
|
|
204
|
+
// Determine if we should use parallel workers
|
|
205
|
+
// - true: always enable
|
|
206
|
+
// - false: never enable
|
|
207
|
+
// - 'auto'/undefined: enable for long-running processes (MCP, servers), skip for CLI
|
|
208
|
+
let shouldTryParallel = false;
|
|
209
|
+
if (config.enableParallel === true) {
|
|
210
|
+
shouldTryParallel = true;
|
|
211
|
+
}
|
|
212
|
+
else if (config.enableParallel === false) {
|
|
213
|
+
shouldTryParallel = false;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
// Auto-detect: check if running as CLI hook or long-running process
|
|
217
|
+
const isCLI = process.argv[1]?.includes('cli.js') ||
|
|
218
|
+
process.argv[1]?.includes('bin/ruvector') ||
|
|
219
|
+
process.env.RUVECTOR_CLI === '1';
|
|
220
|
+
const isMCP = process.env.MCP_SERVER === '1' ||
|
|
221
|
+
process.argv.some(a => a.includes('mcp'));
|
|
222
|
+
const forceParallel = process.env.RUVECTOR_PARALLEL === '1';
|
|
223
|
+
// Enable parallel for MCP/servers or if explicitly requested, skip for CLI
|
|
224
|
+
shouldTryParallel = forceParallel || (isMCP && !isCLI);
|
|
225
|
+
}
|
|
206
226
|
if (shouldTryParallel) {
|
|
207
227
|
await tryInitParallel(config);
|
|
208
228
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel Intelligence - Worker-based acceleration for IntelligenceEngine
|
|
3
|
+
*
|
|
4
|
+
* Provides parallel processing for:
|
|
5
|
+
* - Q-learning batch updates (3-4x faster)
|
|
6
|
+
* - Multi-file pattern matching
|
|
7
|
+
* - Background memory indexing
|
|
8
|
+
* - Parallel similarity search
|
|
9
|
+
* - Multi-file code analysis
|
|
10
|
+
* - Parallel git commit analysis
|
|
11
|
+
*
|
|
12
|
+
* Uses worker_threads for CPU-bound operations, keeping hooks non-blocking.
|
|
13
|
+
*/
|
|
14
|
+
export interface ParallelConfig {
|
|
15
|
+
/** Number of worker threads (default: CPU cores - 1) */
|
|
16
|
+
numWorkers?: number;
|
|
17
|
+
/** Enable parallel processing (default: true for MCP, false for CLI) */
|
|
18
|
+
enabled?: boolean;
|
|
19
|
+
/** Minimum batch size to use parallel (default: 4) */
|
|
20
|
+
batchThreshold?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface BatchEpisode {
|
|
23
|
+
state: string;
|
|
24
|
+
action: string;
|
|
25
|
+
reward: number;
|
|
26
|
+
nextState: string;
|
|
27
|
+
done: boolean;
|
|
28
|
+
metadata?: Record<string, any>;
|
|
29
|
+
}
|
|
30
|
+
export interface PatternMatchResult {
|
|
31
|
+
file: string;
|
|
32
|
+
patterns: Array<{
|
|
33
|
+
pattern: string;
|
|
34
|
+
confidence: number;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
export interface CoEditAnalysis {
|
|
38
|
+
file1: string;
|
|
39
|
+
file2: string;
|
|
40
|
+
commits: string[];
|
|
41
|
+
strength: number;
|
|
42
|
+
}
|
|
43
|
+
export declare class ParallelIntelligence {
|
|
44
|
+
private workers;
|
|
45
|
+
private taskQueue;
|
|
46
|
+
private busyWorkers;
|
|
47
|
+
private config;
|
|
48
|
+
private initialized;
|
|
49
|
+
constructor(config?: ParallelConfig);
|
|
50
|
+
/**
|
|
51
|
+
* Initialize worker pool
|
|
52
|
+
*/
|
|
53
|
+
init(): Promise<void>;
|
|
54
|
+
private processQueue;
|
|
55
|
+
/**
|
|
56
|
+
* Execute task in worker pool
|
|
57
|
+
*/
|
|
58
|
+
private executeInWorker;
|
|
59
|
+
/**
|
|
60
|
+
* Batch Q-learning episode recording (3-4x faster)
|
|
61
|
+
*/
|
|
62
|
+
recordEpisodesBatch(episodes: BatchEpisode[]): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Multi-file pattern matching (parallel pretrain)
|
|
65
|
+
*/
|
|
66
|
+
matchPatternsParallel(files: string[]): Promise<PatternMatchResult[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Background memory indexing (non-blocking)
|
|
69
|
+
*/
|
|
70
|
+
indexMemoriesBackground(memories: Array<{
|
|
71
|
+
content: string;
|
|
72
|
+
type: string;
|
|
73
|
+
}>): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Parallel similarity search with sharding
|
|
76
|
+
*/
|
|
77
|
+
searchParallel(query: string, topK?: number): Promise<Array<{
|
|
78
|
+
content: string;
|
|
79
|
+
score: number;
|
|
80
|
+
}>>;
|
|
81
|
+
/**
|
|
82
|
+
* Multi-file AST analysis for routing
|
|
83
|
+
*/
|
|
84
|
+
analyzeFilesParallel(files: string[]): Promise<Map<string, {
|
|
85
|
+
agent: string;
|
|
86
|
+
confidence: number;
|
|
87
|
+
}>>;
|
|
88
|
+
/**
|
|
89
|
+
* Parallel git commit analysis for co-edit detection
|
|
90
|
+
*/
|
|
91
|
+
analyzeCommitsParallel(commits: string[]): Promise<CoEditAnalysis[]>;
|
|
92
|
+
/**
|
|
93
|
+
* Get worker pool stats
|
|
94
|
+
*/
|
|
95
|
+
getStats(): {
|
|
96
|
+
enabled: boolean;
|
|
97
|
+
workers: number;
|
|
98
|
+
busy: number;
|
|
99
|
+
queued: number;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Shutdown worker pool
|
|
103
|
+
*/
|
|
104
|
+
shutdown(): Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
export declare function getParallelIntelligence(config?: ParallelConfig): ParallelIntelligence;
|
|
107
|
+
export declare function initParallelIntelligence(config?: ParallelConfig): Promise<ParallelIntelligence>;
|
|
108
|
+
export default ParallelIntelligence;
|
|
109
|
+
//# sourceMappingURL=parallel-intelligence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel-intelligence.d.ts","sourceRoot":"","sources":["../../src/core/parallel-intellig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
|
5
|
+
* Provides parallel processing for:
|
|
6
|
+
* - Q-learning batch updates (3-4x faster)
|
|
7
|
+
* - Multi-file pattern matching
|
|
8
|
+
* - Background memory indexing
|
|
9
|
+
* - Parallel similarity search
|
|
10
|
+
* - Multi-file code analysis
|
|
11
|
+
* - Parallel git commit analysis
|
|
12
|
+
*
|
|
13
|
+
* Uses worker_threads for CPU-bound operations, keeping hooks non-blocking.
|
|
14
|
+
*/
|
|
15
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
18
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
19
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(o, k2, desc);
|
|
22
|
+
}) : (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
o[k2] = m[k];
|
|
25
|
+
}));
|
|
26
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
27
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
28
|
+
}) : function(o, v) {
|
|
29
|
+
o["default"] = v;
|
|
30
|
+
});
|
|
31
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
32
|
+
var ownKeys = function(o) {
|
|
33
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
34
|
+
var ar = [];
|
|
35
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
36
|
+
return ar;
|
|
37
|
+
};
|
|
38
|
+
return ownKeys(o);
|
|
39
|
+
};
|
|
40
|
+
return function (mod) {
|
|
41
|
+
if (mod && mod.__esModule) return mod;
|
|
42
|
+
var result = {};
|
|
43
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
44
|
+
__setModuleDefault(result, mod);
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
})();
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.ParallelIntelligence = void 0;
|
|
50
|
+
exports.getParallelIntelligence = getParallelIntelligence;
|
|
51
|
+
exports.initParallelIntelligence = initParallelIntelligence;
|
|
52
|
+
const worker_threads_1 = require("worker_threads");
|
|
53
|
+
const os = __importStar(require("os"));
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// Worker Pool Manager
|
|
56
|
+
// ============================================================================
|
|
57
|
+
class ParallelIntelligence {
|
|
58
|
+
constructor(config = {}) {
|
|
59
|
+
this.workers = [];
|
|
60
|
+
this.taskQueue = [];
|
|
61
|
+
this.busyWorkers = new Set();
|
|
62
|
+
this.initialized = false;
|
|
63
|
+
const isCLI = process.env.RUVECTOR_CLI === '1';
|
|
64
|
+
const isMCP = process.env.MCP_SERVER === '1';
|
|
65
|
+
this.config = {
|
|
66
|
+
numWorkers: config.numWorkers ?? Math.max(1, os.cpus().length - 1),
|
|
67
|
+
enabled: config.enabled ?? (isMCP || (!isCLI && process.env.RUVECTOR_PARALLEL === '1')),
|
|
68
|
+
batchThreshold: config.batchThreshold ?? 4,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Initialize worker pool
|
|
73
|
+
*/
|
|
74
|
+
async init() {
|
|
75
|
+
if (this.initialized || !this.config.enabled)
|
|
76
|
+
return;
|
|
77
|
+
for (let i = 0; i < this.config.numWorkers; i++) {
|
|
78
|
+
const worker = new worker_threads_1.Worker(__filename, {
|
|
79
|
+
workerData: { workerId: i },
|
|
80
|
+
});
|
|
81
|
+
worker.on('message', (result) => {
|
|
82
|
+
this.busyWorkers.delete(worker);
|
|
83
|
+
this.processQueue();
|
|
84
|
+
});
|
|
85
|
+
worker.on('error', (err) => {
|
|
86
|
+
console.error(`Worker ${i} error:`, err);
|
|
87
|
+
this.busyWorkers.delete(worker);
|
|
88
|
+
});
|
|
89
|
+
this.workers.push(worker);
|
|
90
|
+
}
|
|
91
|
+
this.initialized = true;
|
|
92
|
+
console.error(`ParallelIntelligence: ${this.config.numWorkers} workers ready`);
|
|
93
|
+
}
|
|
94
|
+
processQueue() {
|
|
95
|
+
while (this.taskQueue.length > 0 && this.busyWorkers.size < this.workers.length) {
|
|
96
|
+
const availableWorker = this.workers.find(w => !this.busyWorkers.has(w));
|
|
97
|
+
if (!availableWorker)
|
|
98
|
+
break;
|
|
99
|
+
const task = this.taskQueue.shift();
|
|
100
|
+
this.busyWorkers.add(availableWorker);
|
|
101
|
+
availableWorker.postMessage(task.task);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Execute task in worker pool
|
|
106
|
+
*/
|
|
107
|
+
async executeInWorker(task) {
|
|
108
|
+
if (!this.initialized || !this.config.enabled) {
|
|
109
|
+
throw new Error('ParallelIntelligence not initialized');
|
|
110
|
+
}
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
const availableWorker = this.workers.find(w => !this.busyWorkers.has(w));
|
|
113
|
+
if (availableWorker) {
|
|
114
|
+
this.busyWorkers.add(availableWorker);
|
|
115
|
+
const handler = (result) => {
|
|
116
|
+
this.busyWorkers.delete(availableWorker);
|
|
117
|
+
availableWorker.off('message', handler);
|
|
118
|
+
if (result.error) {
|
|
119
|
+
reject(new Error(result.error));
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
resolve(result.data);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
availableWorker.on('message', handler);
|
|
126
|
+
availableWorker.postMessage(task);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
this.taskQueue.push({ task, resolve, reject });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
// =========================================================================
|
|
134
|
+
// Parallel Operations
|
|
135
|
+
// =========================================================================
|
|
136
|
+
/**
|
|
137
|
+
* Batch Q-learning episode recording (3-4x faster)
|
|
138
|
+
*/
|
|
139
|
+
async recordEpisodesBatch(episodes) {
|
|
140
|
+
if (episodes.length < this.config.batchThreshold || !this.config.enabled) {
|
|
141
|
+
// Fall back to sequential
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
// Split into chunks for workers
|
|
145
|
+
const chunkSize = Math.ceil(episodes.length / this.config.numWorkers);
|
|
146
|
+
const chunks = [];
|
|
147
|
+
for (let i = 0; i < episodes.length; i += chunkSize) {
|
|
148
|
+
chunks.push(episodes.slice(i, i + chunkSize));
|
|
149
|
+
}
|
|
150
|
+
await Promise.all(chunks.map(chunk => this.executeInWorker({ type: 'recordEpisodes', episodes: chunk })));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Multi-file pattern matching (parallel pretrain)
|
|
154
|
+
*/
|
|
155
|
+
async matchPatternsParallel(files) {
|
|
156
|
+
if (files.length < this.config.batchThreshold || !this.config.enabled) {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
const chunkSize = Math.ceil(files.length / this.config.numWorkers);
|
|
160
|
+
const chunks = [];
|
|
161
|
+
for (let i = 0; i < files.length; i += chunkSize) {
|
|
162
|
+
chunks.push(files.slice(i, i + chunkSize));
|
|
163
|
+
}
|
|
164
|
+
const results = await Promise.all(chunks.map(chunk => this.executeInWorker({ type: 'matchPatterns', files: chunk })));
|
|
165
|
+
return results.flat();
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Background memory indexing (non-blocking)
|
|
169
|
+
*/
|
|
170
|
+
async indexMemoriesBackground(memories) {
|
|
171
|
+
if (memories.length === 0 || !this.config.enabled)
|
|
172
|
+
return;
|
|
173
|
+
// Fire and forget - non-blocking
|
|
174
|
+
this.executeInWorker({ type: 'indexMemories', memories }).catch(() => { });
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Parallel similarity search with sharding
|
|
178
|
+
*/
|
|
179
|
+
async searchParallel(query, topK = 5) {
|
|
180
|
+
if (!this.config.enabled)
|
|
181
|
+
return [];
|
|
182
|
+
// Each worker searches its shard
|
|
183
|
+
const shardResults = await Promise.all(this.workers.map((_, i) => this.executeInWorker({
|
|
184
|
+
type: 'search',
|
|
185
|
+
query,
|
|
186
|
+
topK,
|
|
187
|
+
shardId: i,
|
|
188
|
+
})));
|
|
189
|
+
// Merge and sort results
|
|
190
|
+
return shardResults
|
|
191
|
+
.flat()
|
|
192
|
+
.sort((a, b) => b.score - a.score)
|
|
193
|
+
.slice(0, topK);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Multi-file AST analysis for routing
|
|
197
|
+
*/
|
|
198
|
+
async analyzeFilesParallel(files) {
|
|
199
|
+
if (files.length < this.config.batchThreshold || !this.config.enabled) {
|
|
200
|
+
return new Map();
|
|
201
|
+
}
|
|
202
|
+
const chunkSize = Math.ceil(files.length / this.config.numWorkers);
|
|
203
|
+
const chunks = [];
|
|
204
|
+
for (let i = 0; i < files.length; i += chunkSize) {
|
|
205
|
+
chunks.push(files.slice(i, i + chunkSize));
|
|
206
|
+
}
|
|
207
|
+
const results = await Promise.all(chunks.map(chunk => this.executeInWorker({
|
|
208
|
+
type: 'analyzeFiles',
|
|
209
|
+
files: chunk,
|
|
210
|
+
})));
|
|
211
|
+
return new Map(results.flat());
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Parallel git commit analysis for co-edit detection
|
|
215
|
+
*/
|
|
216
|
+
async analyzeCommitsParallel(commits) {
|
|
217
|
+
if (commits.length < this.config.batchThreshold || !this.config.enabled) {
|
|
218
|
+
return [];
|
|
219
|
+
}
|
|
220
|
+
const chunkSize = Math.ceil(commits.length / this.config.numWorkers);
|
|
221
|
+
const chunks = [];
|
|
222
|
+
for (let i = 0; i < commits.length; i += chunkSize) {
|
|
223
|
+
chunks.push(commits.slice(i, i + chunkSize));
|
|
224
|
+
}
|
|
225
|
+
const results = await Promise.all(chunks.map(chunk => this.executeInWorker({ type: 'analyzeCommits', commits: chunk })));
|
|
226
|
+
return results.flat();
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Get worker pool stats
|
|
230
|
+
*/
|
|
231
|
+
getStats() {
|
|
232
|
+
return {
|
|
233
|
+
enabled: this.config.enabled,
|
|
234
|
+
workers: this.workers.length,
|
|
235
|
+
busy: this.busyWorkers.size,
|
|
236
|
+
queued: this.taskQueue.length,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Shutdown worker pool
|
|
241
|
+
*/
|
|
242
|
+
async shutdown() {
|
|
243
|
+
await Promise.all(this.workers.map(w => w.terminate()));
|
|
244
|
+
this.workers = [];
|
|
245
|
+
this.busyWorkers.clear();
|
|
246
|
+
this.taskQueue = [];
|
|
247
|
+
this.initialized = false;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
exports.ParallelIntelligence = ParallelIntelligence;
|
|
251
|
+
// ============================================================================
|
|
252
|
+
// Worker Thread Code
|
|
253
|
+
// ============================================================================
|
|
254
|
+
if (!worker_threads_1.isMainThread && worker_threads_1.parentPort) {
|
|
255
|
+
// This code runs in worker threads
|
|
256
|
+
const { workerId } = worker_threads_1.workerData;
|
|
257
|
+
worker_threads_1.parentPort.on('message', async (task) => {
|
|
258
|
+
try {
|
|
259
|
+
let result;
|
|
260
|
+
switch (task.type) {
|
|
261
|
+
case 'recordEpisodes':
|
|
262
|
+
// Process episode batch
|
|
263
|
+
result = await processEpisodes(task.episodes);
|
|
264
|
+
break;
|
|
265
|
+
case 'matchPatterns':
|
|
266
|
+
// Match patterns in files
|
|
267
|
+
result = await matchPatterns(task.files);
|
|
268
|
+
break;
|
|
269
|
+
case 'indexMemories':
|
|
270
|
+
// Index memories
|
|
271
|
+
result = await indexMemories(task.memories);
|
|
272
|
+
break;
|
|
273
|
+
case 'search':
|
|
274
|
+
// Search shard
|
|
275
|
+
result = await searchShard(task.query, task.topK, task.shardId);
|
|
276
|
+
break;
|
|
277
|
+
case 'analyzeFiles':
|
|
278
|
+
// Analyze file ASTs
|
|
279
|
+
result = await analyzeFiles(task.files);
|
|
280
|
+
break;
|
|
281
|
+
case 'analyzeCommits':
|
|
282
|
+
// Analyze git commits
|
|
283
|
+
result = await analyzeCommits(task.commits);
|
|
284
|
+
break;
|
|
285
|
+
default:
|
|
286
|
+
throw new Error(`Unknown task type: ${task.type}`);
|
|
287
|
+
}
|
|
288
|
+
worker_threads_1.parentPort.postMessage({ data: result });
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
worker_threads_1.parentPort.postMessage({ error: error.message });
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
// Worker task implementations
|
|
295
|
+
async function processEpisodes(episodes) {
|
|
296
|
+
// Embed and process episodes
|
|
297
|
+
// In a real implementation, this would use the embedder and update Q-values
|
|
298
|
+
return episodes.length;
|
|
299
|
+
}
|
|
300
|
+
async function matchPatterns(files) {
|
|
301
|
+
// Match patterns in files
|
|
302
|
+
// Would read files and extract patterns
|
|
303
|
+
return files.map(file => ({
|
|
304
|
+
file,
|
|
305
|
+
patterns: [],
|
|
306
|
+
}));
|
|
307
|
+
}
|
|
308
|
+
async function indexMemories(memories) {
|
|
309
|
+
// Index memories in background
|
|
310
|
+
return memories.length;
|
|
311
|
+
}
|
|
312
|
+
async function searchShard(query, topK, shardId) {
|
|
313
|
+
// Search this worker's shard
|
|
314
|
+
return [];
|
|
315
|
+
}
|
|
316
|
+
async function analyzeFiles(files) {
|
|
317
|
+
// Analyze file ASTs
|
|
318
|
+
return files.map(f => [f, { agent: 'coder', confidence: 0.5 }]);
|
|
319
|
+
}
|
|
320
|
+
async function analyzeCommits(commits) {
|
|
321
|
+
// Analyze git commits for co-edit patterns
|
|
322
|
+
return [];
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
// ============================================================================
|
|
326
|
+
// Singleton for easy access
|
|
327
|
+
// ============================================================================
|
|
328
|
+
let instance = null;
|
|
329
|
+
function getParallelIntelligence(config) {
|
|
330
|
+
if (!instance) {
|
|
331
|
+
instance = new ParallelIntelligence(config);
|
|
332
|
+
}
|
|
333
|
+
return instance;
|
|
334
|
+
}
|
|
335
|
+
async function initParallelIntelligence(config) {
|
|
336
|
+
const pi = getParallelIntelligence(config);
|
|
337
|
+
await pi.init();
|
|
338
|
+
return pi;
|
|
339
|
+
}
|
|
340
|
+
exports.default = ParallelIntelligence;
|
package/package.json
CHANGED
package/ruvector.db
CHANGED
|
Binary file
|