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.
Example
Section titled “Example”const lsh = new MinHashLSH<string>({ threshold: 0.8 });lsh.insert("doc-1", MinHash.from(shingles, 0.05));Type Parameters
Section titled “Type Parameters”K
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”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.
Parameters
Section titled “Parameters”params
Section titled “params”Threshold, slot count, weights and seed.
Returns
Section titled “Returns”MinHashLSH<K>
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get bands():
number
Defined in: packages/distillate/src/minhash/lsh.ts:193
Bands each signature is cut into.
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get k():
number
Defined in: packages/distillate/src/minhash/lsh.ts:183
Slots in every sketch the index takes.
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get rows():
number
Defined in: packages/distillate/src/minhash/lsh.ts:198
Slots per band.
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get seed():
number
Defined in: packages/distillate/src/minhash/lsh.ts:188
Hash seed every sketch the index takes must share.
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get size():
number
Defined in: packages/distillate/src/minhash/lsh.ts:203
Keys stored.
Returns
Section titled “Returns”number
threshold
Section titled “threshold”Get Signature
Section titled “Get Signature”get threshold():
number
Defined in: packages/distillate/src/minhash/lsh.ts:178
Similarity the index was tuned for.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”has(
key):boolean
Defined in: packages/distillate/src/minhash/lsh.ts:149
Whether key is stored.
Parameters
Section titled “Parameters”K
The key to look for.
Returns
Section titled “Returns”boolean
insert()
Section titled “insert()”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.
Parameters
Section titled “Parameters”K
The key to store; must not already be stored.
sketch
Section titled “sketch”The key’s set, sketched with this index’s k and seed.
Returns
Section titled “Returns”void
Throws
Section titled “Throws”ParamError on a duplicate key or a sketch whose k or
seed differs from the index’s.
query()
Section titled “query()”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.
Parameters
Section titled “Parameters”sketch
Section titled “sketch”The set to look up.
Returns
Section titled “Returns”K[]
Each candidate key once, in no particular order.
Throws
Section titled “Throws”ParamError if the sketch’s k or seed differs.
remove()
Section titled “remove()”remove(
key):boolean
Defined in: packages/distillate/src/minhash/lsh.ts:121
Unfiles key from every band.
Parameters
Section titled “Parameters”K
The key to remove.
Returns
Section titled “Returns”boolean
true if the key was stored.