use async_trait::async_trait;
use motosan_index_core::core::error::Result;
use motosan_index_core::core::node::NodeWithScore;
use motosan_index_core::traits::post_processor::PostProcessor;

/// Drop nodes whose similarity score falls below a threshold.
pub struct SimilarityCutoff {
    threshold: f32,
}

impl SimilarityCutoff {
    pub fn new(threshold: f32) -> Self {
        Self { threshold }
    }
}

#[async_trait]
impl PostProcessor for SimilarityCutoff {
    async fn process(&self, nodes: Vec<NodeWithScore>) -> Result<Vec<NodeWithScore>> {
        Ok(nodes
            .into_iter()
            .filter(|n| n.score >= self.threshold)
            .collect())
    }
}
