Get recommendations

This is for:

Developer
In this article

The REST Search API allows you to get Coveo Machine Learning (Coveo ML) content recommendations based on users' 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.

Examples

  • Coveo ML response:

    {"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:

    https://platform.cloud.coveo.com/rest/search/v2/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

As this feature is part of a search at REST API, you can call it using all the other parameters. However, you must add the new parameter actionsHistory.

actionsHistory

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

When using the Coveo JavaScript Search Framework, this 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, as in the following example:

[{
  "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.