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

# Deduplicate recommendations

> Remove variants from your recommendations by using Recommend deduplication.

export const Application = () => <Tooltip tip="An Algolia application is a self-contained environment with its own indices, configuration, and API keys. Applications don't share data or settings with each other.">
    application
  </Tooltip>;

export const AlgoliaRecommend = () => <svg xmlns="http://www.w3.org/2000/svg" className="inline" viewBox="0 0 80 80" width="20" height="20" fill="none" role="presentation" ariaLabel="Algolia Recommend">
    <path d="m50 65-4 12H34l-4-12h20Z" fill="#36395A"></path>
    <path d="M68 32c0 15.464-12.536 28-28 28S12 47.464 12 32 24.536 4 40 4s28 12.536 28 28Z" fill="#FF2A6A"></path>
    <path d="M43 34V17L26 34h17Z" fill="#fff"></path>
    <path d="M37 30v17l17-17H37Z" fill="#fff"></path>
  </svg>;

export const AlgoliaSearch = () => <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 80" width="20" height="20" className="inline" fill="none" role="presentation" ariaLabel="Algolia Search">
    <circle cx="40" cy="32" r="28" fill="#5468FF"></circle>
    <rect x="30" y="22" width="20" height="20" rx="10" fill="#fff"></rect>
    <path d="M43 63.5 54.5 60l6 17h-12L43 63.5Z" fill="#36395A"></path>
  </svg>;

With Recommend deduplication, you can refine your recommendations by removing item variants from your AI model training.
The feature offers several advantages:

* **Improves recommendation accuracy and speed** by removing item variants before the training process.
* **Improves recommendation quality** by using events from all item variants.
* **Separates deduplication from search** so it doesn't affect the search experience.

## Recommend deduplication versus search deduplication

Algolia offers two types of deduplication:

* **Search deduplication** [removes duplicate items from search results](/doc/guides/managing-results/refine-results/grouping). This can help improve the relevance of the results and make them more user-friendly.
* **Recommend deduplication** remove duplicate items from Algolia AI recommendations. This can help improve the diversity of the recommendations and make them more personalized.

With Recommend deduplication,
your AI models are **trained with all variants**,
and the recommendations then **filtered by the API** before sending you the results to remove variants.

## How Recommend deduplication works

Recommend deduplication adds two processes to your AI model training:

* **Pre-training process**: generates a training dataset with only one variant per item. It also merges all events from variants of the same item.
* **Post-training process**: add all the variants dropped during the pre-training process back into the final set of recommendations.

<Note>
  Item variants share the same recommendations.
</Note>

## Set up the deduplication for a model

To deduplicate your recommendations, you must first declare an attribute for distinguishing variants, then turn on deduplication when configuring a Recommend model.
After that, verify that the recommendations have been deduplicated.

### Configure an attribute for distinguishing variants

First, choose which attribute defines records as variants:

1. Go to the [Algolia dashboard](https://dashboard.algolia.com/explorer/browse) and select your Algolia <Application />.
2. On the left sidebar, select <AlgoliaSearch /> **Search**.
3. Select your Algolia index.
4. On the [**Configuration**](https://dashboard.algolia.com/explorer/configuration/deduplication-and-grouping) tab, go to the **Deduplication and Grouping** page.
5. In the **Attribute for Distinct** box,
   select or enter the attribute name you want to use to define variants.

   <img src="https://mintcdn.com/algolia/QUuhkPGiow1bP-ae/images/guides/recommend/deduplication-attribute-for-distinct.png?fit=max&auto=format&n=QUuhkPGiow1bP-ae&q=85&s=d5f843f555fdbbe852e71d55f3d965a2" alt="Set the attributeForDistinct in your index settings" width="1670" height="756" data-path="images/guides/recommend/deduplication-attribute-for-distinct.png" />

<Check>
  Only use the `distinct` option if you also want to [deduplicate search results](/doc/guides/managing-results/refine-results/grouping).
</Check>

### Enable Recommend deduplication on your model

1. Go to the [Algolia dashboard](https://dashboard.algolia.com/recommend) and select your Algolia application.
2. On the left sidebar, select <AlgoliaRecommend /> **Recommend**.
3. Create a new Recommend model or edit an existing one for the index you used when setting the [`attributeForDistinct`](/doc/api-reference/api-parameters/attributeForDistinct).
4. In the section **Distinct and deduplication of recommendations**, select the **Deduplicate recommendations** option. The attribute you selected for defining variants is shown.
5. Continue to configure your Recommend model and click **Save**.

   <img src="https://mintcdn.com/algolia/QUuhkPGiow1bP-ae/images/guides/recommend/deduplication-toggle.png?fit=max&auto=format&n=QUuhkPGiow1bP-ae&q=85&s=7988f49b1919ea56fec8c66bea902939" alt="Enable deduplication in your model training configuration" width="2104" height="418" data-path="images/guides/recommend/deduplication-toggle.png" />

### Verify the recommendations

To check that the deduplication is working for your recommendations,
revisit the model configuration once the training process has finished:

1. Go to the **Preview** section.
2. Use the **Search for a record** box to search for an item that should have variants.

This displays the list of recommendations for the selected item.
They shouldn't contain any variants.

## Examples

The following examples illustrate how Recommend deduplication works.
The index has records for T-shirts in different colors and sizes:

* One **red** T-shirt in one size (*XS*)
* Two **green** T-shirts in two sizes (*S*, *M*)
* Three **blue** T-shirts in three sizes (*L*, *XL*, *XXL*)

This example uses the [**Related Items** model](/doc/guides/algolia-recommend/overview#recommend-models) to recommend the top 3 similar items with and without deduplication (with the `color` attribute configured as `attributeForDistinct`).

### Without deduplication

Without deduplication,
recommendations include variants,
such as **blue** (*XXL*) or **green** (*M*),
except for the **red** T-shirt which doesn't have any.

| Base item       | Recommendation 1 | Recommendation 2 | Recommendation 3 |
| --------------- | ---------------- | ---------------- | ---------------- |
| **red** (*XS*)  | **green** (*S*)  | **blue** (*L*)   | **blue** (*XL*)  |
| **green** (*S*) | **green** (*M*)  | **red** (*XS*)   | **blue** (*L*)   |
| **blue** (*L*)  | **blue** (*XL*)  | **blue** (*XXL*) | **green** (*M*)  |

### With deduplication

With deduplication, the recommendations don't include any variants.
However, since this example dataset only includes three records, it can only generate two recommendations.
If you introduce a new item, such as an **orange** T-shirt, it will be added as a third recommendation.

| Base item       | Recommendation 1 | Recommendation 2 | Recommendation 3 |
| --------------- | ---------------- | ---------------- | ---------------- |
| **red** (*XS*)  | **green** (*S*)  | **blue** (*L*)   | Doesn't apply    |
| **green** (*S*) | **red** (*XS*)   | **blue** (*L*)   | Doesn't apply    |
| **blue** (*L*)  | **red** (*XS*)   | **green** (*M*)  | Doesn't apply    |
