Lambda function to query Kendra for Lex Response

0

I am trying to write a Lambda function to filter a SearchKendra intent on Lex v2. I would like to filter based on 'accountId', which I have assigned to a document in the relevant bucket by including a .metadata file in the same location.

Here is my current Lambda function followed by the error that I am receiving. Any ideas what might be going on?

Lambda:

def lambda_handler(event, context):
    kendraQuery = {
    	"AttributeFilter": {
    		"EqualsTo": {
    			"Key": "accountId",
    			"Value": {
    				"StringValue": "123testid"
    			}
    		}
    	},
    	"IndexId": "sample-faq-index"
    }
    return {
        	"dialogAction": {
        		"type": "Delegate",
        		"kendraQueryRequestPayload": kendraQuery
        	}
        }

Here is the error message in the Lex console when testing:

Invalid Lambda Response: Received invalid response from Lambda: Can not construct instance of IntentResponse, problem: The validated object is null at [Source: {"dialogAction": {"type": "Delegate", "kendraQueryRequestPayload": {"AttributeFilter": {"equalsTo": {"key": "accountId", "value": {"stringValue": "123testid"}}}, "IndexId": "sample-faq-index"}}}; line: 1, column: 194]

質問済み 2年前1414ビュー
2回答
0

Hey, can you provide the actual Kendra query request payload that you are performing. from the request payload you provided, it looks like that this is an invalid query.

if you are trying to do a queryless search, you need to make sure both attributeFilter and SortingConfiguration are provided https://docs.aws.amazon.com/kendra/latest/dg/browsing.html

Thanks

AWS
回答済み 2年前
  • This is a lambda function for Lex to query Kendra. Can you provide an example of a lambda function for this purpose that filters documents based on an attribute filter as above? I believe the payload would be the Lex responses, which are included in the intent. They are of the format:

    I found a FAQ question for you: ((x-amz-lex:kendra-search-response-question_answer-question-1)) and the answer is ((x-amz-lex:kendra-search-response-question_answer-answer-1)).

    I found an excerpt from a helpful document: ((x-amz-lex:kendra-search-response-document-1)).

    I think the answer to your questions is ((x-amz-lex:kendra-search-response-answer-1)).

0

Hi,

Your Lambda can provide two attributes to Lex that can be used for Kendra queries: kendraQueryFilterString, and kendraQueryRequestPayload.

kendraQueryRequestPayload requires the entire Kendra query object, while kendraQueryFilterString is only the attribute filter. Looks like what you are looking for is kendraQueryFilterString.

You can see more details here: https://docs.aws.amazon.com/lexv2/latest/dg/built-in-intent-kendra-search.html#kendra-search-lambda

I hope this helps!

Mathilda

AWS
回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