#[derive(Debug, Clone)]
pub(super) struct SearchResult {
pub(super) id: u32,
pub(super) similarity: f32,
}
impl PartialEq for SearchResult {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}
impl Eq for SearchResult {}
impl PartialOrd for SearchResult {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for SearchResult {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.similarity
.partial_cmp(&other.similarity)
.unwrap_or(std::cmp::Ordering::Equal)
}
}
pub(super) fn euclidean_distance(a: &[f32], b: &[f32]) -> f32 {
a.iter()
.zip(b.iter())
.map(|(x, y)| (x - y).powi(2))
.sum::<f32>()
.sqrt()
}