Skip to content

Reranking

After RRF fusion, a cross-encoder reranker scores each candidate against the query and re-sorts results by relevance. This improves precision at the cost of an additional inference pass.

Reranking is applied automatically in search() and searchWithContext() when a reranker is configured. Opt out per-query with { rerank: false }.

The easiest way is via lucerna.config.ts at your project root — the MCP server and CLI pick it up automatically:

lucerna.config.ts
import { VoyageReranker } from '@upstart.gg/lucerna';
export default {
rerankingFunction: new VoyageReranker(),
};

Or use the --reranker flag for a one-off run:

Terminal window
lucerna mcp-server /path/to/project --reranker voyage
lucerna search /path/to/project "auth middleware" --reranker jina
NameClassEnv vars required
cloudflareCloudflareRerankerCLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_API_TOKEN
jinaJinaRerankerJINA_API_KEY
voyageVoyageRerankerVOYAGE_API_KEY

See Built-in Providers for flag usage.

import type { RerankingFunction } from '@upstart.gg/lucerna';
class MyReranker implements RerankingFunction {
async rerank(query: string, texts: string[]): Promise<number[]> {
// Return one relevance score (0–1) per text, in the same order.
}
}