Skip to main content

Module rerank

Module rerank 

Source
Expand description

Reranker trait: post-fusion rescoring by a model that jointly encodes (query, candidate) pairs.

§Why

The retrieve pipeline’s base rankers do not read (query, candidate) jointly:

  • The dense vector ranker is a bi-encoder. It embeds the whole query into one vector and each doc summary into one vector, then compares cosine similarity. It sees phrases but produces only one score per doc; the embeddings are encoded independently and never read together.
  • The learned-sparse ranker scores via a sparse dot product over a shared vocabulary. It too is a bi-encoder.

For compositional paraphrase like “father’s sister == aunt”, you need a model that reads the query and a candidate side-by-side and scores their relevance as a pair. That is a cross-encoder.

§What this module provides

A Reranker trait that adapter crates implement. Industry cross-encoder providers (Cohere rerank, Voyage rerank, Jina rerank, local BGE-reranker ONNX) all fit this shape.

Mnem-core stays tokio-free; adapter crates live next to mnem-embed-providers and do the HTTP work. This file contains only the trait, the error type, and a deterministic mock for tests.

§How it plugs in

crate::retrieve::Retriever::with_reranker takes a Arc<dyn Reranker>. If set, the retriever re-scores the top-K of the fused list before budget packing. Failures fall back to the original fused order (same graceful-degrade policy as the embedder auto-fuse in the CLI).

Structs§

AlwaysFailReranker
Test-only reranker that always errors. Proves the graceful fallback path in crate::retrieve::Retriever::execute.
MockJaccardReranker
Deterministic test-only reranker that scores candidates by their token-overlap Jaccard similarity to the query.

Enums§

RerankError
Error surface for cross-encoder reranker adapters.

Traits§

Reranker
Cross-encoder-style reranker: given a query and a list of candidate texts, return one relevance score per candidate (higher is better).