1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Embeddings with the OpenAI API

Exercise

Adding user history to the recommendation engine

For many recommendation cases, such as film or purchase recommendation, basing the next recommendation on one data point will be insufficient. In these cases, you'll need to embed all or some of the user's history for more accurate and relevant recommendations.

In this exercise, you'll extend your product recommendation system to consider all of the products the user has previously visited, which are stored in a list of dictionaries called user_history.

The following custom functions are available for you to use: create_embeddings(texts), create_product_text(product), and find_n_closest(query_vector, embeddings, n=3). numpy has also been imported as np.

Instructions

100 XP
  • Copy your API key and provide it to the OpenAI client.
  • Combine the text features for each product in user_history, embed the resulting strings, and calculate the mean embeddings using numpy.
  • Filter products to remove any products that are present in user_history.
  • Combine the features for each product in products_filtered and embed the resulting strings.