Skip to main content

Fast minimal implementation of HNSW maps for approximate nearest neighbors searches

Project description

Cover logo

Instant Distance: fast HNSW indexing

Build status License: MIT License: Apache 2.0

Instance Distance is a fast pure-Rust implementation of the Hierarchical Navigable Small Worlds paper by Malkov and Yashunin for finding approximate nearest neighbors. This implementation powers the InstantDomainSearch.com backend services used for word vector indexing.

What it does

Instant Distance is an implementation of a fast approximate nearest neighbor search algorithm. The algorithm is used to find the closest point(s) to a given point in a set. As one example, it can be used to make simple translations.

Using the library

Rust

[dependencies]
instant-distance = "0.5.0"

Example

use instant_distance::{Builder, Search};

fn main() {
    let points = vec![Point(255, 0, 0), Point(255, 0, 0), Point(255, 0, 0)];
    let values = vec!["red", "green", "blue"];

    let map = Builder::default().build(points, values);
    let mut search = Search::default();

    let cambridge_blue = Point(163, 193, 173);

    let closest_point = map.search(&cambridge_blue, &mut search).next().unwrap();

    println!("{:?}", closest_point.value);
}

#[derive(Clone, Copy, Debug)]
struct Point(isize, isize, isize);

impl instant_distance::Point for Point {
    fn distance(&self, other: &Self) -> f32 {
        // Euclidean distance metric
        (((self.0 - other.0).pow(2) + (self.1 - other.1).pow(2) + (self.2 - other.2).pow(2)) as f32)
            .sqrt()
    }
}

Testing

Rust:

cargo t -p instant-distance --all-features

Python:

make test-python

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

instant_distance-0.3.5-cp311-none-win_amd64.whl (262.6 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

instant_distance-0.3.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (346.4 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

instant_distance-0.3.5-cp311-cp311-macosx_10_7_x86_64.whl (327.2 kB view hashes)

Uploaded CPython 3.11 macOS 10.7+ x86-64

instant_distance-0.3.5-cp310-none-win_amd64.whl (262.6 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

instant_distance-0.3.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (346.4 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

instant_distance-0.3.5-cp310-cp310-macosx_10_7_x86_64.whl (327.2 kB view hashes)

Uploaded CPython 3.10 macOS 10.7+ x86-64

instant_distance-0.3.5-cp39-none-win_amd64.whl (262.9 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

instant_distance-0.3.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (346.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

instant_distance-0.3.5-cp39-cp39-macosx_11_0_arm64.whl (311.1 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

instant_distance-0.3.5-cp39-cp39-macosx_10_7_x86_64.whl (327.5 kB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

instant_distance-0.3.5-cp38-none-win_amd64.whl (262.7 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

instant_distance-0.3.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (347.0 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

instant_distance-0.3.5-cp38-cp38-macosx_10_7_x86_64.whl (327.3 kB view hashes)

Uploaded CPython 3.8 macOS 10.7+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page