Skip to main content

vtcode_core/code/code_completion/learning/
data.rs

1use hashbrown::HashMap;
2
3/// Learning data for improving completion suggestions
4#[derive(Debug, Clone, Default)]
5pub struct CompletionLearningData {
6    /// Pattern acceptance rates by context
7    pub pattern_acceptance: HashMap<String, f64>,
8    /// Frequently used symbols by context
9    pub symbol_frequency: HashMap<String, usize>,
10    /// User preferences and patterns
11    pub user_preferences: HashMap<String, f64>,
12    /// Context-specific insights
13    pub context_insights: HashMap<String, HashMap<String, f64>>,
14}
15
16impl CompletionLearningData {
17    /// Update learning data based on user feedback
18    pub fn update_from_feedback(&mut self, suggestion: &str, accepted: bool) {
19        let current_rate = self.pattern_acceptance.get(suggestion).unwrap_or(&0.5);
20        let new_rate = if accepted {
21            (current_rate + 0.1).min(1.0)
22        } else {
23            (current_rate - 0.1).max(0.0)
24        };
25        self.pattern_acceptance.insert(suggestion.into(), new_rate);
26    }
27
28    /// Get insights for a specific context
29    pub fn get_context_insights(&self, context: &str) -> HashMap<String, f64> {
30        self.context_insights
31            .get(context)
32            .cloned()
33            .unwrap_or_default()
34    }
35
36    /// Record symbol usage frequency
37    pub fn record_symbol_usage(&mut self, symbol: &str) {
38        *self.symbol_frequency.entry(symbol.into()).or_insert(0) += 1;
39    }
40}