Why Jaccard similarity catches more duplicates than exact matching
At BudgetTechIndia, I lead the backend engineering efforts, and like many content-driven sites, we rely on automated pipelines to generate articles from a keyword bank. We ran into a significant problem recently where our content pipeline was generating near-duplicate content, leading to Google indexing only our homepage, leaving 21 new posts in the void. This was a clear sign that our duplicate detection system was failing.
The core issue was that the pipeline sometimes targeted very similar, overlapping keywords. For example, it might generate an article for “best phone under 10000” and then another for “best phone under 10000 with 8GB RAM.” While these are distinct keywords, they clearly target the same search intent.
Our initial duplicate check was straightforward: if a new keyword exactly matched an existing post title, it was rejected. This exact string matching approach seemed logical at first, but it proved to be insufficient for the nuances of SEO and semantic content.
The problem with exact matching
Exact matching is simple and effective for identical strings, but it’s blind to semantic variations. It misses content that, while phrased differently, targets the same user intent and covers essentially the same topic. Here are some examples of what our old system missed:
* “Best phone under 10000 India” vs “Top 10 phones under Rs 10000 in India”
* “Best laptop under 35000 with 16GB RAM” vs “Laptop under 35000 with 16GB RAM India”
* “Redmi 13C 5G review” vs “Redmi 13C 5G review India real usage”
In each of these pairs, the underlying search intent is nearly identical. Google’s algorithms are sophisticated enough to recognize this, and publishing multiple articles that address the same intent can lead to penalties like de-indexing or lower rankings, as we experienced. Our exact matching system treated all these as distinct, allowing near-duplicate content to be published.
The solution: Jaccard similarity
To address this, I implemented a new `scoreDuplicate()` function that leverages Jaccard similarity on normalized titles. Jaccard similarity is a measure of the similarity between two sets, defined as the size of the intersection divided by the size of the union of the sets. In our context, these “sets” are the words from our article titles.
The algorithm for calculating Jaccard similarity on titles involves a few key steps:
1. **Strip HTML tags and normalize case:** This ensures that “Best Phone” and “best phone” are treated identically.
2. **Remove year markers and filler words:** Words like “the,” “a,” “an,” “of,” “for,” “in,” “on,” “to,” “and,” “or,” “with,” and specific years (e.g., “2024”) often don’t contribute to the core semantic meaning.
3. **Tokenize into individual words:** Break the cleaned title string into a set of unique words.
4. **Calculate Jaccard similarity:** Apply the Jaccard formula to the two sets of words.
Here’s the core JavaScript function I used:
function jaccardScore(left, right) {
const a = tokenize(left); // tokenize handles normalization and word extraction
const b = tokenize(right);
if (!a.size || !b.size) return 0; // Avoid division by zero if a set is empty
let overlap = 0;
for (const token of a) {
if (b.has(token)) overlap += 1;
}
return overlap / (a.size + b.size - overlap);
}
Let’s walk through an example using two of the titles that exact matching missed: “Best phone under 10000 India” vs “Top 10 phones under Rs 10000 in India”.
* **Original titles:**
* `left`: “Best phone under 10000 India”
* `right`: “Top 10 phones under Rs 10000 in India”
* **After normalization (stripping filler words, case normalization, removing “Rs”):**
* `a`: {“phone”, “10000”, “india”}
* `b`: {“top”, “10”, “phones”, “10000”, “india”}
* **Intersection:** The words common to both sets are {“phone”, “10000”, “india”}.
* `overlap` = 3
* **Union:** All unique words from both sets combined are {“phone”, “10000”, “india”, “top”, “10”, “phones”}.
* `a.size` = 3
* `b.size` = 5
* `union` = `a.size` + `b.size` – `overlap` = 3 + 5 – 3 = 5
* **Jaccard Similarity:** `overlap` / `union` = 3 / 5 = 0.60
With a defined threshold, for instance, 0.65, this pair would be flagged as a duplicate. While 0.60 is just below that threshold, it’s significantly higher than 0 (what exact matching would yield) and indicates a strong similarity. This score contributes to a broader duplicate detection system.
The layered approach
Jaccard similarity alone, while powerful for semantic overlap, isn’t always enough to catch all types of duplicates or to provide a robust confidence score. I found that a layered scoring system provided a more comprehensive and accurate detection mechanism. This system combines multiple signals, each contributing to a final duplicate score:
1. **Exact title match:** A quick check for perfectly identical titles.
2. **Normalized title match:** Checks for titles that are identical after case normalization and punctuation removal.
3. **Slug match:** Compares the URL slugs, which can catch duplicates even if titles are slightly varied but point to the same core topic.
4. **Keyword overlap:** Checks if the incoming keyword appears verbatim or significantly within an existing title.
5. **Category comparison:** Posts within the same category are more likely to be duplicates, so this provides a similarity bonus.
6. **Jaccard similarity:** The semantic overlap score, as described above.
The final score for an incoming post is a weighted sum of these individual components:
score = slugMatch * 1.0 + titleSim * 0.55 + bodySim * 0.35 + sameCategory * 0.1 + keywordHit * 0.2
A post is ultimately rejected as a duplicate if the `score` reaches or exceeds `0.78`. Additionally, specific high similarity thresholds for individual components can also trigger a rejection: if `titleSimilarity` is `0.7` or higher, or `contentSimilarity` (derived from `bodySim`) is `0.8` or higher, the post is also rejected, regardless of the overall weighted score.
A critical fix: don’t strip core keywords
During the implementation and testing of the Jaccard similarity, I discovered a critical flaw in my `normalizeForSeo()` function, which is responsible for cleaning up titles before tokenization. The original function was overly aggressive, stripping words like “india,” “best,” “guide,” “review,” and “budget.”
The problem was that these words are crucial semantic indicators. For example, “Best phone India” and “Top phone India guide” would both become empty strings after normalization if “best,” “top,” “india,” and “guide” were removed. This resulted in empty sets for tokenization, leading to a Jaccard score of 0, effectively missing duplicates that were semantically very close. The system was failing because the input to the similarity algorithm was meaningless.
The fix was to refine the `normalizeForSeo()` function to be much more selective, only stripping pure filler words and year markers that genuinely don’t contribute to the unique meaning of a title:
.replace(/\b(2024|2025|2026|2027|the|a|an|of|for|in|on|to|and|or|with)\b/g, " ")
This change ensured that important keywords remained, allowing the Jaccard similarity algorithm to accurately compare the core semantic content of the titles.
Verification
After implementing the layered approach and, crucially, fixing the normalization function, I tested the new duplicate detection system against the existing 21 posts that were previously published and ignored by Google. The results were encouraging and confirmed the effectiveness of the new system:
* The system correctly identified “Best phone under 10000 with 8GB RAM India” as overlapping with “Best phone under 10000 with NFC India.” These posts had a title similarity of 0.55 and were in the same category, contributing to a high overall duplicate score.
* It also flagged “Best laptop under 35000 with 16GB RAM India” as overlapping with “Best laptop under 35000 India,” showing a title similarity of 0.60.
These pairs would have been published as near-duplicates with the old exact-matching approach, contributing to our indexing problems. The new system successfully identified them, preventing future content pipeline errors.
What I would check first next time
This experience taught me valuable lessons about building robust duplicate detection systems. When approaching similar tasks in the future, I will prioritize these checks:
1. **Test the normalization function early and thoroughly:** Before even implementing the similarity algorithm, I will create a suite of real-world examples and test the normalization function against them. If the normalizer strips too much or too little, the similarity score will be meaningless. It’s the foundation upon which everything else is built.
2. **Implement a keyword cooldown period:** Even if two keywords are not exact or semantic duplicates by the Jaccard score, publishing on the exact same topic within a short timeframe (e.g., 60 days) can still be a signal that Google might penalize. Adding a simple cooldown period for broad topics or keywords can act as an additional safeguard.
By combining semantic similarity with a layered scoring approach and ensuring proper data normalization, I was able to build a much more effective duplicate detection system, preventing future content pipeline issues and ensuring our articles have a better chance of being indexed by Google.




