Skip to content

Rust-port of spotify/annoy as a wrapper for Approximate Nearest Neighbors in C++/Python optimized for memory usage.

License

Notifications You must be signed in to change notification settings

ArthurTh0mas/fareast

Repository files navigation

Fareast

main travis MIT License

This library is a rust port of spotify/annoy , currently only index serving is supported.

It also provides FFI bindings for jvm, dotnet and dart

Metric Serve Build jvm Binding dotnet Binding dart Binding
Angular
Euclidean
Manhattan
Dot
Hamming

Install via crates.io

Crates.io codecov

# Cargo.toml
[dependencies]
annoy-rs = "0"

Usage

use annoy_rs::*;

let index = AnnoyIndex::load(10, "index.ann", IndexType::Angular).unwrap();
let v0 = index.get_item_vector(0);
let nearest = index.get_nearest(v0.as_ref(), 5, -1, true);

FFI support

kotlin/java

It uses JNI bindings to rust crate and is ~5-10x faster than pure java implementation in benchmark scenario

Install via jitpack.io

Release

repositories {
  mavenCentral()
  maven { url 'https://jitpack.io' }
}
  
dependencies {
  implementation 'com.github.ng8eke:Fareast:<tag>'
}

Usage

val index = AnnoyIndex.tryLoad("index.5d.ann", 5, IndexType.Angular)

dotnet

Runtimes Nuget package
Fareast NuGet version
Fareast-Batteries-Windows-x64 NuGet version
Fareast-Batteries-Linux-x64 NuGet version
Fareast-Batteries-Darwin-x64 NuGet version

Install via nuget

  <ItemGroup>
    <PackageReference Include="Fareast" Version="*" />
    <PackageReference Include="Fareast-Batteries-Windows-x64" Version="*" />
  </ItemGroup>

Usage

var index = AnnoyIndex.Load("index.5d.ann", 5, IndexType.Angular);

dart

Install via pub.dev

# pubspec.yaml
dependencies:
  dart_native_annoy: ^0.1.0

Usage

import 'dart:ffi';
import 'package:dart_native_annoy/annoy.dart';

/// Creat factory from DynamicLibrary
final fac = AnnoyIndexFactory(lib: DynamicLibrary.open('libannoy_rs.so'));

/// Load index
final index = indexFactory.loadIndex(
      'index.euclidean.5d.ann', 5, IndexType.Euclidean)!;

print('size: ${index.size}');

final v3 = index.getItemVector(3);

final nearest = index.getNearest(v0, 5, includeDistance: true);

TODO

  • Index building support
  • CLI tool to build index from file

About

Rust-port of spotify/annoy as a wrapper for Approximate Nearest Neighbors in C++/Python optimized for memory usage.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published