retrieve
async
¶
retrieve(
index_id: IndexId,
query_text: QueryText,
*,
config_overrides: Optional[AsynckendraClientConfig] = None,
attribute_filter: Optional[AttributeFilter] = None,
requested_document_attributes: Optional[DocumentAttributeKeyList] = None,
document_relevance_override_configurations: Optional[
DocumentRelevanceOverrideConfigurationList
] = None,
page_number: Optional[Integer] = None,
page_size: Optional[Integer] = None,
user_context: Optional[UserContext] = None,
) -> RetrieveResult
Retrieves relevant passages or text excerpts given an input query.
This API is similar to the Query API. However, by default, the Query API only returns excerpt passages of up to 100 token words. With the Retrieve API, you can retrieve longer passages of up to 200 token words and up to 100 semantically relevant passages. This doesn't include question-answer or FAQ type responses from your index. The passages are text excerpts that can be semantically extracted from multiple documents and multiple parts of the same document. If in extreme cases your documents produce zero passages using the Retrieve API, you can alternatively use the Query API and its types of responses.
You can also do the following:
-
Override boosting at the index level
-
Filter based on document fields or attributes
-
Filter based on the user or their group access to documents
-
View the confidence score bucket for a retrieved passage result. The confidence bucket provides a relative ranking that indicates how confident Amazon Kendra is that the response is relevant to the query.
Confidence score buckets are currently available only for English.
You can also include certain fields in the response that might provide useful additional information.
The Retrieve API shares the number of query capacity units that you set for your index. For more information on what's included in a single capacity unit and the default base capacity for an index, see Adjusting capacity.
If you're using an Amazon Kendra Gen AI Enterprise Edition index, you can only use ATTRIBUTE_FILTER to filter search results by user context. If you're using an Amazon Kendra Gen AI Enterprise Edition index and you try to use USER_TOKEN to configure user context policy, Amazon Kendra returns a ValidationException error.
Parameters:
-
index_id(IndexId) –The identifier of the index to retrieve relevant passages for the search.
-
query_text(QueryText) –The input query text to retrieve relevant passages for the search. Amazon Kendra truncates queries at 30 token words, which excludes punctuation and stop words. Truncation still applies if you use Boolean or more advanced, complex queries. For example,
Timeoff AND October AND Category:HRis counted as 3 tokens:timeoff,october,hr. For more information, see Searching with advanced query syntax in the Amazon Kendra Developer Guide. -
attribute_filter(Optional[AttributeFilter], default:None) –Filters search results by document fields/attributes. You can only provide one attribute filter; however, the
AndAllFilters,NotFilter, andOrAllFiltersparameters contain a list of other filters.The
AttributeFilterparameter means you can create a set of filtering rules that a document must satisfy to be included in the query results.For Amazon Kendra Gen AI Enterprise Edition indices use
AttributeFilterto enable document filtering for end users using_email_idor include public documents (_email_id=null). -
requested_document_attributes(Optional[DocumentAttributeKeyList], default:None) –A list of document fields/attributes to include in the response. You can limit the response to include certain document fields. By default, all document fields are included in the response.
-
document_relevance_override_configurations(Optional[DocumentRelevanceOverrideConfigurationList], default:None) –Overrides relevance tuning configurations of fields/attributes set at the index level.
If you use this API to override the relevance tuning configured at the index level, but there is no relevance tuning configured at the index level, then Amazon Kendra does not apply any relevance tuning.
If there is relevance tuning configured for fields at the index level, and you use this API to override only some of these fields, then for the fields you did not override, the importance is set to 1.
-
page_number(Optional[Integer], default:None) –Retrieved relevant passages are returned in pages the size of the
PageSizeparameter. By default, Amazon Kendra returns the first page of results. Use this parameter to get result pages after the first one. -
page_size(Optional[Integer], default:None) –Sets the number of retrieved relevant passages that are returned in each page of results. The default page size is 10. The maximum number of results returned is 100. If you ask for more than 100 results, only 100 are returned.
-
user_context(Optional[UserContext], default:None) –The user context token or user and group information.
Raises:
-
AccessDeniedException–You don't have sufficient access to perform this action. Please ensure you have the required permission policies and user accounts and try again.
-
ConflictException–A conflict occurred with the request. Please fix any inconsistences with your resources and try again.
-
InternalServerException–An issue occurred with the internal server used for your Amazon Kendra service. Please wait a few minutes and try again, or contact Support for help.
-
ResourceNotFoundException–The resource you want to use doesn’t exist. Please check you have provided the correct resource and try again.
-
ServiceQuotaExceededException– -
ThrottlingException–The request was denied due to request throttling. Please reduce the number of requests and try again.
-
ValidationException–The input fails to satisfy the constraints set by the Amazon Kendra service. Please provide the correct input and try again.
-
UnknownServiceError–The service returned an error code this client does not model.
Source code in docs_src/capo_kendra/_services/async_kendra.py
3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 | |