Filtering batch recommendations - Amazon Personalize

Filtering batch recommendations

Filtering batch recommendations works nearly the same as filtering real-time recommendations. To filter batch recommendations, you create a filter and then apply it to a CreateBatchInferenceJob operation or new batch inference job in the Amazon Personalize console. Amazon Personalize then filters the recommendations from the batch job’s output JSON file. For more information about batch inference jobs, see Creating a batch inference job (console).

For filters with placeholder parameters, such as $GENRE, provide the values in a filterValues object in your input JSON. For a filterValues object, each key is a parameter name and each value is the criteria that you are passing as a parameter. For multiple values, separate each value with a comma. The following is an example of a JSON input file with filter values. The GENRES key corresponds to a $GENRES placeholder in the filter expression.

{"userId": "5","filterValues":{"GENRES":"\"horror\",\"comedy\",\"drama\""}} {"userId": "3","filterValues":{"GENRES":"\"horror\",\"comedy\""}} {"userId": "34","filterValues":{"GENRES":"\"drama\""}}

Filtering batch recommendations (console)

  1. Use the console or the SDK to create a filter.

  2. When you create the batch recommendation job, on the Create batch inference job page, for Filter configuration - optional, Filter name, choose the filter.

Filtering batch recommendations (AWS SDK)

  1. Use the console or the SDKs to create a filter.

  2. Include the FilterArn parameter in the CreateBatchInferenceJob request.

import boto3 personalize = boto3.client("personalize") personalize_rec.create_batch_inference_job ( solutionVersionArn = "Solution version ARN", jobName = "Batch job name", roleArn = "IAM role ARN", filterArn = "Filter ARN", jobInput = {"s3DataSource": {"path": "S3 input path"}}, jobOutput = {"S3DataDestination": {"path": "S3 output path"}} )