Skip to main content

vtcode_core/code/code_completion/engine/
ranking.rs

1use super::suggestions::CompletionSuggestion;
2
3/// Suggestion ranking and filtering system
4pub struct SuggestionRanker {
5    confidence_threshold: f64,
6    max_suggestions: usize,
7}
8
9impl SuggestionRanker {
10    pub fn new() -> Self {
11        Self { confidence_threshold: 0.3, max_suggestions: 10 }
12    }
13
14    /// Rank and filter suggestions based on confidence and relevance
15    pub fn rank_suggestions(&self, mut suggestions: Vec<CompletionSuggestion>) -> Vec<CompletionSuggestion> {
16        // Filter by confidence threshold
17        suggestions.retain(|s| s.confidence >= self.confidence_threshold);
18
19        // Sort by confidence and acceptance rate
20        suggestions.sort_by(|a, b| {
21            let score_a = a.confidence * 0.7 + a.acceptance_rate * 0.3;
22            let score_b = b.confidence * 0.7 + b.acceptance_rate * 0.3;
23            score_b.partial_cmp(&score_a).unwrap_or(std::cmp::Ordering::Equal)
24        });
25
26        // Limit to max suggestions
27        suggestions.truncate(self.max_suggestions);
28        suggestions
29    }
30}
31
32impl Default for SuggestionRanker {
33    fn default() -> Self {
34        Self::new()
35    }
36}