Skip to main content
Vector search (ANN) and keyword search (BM25) efficiently retrieve relevant candidates, but the top results may not always reflect true semantic relevance. Reranking improves result quality by reordering the top-k results using a cross-encoder model. TopK provides built-in reranking via the rerank() query method.

Basic usage

Call rerank() after topk():
.rerank()

# or

.rerank(
    model="cohere/rerank-v3.5",
    query="catcher",
    fields=["title", "description"],
    topk_multiple=2,
)
Parameters
  • model — The reranking model to use (e.g. cohere/rerank-v3.5). Defaults to a built-in model if omitted.
  • query — The query text the cross-encoder scores each document against. If omitted, may be inferred from the filter stage (e.g. match()).
  • fields — Document fields to include when reranking. The reranker concatenates these and scores them against the query. Restricts which text is sent to the model.
  • topk_multiple — Multiple of top-k to consider for reranking. With topk(10) and topk_multiple=2, the reranker receives 20 candidates and returns the top 10. Use a higher value to improve recall at the cost of latency.
Typical flow:
  1. Retrieve top-k candidates using ANN or BM25.
  2. Rerank the top k × N results.
  3. Return the highest-scoring documents after reranking.

Example: Improving lexical search results

Query:
how to reset a router
client.collection(name).query(
    select(
        "title",
        "content",
        title_score=fn.bm25_score(),
    )
    .filter(match("how to reset a router", field="title"))
    .topk(field("title_score"), 10)
)
BM25 ranks documents based on exact term overlap. This is efficient but may not fully capture semantic intent.

Step 2: Apply reranking

client.collection(name).query(
    select(
        "title",
        "content",
        title_score=fn.bm25_score(),
    )
    .filter(match("how to reset a router", field="title"))
    .topk(field("title_score"), 10)
    .rerank(
        query="how to reset a router",
        fields=["content"],
    )
)
The reranker evaluates each candidate against the full query using a cross-encoder model and returns a reordered result set. Each document includes an additional _rerank_score field representing its semantic relevance.

When to use reranking

Reranking is recommended when:
  • Using BM25 for keyword retrieval
  • Using ANN for dense vector search
  • Combining multiple retrieval strategies (hybrid search)
  • Precision at top-k is critical (e.g., RAG, support search, documentation search)
This approach balances retrieval performance with improved ranking accuracy.