SEO

What Is Keyword Clustering and How Do You Do It?

Keyword clustering explained: SERP-based vs semantic grouping, the overlap threshold, 2 tested Python scripts and a worked example with 23 real keywords.

Published On:

Painted alpine valley river with a card showing 4 keyword clusters from one keyword list
Table of contents

Keyword clustering is the step that groups keywords one page can answer, so you plan one page for each group instead of one page for each keyword.

I grouped 23 real autocomplete keywords by shared search results and by meaning, and the 2 methods gave the same answer for 20 of them. This guide covers the 2 methods, the overlap threshold, the steps, 2 Python scripts, an AI prompt, clustering tools and the rule for turning a cluster into a page.

What is keyword clustering?

Keyword clustering is the practice of sorting a keyword list into groups, where every keyword in a group has the same search intent (the reason behind a search). One group becomes one page.

Keyword clustering SEO (search engine optimization) work sits between keyword research and page planning. A finished cluster has 3 parts:

  • Primary keyword: The primary keyword is the main search in the cluster, and it goes in the page title.
  • Secondary keywords: Secondary keywords are the other searches in the cluster, and they become headings, sentences or questions on the page.
  • Page type: The page type is the format that ranks for the cluster, such as a guide, a list, a product page or a free tool.

Google's SEO Starter Guide says its language matching can relate one page to many queries, even when the page does not use the exact terms.[1] One page for a group of searches relies on language matching.

I do keyword research, SERP (search engine results page) analysis and full-site SEO audits. In keyword research, clustering is the check that decides how many pages a keyword list needs.

My guide to how to do keyword research covers the steps before clustering, from seed topics and autocomplete to reading page one.

SERP-based vs semantic keyword clustering: which should you use?

Use SERP-based clustering when a page decision depends on the result, and use semantic keyword clustering to sort a long list fast. The 2 methods look at different evidence:

  • SERP-based clustering: SERP-based clustering groups 2 keywords when the same URLs (web page addresses) rank for both keywords in a search engine.
  • Semantic clustering: Semantic clustering groups 2 keywords when their words mean nearly the same thing, measured by a language model.
  • Hybrid clustering: Hybrid clustering sorts the full list by meaning first, then checks the important groups against search results.

Similar words can hide different results. In my check, "how to check keyword cannibalization" and "how to check keyword cannibalization in semrush" shared only 1 URL.

Different words can also share results. "What is keyword cannibalization" and "how to fix keyword cannibalization" shared 8 of 10 URLs, so one page can define the problem and fix it.

Note: SERP-based clusters change when rankings change, and semantic clusters change when you switch language models. Save the date and the settings next to every cluster list.

Which overlap threshold should you set?

Start with 4 shared URLs in the top 10, the number that gave the cleanest groups in my check. The overlap threshold is the minimum number of shared URLs that puts 2 keywords in one cluster.

Clustering products start from different numbers. Keyword Insights uses a 30% URL overlap by default, which is 3 of the top 10 results.[2]

SE Ranking lets you choose an accuracy from 1 to 9, which is the minimum number of matching URLs.[3] I ran my 23 keywords at 5 thresholds to see what each number does:

  • 2 shared URLs: The list became 3 clusters, and the Google Ads keywords fell into the general SEO group.
  • 3 shared URLs: The list became 4 clusters, but the 2 Semrush keywords were split even though they share 5 URLs.
  • 4 shared URLs: The list became 4 clusters with clean groups for general SEO, Semrush, Google Ads and checker tools.
  • 5 shared URLs: The list became 5 clusters, and "keyword cannibalization examples" was paired with "keyword cannibalization google ads".
  • 6 shared URLs: The list became 8 clusters, and "keyword cannibalization example" sat apart from "keyword cannibalization examples".

The grouping method also changes the clusters. Soft clustering compares each keyword with the group's main keyword only, and hard clustering compares every keyword in the group with every other keyword.

At 4 shared URLs, hard clustering gave my list groups of 18, 2, 2 and 1 keywords. Soft clustering with "what is keyword cannibalization" as the main keyword gave groups of 20, 1, 1 and 1.

How do you do keyword clustering step by step?

To group a keyword list by shared search results in a spreadsheet:

  1. Save one keyword list for one product, audience and country.
  2. Remove duplicates, other languages and brand searches you cannot answer.
  3. Save the top 10 organic URLs for each keyword, without ads.
  4. Remove tracking codes from the URLs so the same page always matches, but keep the video ID in YouTube links.
  5. Count the shared URLs for each pair of keywords.
  6. Put keywords in one group when each pair shares at least 4 URLs.
  7. Open the search results for one keyword per group and write down the page type that ranks.
  8. Name each group after its clearest keyword and assign one URL on your site.

My guide to free keyword research tools covers where to get the list for step 1.

