Giter Site home page Giter Site logo

josephrocca / annoy-js-test Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hanabi1224/ruannoy

0.0 2.0 0.0 7.99 MB

Testing Wasm build of Rust port (https://github.com/hanabi1224/RuAnnoy) of annoy (https://github.com/spotify/annoy)

License: MIT License

Rust 60.96% C# 13.01% Shell 0.94% Python 2.05% Kotlin 17.04% Java 0.82% Batchfile 0.39% Dart 1.94% JavaScript 0.31% Vue 2.26% HTML 0.18% TypeScript 0.10%

annoy-js-test's Introduction

RuAnnoy

main MIT License

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

A live demo using web assembly is available at https://annoy-web-demo.vercel.app/

It also provides FFI bindings for jvm, dotnet and dart

Metric Serve Build jvm binding dotnet binding dart binding WASM support
Angular
Euclidean
Manhattan
Dot
Hamming

Install via crates.io

Crates.io codecov dependency status

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

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);

SIMD support

SIMD is supported via std::simd on nightly rust. Note that avx intrinsics need to be enabled explicitly by setting your cpu features in RUSTFLAGS environment variable.

RUSTFLAGS="-Ctarget-feature=+avx" cargo +nightly build --release
# or
RUSTFLAGS="-Ctarget-cpu=native" cargo +nightly build --release

WASM support

Install wasm-pack

wasm-pack build
wasm-pack test --node

simd128 is supported in chrome by default.

To enable simd128, build with below command

RUSTFLAGS="-Ctarget-feature=+simd128" cargo +nightly build --release --target wasm32-unknown-unknown

An example site is deployed at https://annoy-web-demo.vercel.app/

Source code is under example/web

FFI support

kotlin/java

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

Note that the prebuilt dynamically linked libraries are built with simd support, avx cpu feature is required.

Install via jitpack.io

Release

repositories {
  mavenCentral()
  maven { url 'https://jitpack.io' }
}

dependencies {
  implementation 'com.github.hanabi1224:RuAnnoy:<tag>'
}

Usage

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

dotnet

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

Install via nuget

  <ItemGroup>
    <PackageReference Include="RuAnnoy" Version="*" />
    <PackageReference Include="RuAnnoy-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 indexFactory = AnnoyIndexFactory(lib: DynamicLibrary.open('libannoy_rs_ffi.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

annoy-js-test's People

Contributors

hanabi1224 avatar josephrocca avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.