From e461743dec623c4d355c5165009f8b764674702d Mon Sep 17 00:00:00 2001 From: abhjaw <54004795+abhjaw@users.noreply.github.com> Date: Mon, 18 Dec 2023 13:06:31 -0800 Subject: [PATCH 1/2] Update kendra.py Fixing issue - https://github.com/langchain-ai/langchain/issues/14494 to avoid Kendra query ValidationException --- libs/community/langchain_community/retrievers/kendra.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/community/langchain_community/retrievers/kendra.py b/libs/community/langchain_community/retrievers/kendra.py index ec1554c0abf8b..5254ef49bff1d 100644 --- a/libs/community/langchain_community/retrievers/kendra.py +++ b/libs/community/langchain_community/retrievers/kendra.py @@ -379,7 +379,7 @@ def create_client(cls, values: Dict[str, Any]) -> Dict[str, Any]: def _kendra_query(self, query: str) -> Sequence[ResultItem]: kendra_kwargs = { "IndexId": self.index_id, - "QueryText": query.strip(), + "QueryText": query.strip()[0:999], #trucate the query to ensure that there is no validation exception from Kendra. "PageSize": self.top_k, } if self.attribute_filter is not None: From ac225b840e3ab780103b08d19e64d334e9ff19d5 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Mon, 18 Dec 2023 17:42:00 -0800 Subject: [PATCH 2/2] cr --- 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 5254ef49bff1d..e93ef3ff5695d 100644 --- a/libs/community/langchain_community/retrievers/kendra.py +++ b/libs/community/langchain_community/retrievers/kendra.py @@ -379,7 +379,9 @@ def create_client(cls, values: Dict[str, Any]) -> Dict[str, Any]: def _kendra_query(self, query: str) -> Sequence[ResultItem]: kendra_kwargs = { "IndexId": self.index_id, - "QueryText": query.strip()[0:999], #trucate the query to ensure that there is no validation exception from Kendra. + # 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: