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 {
12            confidence_threshold: 0.3,
13            max_suggestions: 10,
14        }
15    }
16
17    /// Rank and filter suggestions based on confidence and relevance
18    pub fn rank_suggestions(
19        &self,
20        mut suggestions: Vec<CompletionSuggestion>,
21    ) -> Vec<CompletionSuggestion> {
22        // Filter by confidence threshold
23        suggestions.retain(|s| s.confidence >= self.confidence_threshold);
24
25        // Sort by confidence and acceptance rate
26        suggestions.sort_by(|a, b| {
27            let score_a = a.confidence * 0.7 + a.acceptance_rate * 0.3;
28            let score_b = b.confidence * 0.7 + b.acceptance_rate * 0.3;
29            score_b
30                .partial_cmp(&score_a)
31                .unwrap_or(std::cmp::Ordering::Equal)
32        });
33
34        // Limit to max suggestions
35        suggestions.truncate(self.max_suggestions);
36        suggestions
37    }
38}
39
40impl Default for SuggestionRanker {
41    fn default() -> Self {
42        Self::new()
43    }
44}