An e-commerce platform with a large product catalog and user analytics data wants to implement a recommendation system so that users can obtain a list of the most relevant items based on previously viewed products.
- Only the last three viewed items are taken into account.
- The number of events is not considered.
- Other types of events are not considered.
- The server receives a request with a user identifier.
- The application retrieves the last three products viewed by that user.
- It concatenates information such as the name and categories of all these products, forming a single search text.
- The application performs the embedding process on this search text, transforming it into a vector.
- Then, the application searches for the five most relevant items in the vector database. To achieve this, the kNN algorithm - K-nearest neighbors, or simply K-nearest neighbors, is used.
- The result is then mapped to a format that makes sense for the client and returned.
There are some modifications that can be made to achieve greater robustness in the solution.
- Consider other user events. Example:
- Product purchases
- Adding products to the cart
- Consider the number of events per product within a given time period. Example:
- The five most viewed products by a specific user in the last seven days.
- Consider events related to the recommended products. Example:
- The ten most purchased products by users
- The ten most viewed products in the last seven days
- Start the necessary containers for the application
docker-compose up -d
- Install and run a virtual environment
pip3 install virtualenv
python3.8 -m venv venv
venv\Scripts\activate
- Install the project dependencies
pip install redis redis-om scikit-learn flask transformers torche
- Run the application using the command
python server.py
- Make a request to the service and obtain recommendations
curl --request GET
--url 'http://localhost:5000/search?userId=123e4567-e89b-12d3-a456-426614174007'