Google's spam policies name automated queries, including scraping results without permission, as a violation.[4] For step 3 on Google, search by hand for a short list, or use a clustering product that supplies the results.

What does a worked keyword cluster look like?

My worked example starts with 24 autocomplete suggestions about keyword cannibalization (2 pages on one site competing for the same search). A script saved up to 10 DuckDuckGo results for each suggestion, and one suggestion returned no results, so 23 keywords were left.

The count leaves out YouTube videos, because the script saved every YouTube link without its video ID.

23 keywords about keyword cannibalization grouped into 4 clusters by shared search results: 18 definition and fix searches, 2 Semrush searches, 2 Google Ads searches and 1 checker tool search
  • Meaning and fixes, 18 keywords: The same 4 articles ranked for all 18 searches, from "keyword cannibalization meaning" to "how to solve keyword cannibalization".
  • Semrush, 2 keywords: "Keyword cannibalization semrush" and "how to check keyword cannibalization in semrush" shared 5 URLs.
  • Google Ads, 2 keywords: "Keyword cannibalization google ads" and "what is keyword cannibalization in google ads" shared 6 URLs.
  • Checker tool, 1 keyword: "Keyword cannibalization checker tool" shared at most 3 URLs with any other keyword, because tool pages filled its results.

The check used DuckDuckGo, so a Google check of the same list can give different groups. On DuckDuckGo, 23 keywords needed 4 pages.

How do you cluster keywords with Python or AI?

Use a Python script when you want the same result each time, and use an AI assistant for a first draft you will check by hand. I ran both scripts below on the 23 keywords.

Which Python script groups keywords by shared URLs?

The script below needs no extra library. The script reads a file named serps.json, where each keyword has its list of ranking URLs, and prints the hard clusters:

Verified
import json

      serps = json.load(open("serps.json"))   # keyword: list of URLs
      SHARED = 4                              # overlap threshold

      def shared(a, b):
          return len(set(serps[a]) & set(serps[b]))

      clusters = []
      for kw in serps:
          for group in clusters:
              if all(shared(kw, other) >= SHARED for other in group):
                  group.append(kw)
                  break
          else:
              clusters.append([kw])

      for group in clusters:
          print(len(group), group)

The script adds each keyword to the first group that fits, so the order of the file changes the groups. Put your most important keywords first.

How does semantic keyword clustering work in Python?

Semantic clustering in Python turns each keyword into a vector (a list of numbers that stands for meaning) and groups vectors that sit close together. The free all-MiniLM-L6-v2 model gives each keyword 384 numbers.[5]

Verified
# pip install sentence-transformers scikit-learn
      from sentence_transformers import SentenceTransformer
      from sklearn.cluster import AgglomerativeClustering

      keywords = open("keywords.txt", encoding="utf8").read().splitlines()
      model = SentenceTransformer("all-MiniLM-L6-v2")
      vectors = model.encode(keywords, normalize_embeddings=True)

      labels = AgglomerativeClustering(
          n_clusters=None, metric="cosine",
          linkage="average", distance_threshold=0.15
      ).fit_predict(vectors)

      for label in sorted(set(labels)):
          print([k for k, l in zip(keywords, labels) if l == label])

The distance_threshold setting in scikit-learn is the distance at or above which 2 groups are not merged, so a smaller number makes smaller groups.[6] A threshold of 0.10 split my list into 9 clusters, and 0.15 gave 5.

The semantic result matched the SERP result for 20 of 23 keywords. The other 3 keywords contain the word "seo" and became their own group, although each one shared 8 or 9 URLs with "what is keyword cannibalization".

The Sentence Transformers documentation says agglomerative clustering (the method in the script) is quite slow on larger datasets.[7] Split a very long list by subject first.

Which prompt asks an AI assistant to cluster keywords?

Paste your keywords and their ranking URLs, so the AI assistant groups by evidence. An example prompt for a pasted list is:

Verified
Group these keywords into clusters that one page can answer.
      Data: one row per keyword, with its top 10 ranking URLs.
      Rules:
      1. Two keywords join a cluster only if they share 4 or more URLs.
      2. Use every keyword exactly once. Add no new keywords.
      3. For each cluster, give the primary keyword, the page type
         that ranks, and the shared URLs you counted.
      4. List every keyword you are unsure about in a separate group.

I build agentic content workflows with Claude Code skills and n8n, always with a human review step. For clustering, the human review should open the search results for each group before anyone plans a page.

Free AI Product Marketing Playbook to advance your career

When should a keyword cluster become one page?

A keyword cluster becomes one page when its keywords share ranking URLs, one page type and one reader goal. Use 4 rules to make the decision:

  • Keep one page: Keep keywords together when the results overlap and the same page type ranks for every keyword.
  • Split the cluster: Split a keyword out when tool pages, product pages or videos rank for that keyword and guides rank for the rest.
  • Merge 2 pages: Merge 2 live pages when both pages target keywords from the same cluster.
  • Skip the cluster: Skip a cluster when your site has nothing true and useful to add to the pages that already rank.

