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

# Recommend-based groups

> How to inject items from an Algolia Recommend model as a Smart Group inside organic results.

export const SearchQuery = () => <Tooltip tip="The text users enter into a search box. In the Search API, this corresponds to the query parameter. A search query is often used with filters, facets, and other parameters, but these aren't part of the query text itself.">
    search query
  </Tooltip>;

export const Index = () => <Tooltip tip="An Algolia index is a searchable dataset that consists of records and configuration settings. These settings define how the records are searched and ranked.">
    index
  </Tooltip>;

export const Filter = () => <Tooltip tip="A filter is a condition that limits which records Algolia returns. Filters often use one or more facet-value pairs, such as brand:Apple AND color:red. You can also filter by numeric values, dates, tags, booleans, or geographic constraints." cta="Filtering" href="/doc/guides/managing-results/refine-results/faceting">
    filter
  </Tooltip>;

export const organicResultsDefinition = "These are the search results ranked by relevance and your configuration without compositions.";

export const OrganicResults = () => <Tooltip tip={organicResultsDefinition} cta="Smart Groups" href="/doc/guides/managing-results/compositions/smart-groups">
    organic results
  </Tooltip>;

Recommend-based groups let you populate a Smart Group with items from an [Algolia Recommend](/doc/guides/algolia-recommend/overview) model,
such as trending items for a category page or collection.
You define which model to query and Algolia injects its top recommendations at the position you specify in your <OrganicResults />.

## Before you begin

* Review the [Composition API prerequisites](/doc/guides/compositions#before-you-begin-using-the-compositions-api).
* The <Index /> in the Recommend source needs a trained Recommend model. For data and event requirements, see [Recommend models](/doc/guides/algolia-recommend/overview#recommend-models).

## Supported Recommend models

Recommend-based groups support only the `Trending items` model.
`Frequently bought together`, `Related items`, `Related content`, and `Looking similar` aren't supported.

## Configure a Recommend-based group

Configure Recommend-based groups with the [Update and insert Composition API](/doc/rest-api/composition/put-composition) endpoint.

In the `injectedItems` array, each entry uses a `source.recommend` object to reference a Recommend model:

```json JSON icon=braces expandable theme={"system"}
{
  "name": "Product results - United States",
  "objectID": "products-us",
  "behavior": {
    "injection": {
      "main": {
        "source": {
          "search": {
            "index": "products"
          }
        }
      },
      "injectedItems": [
        {
          "key": "trending-products",
          "source": {
            "recommend": {
              "indexName": "products",
              "model": "trending-items",
              "threshold": 60,
              "queryParameters": {
                "facetFilters": ["category:Footwear"]
              },
              "fallbackParameters": {
                "facetFilters": ["category:Footwear"]
              }
            }
          },
          "position": 0,
          "length": 4
        }
      ]
    }
  }
}
```

## Use Recommend as the source for main feed results

You can also use a Recommend model as the source for the main organic results,
not only for an injected group.
Set [`injection.main.source.recommend`](/doc/rest-api/composition/put-composition#body-behavior-one-of-0-injection-main-source-one-of-1-recommend) instead of `injection.main.source.search`:

```json JSON icon=braces theme={"system"}
{
  "behavior": {
    "injection": {
      "main": {
        "source": {
          "recommend": {
            "indexName": "products",
            "model": "trending-items",
            "threshold": 60
          }
        }
      }
    }
  }
}
```

The Recommend source accepts the same fields as an injected group.
Use this pattern when you want the full results page to come from Recommend, for example, on a "Trending now" page.

## Behavior details

Recommend-based groups behave like [search-based groups](/doc/guides/compositions/smart-groups/search-based-groups) for filtering, ranking, and deduplication:

* **Filters.** Use `queryParameters` and `fallbackParameters` to constrain the items returned by the model, for example by category or stock status.
* **Deduplication.** Algolia deduplicates items between organic results and injected groups using the configured strategy.
  See [Choose how to deduplicate results](/doc/guides/compositions/smart-groups/deduplication-strategy).
* **Composition rules and index rules.** [Composition rules apply on top of index rules.](/doc/guides/algolia-recommend/how-to/rules.mdx).

## See also

* [Composition REST API reference](/doc/rest-api/composition)
* [Set up the Trending Items model](/doc/guides/algolia-recommend/overview#trending-items-and-trending-facet-values)
* [Learn about external source groups](/doc/guides/compositions/smart-groups/external-source-groups)
