Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/djc/instant-distance
Fast approximate nearest neighbor searching in Rust, based on HNSW index
https://github.com/djc/instant-distance
approximate-nearest-neighbor-search hnsw rust
Last synced: 22 days ago
JSON representation
Fast approximate nearest neighbor searching in Rust, based on HNSW index
- Host: GitHub
- URL: https://github.com/djc/instant-distance
- Owner: djc
- License: apache-2.0
- Created: 2020-12-14T15:15:27.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-10T13:18:00.000Z (about 1 month ago)
- Last Synced: 2024-10-11T02:19:21.885Z (about 1 month ago)
- Topics: approximate-nearest-neighbor-search, hnsw, rust
- Language: Rust
- Homepage:
- Size: 209 KB
- Stars: 307
- Watchers: 8
- Forks: 26
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Cover logo](./cover.svg)
# Instant Distance: fast HNSW indexing
[![Build status](https://github.com/InstantDomain/instant-distance/workflows/CI/badge.svg)](https://github.com/InstantDomain/instant-distance/actions?query=workflow%3ACI)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE-MIT)
[![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE-APACHE)Instance Distance is a fast pure-Rust implementation of the [Hierarchical
Navigable Small Worlds paper][paper] by Malkov and Yashunin for finding
approximate nearest neighbors. This implementation powers the
[Instant Domain Search][domains] 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][translations].## Using the library
### Rust
```toml
[dependencies]
instant-distance = "0.5.0"
```## Example
```rust
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
```[paper]: https://arxiv.org/abs/1603.09320
[domains]: https://instantdomainsearch.com/
[translations]: https://instantdomains.com/engineering/how-to-use-fasttext-for-instant-translations