Skip to main content

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.

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.

Quickstart

To use a reranker, you run a search and pass the results to the rerank() 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.
RerankerDefault model
RRFRerankerNone (reciprocal rank fusion)
LinearCombinationRerankerNone (weighted score blend)
MRRRerankerNone (weighted reciprocal rank)
CohereRerankerrerank-english-v3.0
CrossEncoderRerankercross-encoder/ms-marco-TinyBERT-L-6
ColbertRerankercolbert-ir/colbertv2.0
AnswerdotaiRerankersanswerdotai/answerai-colbert-small-v1
JinaRerankerjina-reranker-v2-base-multilingual
OpenaiRerankergpt-4-turbo-preview
VoyageAIRerankerNo default (model name required)
The model-based rerankers need their provider package installed, and the hosted ones (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 the rerank method. Here’s an example of how to rerank based on multiple vector columns using the CrossEncoderReranker:
from lancedb.rerankers import CrossEncoderReranker

reranker = CrossEncoderReranker()

query = "hello"

# `deduplicate=True` requires `_rowid` on every input result set,
# so call `.with_row_id(True)` on each search before passing it in.
res1 = table.search(query, vector_column_name="vector").limit(3).with_row_id(True)
res2 = table.search(query, vector_column_name="text_vector").limit(3).with_row_id(True)
res3 = table.search(query, vector_column_name="meta_vector").limit(3).with_row_id(True)

reranked = reranker.rerank_multivector([res1, res2, res3], deduplicate=True)
  • Passing deduplicate=True to rerank_multivector(...) raises a ValueError if any of the input result sets is missing the _rowid column. Therefore, it’s recommended to add .with_row_id(True) to every table.search(...) call before reranking, or omit deduplicate=True if you don’t need it.
  • RRFReranker.rerank_multivector(...) always requires _rowid on its inputs, regardless of the deduplicate flag.

Creating Custom Rerankers

LanceDB also allows you to create custom rerankers by extending the base Reranker 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.