AgentsforBedrockRuntime / Client / rerank
rerank¶
- AgentsforBedrockRuntime.Client.rerank(**kwargs)¶
Reranks the relevance of sources based on queries. For more information, see Improve the relevance of query responses with a reranker model.
See also: AWS API Documentation
Request Syntax
response = client.rerank( queries=[ { 'type': 'TEXT', 'textQuery': { 'text': 'string' } }, ], sources=[ { 'type': 'INLINE', 'inlineDocumentSource': { 'type': 'TEXT'|'JSON', 'textDocument': { 'text': 'string' }, 'jsonDocument': {...}|[...]|123|123.4|'string'|True|None } }, ], rerankingConfiguration={ 'type': 'BEDROCK_RERANKING_MODEL', 'bedrockRerankingConfiguration': { 'numberOfResults': 123, 'modelConfiguration': { 'modelArn': 'string', 'additionalModelRequestFields': { 'string': {...}|[...]|123|123.4|'string'|True|None } } } }, nextToken='string' )
- Parameters:
queries (list) –
[REQUIRED]
An array of objects, each of which contains information about a query to submit to the reranker model.
(dict) –
Contains information about a query to submit to the reranker model.
type (string) – [REQUIRED]
The type of the query.
textQuery (dict) – [REQUIRED]
Contains information about a text query.
text (string) –
The text of the document.
sources (list) –
[REQUIRED]
An array of objects, each of which contains information about the sources to rerank.
(dict) –
Contains information about a source for reranking.
type (string) – [REQUIRED]
The type of the source.
inlineDocumentSource (dict) – [REQUIRED]
Contains an inline definition of a source for reranking.
type (string) – [REQUIRED]
The type of document to rerank.
textDocument (dict) –
Contains information about a text document to rerank.
text (string) –
The text of the document.
jsonDocument (document) –
Contains a JSON document to rerank.
rerankingConfiguration (dict) –
[REQUIRED]
Contains configurations for reranking.
type (string) – [REQUIRED]
The type of reranker that the configurations apply to.
bedrockRerankingConfiguration (dict) – [REQUIRED]
Contains configurations for an Amazon Bedrock reranker.
numberOfResults (integer) –
The number of results to return after reranking.
modelConfiguration (dict) – [REQUIRED]
Contains configurations for a reranker model.
modelArn (string) – [REQUIRED]
The ARN of the reranker model.
additionalModelRequestFields (dict) –
A JSON object whose keys are request fields for the model and whose values are values for those fields.
(string) –
(document) –
nextToken (string) – If the total number of results was greater than could fit in a response, a token is returned in the
nextToken
field. You can enter that token in this field to return the next batch of results.
- Return type:
dict
- Returns:
Response Syntax
{ 'results': [ { 'index': 123, 'relevanceScore': ..., 'document': { 'type': 'TEXT'|'JSON', 'textDocument': { 'text': 'string' }, 'jsonDocument': {...}|[...]|123|123.4|'string'|True|None } }, ], 'nextToken': 'string' }
Response Structure
(dict) –
results (list) –
An array of objects, each of which contains information about the results of reranking.
(dict) –
Contains information about a document that was reranked.
index (integer) –
The ranking of the document. The lower a number, the higher the document is ranked.
relevanceScore (float) –
The relevance score of the document.
document (dict) –
Contains information about the document.
type (string) –
The type of document to rerank.
textDocument (dict) –
Contains information about a text document to rerank.
text (string) –
The text of the document.
jsonDocument (document) –
Contains a JSON document to rerank.
nextToken (string) –
If the total number of results is greater than can fit in the response, use this token in the
nextToken
field when making another request to return the next batch of results.
Exceptions
AgentsforBedrockRuntime.Client.exceptions.ResourceNotFoundException
AgentsforBedrockRuntime.Client.exceptions.ConflictException
AgentsforBedrockRuntime.Client.exceptions.ValidationException
AgentsforBedrockRuntime.Client.exceptions.InternalServerException
AgentsforBedrockRuntime.Client.exceptions.DependencyFailedException
AgentsforBedrockRuntime.Client.exceptions.BadGatewayException
AgentsforBedrockRuntime.Client.exceptions.ThrottlingException
AgentsforBedrockRuntime.Client.exceptions.AccessDeniedException
AgentsforBedrockRuntime.Client.exceptions.ServiceQuotaExceededException