Fast approximate nearest neighbor searching in Rust, based on HNSW index
Go to file
jinglybits ef655dac8f replace GH cover image (#51)
* replaced GH cover image

* replaced cover image with optimized svg
2023-11-15 10:32:08 -08:00
.cargo Fix rustflags setup for PyO3 2021-11-10 09:27:19 +01:00
.github py: looks like we need --no-sdist for publish after all 2023-02-02 13:12:25 +01:00
.vscode First cut of python bindings update 2021-05-21 17:34:33 +02:00
instant-distance Update ordered-float requirement from 3.0 to 4.1 2023-09-25 15:58:39 +02:00
instant-distance-py Upgrade pyo3 to 0.20 2023-10-12 16:26:16 +02:00
.gitignore Ignore .DS_Store cruft 2021-05-17 13:37:11 +02:00
Cargo.toml Set resolver workspace to 2 2023-10-12 16:26:16 +02:00
LICENSE Add LICENSE 2021-08-18 22:05:57 +02:00
Makefile Force rm in clean target 2021-11-10 09:23:50 +01:00
README.md Fix example in README 2023-02-21 19:57:45 +01:00
cover.svg replace GH cover image (#51) 2023-11-15 10:32:08 -08:00
deny.toml Add configuration for cargo-deny 2020-12-16 10:17:29 +01:00

README.md

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(0, 255, 0), Point(0, 0, 255)];
    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