Search code examples
amazon-web-servicesamazon-personalize

Paginate GetRecommendations API of AWS Personalize


I'm currently try to create a recommendation page which incorporates a infinite scrolling pagination (something like Instagram Explore) but could't find a way to do it with AWS SDK out of the box.

Is there any other way to fetch the data from AWS Personalize in a paginated way and ensuring the retrieved data not duplicate?


Solution

  • The GetRecommendations API for Personalize currently does not support pagination so the only way to use this API directly would be to fetch up to 500 items from the client in one call and then progressively reveal recommended items as the user scrolls. Or you could create an intermediate public API endpoint using something like API Gateway & Lambda that supports pagination and then lazily fetch and load recommendations for a user in a datastore like Redis. A Redis lrange or zrange to paginate.

    The advantage of retrieving the max number of recommendations and then paginating over them is that they represent a snapshot of recommendations at a moment in time. Since Personalize will potentially adjust recommendations based on new interactions streamed into the service, recommendations could change from one call to GetRecommendations to the next. This could create a user experience where the same item appears to be duplicated because it drops down in relevancy between calls and shows up in multiple "pages" of results.