MCPcopy Index your code
hub / github.com/djc/instant-distance

github.com/djc/instant-distance @py-0.3.6

Chat with this repo
repository ↗ · DeepWiki ↗ · release py-0.3.6 ↗ · + Follow
101 symbols 251 edges 8 files 20 documented · 20% updated 15d ago★ 3472 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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 Instant Domain Search 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

Extension points exported contracts — how you extend this code

Layer (Interface)
(no doc) [3 implementers]
instant-distance/src/types.rs
Point (Interface)
(no doc) [1 implementers]
instant-distance/src/lib.rs

Core symbols most depended-on inside this repo

iter
called by 16
instant-distance/src/lib.rs
push
called by 16
instant-distance/src/lib.rs
clear
called by 10
instant-distance/src/types.rs
into_inner
called by 5
instant-distance/src/types.rs
search
called by 5
instant-distance/src/lib.rs
next
called by 4
instant-distance/src/types.rs
is_zero
called by 4
instant-distance/src/types.rs
select_heuristic
called by 4
instant-distance/src/lib.rs

Shape

Method 58
Class 27
Function 12
Enum 2
Interface 2

Languages

Rust95%
Python5%

Modules by API surface

instant-distance/src/lib.rs33 symbols
instant-distance/src/types.rs28 symbols
instant-distance-py/src/lib.rs23 symbols
instant-distance/tests/all.rs6 symbols
instant-distance/examples/colors.rs3 symbols
instant-distance/benches/all.rs3 symbols
instant-distance-py/examples/translations/translate.py3 symbols
instant-distance-py/test/test.py2 symbols

For agents

$ claude mcp add instant-distance \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact