Skip to content

Semantic Ranker

Orders documents by relevance to a query, for search and RAG.

  • by Google
  • Rerank
  • $1 per 1,000 requests
On this page

1.Call

Send a query and a list of documents; get them back ordered by relevance. Every response carries an x-request-id trace ID.

curl https://api.ewest.ai/v1/rerank \
  -H "Authorization: Bearer $EWEST_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "ewest/semantic-ranker", "query": "How do I get a refund?", "top_n": 2,
       "documents": ["Refunds are issued within 5 days.", "Our office is in Yerevan.", "Contact support to cancel an order."]}'

# → {"results": [{"index": 0, "relevance_score": 0.91}, {"index": 2, "relevance_score": 0.42}]}

2.Authentication

Send your API key in the Authorization: Bearer header, as the examples above do (clients built for the Anthropic API can use x-api-key). Create keys under API keys. Keep the key on your server, never in browser code. More in the authentication guide.

3.Schema

What you send and what comes back, for ewest/semantic-ranker. The output tables are read from the API's OpenAPI description.

Input

POST /v1/rerank
  • modelstringRequired
    The model id, ewest/semantic-ranker.
  • querystringRequired
    What to search for.
  • documentsarrayRequired
    The texts to order, up to 100.
  • top_nintegerOptional
    Return only the best n results.

Output

Returns a ranking of your documents. POST /v1/rerank answers 200: Results, best first.

  • idstringSometimes
    Unique id of the request.
  • resultsarray of objectAlways
    Ordered by relevance_score, best first.
  • results[].indexintegerAlways
    Position in documents.
  • results[].relevance_scorenumberAlways
    How well the document matches the query; higher is better.
  • results[].documentobjectSometimes
    The document ({"text": ...}). Present on every result when the request set return_documents: true, absent otherwise (use index to find the document in your own list).
  • results[].document.textstringSometimes
    The document text.
  • metaobjectSometimes
    Usage information of the request.
  • meta.billed_unitsobjectSometimes
    What the request was billed for.
  • meta.billed_units.search_unitsintegerSometimes
    Number of search units billed.

Sample response

{
  "results": [
    {
      "index": 0,
      "relevance_score": 0.97
    },
    {
      "index": 1,
      "relevance_score": 0.04
    }
  ]
}

4.Details

Documents
Up to 100 per request
API
POST /v1/rerank (Cohere-style request and response)