MinHashSharp offers a simple lightweight data structure designed to index and estimate Jaccard similarity between sets. Leveraging its robust structure, it has been successfully tested on datasets as large as 60GB, encompassing tens of millions of documents, while ensuring smooth and efficient operations.
To incorporate MinHashSharp into your project, choose one of the following methods:
dotnet add package MinHashSharpInstall-Package MinHashSharpFor detailed package information, visit MinHashSharp on NuGet.
The library currently offers two classes:
MinHash: A probabilistic data structure for computing Jaccard similarity between sets.
MinHashLSH: A class for supporting big-data fast querying using an approximate Jaccard similarity threshold.
strings1="The quick brown fox jumps over the lazy dog and proceeded to run towards the other room";strings2="The slow purple elephant runs towards the happy fox and proceeded to run towards the other room";strings3="The quick brown fox jumps over the angry dog and proceeded to run towards the other room";varm1=newMinHash(numPerm:128).Update(s1.Split());varm2=newMinHash(numPerm:128).Update(s2.Split());varm3=newMinHash(numPerm:128).Update(s3.Split());Console.WriteLine(m1.Jaccard(m2));// 0.51varlsh=newMinHashLSH(threshold:0.8,numPerm:128);lsh.Insert("s1",m1);lsh.Insert("s2",m2);Console.WriteLine(string.Join(", ",lsh.Query(m3)));// s1The library is entirely thread-safe except for the MinHashLSH.Insert function (and the custom injected hash function, if relevant). Therefore, you can create MinHash objects on multiple threads and query the same MinHashLSH object freely. If you are indexing sets on multiple threads, then just make sure to gain exclusive access to the LSH around every Insert call:
lock(lsh){lsh.Insert("s3",m3);}By default, the library uses the Farmhash function introduced by Google for efficiency. For more accurate hashes, one can inject a custom hash function into the MinHash object.
For example, if you want to use the C# default string hash function:
staticuintStringHash(strings)=>(uint)s.GetHashCode();varm=newMinHash(numPerm:128,hashFunc:StringHash).Update(s1.Split());