# ReQL Segmentations

> Source: https://docs.recombee.com/segmentations/reql-segmentations

> For the complete documentation index, see [llms.txt](/llms.txt).

# ReQL Segmentations

There are two types of ReQL Segmentations, both of which allow defining Segments using a ReQL expression.

## Manual ReQL Segmentation

With Manual ReQL Segmentation, you specify individual Segments of the Segmentation.

Each Segment is defined by a [ReQL](/reql) filter: Items passing the filter belong to the Segment.

### Example

Consider the same data about the Items as in [this section](/segmentations/property-based-segmentations#examples).

You can create an Item Segmentation where each Segment will represent one row on the homepage.

With defined Segments as follows:

Items get segmented in this way:

You will get the optimal order of these homepage rows for the particular user by calling the[Recommend Item Segments To User](/api/recommendations#request-recommend-item-segments-to-user)endpoint.

### Creating in the Admin UI

[![You can create individual Segments of the Manual ReQL Segmentation in the Admin UI](/img/segmentations/admin_ui_manual_reql.png)](/img/segmentations/admin_ui_manual_reql.png)

You can create individual Segments of the Manual ReQL Segmentation in the Admin UI

* Navigate to the _Segmentations_ section
* Give the Segmentation a title, which gets translated into the Segmentation ID, and optionally also give a description
* Create the first Segment by giving it a name (which gets again translated into the Segment's ID) and providing the [ReQL](/reql) filter  
   * You can check which Items belong to the Segment by clicking on _Preview items_
* Click _Add Segment_ to add another Segment
* When satisfied with the setup, click _Create_ to confirm it

### Creating via the API

* First, create an empty Segmentation using[Create Manual ReQL Segmentation](/api/segmentations#request-create-manual-reql-segmentation)
* Then, add the individual Segments using[Add Manual ReQL Segment](/api/segmentations#request-add-manual-reql-segment)

## Auto ReQL Segmentation

Auto ReQL Segmentation is specified by a [ReQL](/reql) expression that for each Item returns a **set of Segments** to which the Item belongs.

The individual Segments don't need to be predefined in any way.

### Examples

#### Example 1

The following expression returns the set of _genres_:

ReQL

```
'genres'
```

For example, for _johnny\_english_ it returns `{"Comedy"}` and for _the\_silence\_of\_the\_lambs_ it returns`{"Horror", "Thriller"}`.

Therefore it behaves the same as the[Property-based Segmentation](/segmentations/property-based-segmentations) using the _genres_ property:

#### Example 2

The following Segmentation put the Items into Segments according to their _genres_ and also adds a`Critically Acclaimed` Segment for items with`'critically_acclaimed' == true`.

ReQL

```
'genres' + (if 'critically_acclaimed' then {"Critically Acclaimed"} else {})
```

For example, for _johnny\_english_ it returns `{"Comedy"}`, for _friends_ it returns `{"Comedy", "Critically Acclaimed"}`, and for _the\_silence\_of\_the\_lambs_ it returns `{"Horror", "Thriller", "Critically Acclaimed"}`.

#### Example 3

The Segments of the following Segmentation are a combination of the Item's _genres_ and _country_ (British comedies, US thrillers, etc.).

ReQL

```
map(lambda 'genre': 'genre' + "-" + 'country', 'genres')
```

For example, for _johnny\_english_ it returns `{"Comedy-GB"}`, for _friends_ it returns `{"Comedy-US"}`, and for _the\_silence\_of\_the\_lambs_ it returns`{"Horror-US", "Thriller-US"}`.

### Creating in the Admin UI

[![You can specify the ReQL expression for the Auto ReQL Segmentation in the Admin UI](/img/segmentations/admin_ui_auto_reql.png)](/img/segmentations/admin_ui_auto_reql.png)

You can specify the ReQL expression for the Auto ReQL Segmentation in the Admin UI

* Navigate to the _Segmentations_ section
* Create a new Segmentation of the _Auto ReQL_ type
* Give the Segmentation a title, which gets translated into the Segmentation ID, and optionally also give a description
* Provide the [ReQL](/reql) expression which returns a set of Segments to which an Item belongs
* Check the preview of the resulting Segments and confirm the setup

### Creating via the API

* Call the[Create Auto ReQL Segmentation](/api/segmentations#request-create-auto-reql-segmentation)endpoint.