vtcode_core/code/code_completion/learning/
data.rs

1use std::collections::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
26            .insert(suggestion.to_string(), new_rate);
27    }
28
29    /// Get insights for a specific context
30    pub fn get_context_insights(&self, context: &str) -> HashMap<String, f64> {
31        self.context_insights
32            .get(context)
33            .cloned()
34            .unwrap_or_default()
35    }
36
37    /// Record symbol usage frequency
38    pub fn record_symbol_usage(&mut self, symbol: &str) {
39        *self.symbol_frequency.entry(symbol.to_string()).or_insert(0) += 1;
40    }
41}