One page per keyword variation carries a risk. Google's definition of doorway abuse is sites or pages created to rank for specific, similar queries that lead users to less useful pages in between.[4]

I run technical, on-page and programmatic SEO across SaaS (software as a service) web properties. My programmatic SEO guide covers the case where many similar searches do deserve separate pages.

A finished set of keyword clusters is the input for a topical map (a plan of all the pages a site needs on one subject). My topical authority guide covers the map.

My guide to the pillar page covers the page that introduces a whole group of clusters.

Which keyword clustering tools can you use for each method?

Keyword Insights, SE Ranking, Ahrefs, Semrush and Python group keywords with different evidence. I compared the 4 products using only facts from each vendor's own website:

  • Keyword Insights: Keyword Insights groups keywords with live, country-specific search results and takes up to 200,000 keywords at a time.
  • SE Ranking: SE Ranking Keyword Grouper compares top 10 results and offers soft and hard grouping, so you control how strict the clusters are.
  • Ahrefs: Ahrefs Keywords Explorer clusters by Parent Topic, the keyword that sends the most traffic to the top-ranking page.
  • Semrush: Semrush has a Keyword Strategy Builder that turns up to 5 seed keywords into topics and clusters, with a primary keyword for each page.[8]
  • Python: scikit-learn is an open-source machine learning library that, together with sentence-transformers, groups keywords by meaning on your own computer.

Expect clustering products to disagree at the edges. Ahrefs compared 2 products on one topic, and 38 keywords landed in the same top cluster out of 40 in Keywords Explorer and 50 in Keyword Insights.[9]

To compare 2 keywords in Ahrefs Keywords Explorer:

  1. Enter one of the keywords.
  2. Scroll to the SERP overview.
  3. Click "Compare with".
  4. Enter the second keyword.
  5. Hit "Apply" and read the SERP similarity score out of 100.

My list of the best keyword clustering tools compares 7 tools by method and budget and tests 2 free tools on the same keywords.

Where should you start with keyword clustering?

Start with 20 keywords about one subject, and save the top 10 URLs for each keyword in a spreadsheet. Count the shared URLs, group keywords that share at least 4, and write one page type next to each group.

My take on keyword clustering after the 23-keyword check: use meaning to sort a long list, and use shared URLs for any group that decides whether you build, merge or split a page. When the groups are final, my SEO content strategy guide shows how to turn each cluster into a brief and a publishing plan.

Keyword Clustering FAQs

How do you run semantic keyword clustering in Python?

Semantic keyword clustering in Python takes 2 free libraries: sentence-transformers turns each keyword into a vector, and scikit-learn groups vectors that sit close together. Load the all-MiniLM-L6-v2 model, encode your keyword list, then run AgglomerativeClustering with cosine distance. A distance threshold of 0.15 gave 5 groups from 23 keywords in my check.

What is the best keyword clustering tool?

The best keyword clustering tool is the one that fits your list and shows how it groups keywords. Keyword Insights and SE Ranking compare search results and let you set the overlap. Ahrefs Keywords Explorer groups a list by Parent Topic, and Semrush Keyword Strategy Builder starts from seed keywords instead of a finished list.

Is there a free keyword clustering tool?

Yes, a Python script is a free keyword clustering tool with no account and no paid credits. The semantic script in this guide uses the free sentence-transformers and scikit-learn libraries and needs no search data. A spreadsheet can do the same job: search your keywords by hand, paste the top 10 URLs, and count the shared ones.

How do you use keyword clustering for a page you already have?

To use keyword clustering for an existing page, export the searches that page appears for and cluster them with the page's main keyword. Searches in the same cluster as the main keyword belong on the page as headings or questions. Searches that form a second cluster with a different page type need their own page.

How many keywords should be in one cluster?

A keyword cluster has no fixed size, because shared search results decide which keywords belong together. My check of 23 keywords gave one cluster of 18, 2 clusters of 2, and one keyword alone. A cluster of one keyword is valid when its search results match nothing else on your list.

What is the difference between a keyword cluster and a topic cluster?

A keyword cluster is a group of searches that one page can answer. A topic cluster is a group of pages about one subject, linked to each other and to a main page. Keyword clustering comes first, because each finished keyword cluster becomes one page inside a topic cluster.

Can ChatGPT or Claude cluster keywords?

Yes, ChatGPT and Claude can cluster a pasted keyword list by meaning. An AI assistant that only sees the list cannot know which pages rank for each keyword, so its groups are a first draft. Check the main keyword of each group against live search results before you plan a page.

View all