All Products
Search
Document Center

Artificial Intelligence Recommendation:Use PAI-Rec to build a recommendation service for a details page

Last Updated:Aug 30, 2024

When you use customized recommendation solutions of PAI-Rec, you can use the data generated by the recall model to generate recommendations on details pages. You can use the data of UserGroupHotRecall and UserGlobalHotRecall to supplement global recommendation data. You can also use the item-to-item (I2I) data and popular item data generated in systems such as Spark and Apache Flink as recall data, as long as the data conforms to the recall data format of the PAI-Rec engine.

Configure the PAI-Rec engine

Recall and filtering logic:

  • ProductDetailPageEtrecRecall: generates candidate items by using the collaborative filtering algorithm eTREC. These candidate items have the highest priority.

  • GroupHotRecall: generates top candidate items by categorical features of items. In the following configuration example, the categorical feature category is used.

  • GlobalHotRecall: generates top candidate items based on the overall information of items. If the candidate items generated by ProductDetailPageEtrecRecall and GroupHotRecall are insufficient, the candidate items generated by GlobalHotRecall are used as supplements.

  • UserExposureFilter: blocks the items that have been recommended to the same user.

{

  "RecallConfs": [
    {
      "Name": "ProductDetailPageEtrecRecall",
      "RecallType": "ItemCollaborativeFilterRecall",
      "RecallCount": 50,
      "ItemCollaborativeDaoConf": {
        "AdapterType": "hologres",
        "HologresName": "pairec-holo",
        "Item2ItemTable": "i2i_table"
      }
    },
    {
      "Name":"GroupHotRecall",
      "RecallType": "UserGroupHotRecall",
      "RecallCount" :500,
      "Triggers": [
        {
          "TriggerKey": "category"
        }
      ],
      "DaoConf":{
        "AdapterType": "hologres",
        "HologresName": "holo_info",
        "HologresTableName": "group_hotness_table"
      }
		},
    {
      "Name":"GlobalHotRecall",
      "RecallType": "UserGlobalHotRecall",
      "RecallCount" :500,
      "DaoConf":{
        "AdapterType": "hologres",
        "HologresName": "holo_info",
        "HologresTableName": "global_hotness_table"
    	}
    }
  ],
  "FilterConfs": [
    {
      "Name": "UserExposureFilter",
      "FilterType": "User2ItemExposureFilter",
      "MaxItems": 100,
      "TimeInterval": 7200,
      "WriteLog": true,
      "DaoConf": {
        "AdapterType": "hologres",
        "HologresName": "pairec-holo",
        "HologresTableName": "exposure_history"
      }
    }
  ],
  "SortNames": {
    "default": [
      "ItemRankScore"
    ]
  },
  "FilterNames": {
    "default": [
      "UniqueFilter",
      "UserExposureFilter"
    ]
  },
  "AlgoConfs": [],
  "HologresConfs": {
    "pairec-holo": {
      "DSN": "postgres://{AK}:{SK}@{Host}:{Port}/{DB}?sslmode=disable&connect_timeout=1"
    }
  },
  "KafkaConfs": {},
  "RedisConfs": {},
  "SceneConfs": {
    "product_detail_page": {
      "default": {
        "RecallNames": [
          "ProductDetailPageEtrecRecall"
        ]
      }
    }
  },
  "LogConf": {
    "RetensionDays": 3,
    "DiskSize": 20,
    "LogLevel": "INFO"
  },
  "RankConf": {},
  "FeatureConfs": {}
}

Configure the engine interface

Request path

/api/rec/feed

Request parameters

Parameter

Description

Type

Required

Example

uid

The user ID.

string

Yes

"1000079"

item_id

The item ID.

string

Yes

"9237438"

size

The number of items to be obtained.

integer

Yes

10

scene_id

The scenario ID.

String

Yes

home_feed

features

The context features.

json map

No

{"current_detail_item_id":20, "sex":"male"}

debug

Specifies the logs for debugging.

bool

No

true

Sample requests

curl -v http://host/api/rec/feed -d '
  {"uid":"76295990", 
  "item_id":"9237438"
  "size":1, 
  "scene_id":"home_feed"}' 

Sample responses

{
    "code":200,
    "msg":"success",
    "request_id":"e332fe9c-7d99-45a8-a047-bc7ec33d07f6",
    "size":1,
    "items":[
        {
            "item_id":"3v5RE7417j7R",
            "score":0.0045,
            "retrieve_id":"ProductDetailPageEtrecRecall"
        }
    ]
}