1 个不稳定版本
0.1.0 | 2021年11月27日 |
---|
#14 in #dotnet
Used in vector_base
58KB
1K SLoC
RuAnnoy
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
度量 | 服务 | 构建 | jvm 绑定 | dotnet 绑定 | dart 绑定 |
---|---|---|---|---|---|
Angular | ✅ | ❌ | ✅ | ✅ | ✅ |
欧几里得 | ✅ | ❌ | ✅ | ✅ | ✅ |
曼哈顿 | ✅ | ❌ | ✅ | ✅ | ✅ |
点积 | ✅ | ❌ | ✅ | ✅ | ✅ |
汉明 | ❌ | ❌ | ❌ | ❌ | ❌ |
通过 crates.io 安装
# Cargo.toml
[dependencies]
annoy-rs = "0"
使用
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 支持
kotlin/java
It uses JNI bindings to rust crate and is ~5-10x faster than pure java implementation in benchmark scenario
通过 jitpack.io 安装
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.hanabi1224:RuAnnoy:<tag>'
}
使用
val index = AnnoyIndex.tryLoad("index.5d.ann", 5, IndexType.Angular)
dotnet
运行时 | Nuget 包 |
---|---|
RuAnnoy | |
RuAnnoy-Batteries-Windows-x64 | |
RuAnnoy-Batteries-Linux-x64 | |
RuAnnoy-Batteries-Darwin-x64 |
通过 nuget 安装
<ItemGroup>
<PackageReference Include="RuAnnoy" Version="*" />
<PackageReference Include="RuAnnoy-Batteries-Windows-x64" Version="*" />
</ItemGroup>
使用
var index = AnnoyIndex.Load("index.5d.ann", 5, IndexType.Angular);
dart
通过 pub.dev 安装
# pubspec.yaml
dependencies:
dart_native_annoy: ^0.1.0
使用
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);
待办事项
- 索引构建支持
- 从文件构建索引的 CLI 工具
依赖项
~2MB
~29K SLoC