Skip to main content

uqa_storage/vector_index/config/diskann/
alpha.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7use crate::StorageBackendResult;
8
9/// Euclidean pruning factor with validated, equality-stable IEEE-754 bits.
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub struct DiskANNAlpha(u64);
12
13impl DiskANNAlpha {
14    pub fn new(value: f64) -> StorageBackendResult<Self> {
15        if !value.is_finite() || value < 1.0 || !(value * value).is_finite() {
16            return Err(super::invalid(
17                "alpha",
18                "must be finite, at least 1, and have a finite square",
19            ));
20        }
21        Ok(Self(value.to_bits()))
22    }
23
24    pub fn get(self) -> f64 {
25        f64::from_bits(self.0)
26    }
27
28    pub fn squared(self) -> f64 {
29        self.get() * self.get()
30    }
31}
32
33impl Default for DiskANNAlpha {
34    fn default() -> Self {
35        Self(1.2_f64.to_bits())
36    }
37}