lance
lance copied to clipboard
bug(rust): wrong `q_factor` for Cosine in `RabitQuantizationStorage::dist_calculator`
In RabitQuantizationStorage::dist_calculator, q_factor is computed as:
let q_factor = match self.distance_type {
DistanceType::L2 => dist_q_c,
DistanceType::Cosine | DistanceType::Dot => dist_q_c - 1.0,
_ => unimplemented!(...),
};
dist_q_c is the distance between the query vector and the partition centroid.
However, Cosine distance has already been normalized to L2 distance earlier:
So for DistanceType::Cosine, q_factor should be dist_q_c (same as L2), not dist_q_c - 1.0.
Suggested fix:
let q_factor = match self.distance_type {
DistanceType::L2 | DistanceType::Cosine => dist_q_c,
DistanceType::Dot => dist_q_c - 1.0,
_ => unimplemented!(...),
};