> ## Documentation Index
> Fetch the complete documentation index at: https://help.maestra.io/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Create a Related Products Algorithm

In this article:

* Related Products
* Related Products to a Product List
* Related Products to the Last Order
* Creating the algorithm
* Usage example

You can create three Related Products algorithms:

* Related Products
* Related Products to a Product List
* Related Products to the Last Order

All three algorithms are created in the same way.

Related Products algorithms generate recommendations based on customer actions with products. To produce relevant recommendations, the product you are generating recommendations for must have **at least 100 actions**. Otherwise, the algorithm falls back to displaying popular products.

The algorithm takes into account actions with products from the segments selected in the **Recommend for products** and **Recommend from** settings, over the time period specified in the **Take into account actions with products for** setting.

If none of the products in the segments configured for the algorithm have enough actions, the algorithm stops and a warning is shown on the project.

If this happens, increase the time period for which actions with products are counted, or use a different algorithm type depending on the campaign where you plan to use the recommendations.

## Related Products

This algorithm calculates related products and generates recommendations for an individual product.

Related products are calculated based on how often they appear together in the same receipt. The algorithm also takes into account joint purchases of categories and product attributes. Thanks to the ML model, the algorithm can predict recommendations even for products with no order history.

* **Algorithm type:** product-level recommendations
* **For customers:** identified and anonymous
* **Delivery channels:** API (recommendations widget), email
* **Recalculation frequency:** once a day

Automatically checks that:

* The product is available in the customer's zone
* Product external systems match by default

Recommended for use in:

* "Customers also buy" campaigns

Limit:

* 5 algorithms per project

## Related Products to a Product List

This algorithm calculates related products and generates recommendations for each product in a selected customer product list. The number of recommendations is proportional to product price — more recommendations for expensive items, fewer for cheaper ones. It is recalculated in real time based on customer orders.

Related products are calculated based on how often they appear together in the same receipt. The algorithm also takes into account joint purchases of categories and product attributes. Thanks to the ML model, the algorithm can predict recommendations even for products with no order history.

* **Algorithm type:** personalized recommendations
* **For customers:** identified and anonymous
* **Delivery channels:** API (recommendations widget), email
* **Recalculation frequency:** real time

Automatically checks that:

* The product is available in the customer's zone
* The product brand matches the customer's brand (for multi-brand projects)

Recommended for use in:

* Abandoned cart campaigns
* Wishlist recommendation campaigns
* On-site cart campaigns

Limit:

* 3 algorithms per project

## Related Products to the Last Order

This algorithm calculates related products and generates recommendations for each product in the customer's most recently modified order, in a quantity proportional to product price. More recommendations are generated for expensive products and fewer for cheaper ones. It is recalculated in real time based on customer orders.

Related products are calculated based on how often they appear together in the same receipt. The algorithm also takes into account joint purchases of categories and product attributes. Thanks to the ML model, the algorithm can predict recommendations even for products with no order history.

* **Algorithm type:** personalized recommendations
* **For customers:** identified
* **Delivery channels:** API (recommendations widget), email
* **Recalculation frequency:** real time

Automatically checks that:

* The product is available in the customer's zone
* The product brand matches the customer's brand (for multi-brand projects)

Recommended for use in:

* "Thanks for your order" campaigns
* "Offer for next purchase" campaigns

Limit:

* 1 algorithm per project

## Creating the algorithm

1. Go to **Content** → **Product recommendations** and click **Add mechanic**.

2. Select the algorithm you need.

3. Enter a name and click **Continue**.

4. Configure the **General settings:**

   * **Take into account actions with products for** — order statistics will be counted over a period from 1 to 180 days.
   * **Recommend for products** — the scheduled segment you want to generate recommendations for (optional).
   * **Recommend from** — the scheduled segment that recommendations are generated from (optional).
   * **Brand** (for multi-brand projects) and **Product list** — for the "Related Products to a Product List" algorithm.
   * **Recommend only products from the same external system** — enabled by default, can be turned off.

   You can also configure **Manufacturer exclusions** in the corresponding block.

   For the "Related Products to a Product List" algorithm, also select a product list.

5. Launch the algorithm.

Once the algorithm is running, the recommendations page will display its status and the time of the last update.

## Usage example

For example, you want to show related products from the "Scarves" segment for the "Coats" segment (system name `Coats`).

1. Create a recommendation using the **Related Products** algorithm:

   * Select the segments in the settings.
   * Launch the recommendation.
   * You will get the parameter `Product.Recommendations.Soputstvuyuschieprodukti`.

2. Insert the parameter into your email.

   Use the `Take()` function to limit the segment size so that the email can be generated even when the segment is large.

   Sample markup for this example, which outputs the name of the recommended product:

   ```
   @{for prod in Products.GetBySegment("Coats").Take(5)}
              @{for item in prod.Product.Recommendations.Soputstvuyuschieprodukti.Take(2)}
                 ...${item.Name}...
              @{end for}
           @{end for}
   ```

**Done!**

A selection of related products for an order — how to offer additional products to go with items that have already been purchased.
