notice
This is documentation for Rasa Documentation v2.x, which is no longer actively maintained.
For up-to-date documentation, see the latest version (3.x).
Model Storage
Models can be stored in different places after you trained your assistant. This page explains how to configure Rasa to load your models.
You can load your trained model in three different ways:
Load the model from your local disk (see Load Model from Disk)
Fetch the model from your own HTTP server (see Load Model from Server)
Fetch the model from cloud storage like S3 (see Load Model from Cloud)
By default all commands of Rasa's CLI will load models from your local disk.
Load Model from Disk
By default models will be loaded from your local disk. You can specify the path
to your model with the --model
parameter:
If you want to load the latest model in a directory, you can specify a directory instead of a file:
Rasa Open Source will check all the models in that directory and load the one that was trained most recently.
If you don't specify a --model
argument, Rasa Open Source will look for models in the models/
directory. The two following calls
will load the same model:
Load Model from Server
You can configure the Rasa Open Source server to regularly fetch a model from a server and deploy it.
How to Configure Rasa Open Source
You can configure the HTTP server to fetch models from another URL
by adding it to your endpoints.yml
:
The server will query the url
for a zipped model every wait_time_between_pulls
seconds.
If you want to pull the model only when starting up the server, you can set the time
between pulls to null
:
How to Configure Your Server
Rasa Open Source will send a GET
request to the URL you specified in the
endpoints.yml
, e.g. http://my-server.com/models/default
in the above examples.
You can use any URL.
The GET
request will contain an If-None-Match
header that contains the
model hash of the last model it downloaded. An example request from Rasa Open
Source to your server would look like this:
The response of your server to this GET
request should be one of these:
- a status code of
200
, a zipped Rasa Model and set theETag
header in the response to the hash of the model. - a status code of
304
and an empty response if theIf-None-Match
header of the request matches the model you want your server to return.
Rasa Open Source uses the If-None-Match
and ETag
headers for caching. Setting
the headers will avoid re-downloading the same model over and over, saving
bandwidth and compute resources.
Load Model from Cloud
You can also configure the Rasa server to fetch your model from a remote storage:
The zipped model will be downloaded from cloud storage, unzipped, and deployed. Rasa supports loading models from:
- Amazon S3,
- Google Cloud Storage,
- Azure Storage and
- custom implementations for Other Remote Storages.
Models need to be stored in the root folder of the storage service. Currently, it is not possible to manually specify the path on the cloud storage.
Amazon S3 Storage
Amazon S3 is supported using the boto3
package which you need to install
as an additional dependency using pip3
:
For Rasa to be able to authenticate and download the model, you need to set the following environment variables before running any command requiring the storage:
AWS_SECRET_ACCESS_KEY
: environment variable containing your AWS S3 secret access keyAWS_ACCESS_KEY_ID
: environment variable containing your AWS S3 access key IDAWS_DEFAULT_REGION
: environment variable specifying the region of your AWS S3 bucketBUCKET_NAME
: environment variable specifying the S3 bucketAWS_ENDPOINT_URL
: The complete URL to use for the AWS S3 requests. You need to specify a complete URL (including the "http/https" scheme).
Once all environment variables are set, you can start the Rasa server with
remote-storage
option set to aws
:
Google Cloud Storage
Google Cloud Storage (GCS) is supported using the google-cloud-storage
package
which you need to install as an additional dependency using pip3
:
If you are running Rasa on Google App Engine or Compute Engine, the auth credentials are already set up (for the GCS in the same project). In this case, you can skip setting any additional environment variables.
If you are running locally or on a machine outside of GAE or GCE you need to provide the authentication details to Rasa manually:
- Check out the GCS documentation and follow the descriptions on "Creating a service account" and "Setting the environment variable."
- After you have completed the GCS instructions, you should have set an environment
variable called
GOOGLE_APPLICATION_CREDENTIALS
to the path of a service account key file with access to your GCS.
Once all environment variable is set, you can start the Rasa server with
remote-storage
option set to gcs
:
Azure Storage
Azure Storage is supported using the azure-storage-blob
package which you need
to install as an additional dependency using pip3
:
For Rasa to be able to authenticate and download the model, you need to set the following environment variables before running any command requiring the storage:
AZURE_CONTAINER
: environment variable containing your azure container nameAZURE_ACCOUNT_NAME
: environment variable containing your azure account nameAZURE_ACCOUNT_KEY
: environment variable containing your account key
Once all environment variables are set, you can start the Rasa server with
remote-storage
option set to azure
:
Other Remote Storages
If you want to use any other Cloud Storage, you can provide your own python
implementation of the rasa.nlu.persistor.Persistor
class.
You can start the Rasa server with remote-storage
option set to
the module path of your persistor implementation: