vtcode_core/code/code_completion/learning/
data.rs1use std::collections::HashMap;
2
3#[derive(Debug, Clone, Default)]
5pub struct CompletionLearningData {
6 pub pattern_acceptance: HashMap<String, f64>,
8 pub symbol_frequency: HashMap<String, usize>,
10 pub user_preferences: HashMap<String, f64>,
12 pub context_insights: HashMap<String, HashMap<String, f64>>,
14}
15
16impl CompletionLearningData {
17 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 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 pub fn record_symbol_usage(&mut self, symbol: &str) {
39 *self.symbol_frequency.entry(symbol.to_string()).or_insert(0) += 1;
40 }
41}