Skip to main content

AWS Bedrock - Rerank API

Use Bedrock's Rerank API in the Cohere /rerank format.

Cost Tracking

โœ… Cost tracking is supported for Bedrock Rerank API calls.

Supported Parametersโ€‹

  • model - the foundation model ARN
  • query - the query to rerank against
  • documents - the list of documents to rerank
  • top_n - the number of results to return

Usageโ€‹

from litellm import rerank
import os

os.environ["AWS_ACCESS_KEY_ID"] = ""
os.environ["AWS_SECRET_ACCESS_KEY"] = ""
os.environ["AWS_REGION_NAME"] = ""

response = rerank(
model="bedrock/arn:aws:bedrock:us-west-2::foundation-model/amazon.rerank-v1:0", # provide the model ARN - get this here https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock/client/list_foundation_models.html
query="hello",
documents=["hello", "world"],
top_n=2,
)

print(response)

Authenticationโ€‹

All standard Bedrock authentication methods are supported for rerank. See Bedrock Authentication for details.