hashish
@johnhenry/hashish implements
Locality-Sensitive Hashing
(LSH) for fast, scalable approximate nearest-neighbor / similarity search
over text. Documents are shingled, MinHashed, and bucketed with LSH banding
so that similar documents are cheap to find without comparing every pair.
Provenance:
hashishis a modernized fork ofagtabesh/lsh-js(previously published under that same name), rewritten in TypeScript with a fixed banding algorithm, no native dependencies, and a pluggable storage layer. See the repo’s CHANGELOG for what changed and why — including the banding bug this fork fixes.
- Zero native dependencies. MurmurHash3 is implemented in pure JS (no
node-gyp), works in Node, browsers, and edge runtimes. - Pluggable storage. In-memory by default; bring your own Redis-compatible client to share an index across processes or survive restarts.
- Correct LSH banding. Buckets are keyed by signature position, not just by value.
- TypeScript-first, ESM + CJS builds, no bundled dependencies.
Install
Section titled “Install”npm install @johnhenry/hashishQuick example
Section titled “Quick example”import { Hashish } from '@johnhenry/hashish'
const hashish = new Hashish({ shingleSize: 5, numberOfHashFunctions: 120, bucketSize: 4, // rows per LSH band; lower = more recall, higher = more precision})
await hashish.addDocument(1, 'the quick brown fox jumps over the lazy dog')await hashish.addDocument(2, 'the quick brown fox jumps over the lazy dog again')await hashish.addDocument(3, 'quarterly revenue projections indicate a modest increase')
// find documents similar to document 1const byId = await hashish.query({ id: 1 })
// re-rank LSH candidates by exact Jaccard similarity, and drop weak matchesconst ranked = await hashish.query({ id: 1, rerank: true, minSimilarity: 0.3, limit: 10 })// => [{ id: 2, similarity: 0.87 }]All index/query methods are async, so the same code works whether
storage is in-memory or a network-backed adapter like Redis.
The pages here
Section titled “The pages here”- API — constructor options,
addDocument/queryand the rest of the instance API, exporting/importing/migrating an index, and storage adapters - How it works — shingling, MinHashing, and LSH banding, explained
Development
Section titled “Development”npm installnpm run lintnpm run typechecknpm run testnpm run buildLicense
Section titled “License”MIT