Getting only one matching result from AWS kendra retriver #26428
Replies: 3 comments 16 replies
-
You are getting only one matching result from AWS Kendra Retriever despite setting the Here is the relevant code snippet from the def _kendra_query(self, query: str) -> Sequence[ResultItem]:
kendra_kwargs = {
"IndexId": self.index_id,
"QueryText": query.strip()[0:999],
"PageSize": self.top_k,
}
if self.attribute_filter is not None:
kendra_kwargs["AttributeFilter"] = self.attribute_filter
if self.document_relevance_override_configurations is not None:
kendra_kwargs["DocumentRelevanceOverrideConfigurations"] = (
self.document_relevance_override_configurations
)
if self.user_context is not None:
kendra_kwargs["UserContext"] = self.user_context
response = self.client.retrieve(**kendra_kwargs)
r_result = RetrieveResult.parse_obj(response)
if r_result.ResultItems:
return r_result.ResultItems
# Retrieve API returned 0 results, fall back to Query API
response = self.client.query(**kendra_kwargs)
q_result = QueryResult.parse_obj(response)
return q_result.ResultItems In this code, the To address this, you might want to ensure that your |
Beta Was this translation helpful? Give feedback.
-
can we priotorize the result of query api first and then combine this with retrive api @dosu |
Beta Was this translation helpful? Give feedback.
-
I am Using below code. class CustomAmazonKendraRetriever(AmazonKendraRetriever):
def build_chain(): #llm = OpenAI(batch_size=5, temperature=0, max_tokens=300) The base URL for your Azure OpenAI resource. e.g. "https://.openai.azure.com"#gpt 4 config API version e.g. "2023-07-01-preview"#openai_api_version="2024-03-01-preview" The name of your Azure OpenAI deployment chat model. e.g. "gpt-35-turbo-0613"#deployment_name="gpt-35-turbo" The API key for your Azure OpenAI resource.openai_api_key = os.environ["openai_api_key"] This is set to
|
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
I am using above code. tried to change the topk value to 10. but still getting only one matching result
below is the response
q_result: ResultItems=[QueryResultItem(Id='e64b9d48-7d27-4ce7-b81d-ff7dda60b686-993724c6-54b2-4471-b4f4-1d4788c0b0e9', DocumentId='s3://automatictenderaig/GBC_Master_09122024.json', DocumentURI='https://s3.us-east-1.amazonaws.com/automatictenderaig/GBC_Master_09122024.json', DocumentAttributes=[DocumentAttribute(Key='_data_source_id', Value=DocumentAttributeValue(DateValue=None, LongValue=None, StringListValue=None, StringValue='1bf6a354-7aef-471e-b5b9-9ce733e9d085')), DocumentAttribute(Key='_source_uri', Value=DocumentAttributeValue(DateValue=None, LongValue=None, StringListValue=None, StringValue='https://s3.us-east-1.amazonaws.com/automatictenderaig/GBC_Master_09122024.json'))], ScoreAttributes={'ScoreConfidence': 'MEDIUM'}, DocumentTitle=TextWithHighLights(Text='GBC_Master_09122024', Highlights=[]), FeedbackToken='AYADeIJcFH7jB6tjAgMUGESML3wAXwABABVhd3MtY3J5cHRvLXB1YmxpYy1rZXkAREFzeHl3VFVTMi9idEk4cStrSk4xdXkzejlPNzliRXNHNUpYSnFLd0lDeS91Zi9PaUVGR3ZzWC80eXlJL2pYSUFPUT09AAEAB2F3cy1rbXMAS2Fybjphd3M6a21zOnVzLWVhc3QtMTo3OTQyODk5MjcwNzA6a2V5LzA4YjVkYTRmLWQyOWEtNDU3Mi04OTAwLTRkZjMzN2VjYzljYwC4AQIBAHjHtYTqclWDjf5WL-m_xsZq1b9mncgz9KNLQr3u2EEmpAF9BOgPaFikB1K59u69YJtYAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMo787muuN8hsCo4ivAgEQgDu7HIdxY95c0R5QAN6eNzoDRL_j7tLRAw2NxBXwypj0Wh3MuHPLMNoOqgOgP6J8y61MIIUXWMl42YmUQgIAAAAADAAAEAAAAAAAAAAAAAAAAABFQ3n4_UDS_0_IkyM9elh-___wAAAAEAAAAAAAAAAAAAAAEAAAF2UqgbpLwgYAi497P0Fba4xD2-CJMknK7y27dhyUZNDbBsd6uoIlQj1TySbGxwGucjaaPmdhDbXsexzm-K30A7aWUFIVF0QhpHSahD49AXViTGQOHBd3YJeJB1lYR6WLBpJzLDz2Q0ZScCjsgwjOiYCTq5ELbBSZCxMzDFcv_rX6FhSfkZTj0Q431xzUOc99zBDgDi1hPjyHVKnTOj5Q5sxh-QYeD3AAQDjMi_R3bzzJvXmBrcSfReIBdrx8cufVz9JUq0SVp22ucDrqUGewIbrZG6s_0L5-GY-vlHKVkkEfyb-wT_yn_Su_BEZtezdIxpHjfNNiwt26w-Uv-rtHQSOmHX5kwWX10WOWJjSik-azhlMH6YIQzLbXJVNCSdPs6OCBTnwmn96YkTBjRsqq8bFnEq-wQKmhsV11xfUntA7K0LSc5mxU53VfQ_L_sZuXQFusyzvMojb8JvaN0U9QBDPTevVT-JhRI3ccKpHsdKIC2L_2LNIlsrVtgkv6vd7lc4rnLFTbAGcwZQIwBm5k2qnDlCndcl1DqCqAuGbN-5sdq0FZidr3Rrrlsf6eIXcUE9doHKHSGEymBspzAjEAg2WTKBWnlQrjXHk15Ok5Vhr0te2c1MBkN-kmRyhXjGvb6NC-XTQ0kqep4wUWkeuR.e64b9d48-7d27-4ce7-b81d-ff7dda60b686-993724c6-54b2-4471-b4f4-1d4788c0b0e9', Format='TEXT', Type='DOCUMENT', AdditionalAttributes=[], DocumentExcerpt=TextWithHighLights(Text='...ID": null\n },\n {\n "PRODUCT NAME": "DC Motors",\n "PRODUCT DESCRIPTION": "Slotless Brushless DC Motor",\n "PREFERRED SUPPLIER": "DINGS",\n "SUPPLIER CONTACT": "Daniel Jang",\n "SUPPLIER EMAIL": "[email protected]?cc=mohamed...', Highlights=[{'BeginOffset': 35, 'EndOffset': 39, 'TopAnswer': False, 'Type': 'STANDARD'}, {'BeginOffset': 43, 'EndOffset': 45, 'TopAnswer': False, 'Type': 'STANDARD'}, {'BeginOffset': 46, 'EndOffset': 52, 'TopAnswer': False, 'Type': 'STANDARD'}, {'BeginOffset': 102, 'EndOffset': 104, 'TopAnswer': False, 'Type': 'STANDARD'}, {'BeginOffset': 105, 'EndOffset': 110, 'TopAnswer': False, 'Type': 'STANDARD'}, {'BeginOffset': 128, 'EndOffset': 136, 'TopAnswer': False, 'Type': 'STANDARD'}, {'BeginOffset': 153, 'EndOffset': 161, 'TopAnswer': False, 'Type': 'STANDARD'}, {'BeginOffset': 192, 'EndOffset': 200, 'TopAnswer': False, 'Type': 'STANDARD'}]))] TotalNumberOfResults=1 QueryId='e64b9d48-7d27-4ce7-b81d-ff7dda60b686' FacetResults=[{'DocumentAttributeKey': '_data_source_id', 'DocumentAttributeValueType': 'STRING_VALUE', 'DocumentAttributeValueCountPairs': [{'DocumentAttributeValue': {'StringValue': '1bf6a354-7aef-471e-b5b9-9ce733e9d085'}, 'Count': 1}]}] ResponseMetadata={'RequestId': '2dbc2392-db69-4dca-b617-9faf3544accd', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': '2dbc2392-db69-4dca-b617-9faf3544accd', 'content-type': 'application/x-amz-json-1.1', 'content-length': '3220', 'date': 'Fri, 13 Sep 2024 11:45:01 GMT'}, 'RetryAttempts': 0}
System Info
NA
Beta Was this translation helpful? Give feedback.
All reactions