Refine recommendations with rules
On this page
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.
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.
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
- Go to the Algolia dashboard and select your Algolia application.
-
On the left sidebar, select Recommend.
-
On the Rules page, select the index and model to which you want to apply rules.
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.
-
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.
-
Optional: Add a context for this rule.
Contexts are additional constraints for rules. For more information, see Context-only rules.
-
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
. - 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.