use crate::ModelConfig;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContextualConfig {
pub base_config: ModelConfig,
pub base_dim: usize,
pub context_dim: usize,
pub context_types: Vec<ContextType>,
pub adaptation_strategy: AdaptationStrategy,
pub fusion_method: ContextFusionMethod,
pub temporal_config: TemporalConfig,
pub interactive_config: InteractiveConfig,
pub cache_config: ContextCacheConfig,
}
impl Default for ContextualConfig {
fn default() -> Self {
Self {
base_config: ModelConfig::default(),
base_dim: 768,
context_dim: 512,
context_types: vec![ContextType::Query, ContextType::User, ContextType::Task],
adaptation_strategy: AdaptationStrategy::DynamicAttention,
fusion_method: ContextFusionMethod::MultiHeadAttention,
temporal_config: TemporalConfig::default(),
interactive_config: InteractiveConfig::default(),
cache_config: ContextCacheConfig::default(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum ContextType {
Query,
User,
Task,
Temporal,
Interactive,
Domain,
CrossLingual,
}
#[derive(Debug, Clone, Serialize, Deserialize, Hash, PartialEq, Eq)]
pub enum AdaptationStrategy {
DynamicAttention,
ConditionalLayerNorm,
AdapterLayers,
MetaLearning,
PromptBased,
MemoryAugmented,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ContextFusionMethod {
Concatenation,
WeightedSum,
MultiHeadAttention,
TransformerFusion,
GraphFusion,
NeuralModules,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TemporalConfig {
pub enabled: bool,
pub time_window_hours: f64,
pub decay_factor: f32,
pub trend_analysis: bool,
pub seasonal_adjustment: bool,
pub max_history_entries: usize,
}
impl Default for TemporalConfig {
fn default() -> Self {
Self {
enabled: true,
time_window_hours: 24.0,
decay_factor: 0.9,
trend_analysis: true,
seasonal_adjustment: false,
max_history_entries: 1000,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InteractiveConfig {
pub enabled: bool,
pub feedback_learning_rate: f32,
pub max_feedback_history: usize,
pub aggregation_method: FeedbackAggregation,
pub online_learning: bool,
pub confidence_threshold: f32,
}
impl Default for InteractiveConfig {
fn default() -> Self {
Self {
enabled: true,
feedback_learning_rate: 0.01,
max_feedback_history: 500,
aggregation_method: FeedbackAggregation::WeightedAverage,
online_learning: false,
confidence_threshold: 0.7,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContextCacheConfig {
pub enabled: bool,
pub max_cache_size: usize,
pub ttl_seconds: u64,
pub lru_eviction: bool,
pub hit_ratio_threshold: f32,
}
impl Default for ContextCacheConfig {
fn default() -> Self {
Self {
enabled: true,
max_cache_size: 10000,
ttl_seconds: 3600,
lru_eviction: true,
hit_ratio_threshold: 0.8,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum FeedbackAggregation {
Average,
WeightedAverage,
ExponentialMoving,
ConfidenceWeighted,
}