Guides / Algolia Recommend

Refine recommendations with rules

Rules are if-then statements you can use to refine and curate your recommendations without editing code.

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.
Explore related videos in the Algolia Academy

How rules work

You can apply Recommend rules to an existing recommendation scenario, which is a combination of an Algolia index with a trained Recommend model.

Only trained ‘Frequently Bought Together’ and ‘Related Products’ models are supported for using rules.

Rules are applied on top of the existing set of recommendations. They don’t apply to items that were not recommended by the model.

The maximum number of rules you can apply to a recommendation scenario depends on your Algolia plan.

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

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

  3. On the Rules page, select the index and model to which you want to apply rules.

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

    Only trained ‘Frequently Bought Together’ and ‘Related Products’ models are supported. As an alternative to rules, you can use filters to bury or boost recommendations.

  4. Click Add new Rule and select the conditions when the rule should apply:

    • 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.
  5. Optional: Add a context for this rule.

    Provide a context for which the rules applies

    Contexts are additional constraints for rules. For more information, see Context-only rules.

  6. Under Consequence(-s), select the actions that should be applied to the recommendations when the conditions are met:

    • Pin items. Place a recommendation at a specific position.
    • Hide items. Exclude items from the recommendations.
    • Boost items. Show items that match a filter first.
    • Bury items. Show items that match a filter last.
    • Filter items. Only show recommendations that match the specified filter criteria.

    To only show recommendations with the same facet value as the viewed item, select Filter items consequence and set the value to sameAsViewedItem.

    Screenshot of the menu for configuring the filter items consequence with the sameAsViewedItem option selected

  7. Optional: Add a description for you and your team.

Rules precedence algorithm

Algolia uses the following tie-breaking algorithm to determine which rules should apply first:

  • Context. Contextual rules apply before general rules or rules with filters.
  • Filters. Rules with filters apply before general rules.
  • Temporary. Temporary rules apply before permanent rules.
  • Rule ID. If there are still tied rules, the one with the lowest objectID (alphabetically ordered) wins.

See also

Did you find this page helpful?