> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portkey.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Rerank

> Rerank documents with Bedrock

Bedrock supports document reranking through Cohere models. Portkey provides a unified `/rerank` endpoint to access this capability.

<Note>
  For Bedrock providers, pass the complete ARN along with the model name in the `model` field to make a successful request.

  Example: `arn:aws:bedrock:us-east-1::foundation-model/cohere.rerank-v3-5:0`
</Note>

## Rerank documents

<CodeGroup>
  ```sh cURL theme={"system"}
  curl --location 'https://api.portkey.ai/v1/rerank' \
  --header 'x-portkey-api-key: $PORTKEY_API_KEY' \
  --header 'x-portkey-provider: @BEDROCK_PROVIDER_SLUG' \
  --header 'Content-Type: application/json' \
  --data '{
      "model": "arn:aws:bedrock:us-east-1::foundation-model/cohere.rerank-v3-5:0",
      "query": "What is the capital of the United States?",
      "top_n": 3,
      "documents": [
          "Carson City is the capital city of the American state of Nevada.",
          "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
          "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.",
          "Capitalization or capitalisation in English grammar is the use of a capital letter at the start of a word. English usage varies from capitalization in other languages.",
          "Capital punishment has existed in the United States since before the United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states."
      ]
  }'
  ```

  ```python Python theme={"system"}
  from portkey_ai import Portkey

  client = Portkey(
      api_key="PORTKEY_API_KEY",
      provider="@BEDROCK_PROVIDER_SLUG"
  )

  result = client.post(
      "/rerank",
      model="arn:aws:bedrock:us-east-1::foundation-model/cohere.rerank-v3-5:0",
      query="What is the capital of the United States?",
      top_n=3,
      documents=[
          "Carson City is the capital city of the American state of Nevada.",
          "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
          "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.",
          "Capitalization or capitalisation in English grammar is the use of a capital letter at the start of a word. English usage varies from capitalization in other languages.",
          "Capital punishment has existed in the United States since before the United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states."
      ]
  )

  print(result)
  ```

  ```javascript NodeJS theme={"system"}
  import Portkey from 'portkey-ai';

  const portkey = new Portkey({
      apiKey: "PORTKEY_API_KEY",
      provider: "@BEDROCK_PROVIDER_SLUG"
  });

  const result = await portkey.post('/rerank', {
      model: "arn:aws:bedrock:us-east-1::foundation-model/cohere.rerank-v3-5:0",
      query: "What is the capital of the United States?",
      top_n: 3,
      documents: [
          "Carson City is the capital city of the American state of Nevada.",
          "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
          "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.",
          "Capitalization or capitalisation in English grammar is the use of a capital letter at the start of a word. English usage varies from capitalization in other languages.",
          "Capital punishment has existed in the United States since before the United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states."
      ]
  });

  console.log(result);
  ```
</CodeGroup>

<Note>
  Replace the region in the ARN (e.g., `us-east-1`) with the region where your Bedrock provider is configured.
</Note>

## Related Resources

<Card title="AWS Bedrock Rerank Docs" href="https://docs.aws.amazon.com/bedrock/latest/userguide/rerank.html">
  Official AWS documentation for reranking with Amazon Bedrock reranker models.
</Card>
