AWS personalize get-recommendations bug

0

Hello everyone. I have a problem with the get-recommendations response. For example:

Input data (utf-8 encoding):

{'ItemId': '1', 'properties': '{'description': 'random string\\nnext line '}'}

Output data (using the get-recommendations method):

{'ItemId': 'next line', 'score': 0.1}

So, in my example, I get broken string instead ItemId.

  1. What is a problem can be? How can I fix it?
  2. Is it possible that \n or similar symbols can break the response of this method and return some broken string instead?
gefragt vor 2 Jahren322 Aufrufe
1 Antwort
0

The GetRecommendations API request and response payload you shared above does not match the API definition. Are you using a language SDK or calling the Personalize endpoint directly?

If making a REST call directly to the Personalize campaign/recommender endpoint, the request payload should be in the following format.

{
   "campaignArn": "string",
   "context": { 
      "string" : "string" 
   },
   "filterArn": "string",
   "filterValues": { 
      "string" : "string" 
   },
   "itemId": "string",
   "numResults": number,
   "recommenderArn": "string",
   "userId": "string"
}

If using a language SDK like the AWS SDK for Python, the request parameters are passed as arguments to a function that wraps the REST call.

import boto3

personalizeRt = boto3.client('personalize-runtime')

response = personalizeRt.get_recommendations(
    campaignArn = 'Campaign ARN',
    userId = 'User ID',
    numResults = 10
)

print("Recommended items")
for item in response['itemList']:
    print (item['itemId'])

See examples here.

AWS
James_J
beantwortet vor 2 Jahren
  • I use boto3 library. I don't have any error with putting item or getting them, but in special cases which I describe above, if putting item has \n or similiar in properties, I get wrong data - I expect to get {'ItemId': '1, 'score': 0.1}, but getting {'ItemId': 'next line', 'score': 0.1}. Example:

    personalize_events = boto3.client("personalize-events")
    stream = {'itemId': '1', 'properties': '{"creationTimestamp": 1654676112, "description": "random string\\nnext line ", "userId": "1"}'}
    personalize_events.put_items(items=[stream])
    

    I get response using next code, but instead of {'itemList': [{'ItemId': 'next line', 'score': 0.1}]}

    personalize_events = boto3.client("personalize-events")
    personalize_events.get_recommendations()
    

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen