Giter Site home page Giter Site logo

wherefortravel / minhash-node-rs Goto Github PK

View Code? Open in Web Editor NEW
13.0 19.0 1.0 235 KB

MinHash and LSH index written in Rust for Node.js

JavaScript 0.74% Rust 99.26%
nodejs rust minhash locality-sensitive-hashing lsh minhash-lsh-algorithm node node-js node-module neon-bindings

minhash-node-rs's Introduction

minhash-node-rs

minhash-node-rs is a library for Node.js designed to calculate the MinHash of inputs, as well as being able to index them and allow sub-linear query time in a LSH index.

It is written in Rust for high performance and (relatively) low memory overhead, as well as memory safety.

Why?

Why use MinHash? Sometimes you might want to look for documents that are almost the same, but not exactly, and you want to find them in sub-linear time (less than O(N) on average). LshIndex provides a way to look up near duplicates for a document in near constant time.

Why use Rust? Node.js & V8 can have very poor performance with the garbage collector when objects get large. Since objects such as the LSH index can become huge, we don't want to tax the GC too much. Writing this natively allows for that.

How do I use it?

Here is an example:

import { PermGen, MinHash, LshIndex } from 'minhash-node-rs'

const permGen = new PermGen(128) // 128 is the number of permutations to use when hashing

const hash = new MinHash(permGen) // we allocate MinHash using the permutations of previous PermGen instance

hash.update(permGen, 'hello') // add the word hello
hash.update(permGen, 'world') // add the word world

const hash2 = new MinHash(permGen)

hash2.update(permGen, 'world') // add words
hash2.update(permGen, 'test') // add words

console.log(hash.jaccard(hash2)) // print jaccard similarity

const index = new LshIndex() // construct LSH index

index.insert('hash', hash) // insert hash

console.log(index.query(hash2)) // query for near duplicates

Who uses this?

WhereTo.com uses this in production to detect near duplicate data. If you use this in production, feel free to submit a Pull Request.

minhash-node-rs's People

Contributors

bgdavidx avatar dependabot[bot] avatar mokcrimea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

killix

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.