Grouping thousands of search queries into meaningful topics is now faster and more scalable with Python. Discover how automated clustering can streamline your content planning and boost topical authority.
Manually sorting thousands of SEO keywords into topic groups is a daunting task for any content strategist. Traditional rule-based methods often miss the subtle semantic connections between queries, making it difficult to create content that addresses a broad range of search intents. To address this, a Python-based keyword clustering tool has been developed, leveraging TF-IDF vectorization and the HDBSCAN clustering algorithm to automate the process.
Keyword clustering is essential for building topic-driven content strategies. By grouping related queries, teams can focus on broader themes rather than isolated keywords, strengthening internal linking and improving visibility across related searches. However, the process comes with two main challenges: cleaning noisy keyword data and accurately clustering topics without prior knowledge of how many groups exist.
Python offers a flexible solution for preprocessing large keyword datasets. Automated scripts can efficiently remove stopwords, non-ASCII characters, and other irrelevant data, ensuring that only clean, normalized keywords are used for clustering. This step is crucial, as SEO exports from platforms like Search Console or internal databases often contain significant noise.
Clustering Methods
Unlike k-means, which requires the number of clusters to be set in advance, HDBSCAN can identify natural groupings within the data without this limitation. TF-IDF transforms each keyword into a numerical vector, emphasizing distinctive terms and down-weighting common ones. HDBSCAN then analyzes these vectors, assigning outliers a -1 label to exclude them from clusters, which is especially useful for filtering out long-tail queries that don't fit broader topics.
This approach results in cleaner, more coherent clusters, allowing content teams to focus on high-value topics. For those interested in the technical details, the full script is available on GitHub and can be adapted for different workflows.
Getting Keyword Data
To start, you'll need a comprehensive keyword list. If your Google Search Console property exports data to BigQuery, you can bypass the 1,000-row limit of the UI export and access unsampled data. A simple query against the standard GSC BigQuery schema provides the necessary keywords, which can then be exported as a CSV, reduced to a single column, and saved as a .txt file for clustering.
Even without BigQuery, you can export queries directly from Search Console. The clustering tool only requires a plain list of keywords, making it accessible regardless of your data source. For those managing large-scale SEO projects, this workflow can save significant time and effort.
AI-Driven Improvements
Recent advances in AI have made it easier to fine-tune and adapt the clustering script. Adjustable parameters for cluster sensitivity and minimum cluster size allow users to optimize results for datasets ranging from dozens to tens of thousands of keywords. The script has also been adapted for Google Colab, enabling better visualization and a more user-friendly experience.
AI has streamlined the process of integrating libraries, handling boilerplate code, and making the notebook reusable for different projects. This means content teams can quickly iterate, adjust parameters, and generate topic clusters without deep technical expertise.
Running the Tool
Using the tool is straightforward: upload a .txt file with one keyword per line, and the script will clean the data, apply TF-IDF vectorization, and cluster the keywords using HDBSCAN. Users can experiment with sensitivity and minimum cluster size to achieve the desired number of clusters. Each group receives an auto-generated label based on its most distinctive terms, and results are exported to Excel for further analysis.
The final output includes both a grouped cluster view and a detailed breakdown of each keyword's assignment. This structured approach enables content teams to plan around topics rather than individual queries, accelerating the editorial process and improving SEO outcomes. For those interested in attribution and measurement challenges in digital marketing, related issues are explored in this analysis of conversion reporting discrepancies across ad platforms.
While AI and automation can handle much of the heavy lifting, editorial judgment remains essential for refining clusters and ensuring content aligns with business goals. Integrating this tool into your workflow can eliminate hours of manual work and provide a more strategic foundation for content planning.