@mlx-node/rerank
Rank documents for a query with Jina Reranker v3 and v3.5 or BGE-v2-M3.
Install
bash
npm install @mlx-node/rerank
Get a model
bash
mlx download model --model jinaai/jina-reranker-v3.5-mlx
Jina Reranker v3 and v3.5 and BGE-v2-M3 are supported. The package is MIT licensed, but model weights keep their own licenses. The official Jina checkpoints are CC BY-NC 4.0.
Rank documents
ts
import { homedir } from 'node:os';
import { join } from 'node:path';
import { loadReranker } from '@mlx-node/rerank';
const models = join(homedir(), '.mlx-node', 'models');
const reranker = await loadReranker(join(models, 'jina-reranker-v3.5-mlx'));
try {
const { results } = await reranker.rerank({
query: 'What is unified memory?',
documents: ['CPU and GPU share a memory pool.', 'A city park.'],
topN: 1,
});
console.log(results[0]); // { index, relevanceScore }
} finally {
await reranker.dispose();
}
Each document is a string or { text }. topN limits the list, returnDocuments adds the text to each result, and signal cancels a call. One model instance runs one request at a time.
From the terminal and over HTTP
bash
mlx rerank --model ~/.mlx-node/models/jina-reranker-v3.5-mlx --input request.json
The file holds query and documents, and the ranking is printed as JSON. mlx serve exposes the same model as POST /v1/rerank.
Without the native addon
@mlx-node/rerank/catalog, /types and /protocol do not load the native addon, so a client can share types with a server.
Main exports
| Name | What it is |
|---|---|
loadReranker(path) |
Load a reranker: rerank, dispose |