Overview
Morph’s Rerank API improves search quality by reordering candidate results based on their relevance to a query. Our latestmorph-rerank-v3
model achieves state-of-the-art performance across all coding benchmarks for accuracy:speed ratio - no rerank model comes close. Unlike the Apply and Embedding endpoints, the Rerank API uses a custom endpoint specifically designed for reranking tasks.
API Endpoint
Model Versions
The latest version ismorph-rerank-v3
with state-of-the-art performance across all code benchmarks for its speed-accuracy ratio. morph-rerank-v2
with dims 1536 remains available for backward compatibility.
Example Request
top_n
request parameter is optional and will default to the length of the documents
field. Result documents will be sorted by relevance, and the index
property can be used to determine original order.
Input Format
The request accepts the following parameters:Parameter | Type | Required | Description |
---|---|---|---|
model | string | Yes | The model ID to use for reranking. Use morph-rerank-v3 (latest) or morph-rerank-v3 . |
query | string | Yes | The search query to compare documents against. |
documents | array | No* | An array of document strings to be reranked. Required if embedding_ids is not provided. |
embedding_ids | array | No* | An array of embedding IDs to rerank. Required if documents is not provided. Remote content storage must be enabled. |
top_n | integer | No | Number of top results to return. Default is all documents. |
documents
or embedding_ids
must be provided.
Using Document Content
Using Embedding IDs
When you have previously generated embeddings and enabled remote content storage, you can rerank using embedding IDs:cURL Examples
With Document Content
With Embedding IDs
Response Format
Remote Content Storage
To use embedding IDs for reranking, you must enable remote content storage in your account settings. This allows Morph to retrieve the content associated with each embedding ID for reranking purposes. Without remote content storage enabled, you’ll need to pass in the document content directly. Benefits of using embedding IDs:- Reduced payload size for large document collections
- Improved security as content is stored in your account’s secure storage
- Ability to rerank content that was previously embedded
Integration with Search Systems
The Rerank API is typically used as a second-pass ranking system in a multi-stage retrieval pipeline:Authorizations
Bearer authentication header of the form Bearer <token>
, where <token>
is your auth token.
Body
application/json
Reranking request
ID of the model to use for reranking
Example:
"morph-rerank-v3"
The search query to compare documents against
Example:
"How to implement JWT authentication in Express"
An array of document strings to be reranked. Required if embedding_ids is not provided.
Example:
[
"This Express.js middleware provides authentication using JWT tokens and protects routes.",
"Express.js is a popular web framework for Node.js applications."
]
An array of embedding IDs to rerank. Required if documents is not provided. Remote content storage must be enabled.
Example:
["emb_123456789", "emb_987654321"]
Number of top results to return
Example:
5