Skip to content

search_recommendations

search_recommendations(
    domain_name: name,
    key_name: name,
    key_values: KeyValuesList,
    recommender: Recommender,
    *,
    config_overrides: Optional[CustomerProfilesClientConfig] = None,
    candidate_ids: Optional[CandidateIdList] = None,
    context: Optional[RecommenderContext] = None,
    diversity: Optional[RecommendationDiversityConfig] = None,
    metadata: Optional[RecommendationMetadata] = None,
    max_recommendations: Optional[MaxSize500] = None,
) -> SearchRecommendationsResponse

Retrieves recommendations for a profile in a specific domain. The profile is identified using a search key, which consists of a KeyName and a KeyValues list. The KeyName can be a predefined key (for example, _profileId, _phone, _email) or a custom-defined key.

The search key must match exactly one profile. If no profile matches the search key, the operation returns a ResourceNotFoundException. If more than one profile matches the search key, the operation returns a BadRequestException. You can use the SearchProfiles API to review the matching profiles.

Parameters:

  • domain_name (name) –

    The unique name of the domain.

  • key_name (name) –

    A searchable identifier of a customer profile. You can use a predefined key, such as _profileId, _phone, or _email, or a custom-defined key.

  • key_values (KeyValuesList) –

    A list of key values. Provide one value for each field of the search key.

  • recommender (Recommender) –

    The recommender used to generate the recommendations.

  • candidate_ids (Optional[CandidateIdList], default: None ) –

    A list of item IDs to rank for the user. Use this when you want to re-rank a specific set of items rather than getting recommendations from the full item catalog. Required for personalized-ranking use cases.

  • context (Optional[RecommenderContext], default: None ) –

    The contextual metadata used to provide dynamic runtime information to tailor recommendations.

  • diversity (Optional[RecommendationDiversityConfig], default: None ) –

    Runtime diversity configuration for this request. Enables diversity-aware recommendations and optionally supplies values for placeholder-based diversity caps configured on the recommender.

  • metadata (Optional[RecommendationMetadata], default: None ) –

    Configuration for metadata to include in recommendation responses.

  • max_recommendations (Optional[MaxSize500], default: None ) –

    The maximum number of recommendations to return. The default value is 5.

Raises:

Source code in docs_src/capo_customer_profiles/_services/customer_profiles.py
def search_recommendations(
    self,
    domain_name: "capo_customer_profiles.types.name.name",
    key_name: "capo_customer_profiles.types.name.name",
    key_values: "capo_customer_profiles.types.key_values_list.KeyValuesList",
    recommender: "capo_customer_profiles.types.recommender.Recommender",
    *,
    config_overrides: Optional[CustomerProfilesClientConfig] = None,
    candidate_ids: Optional[
        "capo_customer_profiles.types.candidate_id_list.CandidateIdList"
    ] = None,
    context: Optional[
        "capo_customer_profiles.types.recommender_context.RecommenderContext"
    ] = None,
    diversity: Optional[
        "capo_customer_profiles.types.recommendation_diversity_config.RecommendationDiversityConfig"
    ] = None,
    metadata: Optional[
        "capo_customer_profiles.types.recommendation_metadata.RecommendationMetadata"
    ] = None,
    max_recommendations: Optional[
        "capo_customer_profiles.types.max_size500.MaxSize500"
    ] = None,
) -> "capo_customer_profiles.types.search_recommendations_response.SearchRecommendationsResponse":
    """<p>Retrieves recommendations for a profile in a specific domain. The profile is identified using a search key, which consists of a <code>KeyName</code> and a <code>KeyValues</code> list. The <code>KeyName</code> can be a predefined key (for example, <code>_profileId</code>, <code>_phone</code>, <code>_email</code>) or a custom-defined key.</p> <p>The search key must match exactly one profile. If no profile matches the search key, the operation returns a <code>ResourceNotFoundException</code>. If more than one profile matches the search key, the operation returns a <code>BadRequestException</code>. You can use the SearchProfiles API to review the matching profiles.</p>

    Args:
        domain_name: <p>The unique name of the domain.</p>
        key_name: <p>A searchable identifier of a customer profile. You can use a predefined key, such as <code>_profileId</code>, <code>_phone</code>, or <code>_email</code>, or a custom-defined key.</p>
        key_values: <p>A list of key values. Provide one value for each field of the search key.</p>
        recommender: <p>The recommender used to generate the recommendations.</p>
        candidate_ids: <p>A list of item IDs to rank for the user. Use this when you want to re-rank a specific set of items rather than getting recommendations from the full item catalog. Required for personalized-ranking use cases.</p>
        context: <p>The contextual metadata used to provide dynamic runtime information to tailor recommendations.</p>
        diversity: <p>Runtime diversity configuration for this request. Enables diversity-aware recommendations and optionally supplies values for placeholder-based diversity caps configured on the recommender.</p>
        metadata: <p>Configuration for metadata to include in recommendation responses.</p>
        max_recommendations: <p>The maximum number of recommendations to return. The default value is 5.</p>

    Raises:
        capo_customer_profiles.errors.access_denied_exception.AccessDeniedException: <p>You do not have sufficient access to perform this action.</p>
        capo_customer_profiles.errors.bad_request_exception.BadRequestException: <p>The input you provided is invalid.</p>
        capo_customer_profiles.errors.internal_server_exception.InternalServerException: <p>An internal service error occurred.</p>
        capo_customer_profiles.errors.resource_not_found_exception.ResourceNotFoundException: <p>The requested resource does not exist, or access was denied.</p>
        capo_customer_profiles.errors.throttling_exception.ThrottlingException: <p>You exceeded the maximum number of requests.</p>
        capo_customer_profiles.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_customer_profiles.types.search_recommendations_request.SearchRecommendationsRequest]",
    ) -> OperationResponse[
        "capo_customer_profiles.types.search_recommendations_response.SearchRecommendationsResponse"
    ]:
        import capo_customer_profiles._operations.customer_profiles_20200815.search_recommendations

        output, http_response = (
            capo_customer_profiles._operations.customer_profiles_20200815.search_recommendations.search_recommendations(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_customer_profiles.types.search_recommendations_request.SearchRecommendationsRequest",
    ) -> dict[str, Any]:
        import capo_customer_profiles.types.search_recommendations_request

        return capo_customer_profiles.types.search_recommendations_request.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_customer_profiles.types.search_recommendations_response.SearchRecommendationsResponse",
    ) -> dict[str, Any]:
        import capo_customer_profiles.types.search_recommendations_response

        return capo_customer_profiles.types.search_recommendations_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "SearchRecommendations",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_customer_profiles.types.search_recommendations_request.SearchRecommendationsRequest = {
        "domain_name": domain_name,
        "key_name": key_name,
        "key_values": key_values,
        "recommender": recommender,
    }
    if candidate_ids is not None:
        input_["candidate_ids"] = candidate_ids
    if context is not None:
        input_["context"] = context
    if diversity is not None:
        input_["diversity"] = diversity
    if metadata is not None:
        input_["metadata"] = metadata
    if max_recommendations is not None:
        input_["max_recommendations"] = max_recommendations

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output