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.
- package/dist/agentdb.min.js +4 -4
- package/dist/simulation/cli.js +0 -0
- package/dist/src/cli/lib/config-manager.d.ts.map +1 -1
- package/dist/src/cli/lib/config-manager.js.map +1 -1
- package/dist/src/cli/lib/history-tracker.d.ts.map +1 -1
- package/dist/src/cli/lib/history-tracker.js +7 -1
- package/dist/src/cli/lib/history-tracker.js.map +1 -1
- package/examples/README.md +105 -0
- package/examples/quickstart.js +43 -0
- package/package.json +6 -2
- package/simulation/.claude-flow/metrics/agent-metrics.json +1 -0
- package/simulation/.claude-flow/metrics/performance.json +87 -0
- package/simulation/.claude-flow/metrics/task-metrics.json +10 -0
- package/simulation/COMPLETION-STATUS.md +139 -0
- package/simulation/FINAL-RESULTS.md +414 -0
- package/simulation/FINAL-STATUS.md +281 -0
- package/simulation/INTEGRATION-COMPLETE.md +452 -0
- package/simulation/MIGRATION-STATUS.md +231 -0
- package/simulation/OPTIMIZATION-RESULTS.md +397 -0
- package/simulation/PHASE1-COMPLETE.md +163 -0
- package/simulation/README.md +848 -0
- package/simulation/SIMULATION-RESULTS.md +239 -0
- package/simulation/cli.ts +78 -0
- package/simulation/configs/default.json +37 -0
- package/simulation/data/advanced/aidefence.graph +0 -0
- package/simulation/data/advanced/bmssp.graph +0 -0
- package/simulation/data/advanced/consciousness.graph +0 -0
- package/simulation/data/advanced/goalie.graph +0 -0
- package/simulation/data/advanced/psycho-symbolic.graph +0 -0
- package/simulation/data/advanced/research-swarm.graph +0 -0
- package/simulation/data/advanced/sublinear.graph +0 -0
- package/simulation/data/advanced/temporal.graph +0 -0
- package/simulation/data/causal.graph +0 -0
- package/simulation/data/graph-traversal.graph +0 -0
- package/simulation/data/lean-agentic.graph +0 -0
- package/simulation/data/reflexion.graph +0 -0
- package/simulation/data/skills.graph +0 -0
- package/simulation/data/stock-market.graph +0 -0
- package/simulation/data/strange-loops.graph +0 -0
- package/simulation/data/swarm.graph +0 -0
- package/simulation/data/voting-consensus.graph +0 -0
- package/simulation/docs/CLI-INTEGRATION-PLAN.md +1038 -0
- package/simulation/docs/COMPREHENSIVE-LATENT-SPACE-COMPLETION.md +354 -0
- package/simulation/docs/DOCUMENTATION-INDEX.md +226 -0
- package/simulation/docs/IMPLEMENTATION-COMPLETE.md +521 -0
- package/simulation/docs/OPTIMIZATION-SUMMARY.md +279 -0
- package/simulation/docs/README.md +229 -0
- package/simulation/docs/SWARM-5-INTEGRATION-SUMMARY.md +528 -0
- package/simulation/docs/TESTING-SUMMARY.md +304 -0
- package/simulation/docs/architecture/EXTENSION-API.md +868 -0
- package/simulation/docs/architecture/INTEGRATION-ARCHITECTURE.md +1138 -0
- package/simulation/docs/architecture/OPTIMIZATION-STRATEGY.md +778 -0
- package/simulation/docs/architecture/SIMULATION-ARCHITECTURE.md +892 -0
- package/simulation/docs/guides/CLI-REFERENCE.md +896 -0
- package/simulation/docs/guides/CUSTOM-SIMULATIONS.md +931 -0
- package/simulation/docs/guides/DEPLOYMENT.md +832 -0
- package/simulation/docs/guides/IMPLEMENTATION-SUMMARY.md +544 -0
- package/simulation/docs/guides/MIGRATION-GUIDE.md +591 -0
- package/simulation/docs/guides/QUICK-START.md +361 -0
- package/simulation/docs/guides/README.md +736 -0
- package/simulation/docs/guides/TROUBLESHOOTING.md +817 -0
- package/simulation/docs/guides/WIZARD-GUIDE.md +869 -0
- package/simulation/docs/reports/latent-space/MASTER-SYNTHESIS.md +345 -0
- package/simulation/docs/reports/latent-space/README.md +132 -0
- package/simulation/docs/reports/latent-space/attention-analysis-RESULTS.md +238 -0
- package/simulation/docs/reports/latent-space/clustering-analysis-RESULTS.md +210 -0
- package/simulation/docs/reports/latent-space/hnsw-exploration-RESULTS.md +332 -0
- package/simulation/docs/reports/latent-space/hypergraph-exploration-RESULTS.md +37 -0
- package/simulation/docs/reports/latent-space/neural-augmentation-RESULTS.md +69 -0
- package/simulation/docs/reports/latent-space/quantum-hybrid-RESULTS.md +91 -0
- package/simulation/docs/reports/latent-space/self-organizing-hnsw-RESULTS.md +51 -0
- package/simulation/docs/reports/latent-space/traversal-optimization-RESULTS.md +238 -0
- package/simulation/reports/README.md +397 -0
- package/simulation/reports/advanced-simulations-performance.md +1241 -0
- package/simulation/reports/aidefence-integration-2025-11-30T01-36-53-486Z.json +30 -0
- package/simulation/reports/architecture-analysis.md +1396 -0
- package/simulation/reports/basic-scenarios-performance.md +1840 -0
- package/simulation/reports/bmssp-integration-2025-11-30T01-36-27-193Z.json +30 -0
- package/simulation/reports/bmssp-integration-2025-11-30T03-38-12-887Z.json +30 -0
- package/simulation/reports/causal-reasoning-2025-11-29T23-35-21-795Z.json +36 -0
- package/simulation/reports/causal-reasoning-2025-11-30T00-58-42-862Z.json +30 -0
- package/simulation/reports/causal-reasoning-2025-11-30T00-59-12-546Z.json +40 -0
- package/simulation/reports/consciousness-explorer-2025-11-30T01-36-51-269Z.json +31 -0
- package/simulation/reports/core-benchmarks.md +727 -0
- package/simulation/reports/goalie-integration-2025-11-30T01-36-52-377Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-29T23-35-35-279Z.json +78 -0
- package/simulation/reports/graph-traversal-2025-11-29T23-37-36-697Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-03-59-716Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-05-10-984Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-06-16-334Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-06-53-312Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-07-51-075Z.json +24 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-08-22-179Z.json +42 -0
- package/simulation/reports/lean-agentic-swarm-2025-11-29T23-37-23-804Z.json +148 -0
- package/simulation/reports/lean-agentic-swarm-2025-11-30T01-31-24-401Z.json +31 -0
- package/simulation/reports/lean-agentic-swarm-2025-11-30T03-38-01-470Z.json +31 -0
- package/simulation/reports/multi-agent-swarm-2025-11-29T23-35-28-093Z.json +78 -0
- package/simulation/reports/multi-agent-swarm-2025-11-30T01-03-54-062Z.json +42 -0
- package/simulation/reports/multi-agent-swarm-2025-11-30T01-05-06-092Z.json +42 -0
- package/simulation/reports/psycho-symbolic-reasoner-2025-11-30T01-36-50-180Z.json +30 -0
- package/simulation/reports/quality-metrics.md +727 -0
- package/simulation/reports/reflexion-learning-2025-11-29T23-35-09-774Z.json +48 -0
- package/simulation/reports/reflexion-learning-2025-11-29T23-37-16-934Z.json +36 -0
- package/simulation/reports/reflexion-learning-2025-11-30T00-07-49-259Z.json +30 -0
- package/simulation/reports/reflexion-learning-2025-11-30T00-09-29-319Z.json +51 -0
- package/simulation/reports/reflexion-learning-2025-11-30T00-28-37-659Z.json +51 -0
- package/simulation/reports/reflexion-learning-2025-11-30T01-31-30-690Z.json +29 -0
- package/simulation/reports/reflexion-learning-2025-11-30T03-38-06-937Z.json +29 -0
- package/simulation/reports/research-foundations.md +2004 -0
- package/simulation/reports/research-swarm-2025-11-30T01-36-54-647Z.json +30 -0
- package/simulation/reports/scalability-deployment.md +2404 -0
- package/simulation/reports/skill-evolution-2025-11-29T23-35-15-945Z.json +36 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-03-17-995Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-03-48-441Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-05-00-554Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-06-11-436Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-06-51-979Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-07-32-695Z.json +40 -0
- package/simulation/reports/stock-market-emergence-2025-11-30T00-11-43-865Z.json +56 -0
- package/simulation/reports/stock-market-emergence-2025-11-30T00-28-57-495Z.json +56 -0
- package/simulation/reports/strange-loops-2025-11-29T23-37-30-621Z.json +78 -0
- package/simulation/reports/strange-loops-2025-11-30T00-07-55-415Z.json +30 -0
- package/simulation/reports/strange-loops-2025-11-30T00-09-35-133Z.json +30 -0
- package/simulation/reports/strange-loops-2025-11-30T00-48-50-744Z.json +24 -0
- package/simulation/reports/strange-loops-2025-11-30T00-54-48-044Z.json +24 -0
- package/simulation/reports/strange-loops-2025-11-30T00-57-27-633Z.json +24 -0
- package/simulation/reports/strange-loops-2025-11-30T00-57-59-135Z.json +42 -0
- package/simulation/reports/sublinear-solver-2025-11-30T01-36-33-134Z.json +30 -0
- package/simulation/reports/temporal-lead-solver-2025-11-30T01-36-38-628Z.json +30 -0
- package/simulation/reports/use-cases-applications.md +2212 -0
- package/simulation/reports/voting-system-consensus-2025-11-30T00-11-37-199Z.json +58 -0
- package/simulation/reports/voting-system-consensus-2025-11-30T00-28-47-735Z.json +58 -0
- package/simulation/runner.ts +300 -0
- package/simulation/scenarios/README-advanced/aidefence-integration.md +63 -0
- package/simulation/scenarios/README-advanced/bmssp-integration.md +58 -0
- package/simulation/scenarios/README-advanced/consciousness-explorer.md +53 -0
- package/simulation/scenarios/README-advanced/goalie-integration.md +61 -0
- package/simulation/scenarios/README-advanced/psycho-symbolic-reasoner.md +55 -0
- package/simulation/scenarios/README-advanced/research-swarm.md +63 -0
- package/simulation/scenarios/README-advanced/sublinear-solver.md +58 -0
- package/simulation/scenarios/README-advanced/temporal-lead-solver.md +55 -0
- package/simulation/scenarios/README-basic/causal-reasoning.md +39 -0
- package/simulation/scenarios/README-basic/graph-traversal.md +41 -0
- package/simulation/scenarios/README-basic/lean-agentic-swarm.md +122 -0
- package/simulation/scenarios/README-basic/multi-agent-swarm.md +34 -0
- package/simulation/scenarios/README-basic/reflexion-learning.md +41 -0
- package/simulation/scenarios/README-basic/skill-evolution.md +38 -0
- package/simulation/scenarios/README-basic/stock-market-emergence.md +28 -0
- package/simulation/scenarios/README-basic/strange-loops.md +36 -0
- package/simulation/scenarios/README-basic/voting-system-consensus.md +28 -0
- package/simulation/scenarios/README.md +438 -0
- package/simulation/scenarios/aidefence-integration.ts +165 -0
- package/simulation/scenarios/bmssp-integration.ts +137 -0
- package/simulation/scenarios/causal-reasoning.ts +143 -0
- package/simulation/scenarios/consciousness-explorer.ts +139 -0
- package/simulation/scenarios/domain-examples/.claude-flow/metrics/agent-metrics.json +1 -0
- package/simulation/scenarios/domain-examples/.claude-flow/metrics/performance.json +87 -0
- package/simulation/scenarios/domain-examples/.claude-flow/metrics/task-metrics.json +10 -0
- package/simulation/scenarios/domain-examples/README.md +525 -0
- package/simulation/scenarios/domain-examples/e-commerce-recommendations.ts +220 -0
- package/simulation/scenarios/domain-examples/index.ts +81 -0
- package/simulation/scenarios/domain-examples/iot-sensor-networks.ts +290 -0
- package/simulation/scenarios/domain-examples/medical-imaging.ts +181 -0
- package/simulation/scenarios/domain-examples/robotics-navigation.ts +214 -0
- package/simulation/scenarios/domain-examples/scientific-research.ts +250 -0
- package/simulation/scenarios/domain-examples/trading-systems.ts +138 -0
- package/simulation/scenarios/goalie-integration.ts +161 -0
- package/simulation/scenarios/graph-traversal.ts +129 -0
- package/simulation/scenarios/latent-space/OPTIMIZATION-COMPLETE.md +287 -0
- package/simulation/scenarios/latent-space/README-attention-analysis.md +170 -0
- package/simulation/scenarios/latent-space/README-clustering-analysis.md +239 -0
- package/simulation/scenarios/latent-space/README-hnsw-exploration.md +199 -0
- package/simulation/scenarios/latent-space/README-hypergraph-exploration.md +279 -0
- package/simulation/scenarios/latent-space/README-neural-augmentation.md +267 -0
- package/simulation/scenarios/latent-space/README-quantum-hybrid.md +276 -0
- package/simulation/scenarios/latent-space/README-self-organizing-hnsw.md +244 -0
- package/simulation/scenarios/latent-space/README-traversal-optimization.md +212 -0
- package/simulation/scenarios/latent-space/attention-analysis.ts +598 -0
- package/simulation/scenarios/latent-space/clustering-analysis.ts +796 -0
- package/simulation/scenarios/latent-space/hnsw-exploration.ts +526 -0
- package/simulation/scenarios/latent-space/hypergraph-exploration.ts +706 -0
- package/simulation/scenarios/latent-space/index.ts +47 -0
- package/simulation/scenarios/latent-space/neural-augmentation.ts +604 -0
- package/simulation/scenarios/latent-space/quantum-hybrid.ts +508 -0
- package/simulation/scenarios/latent-space/self-organizing-hnsw.ts +680 -0
- package/simulation/scenarios/latent-space/traversal-optimization.ts +782 -0
- package/simulation/scenarios/lean-agentic-swarm.ts +182 -0
- package/simulation/scenarios/multi-agent-swarm.ts +146 -0
- package/simulation/scenarios/psycho-symbolic-reasoner.ts +136 -0
- package/simulation/scenarios/reflexion-learning.ts +132 -0
- package/simulation/scenarios/research-swarm.ts +187 -0
- package/simulation/scenarios/skill-evolution.ts +135 -0
- package/simulation/scenarios/stock-market-emergence.ts +323 -0
- package/simulation/scenarios/strange-loops.ts +175 -0
- package/simulation/scenarios/sublinear-solver.ts +108 -0
- package/simulation/scenarios/temporal-lead-solver.ts +121 -0
- package/simulation/scenarios/voting-system-consensus.ts +251 -0
- package/simulation/tests/latent-space/attention-analysis.test.ts +204 -0
- package/simulation/tests/latent-space/clustering-analysis.test.ts +281 -0
- package/simulation/tests/latent-space/hnsw-exploration.test.ts +253 -0
- package/simulation/tests/latent-space/hypergraph-exploration.test.ts +295 -0
- package/simulation/tests/latent-space/neural-augmentation.test.ts +326 -0
- package/simulation/tests/latent-space/quantum-hybrid.test.ts +307 -0
- package/simulation/tests/latent-space/self-organizing-hnsw.test.ts +291 -0
- package/simulation/tests/latent-space/traversal-optimization.test.ts +261 -0
- package/simulation/types.ts +177 -0
- package/simulation/utils/PerformanceOptimizer.ts +269 -0
- package/src/cli/lib/history-tracker.ts +7 -1
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* E-Commerce Recommendations: Personalized Product Discovery
|
|
3
|
+
*
|
|
4
|
+
* Use Case: Recommend similar products based on user preferences,
|
|
5
|
+
* browsing history, and product embeddings.
|
|
6
|
+
*
|
|
7
|
+
* Optimization Priority: DIVERSITY + RELEVANCE
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { UnifiedMetrics } from '../../types';
|
|
11
|
+
|
|
12
|
+
export const ECOMMERCE_ATTENTION_CONFIG = {
|
|
13
|
+
heads: 8, // Optimal for balanced performance
|
|
14
|
+
forwardPassTargetMs: 20, // 20ms acceptable for recommendations
|
|
15
|
+
batchSize: 64, // Batch user requests
|
|
16
|
+
precision: 'float32' as const, // Full precision for quality
|
|
17
|
+
diversityBoost: true, // Promote diverse recommendations
|
|
18
|
+
|
|
19
|
+
// Louvain clustering for product categories
|
|
20
|
+
clustering: {
|
|
21
|
+
algorithm: 'louvain' as const,
|
|
22
|
+
minModularity: 0.75, // High-quality clusters
|
|
23
|
+
semanticPurity: 0.87, // 87.2% purity validated
|
|
24
|
+
hierarchicalLevels: 3 // Category hierarchy (dept > category > subcategory)
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
// Dynamic-k based on user engagement
|
|
28
|
+
dynamicK: {
|
|
29
|
+
min: 10, // Minimum 10 recommendations
|
|
30
|
+
max: 50, // Maximum 50 for exploration
|
|
31
|
+
adaptationStrategy: 'user-engagement' as const // Active users get more
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// E-commerce-specific metrics
|
|
36
|
+
export interface ECommerceMetrics extends UnifiedMetrics {
|
|
37
|
+
clickThroughRate: number; // CTR on recommendations
|
|
38
|
+
conversionRate: number; // Purchase conversion rate
|
|
39
|
+
diversityScore: number; // Recommendation diversity
|
|
40
|
+
categoryBalanceScore: number; // Cross-category recommendations
|
|
41
|
+
userSatisfaction: number; // Implicit feedback signals
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Recommendation interface
|
|
45
|
+
export interface Recommendation {
|
|
46
|
+
productId: string;
|
|
47
|
+
relevanceScore: number;
|
|
48
|
+
category: string;
|
|
49
|
+
cluster: string;
|
|
50
|
+
priceUSD: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Example: Product recommendation with diversity
|
|
54
|
+
export async function recommendProducts(
|
|
55
|
+
userProfile: Float32Array, // User preferences embeddings
|
|
56
|
+
productCatalog: any, // HNSWGraph type
|
|
57
|
+
userEngagement: number,
|
|
58
|
+
applyAttention: (data: Float32Array, config: any) => Promise<Float32Array>,
|
|
59
|
+
applyDiversityBoost: (candidates: any[], weight: number) => Promise<any[]>,
|
|
60
|
+
clusterRecommendations: (items: any[], config: any) => Promise<any[]>,
|
|
61
|
+
findCluster: (item: any, clusters: any[]) => string,
|
|
62
|
+
diversityWeight: number = 0.3
|
|
63
|
+
): Promise<Recommendation[]> {
|
|
64
|
+
const config = ECOMMERCE_ATTENTION_CONFIG;
|
|
65
|
+
|
|
66
|
+
// 8-head attention for user query enhancement
|
|
67
|
+
const enhanced = await applyAttention(userProfile, config);
|
|
68
|
+
|
|
69
|
+
// Dynamic-k based on user engagement (engaged users get more options)
|
|
70
|
+
const k = Math.round(10 + userEngagement * 40); // 10-50 range
|
|
71
|
+
|
|
72
|
+
// Search with clustering for category diversity
|
|
73
|
+
const candidates = await productCatalog.search(enhanced, k);
|
|
74
|
+
|
|
75
|
+
// Apply diversity boost (promote different categories)
|
|
76
|
+
const diversified = await applyDiversityBoost(candidates, diversityWeight);
|
|
77
|
+
|
|
78
|
+
// Cluster recommendations by category (Louvain)
|
|
79
|
+
const clusters = await clusterRecommendations(diversified, config.clustering);
|
|
80
|
+
|
|
81
|
+
return diversified.map((p: any) => ({
|
|
82
|
+
productId: p.id,
|
|
83
|
+
relevanceScore: p.score,
|
|
84
|
+
category: p.metadata.category,
|
|
85
|
+
cluster: findCluster(p, clusters),
|
|
86
|
+
priceUSD: p.metadata.price
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Performance targets for e-commerce
|
|
91
|
+
export const ECOMMERCE_PERFORMANCE_TARGETS = {
|
|
92
|
+
p95LatencyMs: 50, // 50ms p95 (user experience)
|
|
93
|
+
clickThroughRate: 0.15, // 15% CTR target
|
|
94
|
+
conversionRate: 0.05, // 5% conversion target
|
|
95
|
+
diversityScore: 0.7, // 70% category diversity
|
|
96
|
+
uptimePercent: 99.9 // 99.9% uptime (3 nines)
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// E-commerce platform-specific configurations
|
|
100
|
+
export const ECOMMERCE_CONFIG_VARIATIONS = {
|
|
101
|
+
// Fashion/apparel (high visual similarity)
|
|
102
|
+
fashion: {
|
|
103
|
+
...ECOMMERCE_ATTENTION_CONFIG,
|
|
104
|
+
heads: 12, // More heads for visual nuance
|
|
105
|
+
diversityBoost: true,
|
|
106
|
+
clustering: {
|
|
107
|
+
...ECOMMERCE_ATTENTION_CONFIG.clustering,
|
|
108
|
+
hierarchicalLevels: 4 // Deeper taxonomy (category > subcategory > style > color)
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
// Electronics (specification-driven)
|
|
113
|
+
electronics: {
|
|
114
|
+
...ECOMMERCE_ATTENTION_CONFIG,
|
|
115
|
+
heads: 8,
|
|
116
|
+
specificationWeight: 0.6, // Emphasize specs over style
|
|
117
|
+
diversityBoost: false // Users want specific features
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
// Grocery (frequent purchases)
|
|
121
|
+
grocery: {
|
|
122
|
+
...ECOMMERCE_ATTENTION_CONFIG,
|
|
123
|
+
heads: 6,
|
|
124
|
+
forwardPassTargetMs: 10, // Faster for mobile
|
|
125
|
+
batchSize: 128, // High volume
|
|
126
|
+
dynamicK: { min: 15, max: 30, adaptationStrategy: 'cart-size' as const }
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
// Luxury goods (personalization critical)
|
|
130
|
+
luxury: {
|
|
131
|
+
...ECOMMERCE_ATTENTION_CONFIG,
|
|
132
|
+
heads: 16, // Maximum personalization
|
|
133
|
+
forwardPassTargetMs: 50, // Allow more time
|
|
134
|
+
diversityBoost: false, // Highly targeted
|
|
135
|
+
precision: 'float32' as const
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// User segment adaptations
|
|
140
|
+
export function adaptConfigToUserSegment(
|
|
141
|
+
baseConfig: typeof ECOMMERCE_ATTENTION_CONFIG,
|
|
142
|
+
segment: 'browser' | 'buyer' | 'loyal' | 'vip'
|
|
143
|
+
): typeof ECOMMERCE_ATTENTION_CONFIG {
|
|
144
|
+
switch (segment) {
|
|
145
|
+
case 'browser':
|
|
146
|
+
return {
|
|
147
|
+
...baseConfig,
|
|
148
|
+
dynamicK: { ...baseConfig.dynamicK, min: 20, max: 50 }, // More exploration
|
|
149
|
+
diversityBoost: true // Show variety
|
|
150
|
+
};
|
|
151
|
+
case 'buyer':
|
|
152
|
+
return {
|
|
153
|
+
...baseConfig,
|
|
154
|
+
dynamicK: { ...baseConfig.dynamicK, min: 10, max: 30 }, // Focused recommendations
|
|
155
|
+
diversityBoost: false
|
|
156
|
+
};
|
|
157
|
+
case 'loyal':
|
|
158
|
+
return {
|
|
159
|
+
...baseConfig,
|
|
160
|
+
heads: 12, // Better personalization
|
|
161
|
+
dynamicK: { ...baseConfig.dynamicK, min: 15, max: 40 }
|
|
162
|
+
};
|
|
163
|
+
case 'vip':
|
|
164
|
+
return {
|
|
165
|
+
...baseConfig,
|
|
166
|
+
heads: 16, // Maximum personalization
|
|
167
|
+
forwardPassTargetMs: 30,
|
|
168
|
+
precision: 'float32' as const
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Seasonal/promotional adaptations
|
|
174
|
+
export interface PromotionalContext {
|
|
175
|
+
isSale: boolean;
|
|
176
|
+
seasonalEvent: string | null;
|
|
177
|
+
inventoryPressure: number; // 0-1, how much to push certain items
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function adaptConfigToPromotion(
|
|
181
|
+
baseConfig: typeof ECOMMERCE_ATTENTION_CONFIG,
|
|
182
|
+
context: PromotionalContext
|
|
183
|
+
): typeof ECOMMERCE_ATTENTION_CONFIG {
|
|
184
|
+
if (context.isSale) {
|
|
185
|
+
return {
|
|
186
|
+
...baseConfig,
|
|
187
|
+
dynamicK: { ...baseConfig.dynamicK, min: 20, max: 60 }, // Show more options
|
|
188
|
+
diversityBoost: true // Cross-sell opportunities
|
|
189
|
+
// Note: Sale boost handled in ranking layer
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
return baseConfig;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// A/B testing configuration generator
|
|
196
|
+
export function generateABTestConfigs(
|
|
197
|
+
baseConfig: typeof ECOMMERCE_ATTENTION_CONFIG
|
|
198
|
+
): Record<string, typeof ECOMMERCE_ATTENTION_CONFIG> {
|
|
199
|
+
return {
|
|
200
|
+
control: baseConfig,
|
|
201
|
+
|
|
202
|
+
moreHeads: {
|
|
203
|
+
...baseConfig,
|
|
204
|
+
heads: 12
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
moreDiversity: {
|
|
208
|
+
...baseConfig,
|
|
209
|
+
diversityBoost: true,
|
|
210
|
+
dynamicK: { ...baseConfig.dynamicK, min: 15, max: 60 }
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
fasterLatency: {
|
|
214
|
+
...baseConfig,
|
|
215
|
+
heads: 6,
|
|
216
|
+
forwardPassTargetMs: 10,
|
|
217
|
+
precision: 'float32' as const // Lower precision not yet supported
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain-Specific Attention Configuration Examples
|
|
3
|
+
*
|
|
4
|
+
* This module exports real-world configurations and examples for various industries
|
|
5
|
+
* and use cases, demonstrating how to adapt AgentDB's attention mechanisms for
|
|
6
|
+
* specific requirements.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
TRADING_ATTENTION_CONFIG,
|
|
11
|
+
TRADING_PERFORMANCE_TARGETS,
|
|
12
|
+
TRADING_CONFIG_VARIATIONS,
|
|
13
|
+
type TradingMetrics,
|
|
14
|
+
type TradingSignal,
|
|
15
|
+
matchTradingPattern,
|
|
16
|
+
adaptConfigToMarket
|
|
17
|
+
} from './trading-systems';
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
MEDICAL_ATTENTION_CONFIG,
|
|
21
|
+
MEDICAL_PERFORMANCE_TARGETS,
|
|
22
|
+
MEDICAL_CONFIG_VARIATIONS,
|
|
23
|
+
type MedicalMetrics,
|
|
24
|
+
type SimilarCase,
|
|
25
|
+
type MedicalDataQuality,
|
|
26
|
+
findSimilarCases,
|
|
27
|
+
adaptConfigToUrgency,
|
|
28
|
+
validateMedicalData
|
|
29
|
+
} from './medical-imaging';
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
ROBOTICS_ATTENTION_CONFIG,
|
|
33
|
+
ROBOTICS_PERFORMANCE_TARGETS,
|
|
34
|
+
ROBOTICS_CONFIG_VARIATIONS,
|
|
35
|
+
type RoboticsMetrics,
|
|
36
|
+
type RobotContext,
|
|
37
|
+
type NavigationPlan,
|
|
38
|
+
matchEnvironment,
|
|
39
|
+
adaptConfigToEnvironment,
|
|
40
|
+
adaptConfigToPower
|
|
41
|
+
} from './robotics-navigation';
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
ECOMMERCE_ATTENTION_CONFIG,
|
|
45
|
+
ECOMMERCE_PERFORMANCE_TARGETS,
|
|
46
|
+
ECOMMERCE_CONFIG_VARIATIONS,
|
|
47
|
+
type ECommerceMetrics,
|
|
48
|
+
type Recommendation,
|
|
49
|
+
type PromotionalContext,
|
|
50
|
+
recommendProducts,
|
|
51
|
+
adaptConfigToUserSegment,
|
|
52
|
+
adaptConfigToPromotion,
|
|
53
|
+
generateABTestConfigs
|
|
54
|
+
} from './e-commerce-recommendations';
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
RESEARCH_ATTENTION_CONFIG,
|
|
58
|
+
RESEARCH_PERFORMANCE_TARGETS,
|
|
59
|
+
RESEARCH_CONFIG_VARIATIONS,
|
|
60
|
+
type ResearchMetrics,
|
|
61
|
+
type ResearchConnection,
|
|
62
|
+
type CitationNetworkMetrics,
|
|
63
|
+
discoverRelatedResearch,
|
|
64
|
+
adaptConfigToSearchMode,
|
|
65
|
+
adaptConfigToResearchStage,
|
|
66
|
+
analyzeCitationNetwork
|
|
67
|
+
} from './scientific-research';
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
IOT_ATTENTION_CONFIG,
|
|
71
|
+
IOT_PERFORMANCE_TARGETS,
|
|
72
|
+
IOT_CONFIG_VARIATIONS,
|
|
73
|
+
type IoTMetrics,
|
|
74
|
+
type Sensor,
|
|
75
|
+
type AnomalyAlert,
|
|
76
|
+
type NetworkTopology,
|
|
77
|
+
detectAnomalies,
|
|
78
|
+
adaptConfigToDeployment,
|
|
79
|
+
adaptConfigToBattery,
|
|
80
|
+
adaptConfigToTopology
|
|
81
|
+
} from './iot-sensor-networks';
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IoT Sensor Networks: Distributed Anomaly Detection
|
|
3
|
+
*
|
|
4
|
+
* Use Case: Real-time anomaly detection in IoT sensor networks
|
|
5
|
+
* with limited compute resources.
|
|
6
|
+
*
|
|
7
|
+
* Optimization Priority: POWER EFFICIENCY + LATENCY
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { UnifiedMetrics } from '../../types';
|
|
11
|
+
|
|
12
|
+
export const IOT_ATTENTION_CONFIG = {
|
|
13
|
+
heads: 4, // Lightweight for edge devices
|
|
14
|
+
forwardPassTargetMs: 5, // 5ms for real-time monitoring
|
|
15
|
+
batchSize: 1, // Single-sensor processing
|
|
16
|
+
precision: 'int8' as const, // Quantized for edge (NVIDIA TensorRT, TFLite)
|
|
17
|
+
edgeOptimized: true, // ESP32, Raspberry Pi, Coral TPU
|
|
18
|
+
powerBudgetMw: 500, // 500mW power budget
|
|
19
|
+
|
|
20
|
+
// Hypergraph for multi-sensor correlations
|
|
21
|
+
hypergraph: {
|
|
22
|
+
enabled: true,
|
|
23
|
+
maxHyperedgeSize: 5, // 5-sensor correlations
|
|
24
|
+
compressionRatio: 3.7, // 3.7x edge compression validated
|
|
25
|
+
distributedProcessing: true // Process across sensor network
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
// Dynamic-k based on anomaly severity
|
|
29
|
+
dynamicK: {
|
|
30
|
+
min: 3, // Minimum candidates (normal operation)
|
|
31
|
+
max: 15, // Maximum candidates (anomaly detected)
|
|
32
|
+
adaptationStrategy: 'anomaly-severity' as const
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
// Self-healing for autonomous operation
|
|
36
|
+
selfHealing: {
|
|
37
|
+
enabled: true,
|
|
38
|
+
adaptationIntervalMs: 1000, // 1s monitoring
|
|
39
|
+
degradationThreshold: 0.10, // 10% tolerance (edge constraints)
|
|
40
|
+
networkResilience: true // Handle node failures
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// IoT-specific metrics
|
|
45
|
+
export interface IoTMetrics extends UnifiedMetrics {
|
|
46
|
+
anomalyDetectionRate: number; // True positive anomaly detection
|
|
47
|
+
falseAlarmRate: number; // False positive rate (minimize network traffic)
|
|
48
|
+
powerConsumptionMw: number; // Power consumption (battery life critical)
|
|
49
|
+
networkLatencyMs: number; // Multi-hop network latency
|
|
50
|
+
sensorCoverage: number; // Sensor network coverage
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Sensor interface
|
|
54
|
+
export interface Sensor {
|
|
55
|
+
id: string;
|
|
56
|
+
reading: Float32Array;
|
|
57
|
+
timestamp: number;
|
|
58
|
+
batteryPercent: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Anomaly alert interface
|
|
62
|
+
export interface AnomalyAlert {
|
|
63
|
+
sensorId: string;
|
|
64
|
+
anomalyScore: number;
|
|
65
|
+
severity: 'warning' | 'critical';
|
|
66
|
+
correlatedSensors: string[];
|
|
67
|
+
timestamp: number;
|
|
68
|
+
latencyMs: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Example: Distributed anomaly detection
|
|
72
|
+
export async function detectAnomalies(
|
|
73
|
+
sensorReading: Float32Array & { id: string },
|
|
74
|
+
normalPatterns: any, // HNSWGraph type
|
|
75
|
+
neighborSensors: Sensor[],
|
|
76
|
+
applyAttention: (data: Float32Array, config: any) => Promise<Float32Array>,
|
|
77
|
+
createHyperedge: (readings: Float32Array[]) => Promise<Float32Array>,
|
|
78
|
+
severityThreshold: number = 0.8
|
|
79
|
+
): Promise<AnomalyAlert[]> {
|
|
80
|
+
const startTime = Date.now();
|
|
81
|
+
const config = IOT_ATTENTION_CONFIG;
|
|
82
|
+
|
|
83
|
+
// 4-head attention for lightweight processing
|
|
84
|
+
const enhanced = await applyAttention(sensorReading, config);
|
|
85
|
+
|
|
86
|
+
// Hypergraph: Correlate with neighbor sensors (multi-sensor patterns)
|
|
87
|
+
const hyperedge = await createHyperedge([
|
|
88
|
+
sensorReading,
|
|
89
|
+
...neighborSensors.map(s => s.reading)
|
|
90
|
+
]);
|
|
91
|
+
|
|
92
|
+
// Search for normal patterns
|
|
93
|
+
const matches = await normalPatterns.search(enhanced, 10);
|
|
94
|
+
|
|
95
|
+
// Anomaly = low similarity to normal patterns
|
|
96
|
+
const anomalyScore = 1 - matches[0].score;
|
|
97
|
+
|
|
98
|
+
if (anomalyScore > severityThreshold) {
|
|
99
|
+
// Dynamic-k: Get more candidates for anomaly analysis
|
|
100
|
+
const k = Math.round(3 + anomalyScore * 12); // 3-15 range
|
|
101
|
+
const detailedMatches = await normalPatterns.search(enhanced, k);
|
|
102
|
+
|
|
103
|
+
return [{
|
|
104
|
+
sensorId: sensorReading.id,
|
|
105
|
+
anomalyScore,
|
|
106
|
+
severity: anomalyScore > 0.9 ? 'critical' : 'warning',
|
|
107
|
+
correlatedSensors: neighborSensors.map(s => s.id),
|
|
108
|
+
timestamp: Date.now(),
|
|
109
|
+
latencyMs: Date.now() - startTime
|
|
110
|
+
}];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Performance targets for IoT
|
|
117
|
+
export const IOT_PERFORMANCE_TARGETS = {
|
|
118
|
+
p50LatencyMs: 5, // 5ms median (real-time monitoring)
|
|
119
|
+
anomalyDetectionRate: 0.95, // 95% true positive rate
|
|
120
|
+
falseAlarmRate: 0.05, // 5% false positive rate
|
|
121
|
+
powerConsumptionMw: 500, // 500mW max (battery life)
|
|
122
|
+
uptimePercent: 99.9 // 99.9% uptime (3 nines, edge resilience)
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// IoT platform-specific configurations
|
|
126
|
+
export const IOT_CONFIG_VARIATIONS = {
|
|
127
|
+
// ESP32 (very constrained, WiFi)
|
|
128
|
+
esp32: {
|
|
129
|
+
...IOT_ATTENTION_CONFIG,
|
|
130
|
+
heads: 2, // Minimal heads
|
|
131
|
+
precision: 'int8' as const,
|
|
132
|
+
powerBudgetMw: 200,
|
|
133
|
+
forwardPassTargetMs: 10,
|
|
134
|
+
batchSize: 1
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
// Raspberry Pi (more capable, still battery)
|
|
138
|
+
raspberryPi: {
|
|
139
|
+
...IOT_ATTENTION_CONFIG,
|
|
140
|
+
heads: 4,
|
|
141
|
+
precision: 'float16' as const,
|
|
142
|
+
powerBudgetMw: 1000, // 1W budget
|
|
143
|
+
forwardPassTargetMs: 5
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
// NVIDIA Jetson Nano (edge AI, powered)
|
|
147
|
+
jetsonNano: {
|
|
148
|
+
...IOT_ATTENTION_CONFIG,
|
|
149
|
+
heads: 8, // More capable
|
|
150
|
+
precision: 'float16' as const,
|
|
151
|
+
powerBudgetMw: 5000, // 5W budget
|
|
152
|
+
forwardPassTargetMs: 3,
|
|
153
|
+
batchSize: 4
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
// Google Coral TPU (ML accelerator)
|
|
157
|
+
coralTPU: {
|
|
158
|
+
...IOT_ATTENTION_CONFIG,
|
|
159
|
+
heads: 6,
|
|
160
|
+
precision: 'int8' as const, // TPU optimized
|
|
161
|
+
powerBudgetMw: 2000, // 2W budget
|
|
162
|
+
forwardPassTargetMs: 2,
|
|
163
|
+
batchSize: 8
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// Deployment environment adaptations
|
|
168
|
+
export function adaptConfigToDeployment(
|
|
169
|
+
baseConfig: typeof IOT_ATTENTION_CONFIG,
|
|
170
|
+
environment: 'urban' | 'industrial' | 'agricultural' | 'remote'
|
|
171
|
+
): typeof IOT_ATTENTION_CONFIG {
|
|
172
|
+
switch (environment) {
|
|
173
|
+
case 'urban':
|
|
174
|
+
return {
|
|
175
|
+
...baseConfig,
|
|
176
|
+
heads: 6, // More sensors, more complex
|
|
177
|
+
hypergraph: {
|
|
178
|
+
...baseConfig.hypergraph,
|
|
179
|
+
maxHyperedgeSize: 8 // Dense sensor network
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
case 'industrial':
|
|
183
|
+
return {
|
|
184
|
+
...baseConfig,
|
|
185
|
+
heads: 8, // High reliability needed
|
|
186
|
+
forwardPassTargetMs: 3,
|
|
187
|
+
powerBudgetMw: 2000 // Powered sensors
|
|
188
|
+
};
|
|
189
|
+
case 'agricultural':
|
|
190
|
+
return {
|
|
191
|
+
...baseConfig,
|
|
192
|
+
heads: 4,
|
|
193
|
+
powerBudgetMw: 300, // Solar-powered, battery constrained
|
|
194
|
+
selfHealing: {
|
|
195
|
+
...baseConfig.selfHealing,
|
|
196
|
+
networkResilience: true // Sparse network
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
case 'remote':
|
|
200
|
+
return {
|
|
201
|
+
...baseConfig,
|
|
202
|
+
heads: 2, // Minimal computation
|
|
203
|
+
precision: 'int8' as const,
|
|
204
|
+
powerBudgetMw: 100, // Extreme battery constraint
|
|
205
|
+
forwardPassTargetMs: 20 // Slower acceptable
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Battery-aware configuration
|
|
211
|
+
export function adaptConfigToBattery(
|
|
212
|
+
baseConfig: typeof IOT_ATTENTION_CONFIG,
|
|
213
|
+
batteryPercent: number,
|
|
214
|
+
chargingStatus: 'charging' | 'discharging' | 'solar'
|
|
215
|
+
): typeof IOT_ATTENTION_CONFIG {
|
|
216
|
+
if (chargingStatus === 'charging') {
|
|
217
|
+
return {
|
|
218
|
+
...baseConfig,
|
|
219
|
+
heads: 8 // Use more resources when charging
|
|
220
|
+
// Note: Precision optimization coming in future release
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (batteryPercent < 10) {
|
|
225
|
+
// Critical battery
|
|
226
|
+
return {
|
|
227
|
+
...baseConfig,
|
|
228
|
+
heads: 2,
|
|
229
|
+
precision: 'int8' as const,
|
|
230
|
+
powerBudgetMw: 100,
|
|
231
|
+
batchSize: 1
|
|
232
|
+
};
|
|
233
|
+
} else if (batteryPercent < 30) {
|
|
234
|
+
// Low battery
|
|
235
|
+
return {
|
|
236
|
+
...baseConfig,
|
|
237
|
+
heads: 3,
|
|
238
|
+
precision: 'int8' as const,
|
|
239
|
+
powerBudgetMw: 300
|
|
240
|
+
};
|
|
241
|
+
} else if (chargingStatus === 'solar') {
|
|
242
|
+
// Solar powered - adaptive
|
|
243
|
+
return {
|
|
244
|
+
...baseConfig,
|
|
245
|
+
heads: 5,
|
|
246
|
+
powerBudgetMw: 600
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return baseConfig;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Network topology adaptations
|
|
254
|
+
export interface NetworkTopology {
|
|
255
|
+
nodeCount: number;
|
|
256
|
+
averageDegree: number;
|
|
257
|
+
meshDensity: number;
|
|
258
|
+
gatewayDistance: number;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export function adaptConfigToTopology(
|
|
262
|
+
baseConfig: typeof IOT_ATTENTION_CONFIG,
|
|
263
|
+
topology: NetworkTopology
|
|
264
|
+
): typeof IOT_ATTENTION_CONFIG {
|
|
265
|
+
if (topology.meshDensity > 0.7) {
|
|
266
|
+
// Dense mesh - can use more correlations
|
|
267
|
+
return {
|
|
268
|
+
...baseConfig,
|
|
269
|
+
hypergraph: {
|
|
270
|
+
...baseConfig.hypergraph,
|
|
271
|
+
maxHyperedgeSize: 8
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
} else if (topology.meshDensity < 0.3) {
|
|
275
|
+
// Sparse mesh - limited correlations
|
|
276
|
+
return {
|
|
277
|
+
...baseConfig,
|
|
278
|
+
hypergraph: {
|
|
279
|
+
...baseConfig.hypergraph,
|
|
280
|
+
maxHyperedgeSize: 3
|
|
281
|
+
},
|
|
282
|
+
selfHealing: {
|
|
283
|
+
...baseConfig.selfHealing,
|
|
284
|
+
networkResilience: true
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return baseConfig;
|
|
290
|
+
}
|