agentdb 2.0.0-alpha.1 → 2.0.0-alpha.2

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 (208) hide show
  1. package/dist/agentdb.min.js +4 -4
  2. package/dist/simulation/cli.js +0 -0
  3. package/dist/src/cli/lib/config-manager.d.ts.map +1 -1
  4. package/dist/src/cli/lib/config-manager.js.map +1 -1
  5. package/dist/src/cli/lib/history-tracker.d.ts.map +1 -1
  6. package/dist/src/cli/lib/history-tracker.js +7 -1
  7. package/dist/src/cli/lib/history-tracker.js.map +1 -1
  8. package/examples/README.md +105 -0
  9. package/examples/quickstart.js +43 -0
  10. package/package.json +6 -2
  11. package/simulation/.claude-flow/metrics/agent-metrics.json +1 -0
  12. package/simulation/.claude-flow/metrics/performance.json +87 -0
  13. package/simulation/.claude-flow/metrics/task-metrics.json +10 -0
  14. package/simulation/COMPLETION-STATUS.md +139 -0
  15. package/simulation/FINAL-RESULTS.md +414 -0
  16. package/simulation/FINAL-STATUS.md +281 -0
  17. package/simulation/INTEGRATION-COMPLETE.md +452 -0
  18. package/simulation/MIGRATION-STATUS.md +231 -0
  19. package/simulation/OPTIMIZATION-RESULTS.md +397 -0
  20. package/simulation/PHASE1-COMPLETE.md +163 -0
  21. package/simulation/README.md +848 -0
  22. package/simulation/SIMULATION-RESULTS.md +239 -0
  23. package/simulation/cli.ts +78 -0
  24. package/simulation/configs/default.json +37 -0
  25. package/simulation/data/advanced/aidefence.graph +0 -0
  26. package/simulation/data/advanced/bmssp.graph +0 -0
  27. package/simulation/data/advanced/consciousness.graph +0 -0
  28. package/simulation/data/advanced/goalie.graph +0 -0
  29. package/simulation/data/advanced/psycho-symbolic.graph +0 -0
  30. package/simulation/data/advanced/research-swarm.graph +0 -0
  31. package/simulation/data/advanced/sublinear.graph +0 -0
  32. package/simulation/data/advanced/temporal.graph +0 -0
  33. package/simulation/data/causal.graph +0 -0
  34. package/simulation/data/graph-traversal.graph +0 -0
  35. package/simulation/data/lean-agentic.graph +0 -0
  36. package/simulation/data/reflexion.graph +0 -0
  37. package/simulation/data/skills.graph +0 -0
  38. package/simulation/data/stock-market.graph +0 -0
  39. package/simulation/data/strange-loops.graph +0 -0
  40. package/simulation/data/swarm.graph +0 -0
  41. package/simulation/data/voting-consensus.graph +0 -0
  42. package/simulation/docs/CLI-INTEGRATION-PLAN.md +1038 -0
  43. package/simulation/docs/COMPREHENSIVE-LATENT-SPACE-COMPLETION.md +354 -0
  44. package/simulation/docs/DOCUMENTATION-INDEX.md +226 -0
  45. package/simulation/docs/IMPLEMENTATION-COMPLETE.md +521 -0
  46. package/simulation/docs/OPTIMIZATION-SUMMARY.md +279 -0
  47. package/simulation/docs/README.md +229 -0
  48. package/simulation/docs/SWARM-5-INTEGRATION-SUMMARY.md +528 -0
  49. package/simulation/docs/TESTING-SUMMARY.md +304 -0
  50. package/simulation/docs/architecture/EXTENSION-API.md +868 -0
  51. package/simulation/docs/architecture/INTEGRATION-ARCHITECTURE.md +1138 -0
  52. package/simulation/docs/architecture/OPTIMIZATION-STRATEGY.md +778 -0
  53. package/simulation/docs/architecture/SIMULATION-ARCHITECTURE.md +892 -0
  54. package/simulation/docs/guides/CLI-REFERENCE.md +896 -0
  55. package/simulation/docs/guides/CUSTOM-SIMULATIONS.md +931 -0
  56. package/simulation/docs/guides/DEPLOYMENT.md +832 -0
  57. package/simulation/docs/guides/IMPLEMENTATION-SUMMARY.md +544 -0
  58. package/simulation/docs/guides/MIGRATION-GUIDE.md +591 -0
  59. package/simulation/docs/guides/QUICK-START.md +361 -0
  60. package/simulation/docs/guides/README.md +736 -0
  61. package/simulation/docs/guides/TROUBLESHOOTING.md +817 -0
  62. package/simulation/docs/guides/WIZARD-GUIDE.md +869 -0
  63. package/simulation/docs/reports/latent-space/MASTER-SYNTHESIS.md +345 -0
  64. package/simulation/docs/reports/latent-space/README.md +132 -0
  65. package/simulation/docs/reports/latent-space/attention-analysis-RESULTS.md +238 -0
  66. package/simulation/docs/reports/latent-space/clustering-analysis-RESULTS.md +210 -0
  67. package/simulation/docs/reports/latent-space/hnsw-exploration-RESULTS.md +332 -0
  68. package/simulation/docs/reports/latent-space/hypergraph-exploration-RESULTS.md +37 -0
  69. package/simulation/docs/reports/latent-space/neural-augmentation-RESULTS.md +69 -0
  70. package/simulation/docs/reports/latent-space/quantum-hybrid-RESULTS.md +91 -0
  71. package/simulation/docs/reports/latent-space/self-organizing-hnsw-RESULTS.md +51 -0
  72. package/simulation/docs/reports/latent-space/traversal-optimization-RESULTS.md +238 -0
  73. package/simulation/reports/README.md +397 -0
  74. package/simulation/reports/advanced-simulations-performance.md +1241 -0
  75. package/simulation/reports/aidefence-integration-2025-11-30T01-36-53-486Z.json +30 -0
  76. package/simulation/reports/architecture-analysis.md +1396 -0
  77. package/simulation/reports/basic-scenarios-performance.md +1840 -0
  78. package/simulation/reports/bmssp-integration-2025-11-30T01-36-27-193Z.json +30 -0
  79. package/simulation/reports/bmssp-integration-2025-11-30T03-38-12-887Z.json +30 -0
  80. package/simulation/reports/causal-reasoning-2025-11-29T23-35-21-795Z.json +36 -0
  81. package/simulation/reports/causal-reasoning-2025-11-30T00-58-42-862Z.json +30 -0
  82. package/simulation/reports/causal-reasoning-2025-11-30T00-59-12-546Z.json +40 -0
  83. package/simulation/reports/consciousness-explorer-2025-11-30T01-36-51-269Z.json +31 -0
  84. package/simulation/reports/core-benchmarks.md +727 -0
  85. package/simulation/reports/goalie-integration-2025-11-30T01-36-52-377Z.json +30 -0
  86. package/simulation/reports/graph-traversal-2025-11-29T23-35-35-279Z.json +78 -0
  87. package/simulation/reports/graph-traversal-2025-11-29T23-37-36-697Z.json +30 -0
  88. package/simulation/reports/graph-traversal-2025-11-30T01-03-59-716Z.json +30 -0
  89. package/simulation/reports/graph-traversal-2025-11-30T01-05-10-984Z.json +30 -0
  90. package/simulation/reports/graph-traversal-2025-11-30T01-06-16-334Z.json +30 -0
  91. package/simulation/reports/graph-traversal-2025-11-30T01-06-53-312Z.json +30 -0
  92. package/simulation/reports/graph-traversal-2025-11-30T01-07-51-075Z.json +24 -0
  93. package/simulation/reports/graph-traversal-2025-11-30T01-08-22-179Z.json +42 -0
  94. package/simulation/reports/lean-agentic-swarm-2025-11-29T23-37-23-804Z.json +148 -0
  95. package/simulation/reports/lean-agentic-swarm-2025-11-30T01-31-24-401Z.json +31 -0
  96. package/simulation/reports/lean-agentic-swarm-2025-11-30T03-38-01-470Z.json +31 -0
  97. package/simulation/reports/multi-agent-swarm-2025-11-29T23-35-28-093Z.json +78 -0
  98. package/simulation/reports/multi-agent-swarm-2025-11-30T01-03-54-062Z.json +42 -0
  99. package/simulation/reports/multi-agent-swarm-2025-11-30T01-05-06-092Z.json +42 -0
  100. package/simulation/reports/psycho-symbolic-reasoner-2025-11-30T01-36-50-180Z.json +30 -0
  101. package/simulation/reports/quality-metrics.md +727 -0
  102. package/simulation/reports/reflexion-learning-2025-11-29T23-35-09-774Z.json +48 -0
  103. package/simulation/reports/reflexion-learning-2025-11-29T23-37-16-934Z.json +36 -0
  104. package/simulation/reports/reflexion-learning-2025-11-30T00-07-49-259Z.json +30 -0
  105. package/simulation/reports/reflexion-learning-2025-11-30T00-09-29-319Z.json +51 -0
  106. package/simulation/reports/reflexion-learning-2025-11-30T00-28-37-659Z.json +51 -0
  107. package/simulation/reports/reflexion-learning-2025-11-30T01-31-30-690Z.json +29 -0
  108. package/simulation/reports/reflexion-learning-2025-11-30T03-38-06-937Z.json +29 -0
  109. package/simulation/reports/research-foundations.md +2004 -0
  110. package/simulation/reports/research-swarm-2025-11-30T01-36-54-647Z.json +30 -0
  111. package/simulation/reports/scalability-deployment.md +2404 -0
  112. package/simulation/reports/skill-evolution-2025-11-29T23-35-15-945Z.json +36 -0
  113. package/simulation/reports/skill-evolution-2025-11-30T01-03-17-995Z.json +30 -0
  114. package/simulation/reports/skill-evolution-2025-11-30T01-03-48-441Z.json +30 -0
  115. package/simulation/reports/skill-evolution-2025-11-30T01-05-00-554Z.json +30 -0
  116. package/simulation/reports/skill-evolution-2025-11-30T01-06-11-436Z.json +30 -0
  117. package/simulation/reports/skill-evolution-2025-11-30T01-06-51-979Z.json +30 -0
  118. package/simulation/reports/skill-evolution-2025-11-30T01-07-32-695Z.json +40 -0
  119. package/simulation/reports/stock-market-emergence-2025-11-30T00-11-43-865Z.json +56 -0
  120. package/simulation/reports/stock-market-emergence-2025-11-30T00-28-57-495Z.json +56 -0
  121. package/simulation/reports/strange-loops-2025-11-29T23-37-30-621Z.json +78 -0
  122. package/simulation/reports/strange-loops-2025-11-30T00-07-55-415Z.json +30 -0
  123. package/simulation/reports/strange-loops-2025-11-30T00-09-35-133Z.json +30 -0
  124. package/simulation/reports/strange-loops-2025-11-30T00-48-50-744Z.json +24 -0
  125. package/simulation/reports/strange-loops-2025-11-30T00-54-48-044Z.json +24 -0
  126. package/simulation/reports/strange-loops-2025-11-30T00-57-27-633Z.json +24 -0
  127. package/simulation/reports/strange-loops-2025-11-30T00-57-59-135Z.json +42 -0
  128. package/simulation/reports/sublinear-solver-2025-11-30T01-36-33-134Z.json +30 -0
  129. package/simulation/reports/temporal-lead-solver-2025-11-30T01-36-38-628Z.json +30 -0
  130. package/simulation/reports/use-cases-applications.md +2212 -0
  131. package/simulation/reports/voting-system-consensus-2025-11-30T00-11-37-199Z.json +58 -0
  132. package/simulation/reports/voting-system-consensus-2025-11-30T00-28-47-735Z.json +58 -0
  133. package/simulation/runner.ts +300 -0
  134. package/simulation/scenarios/README-advanced/aidefence-integration.md +63 -0
  135. package/simulation/scenarios/README-advanced/bmssp-integration.md +58 -0
  136. package/simulation/scenarios/README-advanced/consciousness-explorer.md +53 -0
  137. package/simulation/scenarios/README-advanced/goalie-integration.md +61 -0
  138. package/simulation/scenarios/README-advanced/psycho-symbolic-reasoner.md +55 -0
  139. package/simulation/scenarios/README-advanced/research-swarm.md +63 -0
  140. package/simulation/scenarios/README-advanced/sublinear-solver.md +58 -0
  141. package/simulation/scenarios/README-advanced/temporal-lead-solver.md +55 -0
  142. package/simulation/scenarios/README-basic/causal-reasoning.md +39 -0
  143. package/simulation/scenarios/README-basic/graph-traversal.md +41 -0
  144. package/simulation/scenarios/README-basic/lean-agentic-swarm.md +122 -0
  145. package/simulation/scenarios/README-basic/multi-agent-swarm.md +34 -0
  146. package/simulation/scenarios/README-basic/reflexion-learning.md +41 -0
  147. package/simulation/scenarios/README-basic/skill-evolution.md +38 -0
  148. package/simulation/scenarios/README-basic/stock-market-emergence.md +28 -0
  149. package/simulation/scenarios/README-basic/strange-loops.md +36 -0
  150. package/simulation/scenarios/README-basic/voting-system-consensus.md +28 -0
  151. package/simulation/scenarios/README.md +438 -0
  152. package/simulation/scenarios/aidefence-integration.ts +165 -0
  153. package/simulation/scenarios/bmssp-integration.ts +137 -0
  154. package/simulation/scenarios/causal-reasoning.ts +143 -0
  155. package/simulation/scenarios/consciousness-explorer.ts +139 -0
  156. package/simulation/scenarios/domain-examples/.claude-flow/metrics/agent-metrics.json +1 -0
  157. package/simulation/scenarios/domain-examples/.claude-flow/metrics/performance.json +87 -0
  158. package/simulation/scenarios/domain-examples/.claude-flow/metrics/task-metrics.json +10 -0
  159. package/simulation/scenarios/domain-examples/README.md +525 -0
  160. package/simulation/scenarios/domain-examples/e-commerce-recommendations.ts +220 -0
  161. package/simulation/scenarios/domain-examples/index.ts +81 -0
  162. package/simulation/scenarios/domain-examples/iot-sensor-networks.ts +290 -0
  163. package/simulation/scenarios/domain-examples/medical-imaging.ts +181 -0
  164. package/simulation/scenarios/domain-examples/robotics-navigation.ts +214 -0
  165. package/simulation/scenarios/domain-examples/scientific-research.ts +250 -0
  166. package/simulation/scenarios/domain-examples/trading-systems.ts +138 -0
  167. package/simulation/scenarios/goalie-integration.ts +161 -0
  168. package/simulation/scenarios/graph-traversal.ts +129 -0
  169. package/simulation/scenarios/latent-space/OPTIMIZATION-COMPLETE.md +287 -0
  170. package/simulation/scenarios/latent-space/README-attention-analysis.md +170 -0
  171. package/simulation/scenarios/latent-space/README-clustering-analysis.md +239 -0
  172. package/simulation/scenarios/latent-space/README-hnsw-exploration.md +199 -0
  173. package/simulation/scenarios/latent-space/README-hypergraph-exploration.md +279 -0
  174. package/simulation/scenarios/latent-space/README-neural-augmentation.md +267 -0
  175. package/simulation/scenarios/latent-space/README-quantum-hybrid.md +276 -0
  176. package/simulation/scenarios/latent-space/README-self-organizing-hnsw.md +244 -0
  177. package/simulation/scenarios/latent-space/README-traversal-optimization.md +212 -0
  178. package/simulation/scenarios/latent-space/attention-analysis.ts +598 -0
  179. package/simulation/scenarios/latent-space/clustering-analysis.ts +796 -0
  180. package/simulation/scenarios/latent-space/hnsw-exploration.ts +526 -0
  181. package/simulation/scenarios/latent-space/hypergraph-exploration.ts +706 -0
  182. package/simulation/scenarios/latent-space/index.ts +47 -0
  183. package/simulation/scenarios/latent-space/neural-augmentation.ts +604 -0
  184. package/simulation/scenarios/latent-space/quantum-hybrid.ts +508 -0
  185. package/simulation/scenarios/latent-space/self-organizing-hnsw.ts +680 -0
  186. package/simulation/scenarios/latent-space/traversal-optimization.ts +782 -0
  187. package/simulation/scenarios/lean-agentic-swarm.ts +182 -0
  188. package/simulation/scenarios/multi-agent-swarm.ts +146 -0
  189. package/simulation/scenarios/psycho-symbolic-reasoner.ts +136 -0
  190. package/simulation/scenarios/reflexion-learning.ts +132 -0
  191. package/simulation/scenarios/research-swarm.ts +187 -0
  192. package/simulation/scenarios/skill-evolution.ts +135 -0
  193. package/simulation/scenarios/stock-market-emergence.ts +323 -0
  194. package/simulation/scenarios/strange-loops.ts +175 -0
  195. package/simulation/scenarios/sublinear-solver.ts +108 -0
  196. package/simulation/scenarios/temporal-lead-solver.ts +121 -0
  197. package/simulation/scenarios/voting-system-consensus.ts +251 -0
  198. package/simulation/tests/latent-space/attention-analysis.test.ts +204 -0
  199. package/simulation/tests/latent-space/clustering-analysis.test.ts +281 -0
  200. package/simulation/tests/latent-space/hnsw-exploration.test.ts +253 -0
  201. package/simulation/tests/latent-space/hypergraph-exploration.test.ts +295 -0
  202. package/simulation/tests/latent-space/neural-augmentation.test.ts +326 -0
  203. package/simulation/tests/latent-space/quantum-hybrid.test.ts +307 -0
  204. package/simulation/tests/latent-space/self-organizing-hnsw.test.ts +291 -0
  205. package/simulation/tests/latent-space/traversal-optimization.test.ts +261 -0
  206. package/simulation/types.ts +177 -0
  207. package/simulation/utils/PerformanceOptimizer.ts +269 -0
  208. package/src/cli/lib/history-tracker.ts +7 -1
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Shared TypeScript types for AgentDB simulation framework
3
+ */
4
+
5
+ export interface SimulationScenario {
6
+ id: string;
7
+ name: string;
8
+ category: string;
9
+ description: string;
10
+ config: any;
11
+ run(config: any): Promise<SimulationReport>;
12
+ }
13
+
14
+ export interface SimulationReport {
15
+ scenarioId: string;
16
+ timestamp: string;
17
+ executionTimeMs: number;
18
+ summary: Record<string, any>;
19
+ metrics: Record<string, any>;
20
+ detailedResults?: any[];
21
+ analysis?: string;
22
+ recommendations?: string[];
23
+ artifacts?: Record<string, any>;
24
+ }
25
+
26
+ // Unified metrics interface for all scenarios
27
+ export interface UnifiedMetrics {
28
+ latencyUs: {
29
+ p50: number;
30
+ p95: number;
31
+ p99: number;
32
+ };
33
+ recallAtK: {
34
+ k10: number;
35
+ k50: number;
36
+ k100: number;
37
+ };
38
+ qps: number;
39
+ memoryMB: number;
40
+ coherenceScore?: number; // Multi-run consistency 0-1
41
+ }
42
+
43
+ export interface PerformanceMetrics {
44
+ throughput?: number;
45
+ latencyMs?: number;
46
+ memoryMB?: number;
47
+ cpuPercent?: number;
48
+ [key: string]: any;
49
+ }
50
+
51
+ export interface SearchResult {
52
+ id: string;
53
+ distance: number;
54
+ metadata?: any;
55
+ }
56
+
57
+ export interface TrainingExample {
58
+ input: any;
59
+ output: any;
60
+ metadata?: any;
61
+ }
62
+
63
+ export interface SearchOptions {
64
+ k?: number;
65
+ ef?: number;
66
+ filter?: any;
67
+ [key: string]: any;
68
+ }
69
+
70
+ export interface GraphPath {
71
+ nodes: string[];
72
+ edges: Array<{ from: string; to: string; weight?: number }>;
73
+ length: number;
74
+ cost?: number;
75
+ }
76
+
77
+ // === Clustering Analysis Types ===
78
+
79
+ export interface LouvainConfig {
80
+ resolutionParameter: number;
81
+ convergenceThreshold: number;
82
+ minModularity: number;
83
+ targetSemanticPurity: number;
84
+ hierarchicalLevels: number;
85
+ }
86
+
87
+ export interface Community {
88
+ id: string;
89
+ nodes: any[];
90
+ internalEdges: number;
91
+ totalDegree: number;
92
+ modularity: number;
93
+ semanticPurity: number;
94
+ }
95
+
96
+ // === Self-Organizing HNSW Types ===
97
+
98
+ export interface MPCConfig {
99
+ predictionHorizon: number;
100
+ controlHorizon: number;
101
+ adaptationIntervalMs: number;
102
+ degradationThreshold: number;
103
+ preventionRate: number;
104
+ }
105
+
106
+ export interface DegradationForecast {
107
+ step: number;
108
+ predictedLatency: number;
109
+ confidence: number;
110
+ }
111
+
112
+ // === Neural Augmentation Types ===
113
+
114
+ export interface GNNEdgeSelectionConfig {
115
+ adaptiveM: { min: number; max: number };
116
+ targetMemoryReduction: number;
117
+ gnnLayers: number;
118
+ hiddenDim: number;
119
+ }
120
+
121
+ export interface RLNavigationConfig {
122
+ trainingEpisodes: number;
123
+ convergenceEpisodes: number;
124
+ targetHopReduction: number;
125
+ learningRate: number;
126
+ }
127
+
128
+ export interface JointOptimizationConfig {
129
+ refinementCycles: number;
130
+ targetGain: number;
131
+ learningRate: number;
132
+ }
133
+
134
+ export interface NeuralPolicyQuality {
135
+ quality: number; // 0-1 score
136
+ convergedAt: number; // Episode number
137
+ hopReduction: number; // % reduction vs greedy
138
+ }
139
+
140
+ // === Hypergraph Exploration Types ===
141
+
142
+ export interface HypergraphConfig {
143
+ avgHyperedgeSize: number;
144
+ compressionRatio: number;
145
+ cypherQueryTargetMs: number;
146
+ taskCoverage: number;
147
+ }
148
+
149
+ export interface HyperedgeMetrics {
150
+ size: number;
151
+ pattern: string;
152
+ nodes: number[];
153
+ weight: number;
154
+ }
155
+
156
+ // === Quantum-Hybrid Types ===
157
+
158
+ export interface QuantumViabilityTimeline {
159
+ current2025: { viability: number; bottleneck: string };
160
+ nearTerm2030: { viability: number; bottleneck: string };
161
+ longTerm2040: { viability: number; ready: boolean };
162
+ }
163
+
164
+ export interface QuantumHardwareProfile {
165
+ year: number;
166
+ qubits: number;
167
+ errorRate: number;
168
+ coherenceMs: number;
169
+ viabilityScore?: number;
170
+ }
171
+
172
+ export interface TheoreticalSpeedup {
173
+ groverSpeedup: number; // √M for neighbor selection
174
+ quantumWalkSpeedup: number; // √log N for graph traversal
175
+ amplitudeEncodingSpeedup: number; // O(1) vs O(d)
176
+ overall: number;
177
+ }
@@ -0,0 +1,269 @@
1
+ /**
2
+ * Performance Optimizer for AgentDB Simulations
3
+ *
4
+ * Optimizations:
5
+ * - Batch database operations
6
+ * - Intelligent caching
7
+ * - Parallel agent execution
8
+ * - Memory pooling
9
+ * - Query optimization
10
+ * - Connection pooling
11
+ */
12
+
13
+ export class PerformanceOptimizer {
14
+ private batchQueue: Array<() => Promise<any>> = [];
15
+ private batchSize: number = 100;
16
+ private cache: Map<string, { data: any; timestamp: number; ttl: number }> = new Map();
17
+ private metrics: {
18
+ batchOperations: number;
19
+ cacheHits: number;
20
+ cacheMisses: number;
21
+ totalLatency: number;
22
+ operations: number;
23
+ } = {
24
+ batchOperations: 0,
25
+ cacheHits: 0,
26
+ cacheMisses: 0,
27
+ totalLatency: 0,
28
+ operations: 0
29
+ };
30
+
31
+ constructor(options: { batchSize?: number } = {}) {
32
+ this.batchSize = options.batchSize || 100;
33
+ }
34
+
35
+ /**
36
+ * Add operation to batch queue
37
+ */
38
+ queueOperation(operation: () => Promise<any>): void {
39
+ this.batchQueue.push(operation);
40
+ }
41
+
42
+ /**
43
+ * Execute all queued operations in parallel batches
44
+ */
45
+ async executeBatch(): Promise<any[]> {
46
+ if (this.batchQueue.length === 0) return [];
47
+
48
+ const startTime = performance.now();
49
+ const results: any[] = [];
50
+
51
+ // Process in batches to avoid overwhelming the system
52
+ for (let i = 0; i < this.batchQueue.length; i += this.batchSize) {
53
+ const batch = this.batchQueue.slice(i, i + this.batchSize);
54
+ const batchResults = await Promise.all(batch.map(op => op()));
55
+ results.push(...batchResults);
56
+ this.metrics.batchOperations++;
57
+ }
58
+
59
+ this.batchQueue = [];
60
+ const endTime = performance.now();
61
+ this.metrics.totalLatency += endTime - startTime;
62
+ this.metrics.operations += results.length;
63
+
64
+ return results;
65
+ }
66
+
67
+ /**
68
+ * Cache data with TTL
69
+ */
70
+ setCache(key: string, data: any, ttl: number = 60000): void {
71
+ this.cache.set(key, {
72
+ data,
73
+ timestamp: Date.now(),
74
+ ttl
75
+ });
76
+ }
77
+
78
+ /**
79
+ * Get cached data
80
+ */
81
+ getCache(key: string): any | null {
82
+ const cached = this.cache.get(key);
83
+
84
+ if (!cached) {
85
+ this.metrics.cacheMisses++;
86
+ return null;
87
+ }
88
+
89
+ // Check if expired
90
+ if (Date.now() - cached.timestamp > cached.ttl) {
91
+ this.cache.delete(key);
92
+ this.metrics.cacheMisses++;
93
+ return null;
94
+ }
95
+
96
+ this.metrics.cacheHits++;
97
+ return cached.data;
98
+ }
99
+
100
+ /**
101
+ * Clear expired cache entries
102
+ */
103
+ clearExpiredCache(): void {
104
+ const now = Date.now();
105
+ for (const [key, value] of this.cache.entries()) {
106
+ if (now - value.timestamp > value.ttl) {
107
+ this.cache.delete(key);
108
+ }
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Get cache statistics
114
+ */
115
+ getCacheStats() {
116
+ const hitRate = this.metrics.cacheHits + this.metrics.cacheMisses > 0
117
+ ? (this.metrics.cacheHits / (this.metrics.cacheHits + this.metrics.cacheMisses)) * 100
118
+ : 0;
119
+
120
+ return {
121
+ size: this.cache.size,
122
+ hits: this.metrics.cacheHits,
123
+ misses: this.metrics.cacheMisses,
124
+ hitRate: hitRate.toFixed(2) + '%'
125
+ };
126
+ }
127
+
128
+ /**
129
+ * Get performance metrics
130
+ */
131
+ getMetrics() {
132
+ const avgLatency = this.metrics.operations > 0
133
+ ? this.metrics.totalLatency / this.metrics.operations
134
+ : 0;
135
+
136
+ return {
137
+ batchOperations: this.metrics.batchOperations,
138
+ totalOperations: this.metrics.operations,
139
+ avgLatency: avgLatency.toFixed(2) + 'ms',
140
+ cacheStats: this.getCacheStats()
141
+ };
142
+ }
143
+
144
+ /**
145
+ * Reset metrics
146
+ */
147
+ resetMetrics(): void {
148
+ this.metrics = {
149
+ batchOperations: 0,
150
+ cacheHits: 0,
151
+ cacheMisses: 0,
152
+ totalLatency: 0,
153
+ operations: 0
154
+ };
155
+ }
156
+
157
+ /**
158
+ * Clear all cache
159
+ */
160
+ clearCache(): void {
161
+ this.cache.clear();
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Parallel execution utility
167
+ */
168
+ export async function executeParallel<T>(
169
+ tasks: Array<() => Promise<T>>,
170
+ concurrency: number = 10
171
+ ): Promise<T[]> {
172
+ const results: T[] = [];
173
+
174
+ for (let i = 0; i < tasks.length; i += concurrency) {
175
+ const batch = tasks.slice(i, i + concurrency);
176
+ const batchResults = await Promise.all(batch.map(task => task()));
177
+ results.push(...batchResults);
178
+ }
179
+
180
+ return results;
181
+ }
182
+
183
+ /**
184
+ * Memory pooling for agent objects
185
+ */
186
+ export class AgentPool<T> {
187
+ private pool: T[] = [];
188
+ private factory: () => T;
189
+ private maxSize: number;
190
+
191
+ constructor(factory: () => T, maxSize: number = 100) {
192
+ this.factory = factory;
193
+ this.maxSize = maxSize;
194
+ }
195
+
196
+ /**
197
+ * Get agent from pool or create new
198
+ */
199
+ acquire(): T {
200
+ if (this.pool.length > 0) {
201
+ return this.pool.pop()!;
202
+ }
203
+ return this.factory();
204
+ }
205
+
206
+ /**
207
+ * Return agent to pool
208
+ */
209
+ release(agent: T): void {
210
+ if (this.pool.length < this.maxSize) {
211
+ this.pool.push(agent);
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Clear pool
217
+ */
218
+ clear(): void {
219
+ this.pool = [];
220
+ }
221
+
222
+ /**
223
+ * Get pool size
224
+ */
225
+ size(): number {
226
+ return this.pool.length;
227
+ }
228
+ }
229
+
230
+ /**
231
+ * Query optimizer for database operations
232
+ */
233
+ export class QueryOptimizer {
234
+ private queryCache: Map<string, any> = new Map();
235
+
236
+ /**
237
+ * Optimize Cypher query with caching
238
+ */
239
+ async executeOptimized(
240
+ queryFn: () => Promise<any>,
241
+ cacheKey?: string,
242
+ ttl: number = 5000
243
+ ): Promise<any> {
244
+ if (cacheKey) {
245
+ const cached = this.queryCache.get(cacheKey);
246
+ if (cached && Date.now() - cached.timestamp < ttl) {
247
+ return cached.data;
248
+ }
249
+ }
250
+
251
+ const result = await queryFn();
252
+
253
+ if (cacheKey) {
254
+ this.queryCache.set(cacheKey, {
255
+ data: result,
256
+ timestamp: Date.now()
257
+ });
258
+ }
259
+
260
+ return result;
261
+ }
262
+
263
+ /**
264
+ * Clear query cache
265
+ */
266
+ clearCache(): void {
267
+ this.queryCache.clear();
268
+ }
269
+ }
@@ -272,7 +272,13 @@ export class HistoryTracker {
272
272
 
273
273
  baseline = {
274
274
  ...currentRun,
275
- metrics: avgMetrics
275
+ metrics: {
276
+ recall: 0,
277
+ latency: 0,
278
+ throughput: 0,
279
+ memoryUsage: 0,
280
+ ...avgMetrics
281
+ }
276
282
  };
277
283
  }
278
284