Skip to Content
GraphQL APIFetching similar content

Fetching similar content

Display content similar to a given item based on common content attributes and content. Check out the Recommendations guide for a quick introduction.

The GraphQL API creates a corresponding GraphQL Type with a “similarity” algorithm for each content model in your environment. The plural Type name of the content model is prefixed with Similar_. For example Post generates a Type Similar_Posts. Pagination options (except limit) and the total items field are disabled when using this query.

query { Similar_Posts( id : "b3f76d7d-732b-4fd6-a9e9-a967dba3d09b" ) { items { _id, title } } }

To narrow down the recommended content items, use the same filters that are available when filtering collections.

In the following example, we query all Posts where premium is set to true.

query { Similar_Posts( id : "b3f76d7d-732b-4fd6-a9e9-a967dba3d09b", where : { premium : true } ) { items { _id } } }

Optimizing the recommendation algorithm

The recommendation algorithm for similar items finds items based on the following criteria:

CriteriaDefault weightDescription
Topics1.4Highest weight. Topics are extracted automatically by the AI text analysis engine. It identifies specific people, places, or concepts within the item text and finds items with matching topics.
Content References1.2Matches content items linked to the main item through any content references whether in the Stack, Component or Dynamic content field. For example, articles in the same category and articles by the same author.
Tags0.8Matches items based on tag values in the main content item.

You can tweak the default logic to align with your own business priorities. For example, if your content items are related more by their common tags rather than linked items, you can increase the importance of Tags.

Here’s an example of how that works:

query { Similar_Articles( id: "0cbe2455-124c-4820-b2ac-dcc4261e150c" where: { _publish_on_gt: "2021-01-01T00:00:00+00:00" categories: { _slug_any: [ "ux-design", "development" ] } }, limit: 3 rules: { entities: 0 tags: 1 references: 0.5 } ) { items { _id title } } }
  • We added rules: { entities: 0, tags: 1, references: 0.5 } to indicate that topics should not be included and that the tag criteria has higher priority than references.

We recommend starting with the default setting and adding rules only if the result does not meet your expectations.

Last updated on