Rerank
Rerank models sort text passages / documents by semantic relevance to a specific query. They are often used to sort search results returned by an existing search solution.
Let's try to identify the 3 most relevant documents for a specific question:
- cURL
- Python (OpenAI клиент)
curl -X POST "http://localhost:5000/v1/rerank" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer Your_API_key_Compressa" \
-d '{
"model": "Compressa-ReRank",
"query": "What is the capital of the United States of America?",
"documents": [
"Carson City is the capital of the US state of Nevada.\nAccording to the 2010 US Census, the population of Carson City was 55,274.",
"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean,\nwhich is a political division controlled by the United States.\nThe capital is Saipan.",
"Charlotte Amalie is the capital and largest city of the US Virgin Islands.\nIt has a population of about 20,000. The city is located on the island of Saint Thomas."
],
"return_documents": false
}'
import requests
def rerank_openai(query, documents, api_base, model, api_key=None, top_n=None):
url = f"{api_base}/v1/rerank"
headers = {
"Content-Type": "application/json"
}
if api_key:
headers["Authorization"] = f"Bearer {api_key}"
payload = {
"model": model,
"query": query,
"documents": documents,
}
if top_n is not None:
payload["top_n"] = top_n
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
return response.json()