The recommendation server for Lenskit is a web server that exposes LensKit’s recommendation and rating prediction capabilities.
The recommendation server makes it much easier to use LensKit in deployed applications and interactive research where end users are actively involved, extending the reach and research impact of LensKit.
The user of the recommendation server can be anyone who knows how to build a web application, such as a software developer or a researcher. They need to create an application, which will itself have end users, and the recommendation server will generate recommendations for them.
The recommendation server is able to handle multiple concurrent requests and load and reload of recommendation models. It also provides recommendations on demand based on the latest ratings end users have provided.
To start using the recommendation server we need to follow some steps:
-
Create your model files by using util/train_save_model.py script. You need to have the ratings in your database or in a file. You can configure the database connection, folder paths and file names on util/train_save_model_config.json
-
As an optional step, you can create a python virtual environment or an anaconda environment.
-
Install the python dependencies by executing pip install -r requirements.txt
-
Configure your database connection and default algorithm in config.cfg
-
Start gunicorn. For instance, you can start it with 4 workers using the default port by running: gunicorn -w 4 wsgi:app
-
Place the model files inside the lkweb/models folder manually or upload them by using the endpoint ‘/algorithms//modelfile’
To make sure everything works fine, you can execute the functional tests by running pytest. We use pytest-docker, so all functional tests will be executed in a docker environment. The whole docker machines (recommendation server and database) will be created for you. You only need to place your items.csv and ratings.csv in the test_db folder and the whole process is automatically executed for you.
All the packages necessary to run the recommendation server are in requirements.txt file, which can be easily installed with the command: pip -r requirements.txt
If you just want to deploy the recommendation server and a postgres database in docker using data files located in test_db/ then follow these steps:
-
Move to the tests folder
-
Run the command “docker-compose up”
-
Update the configuration values from util/train_save_model_config.json to reflect your desired values.
-
Run the util/train_save_model.py script to create the model files and upload them to the recommendation server.
If you want to use a your own database, then you can build only the Dockerfile from lkweb folder.
The steps to setup the recommendation server using Docker are:
-
Update the db configuration from config.cfg
-
Move to the lkweb folder: cd lkweb
-
Build the rec server image from the Dockerfile: docker build -t rec-server .
-
Update the values from util/train_save_model_config.json to reflect your desired values.
-
Run the util/train_save_model.py script to create the model files and upload them to the recommendation server.
The steps to setup the recommendation server without Docker are:
-
Update the db configuration from config.cfg
-
Install the python packages from requirements.txt by calling: pip install -r requirements.txt
-
Start the recommendation server with 4 workers in gunicorn: gunicorn -w 4 wsgi:app
-
Update the values from util/train_save_model_config.json to reflect your desired values.
-
Run the util/train_save_model.py script to create the model files and upload them to the recommendation server.
It is recommended to create a python virtual environment before step 2.