A Guide To Google’s Knowledge Graph Search API For SEO

Google introduced the Knowledge Graph in 2012 to help users find new information faster.

Essentially, users can search for places, people, companies and products and find immediate results that are most relevant to the query.

A knowledge graph is a collection of topics, also known as entities, that connect to other entities. Entities are individual information objects that can be uniquely defined.

They allow Google to go beyond just matching keywords when returning answers to a specific query. This further helps Google achieve its goal of becoming the answer engine.

Google will display Knowledge Graph data within SERP features such as Knowledge Panels, Knowledge Cards, and Featured Snippets.

This can help brands become more visible in search results and build authority for certain topics. Structured data on web pages can affect the data drawn into the Knowledge Graph.

Google uses the Knowledge Graph to provide users with a better search experience because it can better understand different topics and how they relate to each other.

For example, if we want to see the cast of a movie, Google can display it as a carousel on the search results page.

Screenshot from Google, September 2022

However, these SERP (search engine results page) features can also lead to fewer clicks to the website, as Google can display much more information on the search results page.

This allows them to provide a quick and accurate answer for searchers and direct them to other search results, with features such as “People also searched” and relevant queries related to the main search term.

For example, if we take the K-pop group BTS, within one search, I can see a list of all the members, their songs and albums, as well as upcoming events, awards they have won, and different places where I can listen to their music myself.

All in one search without having to visit an external website.

Screenshot from Google, September 2022

The Knowledge Graph API

The Knowledge Graph API, created by Google, allows us to find entities within the Google Knowledge Graph for specific queries.

It gives us direct access to the database to see the entities tagged for each query. It is also independent of the user’s location, providing a more accurate representation of the knowledge graph.

Some examples of API usage, as provided by Google, include:

As the documentation states, the API itself only returns single matching entities, not graphs of interconnected entities.

Using Python To Call The API

There are four different clients through which Google makes API calls possible: Python, Java, JavaScript, and PHP.

An example starting point for each can be found on the corresponding page in the documentation.

For this example, I’ll use Python because it’s the language I’m most familiar with.

Creating An API Key

The first step is to create an API key to send requests to the API.

To generate an API key, go to the Google API console and go to the credentials page.

The next step is to go to the API library, search for Knowledge Graph, and then enable it.

Screenshot from the Knowledge Graph API, September 2022

You can save a note of your API key, but you can also easily find the API key again by clicking on the API you’ve already generated.

Screenshot from the Knowledge Graph API, September 2022

A Simple API Request

To return the entities that match the query, along with the result for each entity, there is a simple piece of Python code that you can run, either in Google Colab (easily accessible for beginners) or in your local environment.

This will produce a result like below:

Screenshot from Google Colab, September 2022

Within that we can set several parameters, depending on what we are looking for.

The first thing you’ll need to add is your API key, followed by the query you want to generate results for.

The parameters are then set to call the API key you’ve already added and the query you’ve chosen.

This allows you to easily change the query you’re looking for each time you run the code.

Then we have a limit, which is the number of entities you want to return. The default for this is 20, with a maximum of 500. Note that requests with high limits have a higher chance of timing out.

We can then use a Boolean (True or False) to decide if we want to indent the JSON response for easy formatting.

There are other parameters you can include, such as:

We then ask the script to call the URL, complete the request, and parse the result into a simple printout of the entity name and result result for each entity, which will be in parentheses.

Extracting Even More

Returning entities and their results is just scratching the surface. There’s a lot more we can get from the Knowledge Graph API.

We can return a JSON object containing all response fields stored for each entity with a few more lines of code and some functions.

First, we want to request the return of the session page that will be searched through the API.

Then, using a similar API request as in the original code, we can call it in conjunction with our query request using the same parameters.

We then enter our API key to return our response object with the full data.

To make the results a little easier to see and help make more sense of the response, we can normalize the JSON object into a Pandas DataFrame. This will take each field and transfer it to a column, with each entity in a different row.

pd.json_normalize(knowledge_graph_json, record_path=’itemListElement’)

I also found it interesting to run this code on different days with the same query and see how the results change.

Response Fields

Several fields will be set aside for each entity within the Knowledge Graph API:

The id field refers to the MID (Machine Generated Identifier), a unique identifier for each entity.

This usually starts with kg:/m/ followed by a short appended string. MIDs break down human language into a format that machines can understand.

These MIDs also match the entity in Google Trends and can also be used to retrieve the URL of each entity, even if there is no knowledge panel for it.

Confidence Score

The ResultScore (also known as the Trust Score) represents Google’s confidence in its understanding of the entity. It is essentially the perceived strength of the relationship between the entity that Google recognized for the query and the entity that was returned.

The higher the score, the more confident Google is in the entity that best matches the query.

However, there is no guarantee that the top-scoring entity will appear as a featured snippet in search results.

This score is particularly useful when analyzing different queries for opportunities.

For example, suppose you notice low voter ratings for a particular query. In this case, this highlights the ability to optimize pages to outperform the identified pages for the entity.

The URL for the entity is also considered the “home of the entity,” which is the website and page that Google recognizes as the most authoritative source with the most accurate information about the entity.

To improve your trust score, it’s important to make sure your website is consistent with your subject’s home information.

Improving the quality and detail on the website will also help improve the trust score, pairing this with PR activities to further improve the authority of the website for the entity’s chosen topic.

Extracting Insights

You can do several things with your Knowledge Graph response results, including identifying areas of opportunity and viewing current entities and entity homes for specific queries.

For example, making sure you have the most appropriate schema markup and on-page optimization to link to your target entities is an important first step.

Keyword Research

When completing your keyword research, it’s worth considering whether your current targeting makes sense if there is a strong entity for a particular keyword.

After all, Google’s overarching goal is to provide the most useful information in search results. With the increase in click-free search, the competition for search terms and the ability to appear in SERPs also increases.

Brand Building

Using entities is a great way to build presence and authority in organic search for a brand or company in a specific space.

It is useful to know the entities behind a particular query. They can give us insight into keyword searches and make it even easier to create authoritative, useful content accordingly.

Competitor Research

As the API provides a ranked list of entities that appear for queries, you can see a high level of insight instead of performing numerous searches to see what appears.

This will allow you to review the performance of your competitors for specific queries and how you compare.

You can also use these insights to make sure you can increase your confidence score to outscore your competitors.

The API allows you to monitor this regularly and report any changes you see, potentially before any SERP features change.

In Summary

I hope this has given you a place to start analyzing the knowledge graph and extracting valuable insights to help you optimize your appearance in search functions.

As Google explains, the Knowledge Graph is used to improve Google search to find the right thing, get the best summary, and go deeper and wider.

Being able to see under the hood of the Knowledge Graph is a great place to start to make sure your website is the best source for Google to use just that.

Here I have created a Google Colab notebook for you to use and play with the code.

I’d love to know what insights you’ve drawn for your inquiries. (Don’t forget to make a copy and add your own generated API).

You can also find a version of the code on GitHub here.

Featured image: REDPIXEL.PL/Shutterstock



* This article was originally published here

Comments

Popular Posts