1use crate::ModelConfig;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct ContextualConfig {
9 pub base_config: ModelConfig,
10 pub base_dim: usize,
12 pub context_dim: usize,
14 pub context_types: Vec<ContextType>,
16 pub adaptation_strategy: AdaptationStrategy,
18 pub fusion_method: ContextFusionMethod,
20 pub temporal_config: TemporalConfig,
22 pub interactive_config: InteractiveConfig,
24 pub cache_config: ContextCacheConfig,
26}
27
28impl Default for ContextualConfig {
29 fn default() -> Self {
30 Self {
31 base_config: ModelConfig::default(),
32 base_dim: 768,
33 context_dim: 512,
34 context_types: vec![ContextType::Query, ContextType::User, ContextType::Task],
35 adaptation_strategy: AdaptationStrategy::DynamicAttention,
36 fusion_method: ContextFusionMethod::MultiHeadAttention,
37 temporal_config: TemporalConfig::default(),
38 interactive_config: InteractiveConfig::default(),
39 cache_config: ContextCacheConfig::default(),
40 }
41 }
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
46pub enum ContextType {
47 Query,
49 User,
51 Task,
53 Temporal,
55 Interactive,
57 Domain,
59 CrossLingual,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize, Hash, PartialEq, Eq)]
65pub enum AdaptationStrategy {
66 DynamicAttention,
68 ConditionalLayerNorm,
70 AdapterLayers,
72 MetaLearning,
74 PromptBased,
76 MemoryAugmented,
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
82pub enum ContextFusionMethod {
83 Concatenation,
85 WeightedSum,
87 MultiHeadAttention,
89 TransformerFusion,
91 GraphFusion,
93 NeuralModules,
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize)]
99pub struct TemporalConfig {
100 pub enabled: bool,
102 pub time_window_hours: f64,
104 pub decay_factor: f32,
106 pub trend_analysis: bool,
108 pub seasonal_adjustment: bool,
110 pub max_history_entries: usize,
112}
113
114impl Default for TemporalConfig {
115 fn default() -> Self {
116 Self {
117 enabled: true,
118 time_window_hours: 24.0,
119 decay_factor: 0.9,
120 trend_analysis: true,
121 seasonal_adjustment: false,
122 max_history_entries: 1000,
123 }
124 }
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize)]
129pub struct InteractiveConfig {
130 pub enabled: bool,
132 pub feedback_learning_rate: f32,
134 pub max_feedback_history: usize,
136 pub aggregation_method: FeedbackAggregation,
138 pub online_learning: bool,
140 pub confidence_threshold: f32,
142}
143
144impl Default for InteractiveConfig {
145 fn default() -> Self {
146 Self {
147 enabled: true,
148 feedback_learning_rate: 0.01,
149 max_feedback_history: 500,
150 aggregation_method: FeedbackAggregation::WeightedAverage,
151 online_learning: false,
152 confidence_threshold: 0.7,
153 }
154 }
155}
156
157#[derive(Debug, Clone, Serialize, Deserialize)]
159pub struct ContextCacheConfig {
160 pub enabled: bool,
162 pub max_cache_size: usize,
164 pub ttl_seconds: u64,
166 pub lru_eviction: bool,
168 pub hit_ratio_threshold: f32,
170}
171
172impl Default for ContextCacheConfig {
173 fn default() -> Self {
174 Self {
175 enabled: true,
176 max_cache_size: 10000,
177 ttl_seconds: 3600,
178 lru_eviction: true,
179 hit_ratio_threshold: 0.8,
180 }
181 }
182}
183
184#[derive(Debug, Clone, Serialize, Deserialize)]
186pub enum FeedbackAggregation {
187 Average,
189 WeightedAverage,
191 ExponentialMoving,
193 ConfidenceWeighted,
195}