Using the Amazon Kendra API to submit feedback - Amazon Kendra

Using the Amazon Kendra API to submit feedback

To use the Amazon Kendra API to submit query feedback, use the SubmitFeedback operation. To identify the query, you supply the IndexID of the index that the query applies to, and the QueryId returned in the response from the Query operation.

The following example shows how to submit click and relevance feedback using the Amazon Kendra API. You can submit multiple sets of feedback through the ClickFeedbackItems and RelevanceFeedbackItems arrays. This example submits a single click and a single relevance feedback item. The feedback submittal uses the current time.

To submit feedback for a search (AWS SDK)

  1. Use the following code and change the following values:

    1. index id  - Change to the ID of the index that the query applies to.

    2. query id - Change to the query that you want to provide feedback on.

    3. result id - Change to the ID of the query result that you want to provide feedback on. The query response contains the result ID.

    4. relevance value - Change to either RELEVANT (the query result is relevant) or NOT_RELEVANT (the query result is not relevant).

    Python
    import boto3 import time kendra = boto3.client('kendra') index_id = '${indexID}' query_id = '${queryID}' result_id = '${resultID}' feedback_item = {'ClickTime': int(time.time()), 'ResultId':result_id} relevance_value = 'RELEVANT' relevance_item = {'RelevanceValue': relevance_value, 'ResultId':result_id } response=kendra.submit_feedback( QueryId = query_id, IndexId = index_id, ClickFeedbackItems = [feedback_item], RelevanceFeedbackItems = [relevance_item] ) print ('Submitted feedback for query: ' + query_id)
    Java
    package com.amazonaws.kendra; import java.time.Instant; import software.amazon.awssdk.services.kendra.KendraClient; import software.amazon.awssdk.services.kendra.model.ClickFeedback; import software.amazon.awssdk.services.kendra.model.RelevanceFeedback; import software.amazon.awssdk.services.kendra.model.RelevanceType; import software.amazon.awssdk.services.kendra.model.SubmitFeedbackRequest; import software.amazon.awssdk.services.kendra.model.SubmitFeedbackResponse; public class SubmitFeedbackExample { public static void main(String[] args) { KendraClient kendra = KendraClient.builder().build(); SubmitFeedbackRequest submitFeedbackRequest = SubmitFeedbackRequest .builder() .indexId("anIndexId") .queryId("aQueryId") .clickFeedbackItems( ClickFeedback .builder() .clickTime(Instant.now()) .resultId("aResultId") .build()) .relevanceFeedbackItems( RelevanceFeedback .builder() .relevanceValue(RelevanceType.RELEVANT) .resultId("aResultId") .build()) .build(); SubmitFeedbackResponse response = kendra.submitFeedback(submitFeedbackRequest); System.out.println("Feedback is submitted"); } }
  2. Run the code. After the feedback has been submitted, the code displays a message.