unum-cloud / usearch

Fast Open-Source Search & Clustering engine Γ— for Vectors & πŸ”œ Strings Γ— in C++, C, Python, JavaScript, Rust, Java, Objective-C, Swift, C#, GoLang, and Wolfram πŸ”
https://unum-cloud.github.io/usearch/
Apache License 2.0
2.11k stars 122 forks source link

Bug: [Rust] all distances are zero #450

Closed embe-pw closed 3 weeks ago

embe-pw commented 1 month ago

Describe the bug

The computed L2sq distances seem to be always 0.

Steps to reproduce

use usearch::ffi::{IndexOptions, MetricKind};
use usearch::new_index;

fn main() {
    let options = IndexOptions {
        dimensions: 3,
        metric: MetricKind::L2sq,
        ..Default::default()
    };

    let index = new_index(&options).unwrap();
    index.reserve(10).unwrap();
    index.add(0, &[0.4, 0.1, 0.1]).unwrap();
    index.add(1, &[0.5, 0.1, 0.1]).unwrap();
    index.add(2, &[0.6, 0.1, 0.1]).unwrap();
    println!("{:?}", index.search(&[0.05, 0.1, 0.1], 2).unwrap());
}

prints

Matches { keys: [2, 1], distances: [0.0, 0.0] }

Expected behavior

Expected (and this is what usearch 2.9.2, which seems to be the last working version, outputs):

Matches { keys: [0, 1], distances: [0.122499995, 0.20249999] }

USearch version

2.12.0

Operating System

CentOS Stream 9

Hardware architecture

x86

Which interface are you using?

Other bindings

Contact Details

No response

Are you open to being tagged as a contributor?

Is there an existing issue for this?

Code of Conduct

ashvardanian commented 1 month ago

Interesting! Is it true for both f32 and f16 representations? Can you please share the exact model of the CPU printed from lscpu and the index.hardware_acceleration(). Thanks, @embe-pw πŸ€—

embe-pw commented 1 month ago

index.hardware_acceleration() returns "serial". CPU model is AMD EPYC 7413 24-Core Processor.

quantization: ScalarKind::F32 and quantization: ScalarKind::F64 seem to work correctly.

I can also reproduce this on an M1 Mac (with index.hardware_acceleration() == "neon"