Rerank
Order documents by relevance to a query with a model of kind rerank.
Rerank documents#
POST /v1/rerank scores each document for relevance to the query and returns the results ordered by score, each with the index of the document in your list.
rerank is offered yet404 model_not_found for every model id. The samples below show the request for when one is offered.Set PANWARD_RERANK_MODEL to the id of a model of kind rerank from the model catalog. An id that is not a canonical id answers 404 model_not_found.
cat > body.json <<EOF {"model": "$PANWARD_RERANK_MODEL", "query": "Which note mentions a penicillin allergy?", "documents": ["Discharge note, ward 4: no known allergies.", "Referral letter: allergic to penicillin.", "Lab report: normal values."], "top_n": 2} EOF curl https://api.panward.ai/v1/rerank \ -H "Authorization: Bearer $PANWARD_API_KEY" \ -H "Content-Type: application/json" \ --data-binary @body.json
import os import requests r = requests.post( "https://api.panward.ai/v1/rerank", headers={"Authorization": f"Bearer {os.environ['PANWARD_API_KEY']}"}, json={ "model": os.environ["PANWARD_RERANK_MODEL"], "query": "Which note mentions a penicillin allergy?", "documents": [ "Discharge note, ward 4: no known allergies.", "Referral letter: allergic to penicillin.", "Lab report: normal values.", ], "top_n": 2, "return_documents": True, }, ) r.raise_for_status() print(r.headers["panward-receipt-id"]) for result in r.json()["results"]: print(result)
const response = await fetch("https://api.panward.ai/v1/rerank", { method: "POST", headers: { Authorization: `Bearer ${process.env.PANWARD_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ model: process.env.PANWARD_RERANK_MODEL, query: "Which note mentions a penicillin allergy?", documents: [ "Discharge note, ward 4: no known allergies.", "Referral letter: allergic to penicillin.", "Lab report: normal values.", ], top_n: 2, return_documents: true, }), }); if (!response.ok) throw new Error(`rerank: ${response.status}`); console.log(response.headers.get("panward-receipt-id")); const { results } = (await response.json()) as { results: unknown[] }; for (const result of results) console.log(result);
Request fields#
| Field | Required | Values | Limits | Notes |
|---|---|---|---|---|
| model | Yes | string | Canonical id of a model of kind `rerank`. | |
| query | Yes | string | ||
| documents | Yes | array of string | min items 1; max items 1000 | |
| top_n | No | integer | min 1 | Return only the best `top_n` results. Defaults to all documents. |
| return_documents | No | boolean | Include each document's text in the results. |
Not part of the OpenAI API#
Rerank is a Panward addition, so the OpenAI SDKs have no call for it. Call it with plain HTTP, as above.
Receipts and billing#
The response carries the same headers as a chat completion, among them panward-receipt-id, panward-tier and panward-region, and the request has a receipt like any other (Receipts and verification). panward-hold-until-verified: true is accepted: the response waits until the verification level is known and the answer is 503 verification_unavailable instead of an unverified one.
Rerank is billed on input tokens.