Skip to content

MinHashLSH

Defined in: packages/distillate/src/minhash/lsh.ts:40

A banded locality-sensitive hashing index over MinHash signatures: finds the stored keys whose sets are likely at least threshold similar to a query, without comparing against every one.

const lsh = new MinHashLSH<string>({ threshold: 0.8 });
lsh.insert("doc-1", MinHash.from(shingles, 0.05));

K

new MinHashLSH<K>(params): MinHashLSH<K>

Defined in: packages/distillate/src/minhash/lsh.ts:57

Creates an empty index, choosing bands and rows with lshSizing, whose search costs about 10 ms at k 128 and a few hundred ms at 4096.

MinHashLSHParams

Threshold, slot count, weights and seed.

MinHashLSH<K>

get bands(): number

Defined in: packages/distillate/src/minhash/lsh.ts:193

Bands each signature is cut into.

number


get k(): number

Defined in: packages/distillate/src/minhash/lsh.ts:183

Slots in every sketch the index takes.

number


get rows(): number

Defined in: packages/distillate/src/minhash/lsh.ts:198

Slots per band.

number


get seed(): number

Defined in: packages/distillate/src/minhash/lsh.ts:188

Hash seed every sketch the index takes must share.

number


get size(): number

Defined in: packages/distillate/src/minhash/lsh.ts:203

Keys stored.

number


get threshold(): number

Defined in: packages/distillate/src/minhash/lsh.ts:178

Similarity the index was tuned for.

number

has(key): boolean

Defined in: packages/distillate/src/minhash/lsh.ts:149

Whether key is stored.

K

The key to look for.

boolean


insert(key, sketch): void

Defined in: packages/distillate/src/minhash/lsh.ts:79

Files a sketch under key, so later queries similar to it find key.

K

The key to store; must not already be stored.

MinHash

The key’s set, sketched with this index’s k and seed.

void

ParamError on a duplicate key or a sketch whose k or seed differs from the index’s.


query(sketch): K[]

Defined in: packages/distillate/src/minhash/lsh.ts:105

Finds the stored keys sharing at least one band with sketch: likely, not certainly, at least threshold similar. Confirm with MinHash.jaccard where it matters.

MinHash

The set to look up.

K[]

Each candidate key once, in no particular order.

ParamError if the sketch’s k or seed differs.


remove(key): boolean

Defined in: packages/distillate/src/minhash/lsh.ts:121

Unfiles key from every band.

K

The key to remove.

boolean

true if the key was stored.