- Reordering results from an initial search so the most relevant documents appear first.
- Improving RAG answer quality by scoring each document directly against the query.
- Screening user input or generated output for harmful content before it is shown.
Rerank
Overview
The AI Gateway exposesPOST /rerank on the OpenAI-compatible API base URL (https://api.orq.ai/v3/router). Send a query and a list of documents, and receive the documents ordered by relevance to the query. Reranking re-orders the results of an initial retrieval (for example a vector or keyword search) with a cross-encoder model, a model that reads the query and each document together. This is slower but more accurate than comparing embeddings alone.
The request requires three fields: query, documents, and model. Send no more than 1,000 documents in a single request.
Quick Start
Response
Each entry in theresults array contains:
Results are ordered by
relevance_score descending, so the most relevant document is first. Pass top_n to limit the number of results returned; it defaults to the full length of documents. Pass return_documents: true to include the original document text in each result.
Rerank and Knowledge Base Search
Knowledge Base search already supports reranking: thesearch-knowledge-base endpoint accepts a rerank_config object and returns a rerank_score alongside the search_score for every retrieved chunk.
rerank_config fields:
model: The rerank model to usetop_k: Number of top results to return after reranking; defaults to the Knowledge Basetop_kthreshold: Only return documents with a relevance score above this value; defaults to0
- Inside a Knowledge Base: pass
rerank_configwhen retrieval stays inside the gateway. - Directly via
POST /rerank: call the endpoint when the initial candidates come from an external store, for example a third-party vector database, and only the final ordering should happen in the gateway.
Moderations
Overview
The AI Gateway exposesPOST /moderations on the OpenAI-compatible API base URL (https://api.orq.ai/v3/router). Send text and receive safety classifications: for each input, the response reports whether it is flagged and, per category, a boolean categories verdict and a category_scores confidence score.
The request requires input; model defaults to openai/omni-moderation-latest. Other available models include openai/text-moderation-latest, openai/text-moderation-stable, and mistral/mistral-moderation-2603.
Quick Start
Response
Each entry in theresults array corresponds to one input and contains:
Categories include
hate, harassment, illicit, self-harm, sexual, violence, and their subcategories such as hate/threatening and self-harm/intent. Use flagged or the individual category scores to decide what the application does, for example blocking output above a violence score threshold.
Category names and scores vary by model. OpenAI-compatible models return the 13-category set above. Mistral models (
mistral/mistral-moderation-*) return their own set: sexual, hate_and_discrimination, violence_and_threats, dangerous_and_criminal_content, selfharm, health, financial, law, pii.