POST
/
rerank
from together import Together
import os

client = Together(
api_key=os.environ.get("TOGETHER_API_KEY"),
)

documents = [
{
"title": "Llama",
"text": "The llama is a domesticated South American camelid, widely used as a meat and pack animal by Andean cultures since the pre-Columbian era."
},
{
"title": "Panda",
"text": "The giant panda (Ailuropoda melanoleuca), also known as the panda bear or simply panda, is a bear species endemic to China."
},
{
"title": "Guanaco",
"text": "The guanaco is a camelid native to South America, closely related to the llama. Guanacos are one of two wild South American camelids; the other species is the vicuña, which lives at higher elevations."
},
{
"title": "Wild Bactrian camel",
"text": "The wild Bactrian camel (Camelus ferus) is an endangered species of camel endemic to Northwest China and southwestern Mongolia."
}
]

response = client.rerank.create(
model="Salesforce/Llama-Rank-v1",
query="What animals can I find near Peru?",
documents=documents,
)

for result in response.results:
print(f"Rank: {result.index + 1}")
print(f"Title: {documents[result.index]['title']}")
print(f"Text: {documents[result.index]['text']}")
{
  "object": "rerank",
  "id": "9dfa1a09-5ebc-4a40-970f-586cb8f4ae47",
  "model": "salesforce/turboranker-0.8-3778-6328",
  "results": [
    {
      "index": 0,
      "relevance_score": 0.29980177813003117,
      "document": {
        "text": "{\"title\":\"Llama\",\"text\":\"The llama is a domesticated South American camelid, widely used as a meat and pack animal by Andean cultures since the pre-Columbian era.\"}"
      }
    },
    {
      "index": 2,
      "relevance_score": 0.2752447527354349,
      "document": {
        "text": "{\"title\":\"Guanaco\",\"text\":\"The guanaco is a camelid native to South America, closely related to the llama. Guanacos are one of two wild South American camelids; the other species is the vicuña, which lives at higher elevations.\"}"
      }
    }
  ],
  "usage": {
    "prompt_tokens": 1837,
    "completion_tokens": 0,
    "total_tokens": 1837
  }
}

Authorizations

Authorization
string
header
default:default
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

Response

200
application/json

200

The response is of type object.