Reranking is the process of re-ordering search results to improve relevance, often using a different model than the one used for the initial search. LanceDB has built-in support for reranking with models from Cohere, Sentence-Transformers, and more.Documentation Index
Fetch the complete documentation index at: https://lancedb-bcbb4faf-mintlify-f5da8d82.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Quickstart
To use a reranker, you run a search and pass the results to thererank() method. The examples below
move from the simplest, model-free rerankers to a model-based one. Each is a complete, runnable script.
1. Linear combination (simplest). LinearCombinationReranker normalizes the vector and full-text
scores and blends them with a single weight (default 0.7, favoring the vector score). It runs no
model, and reranks hybrid search results.
2. Reciprocal Rank Fusion. RRFReranker fuses results by rank position instead of raw score, so it
sidesteps having to make vector and full-text scores comparable. It loads no model either, and it’s the
default reranker for hybrid search.
3. Cohere (model-based). For higher relevance, a model-based reranker scores each result against the
query with a trained model. CohereReranker works with vector, full-text, or hybrid search, and needs
the cohere package plus either COHERE_API_KEY in the environment or an api_key argument.
Reach for the model-free rerankers (LinearCombinationReranker, RRFReranker) when cost and latency
matter most; reach for a model-based one like CohereReranker or CrossEncoderReranker when you need
higher relevance and can afford to score every query and document pair with a model.
Supported Rerankers
LanceDB supports the following rerankers out of the box. The first three are score-based and run no model; the rest are model-based. The built-in rerankers are documented in this section; the hosted providers that need an API key live under integrations.| Reranker | Default model |
|---|---|
RRFReranker | None (reciprocal rank fusion) |
LinearCombinationReranker | None (weighted score blend) |
MRRReranker | None (weighted reciprocal rank) |
CohereReranker | rerank-english-v3.0 |
CrossEncoderReranker | cross-encoder/ms-marco-TinyBERT-L-6 |
ColbertReranker | colbert-ir/colbertv2.0 |
AnswerdotaiRerankers | answerdotai/answerai-colbert-small-v1 |
JinaReranker | jina-reranker-v2-base-multilingual |
OpenaiReranker | gpt-4-turbo-preview |
VoyageAIReranker | No default (model name required) |
CohereReranker, JinaReranker, OpenaiReranker, VoyageAIReranker) also need an API key, passed
as an api_key argument or set in the provider-specific environment variable.
Rerankers add _relevance_score and return rows ordered by descending relevance. Python rerankers
accept return_score="relevance" or return_score="all" − use "all" when you want to keep the
original vector distance or FTS score columns for debugging. Model-based rerankers read from
column="text" by default, so either return that column in the search results or pass a different
column.
SDK coverage differs across languagesThe provider-specific rerankers in the table above
(
CohereReranker, CrossEncoderReranker, ColbertReranker, and others under lancedb.rerankers)
are currently Python-only. The TypeScript and Rust SDKs currently expose the generic Reranker
interface (rerankHybrid / rerank_hybrid) and the built-in RRFReranker. To use a
model-based reranker from TypeScript or Rust, you must implement the Reranker interface yourself.Multi-vector reranking
Most rerankers support reranking based on multiple vectors. To rerank based on multiple vectors, you can pass a list of vectors to thererank method. Here’s an example of how to rerank based on multiple vector columns using the CrossEncoderReranker:
- Passing
deduplicate=Truetorerank_multivector(...)raises aValueErrorif any of the input result sets is missing the_rowidcolumn. Therefore, it’s recommended to add.with_row_id(True)to everytable.search(...)call before reranking, or omitdeduplicate=Trueif you don’t need it. RRFReranker.rerank_multivector(...)always requires_rowidon its inputs, regardless of thededuplicateflag.
Creating Custom Rerankers
LanceDB also allows you to create custom rerankers by extending the baseReranker class. The custom reranker
should implement the rerank method that takes a list of search results and returns a reranked list of
search results. This is covered in more detail in the creating custom rerankers section.