retrieve method
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.
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.
May throw AccessDeniedException.
May throw ConflictException.
May throw InternalServerException.
May throw ResourceNotFoundException.
May throw ServiceQuotaExceededException.
May throw ThrottlingException.
May throw ValidationException.
Parameter indexId :
The identifier of the index to retrieve relevant passages for the search.
Parameter 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:HR is counted as 3 tokens: timeoff,
october, hr. For more information, see Searching
with advanced query syntax in the Amazon Kendra Developer Guide.
Parameter attributeFilter :
Filters search results by document fields/attributes. You can only provide
one attribute filter; however, the AndAllFilters,
NotFilter, and OrAllFilters parameters contain a
list of other filters.
The AttributeFilter parameter means you can create a set of
filtering rules that a document must satisfy to be included in the query
results.
Parameter documentRelevanceOverrideConfigurations :
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.
Parameter pageNumber :
Retrieved relevant passages are returned in pages the size of the
PageSize parameter. By default, Amazon Kendra returns the
first page of results. Use this parameter to get result pages after the
first one.
Parameter pageSize :
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.
Parameter requestedDocumentAttributes :
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.
Parameter userContext :
The user context token or user and group information.
Implementation
Future<RetrieveResult> retrieve({
required String indexId,
required String queryText,
AttributeFilter? attributeFilter,
List<DocumentRelevanceConfiguration>?
documentRelevanceOverrideConfigurations,
int? pageNumber,
int? pageSize,
List<String>? requestedDocumentAttributes,
UserContext? userContext,
}) async {
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'AWSKendraFrontendService.Retrieve'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'IndexId': indexId,
'QueryText': queryText,
if (attributeFilter != null) 'AttributeFilter': attributeFilter,
if (documentRelevanceOverrideConfigurations != null)
'DocumentRelevanceOverrideConfigurations':
documentRelevanceOverrideConfigurations,
if (pageNumber != null) 'PageNumber': pageNumber,
if (pageSize != null) 'PageSize': pageSize,
if (requestedDocumentAttributes != null)
'RequestedDocumentAttributes': requestedDocumentAttributes,
if (userContext != null) 'UserContext': userContext,
},
);
return RetrieveResult.fromJson(jsonResponse.body);
}