In computer science, SimHash is a technique for quickly estimating how similar two sets are. The algorithm is used by the Google Crawler to find near duplicate pages. It was created by Moses Charikar. In 2021 Google announced its intent to also use the algorithm in their newly created FLoC (Federated Learning of Cohorts) system.
A hash function maps arbitrary data onto outputs of a fixed size. Hashing the same data produces the same result each time; a different hash output implies a distinct input. This, along with their fixed size, makes hashes useful for the comparison of large data. However, small differences in input data can yield significantly different hashes. Hash comparison is a binary signal (different or not), rather than a continuous similarity measure.
In contrast, SimHash creates hashes that produce similar hashes for similar input data, measured as the bitwise hamming distance between values. This means that not only do SimHashes indicate whether two inputs are different or not, but also their degree of difference, unlike other hashing functions.
The function operates by first breaking input data into a set of features. Each feature in the set is then hashed. The overall hash is defined by, for each bit within the input hashes, subtracting the count of hashes where the bit is not set (0) from the count of hashes where the bit is set (1). For indices of the hash where the difference is positive, the bit is set. For indices with a greater number of bits not set, the bit at that index in the final hash is not set.
In other words, each bit of the SimHash of a datum is set if, for each hash of the set of features in that datum, the sum of bits at that index is greater than the sum of the bitwise NOT of bits at that index.
As a result, two pieces of data with similar feature sets will have hashes that differ less than data where the sets of features diverge further. Additionally, "if the SimHash bitwise hamming distance of two phrases is low then their Jaccard coefficient is high." This allows for efficiencies including more efficient sorting (by comparing objects' SimHashes, rather than the entire object) and faster discovery of similar objects by sorting a list and comparing adjacent objects rather than the O(n^2) computation of each comparison in the list.
A large scale evaluation has been conducted by Google in 2006 to compare the performance of Minhash and Simhash algorithms. In 2007 Google reported using Simhash for duplicate detection for web crawling and using Minhash and LSH for Google News personalization.