Knowledge Graph API Extraction and Entity Relationship Analysis for Semantic Keyword Research (Notebook)
Manually identifying related entities and topical connections for keyword research is limited by human knowledge and time constraints—this comprehensive Google Colab notebook automates entity discovery and relationship mapping by querying Google’s Knowledge Graph Search API to extract related entities, measure popularity scores, perform knowledge-based keyword clustering, and visualize entity-keyword networks for semantic keyword research expansion. Created by Lazarina Stoy for MLforSEO Academy as a practical lab for the Semantic ML-enabled Keyword Research Course, this workflow enables SEO professionals to tap into Google’s structured entity database (the same Knowledge Graph that powers knowledge panels and entity-based search features) to systematically discover related concepts, evaluate entity prominence through result scores, identify semantic relationships between keywords and entities, and build comprehensive topical maps that reveal content opportunities beyond traditional keyword tools. The notebook implements five progressive exercises covering the complete Knowledge Graph research workflow: exploring individual entity data, discovering all related entities for keyword expansion, measuring entity popularity for prioritization, clustering keywords based on shared entity relationships, and creating network graph visualizations that show how keywords and entities interconnect—transforming abstract entity relationships into actionable keyword research insights.
The notebook implements a modular API query framework with increasing sophistication across multiple code sections. Initial setup covers Google Cloud project configuration (enabling Knowledge Graph Search API, generating API key with 100,000 free daily queries), with clear authentication instructions for storing the API key. The first entity exploration function queries individual entities (example: iPhone) and returns basic attributes like name, description, and detailed URL from the Knowledge Graph response JSON. Two enhanced parsing functions follow: one extracts common API fields (Name, Description, Image URL, Details, Details URL, License, Result Score, Entity URL) into structured DataFrames for easy CSV export, while another dynamically flattens all nested JSON fields to capture every possible API response attribute regardless of entity type—handling cases where different entities return different data structures.
The related entity discovery section provides the core keyword expansion functionality through a bulk processing function: users upload a CSV with an Entity column (or manually input keywords), and the script queries the Knowledge Graph for each entity, retrieving up to 10 related entities per input (configurable limit parameter). Results output as a two-column CSV (Entity, Related entity) showing all discovered relationships—for example, querying marketing returns Digital marketing, Search engine optimization, Affiliate marketing, Social media marketing, and more. The example processes a keyword universe dataset and generates 3,995 entity-relationship pairs, demonstrating scalability for large keyword lists. Entity popularity measurement follows, extracting resultScore values from API responses to quantify entity prominence (example: Digital marketing scores 20,924.26, indicating high Knowledge Graph prominence)—enabling prioritization of entities with stronger signals for content targeting.
The keyword clustering exercise groups keywords based on shared related entities: input a list of seed keywords (SEO, Digital Marketing, Content Marketing, Social Media Marketing, etc.) and the function queries each keyword’s related entities, returning a dictionary mapping keywords to their entity clusters. This reveals semantic groupings where keywords share entity relationships—identifying which terms belong to the same topical clusters based on Knowledge Graph connections rather than just string similarity or search volume co-occurrence. The final visualization exercise uses NetworkX and Matplotlib to create network graphs showing keyword-entity relationships visually: keywords appear as nodes, related entities as connected nodes, with edges representing relationships discovered through the Knowledge Graph. The resulting graph (20×16 figure size, 3000 node size, labels enabled) provides an intuitive view of how marketing keywords interconnect through shared entities—revealing central entities that bridge multiple keywords and isolated terms that may require separate content strategies.
Use this for:
‧ Entity-driven keyword expansion by automatically discovering related concepts from Google’s Knowledge Graph rather than relying solely on search suggestion tools or manual brainstorming
‧ Topical authority mapping by identifying all entities related to core business topics, then building content strategies that comprehensively cover these entity relationships
‧ Keyword clustering validation using Knowledge Graph connections to verify that ML-based or manual keyword clusters actually share semantic relationships according to Google’s entity database
‧ Content gap identification by comparing entities mentioned in competitor content against Knowledge Graph related entities for your target keywords—finding missing entity coverage
‧ Entity prioritization through popularity scores to focus content development on high-prominence entities that have stronger Knowledge Graph signals and structured data
‧ Semantic relationship visualization for client presentations or team alignment meetings by showing network graphs that make abstract entity relationships tangible and actionable
‧ Knowledge panel optimization research by understanding which related entities Google associates with target keywords, informing structured data markup and content entity targeting
‧ Cross-topic content opportunities by discovering unexpected entity relationships in the Knowledge Graph that reveal content angles competitors haven’t explored
‧ Bulk entity research for large keyword universes (500+ keywords) using the CSV import/export functionality to process entire keyword databases through Knowledge Graph analysis
‧ Course learning reinforcement for MLforSEO Academy students by providing hands-on exercises that translate Knowledge Graph theory into practical API implementation and data analysis
This is perfect for SEO strategists, content planners, semantic search specialists, and technical SEO professionals implementing entity-based optimization strategies—particularly valuable when building comprehensive topical maps for pillar-cluster content architectures, when validating keyword clustering approaches against Google’s own entity relationships, when prioritizing content development using entity prominence scores rather than just search volume, when exploring unfamiliar industries where manual entity discovery would be time-prohibitive, or when creating data-driven presentations that demonstrate semantic keyword research methodology to stakeholders through network visualizations showing how target keywords connect through shared entities in Google’s Knowledge Graph—all implemented through production-ready Python code with error handling, CSV workflows, and visualization outputs rather than just theoretical entity relationship concepts.
What’s Included
- Five progressive exercises cover complete Knowledge Graph research workflow from basic entity exploration through related entity discovery, popularity measurement, keyword clustering, and network visualization
- Bulk CSV processing enables scalable analysis with Entity column import, automatic API queries for all entries, and downloadable two-column output showing entity-relationship pairs for large keyword lists
- Entity popularity scoring extracts resultScore values (example: Digital marketing = 20,924.26) enabling prioritization of high-prominence entities with stronger Knowledge Graph signals
- Network graph visualization using NetworkX creates visual maps of keyword-entity relationships showing how semantic connections cluster around central entities versus isolated terms requiring separate strategies
Created by
Semantic ML-enabled Keyword Research
This resource is part of a comprehensive course. Access the full curriculum and learning path.
View Full CourseRelated Concepts
Get Instant Access
Enter your email and we’ll send you the download link immediately.
