Guides / Algolia Recommend

Refine recommendations with rules

With Recommend Rules, you can optimize your recommendations towards your business goals without changing code. Rules let you tweak recommendations generated by the Recommend models and dynamically shape your user experience.

Example use cases for Recommend Rules include:

  • Only show related products from the same category as the viewed product.
  • Don’t show recommendations for out-of-stock products.
  • Recommend a newly launched product first by pinning it to the first position.
  • For all products from a specific category, pin items to the top of the recommendations. For example, for all “hair” products, recommend all “shampoo” products first.

How Recommend Rules work

You can apply Recommend Rules to an existing recommendation scenario. A recommendation scenario combines an Algolia index with a trained Recommend model.

Recommend Rules are applied as a post-processing step on top of the existing set of recommendations and cannot be applied to items that were not recommended by the models.

You can apply up to 10,000 rules per recommendation scenario.

Rules have conditions and consequences. When the condition (if) is met, the consequence (then) is applied to the recommendation scenario.

Add rules to a recommendation scenario

To add new Recommend Rules, follow these steps:

  1. If you want to boost, bury, or filter items by a filter attribute, ensure you include this attribute in the attributes for faceting.

  2. Go to the Algolia dashboard and select your Algolia application.
  3. On the left sidebar, select Algolia Recommend Recommend.

  4. On the Recommend Rules page, select the model to which you want to apply rules (related-products or bought-together).

    Recommend Rules don’t support the Trending Items, Trending Facet Values, or LookingSimilar models. As an alternative, consider using filters for promoting and burying items.

    Select the trained Recommend model to which you want to apply recommendations

  5. Click Add new Rule and specify the Conditions when the rule applies.

    Specify the conditions when a Recommend Rule applies

    Recommend supports these conditions:

    • Any item is a source item. The rule applies to all recommendations.
    • Specific item is viewed. The rule applies when a specific item (identified by its objectID) is viewed.
    • Subset of source items. The rule applies to items that match a filter.
  6. Optional: enter a label for a Context defined in your app

    Provide a context for which the rules applies

    Contexts act as additional constraints for rules. Common use cases for context-only rules are distinguishing users by device type, language preference, or country. For an example of defining a context, see Identifying your user’s device.

  7. Specify the Consequences to determine what actions are applied to the recommendations when the conditions are met.

    Specify which actions or consequences should apply when the conditions are met

    Recommend supports these consequences:

    • Pin items. The rule places a recommendation at a specific position.
    • Hide items. The rule excludes items from the recommendation.
    • Boost items. The rule places items higher up within recommendations.
    • Bury items. The rule places items lower down within recommendations
    • Filter items. The rule only shows recommendations that match the specified filter criteria.

    When you select Filter items as a consequence, select same as viewed items to let the filter criteria match the same value as the viewed item:

    Select the same as viewed filter criteria to match the filtered attribute to the viewed item

    For example, if you only want to show book recommendations of the same genre as the viewed item, set “Genre” > “sameAsViewedItem”.

  8. Optional: add a description for you and your team.

Rules precedence algorithm

Algolia uses a tie-breaking algorithm, much like the ranking formula, to determine the precedence of all the rules that apply to any given model. In other words, a criterion is only considered when all its preceding criteria rank equal.

The Recommend Rule precedence logic is the same as search rule precedence logic, ranked by importance. Although it’s a bit simpler, because it doesn’t match on a query pattern, is as follows:

  • Context: a contextual rule has higher priority than a general rule or a rule using filters.
  • Filters: a rule using filters has higher priority than a general rule.
  • Temporary over permanent: if both a temporary and a permanent rule match, the temporary rule takes precedence.
  • Rule ID: if there are still conflicts after all other criteria have been applied, the record with the smallest objectID in lexicographical order wins. This final criterion is guaranteed to break any tie. It most likely applies only when there are duplicate rules.
Did you find this page helpful?