Skip to Content
Product Information
Author's profile photo Steven Fu

Step 3: Real-Time Inference

In this part of our blog series, you’ll call a real-time inference according to the payload.

Getting Started with Personalized Recommendation 

Step 1: Setup

Step 2: Model Training and Serving

Step 3: Real-Time Inference 

Step 4: Use Your Own Data

In Step 2, we learned how to train and serve the model using the Swagger API page. In this step, we’ll learn how to call a real-time inference using a clickstream. Here’s a short video to demonstrate how to do this: 

Video Walk-Through of Step 1

Inference Input and Output

To make the real-time inference call, navigate to the Inference section. There are three different inference calls. However, for this guide, we’ll use the next-items endpoint. The details of each endpoint are described in the following documentation.

Inference APIs on the Swagger API Page

After you open the next-items dropdown, you must complete some actions similar to those during model training:

  1. Enter tenant name.
    You must use the same tenant name that you entered during the training process.
  2. Insert Payload.
    Here, you provide all the relevant inference input data in the payload. Each of the different inference endpoints has different requirements: For next_items, the items_ls parameter is required while the other parameters are not required (but are imputable). The items_ls parameter is a list of item_id representing the user’s past item interactions (clickstream) to generate the recommendations.

For this parameter to be valid, the input must meet the following requirements:

  • Correspond to an object entry in the item_catalogue training data used to train the model, or
  • Be provided as an entry in the metadata parameter as a cold start item, or
  • Be provided as a cold start item via the “metadata update” feature

Taking an example from our sample dataset, insert a payload with the content
{ “items_ls”: [“2858”] }

Request Payload on the Swagger API Page

For more details of the payload input, refer to this documentation.

After clicking Execute, you can expect the following responses:

  1. The training process has not finished yet. This returns a 404 code, stating that no model instances were found.

    Error Not Found in the API Response

  2. The user inputted an incorrect payload. This returns a 400 code, stating that the model doesn’t understand the payload request.

    Error Bad Request in the API Response

  3. The model is able to understand the request and successfully return a set of recommendations. This returns a 200 code, stating the recommended items with their respective confidence scores.

    Recommendation Result Sample in the API Response

  4. Forbidden. The user has exceeded their inference quota for the month. A short message is displayed with code 403.

    Error Forbidden in the API Response

Cheers

At this point, we have successfully called inferences. If you have encountered any issues, feel free to leave a comment below. My team will definitely help you out. Alternatively, check out the Q&A area in the community or visit our community page to browse our use cases and learning materials.

In the next step, we will be using your own data to train a model for your own use case. Feel free to follow my profile and stay tuned for the next steps. See you in the next blog!

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Phil Cooley
      Phil Cooley

      Thanks for this Steven Fu really cool new BTP service. I have tried this out but I keep receiving an Unauthorized issue. I used Postman and most of it worked except this step.

      When I post this step 3 I get the following error occur

      {
        "message": "Invalid Authorization header. The expected format is Bearer xxxx"
      }
      
      I did successfully get the token so not sure why it is complaining. I ran all previous steps in Postman and it worked well however I was not sure how to load the file for this step.
      
      Just wondering how I can proceed?
      
      thanks
      Phil Cooley
      Author's profile photo Steven Fu
      Steven Fu
      Blog Post Author

      Hi Phil Cooley , let's have a call tomorrow day time. Then we will post the solution here, so the rest can benefit from it as well.

      ===

      Hi Phil Cooley

      Looks like you were not able to join the call. Anyway, this looks like a very generic error.

      If the token looks like ey..........OswtpGnQ,

      you should enter Bear ey..........OswtpGnQ in the authorization header.

      Leave a comment, or email me if you can't resolve the error. Thank you!