horajs
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

hora-wasm

[Homepage] [Document] [Examples] [Hora]

Javascript bidding for the Hora Approximate Nearest Neighbor Search, in WebAssembly way.

Node Versions

The rust getrandom library, when used in ESM, requires a polyfill into globalThis.crypto. This is done automatically if you use Node 18 or lower, but you should know that this package overrides the globalThis.crypto.

import { webcrypto } from "node:crypto";
globalThis.crypto = webcrypto;

If using Node 19, 20 or greater this works out of the box.

Features

  • Performant ⚡️

    • SIMD-Accelerated (packed_simd)
    • Stable algorithm implementation
    • Multiple threads design
  • Multiple Indexes Support 🚀

    • Hierarchical Navigable Small World Graph Index(HNSWIndex) (detail)
    • Satellite System Graph (SSGIndex) (detail)
    • Product Quantization Inverted File(PQIVFIndex) (detail)
    • Random Projection Tree(RPTIndex) (LSH, WIP)
    • BruteForce (BruteForceIndex) (naive implementation with SIMD)
  • Reliability 🔒

    • Rust compiler secure all code
    • Memory managed by Rust for all language libs such as Python lib
    • Broad testing coverage
  • Multiple Distances Support 🧮

    • Dot Product Distance
      • equation
    • Euclidean Distance
      • equation
    • Manhattan Distance
      • equation
    • Cosine Similarity
      • equation
  • Productive

    • Well documented
    • Elegant and simple API, easy to learn

Benchmark

by aws t2.medium (CPU: Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz) more information

Installation

yarn add horajs

Example

import horaPromise from "horajs";

const demo = async () => {
    const hora = await horaPromise;
    await hora.init_env();
    await horajs.init_env();
    const dimension = 50;
    var bf_idx = horajs.BruteForceIndexUsize.new(dimension);
    // var hnsw_idx = horajs.HNSWIndexUsize.new(dimension, 1000000, 32, 64, 20, 500, 16, false);
    for (var i = 0; i < 1000; i++) {
        var feature = [];
        for (var j = 0; j < dimension; j++) {
            feature.push(Math.random());
        }
        bf_idx.add(feature, i); // add point
    }
    bf_idx.build("euclidean"); // build index
    var feature = [];
    for (var j = 0; j < dimension; j++) {
        feature.push(Math.random());
    }
    console.log("bf result", bf_idx.search(feature, 10)); //bf result Uint32Array(10) [704, 113, 358, 835, 408, 379, 117, 414, 808, 826]
}

demo();

License

The entire repo is under Apache License.

Contribution

Build scripts borrowed from brotli-wasm

Readme

Keywords

none

Package Sidebar

Install

npm i horajs

Weekly Downloads

1

Version

1.4.0

License

none

Unpacked Size

344 kB

Total Files

10

Last publish

Collaborators

  • jonluca