# Composite entities

A composite entity is a combination of two or more different, yet related [entities](https://docs.chatlayer.ai/nlp/natural-language-processing-nlp/detect-information-with-entities/..#entity-types). This type of entity allows you to combine two separate entities into a single one.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F4Ux34rQURegq9NTCTKvA%2FScreenshot%202024-08-23%20at%2012.24.20.png?alt=media&#x26;token=336e35f1-1fd5-42d3-a22e-96b81a6022ef" alt=""><figcaption><p>Composite entities tab.</p></figcaption></figure>

<details>

<summary>Example of composite entity</summary>

When a user tells the bot *Two fries please*, the bot will understand this as the predefined composite entity `@order`*,* which consists of two separate entities:&#x20;

* `@sys.number` **:** *2*, a [system entity](https://docs.chatlayer.ai/nlp/natural-language-processing-nlp/detect-information-with-entities/system-entities).
* and `@foodItem`: *fries*, a [match entity](https://docs.chatlayer.ai/nlp/natural-language-processing-nlp/detect-information-with-entities/match-entities).&#x20;

</details>

### Add a composite entities

To add a composite entity to your bot:

1. From your [**Entities**](https://docs.chatlayer.ai/navigation/natural-language-processing-nlp/synonym-entities) tab, make sure that you have different entities that your composite would be made of. For this example, we created a `@car_brand` match entity and will use `@sys.number`.&#x20;
2. Click on **Composite entitie**s.
3. Click on **Add composite entity**.
4. Fill in the **Entity name**.
5. Under **Entity values**, add the entities that will make the composite one.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FmtUk0VUKpBrs8sw74EjW%2FScreenshot%202024-08-23%20at%2012.25.24.png?alt=media&#x26;token=3c8d2f1e-0c62-45dd-93c4-f2d801a53496" alt="" width="375"><figcaption><p>Add a composite entity.</p></figcaption></figure>

6. Click on **Create entity**.

### Route your conversation based on composite entity values

To route your flow based on composite entities:

1. Create a [**Collect input**](https://docs.chatlayer.ai/buildabot/flow-logic/dialog-state/user-input-bot-dialog) block where you composite entity will be detected. In this example, we detect `@car_info`.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2Fa6GTfBYlpy3UoXBSEOgu%2FScreenshot%202024-08-23%20at%2012.30.19.png?alt=media&#x26;token=9696bd82-eb95-4517-8953-9edcc66814e5" alt="" width="375"><figcaption><p>Detect a composite entity inside your flow.</p></figcaption></figure>

2. Let's say you now want to route the flow based on the year of the car. For instance:&#x20;
   * When the year is equal to or more than 2016, the car is a green car
   * When the year is less than 2016, the car is not a green car.
3. Create a [**Condition**](https://docs.chatlayer.ai/buildabot/flow-logic/dialog-state/plugins) block that checks the `@car_brand.sys.number` variable.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FIcH9cfTF1Pnw8eTcK2G6%2FScreenshot%202024-08-23%20at%2012.35.42.png?alt=media&#x26;token=faaeb6ab-e8f7-4ad2-8992-e97bdcc44f66" alt="" width="375"><figcaption><p>Route the flow based on part of a composite entity.</p></figcaption></figure>

4. Click **Save**.
