From 6fbd068b3fc9e3c6a34c4c01b61f9e6f4205925a Mon Sep 17 00:00:00 2001 From: abhjaw <54004795+abhjaw@users.noreply.github.com> Date: Mon, 18 Dec 2023 17:46:18 -0800 Subject: [PATCH] Update kendra.py to avoid Kendra query ValidationException (#14866) Fixing issue - https://github.com/langchain-ai/langchain/issues/14494 to avoid Kendra query ValidationException --------- Co-authored-by: Harrison Chase --- libs/community/langchain_community/retrievers/kendra.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/community/langchain_community/retrievers/kendra.py b/libs/community/langchain_community/retrievers/kendra.py index ec1554c0ab..e93ef3ff56 100644 --- a/libs/community/langchain_community/retrievers/kendra.py +++ b/libs/community/langchain_community/retrievers/kendra.py @@ -379,7 +379,9 @@ class AmazonKendraRetriever(BaseRetriever): def _kendra_query(self, query: str) -> Sequence[ResultItem]: kendra_kwargs = { "IndexId": self.index_id, - "QueryText": query.strip(), + # truncate the query to ensure that + # there is no validation exception from Kendra. + "QueryText": query.strip()[0:999], "PageSize": self.top_k, } if self.attribute_filter is not None: