# Train the Model

## Prerequisites

Before training a model, make sure you have formed a data layout and imported your data through our batch loading API.  For more infomation, please see:

* [Overview of data model](/devdocs/products/recommendation/overview.md#setting-up-your-data)
* [Importing data](/devdocs/products/recommendation/how-to-guide/import-data.md)

## Configuring a model

Once you have your data imported, you can move on to configuring and training your recommender model. &#x20;

Model training is initiated via an API call to the **/recommender/train** endpoint.  This endpoint has several parameters to customize your model.

<table><thead><tr><th width="245">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>model_id</code></td><td>An optional unique ID for this model.  If this <code>model_id</code> has been used before, then this trained model will replace the previous model.</td></tr><tr><td><code>maximum_interaction_age_days</code></td><td>An optional integer value, specifying the maximum age of an interaction, in days.  For example, if you specify <code>90</code>, then interactions older than 90 days will be ignored by the model.  Interactions that do not have a timestamp associated with them will always be included.</td></tr><tr><td><code>data_tags</code></td><td>An optional list of data tags to include when training your model.  This can be used to filter which data is used, allowing different models to be trained on different datasets.</td></tr><tr><td><code>data_filters</code></td><td>An optional set of filters to act on both entities and interactions to only include a subset.</td></tr><tr><td><code>callback_url</code></td><td>A URL to trigger when the training is complete.  This can be used to notify your site or app when the model is ready.</td></tr></tbody></table>

{% hint style="info" %}
Note that the `data_filters` are currently in beta and may not yet be fully functional.
{% endhint %}

## Training the model

Training typically takes several minutes to hours, depending on the size of your dataset.  To see the size of your dataset before training, please refer to the section on [querying batch metadata](/devdocs/products/recommendation/how-to-guide/import-data.md#getting-dataset-info).

When you initiate a training request via the `train/` endpoint, you will be returned status information.  While the model is training, you can also query the `status/` endpoint to check on progress.

<table><thead><tr><th width="234">Name</th><th>Description</th></tr></thead><tbody><tr><td><code>model_id</code></td><td>The unique model identifier assigned to this model when training was initiated.</td></tr><tr><td><code>start_timestamp</code></td><td>The timestamp for when training started.</td></tr><tr><td><code>end_timestamp</code></td><td>The timestamp for when training completed.</td></tr><tr><td><code>status</code></td><td>The status: will be <code>running</code>, <code>completed</code>, or <code>error</code></td></tr><tr><td><code>message</code></td><td>Any error messages associated with the run if something goes wrong.</td></tr><tr><td><code>progress</code></td><td>An estimate of the progress, ranging from 0-100.</td></tr><tr><td><code>data_batch_ids</code></td><td>A list of the data <code>batch_id</code> values used for training this model.</td></tr></tbody></table>

Lucid recommends that you use the `callback_url` to set a webhook for when the training is completed.  This allows immediate notification without needing to repeatedly query the training status.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lucid-ai.gitbook.io/devdocs/products/recommendation/how-to-guide/train-the-model.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
