Getting Recommendations

The REST Search API allows you to get Coveo™ Machine Learning (Coveo ML) content recommendations based on the user action history such as their recently viewed pages.

The pipeline uses these recommendations to change the advancedExpression and rankingExpression before sending the request to the index.

  • Coveo ML response example:

      {"recommendations":[
        {
            "eventType":"url",
            "name":"PageVisit",
            "explanations":[],
            "score":46.20083214759826,
            "metadata":
              {
                  "contentType": "Documentation",
                  "contentIDKey": "sfid",
                  "contentIDValue": "kA130000000Pv61CAC",
                  "language":"en",
                  "topValue":"top",
                  "trendingValue":"trending",
                  "title":"Configuring the server"
              },
            "value":"https://mycompany.com/htviewhelpdoc?id=configuring_the_server.htm"
        }
      ]
    
  • REST API call to get content recommendations:

      /rest/search/q=test&actionsHistory=[{"name":"PageView", "value":"https://www.dropbox.com/home/NTO-Manuals/Camping?select=mec-cabin-4.html", "time":"2016-06-03T00:00:00.0000Z"}]
    

    Ranking expression in the response block:

      ...
      "rankingExpressions" : [ {
          "expression" : "@urihash=\"vlTp6wQP Z 6wSKF\"",
          "modifier" : 250,
          "isConstant" : false
        }, {
          "expression" : "@urihash=\"VrulQxaNUFgGzENC\"",
          "modifier" : 107,
          "isConstant" : false
        }, {
          "expression" : "@urihash=\"cBQGBj1wEoVt9ETR\"",
          "modifier" : 102,
          "isConstant" : false
        }, {
          "expression" : "@urihash=\"5Ht1bPr4tbQd Ns \"",
          "modifier" : 95,
          "isConstant" : false
        }, {
          "expression" : "@urihash=\"wKxci395EKjpbIDl\"",
          "modifier" : 93,
          "isConstant" : false
        } ],
      ...
    

    Advanced expression in the response block:

      ...
      "advancedExpression" : "@urihash=\"vlTp6wQP Z 6wSKF\" OR @urihash=\"VrulQxaNUFgGzENC\" OR @urihash=\"cBQGBj1wEoVt9ETR\" OR @urihash=\"5Ht1bPr4tbQd Ns \" OR @urihash=\"wKxci395EKjpbIDl\"",
      ...
    

Parameters

Since this feature is part of a search at REST API, you can call it using all the other parameters. Only make sure to add the new parameter actionHistory.

actionHistory

The history of action with the 10 last actions taken by the current user.

When using the Coveo JavaScript Search Framework that information will be stored in a cookie and sent to the server when the recommendation feature is activated.

Each action history must contain a name, value and time.

[{
  "name":"PageView", "value":"https://www.dropbox.com/home/NTO-Manuals/Camping?select=mec-cabin-4.html",
  "time":"2016-06-03T00:00:00.0000Z"
}]

format

The format of the results. Use xlsx for excel and json for JSON. By default, the service returns the results in a JSON format.