Skip to main content
This tutorial walks through reranking strategies in Actian VectorAI DB that improve search relevance beyond a single-pass vector search. A single-pass search returns results ranked by embedding similarity, which is a good starting point but often not good enough. The initial ranking can miss nuance because:
  • Embedding models are general-purpose. A 384-dim model captures broad semantics but may not distinguish subtle relevance differences in your domain.
  • ANN search is approximate. HNSW may miss some true nearest neighbours, especially with conservative hnsw_ef.
  • Relevance is multidimensional. A product search cares about semantic match, recency, popularity, and price—not just vector distance.
Reranking fixes this by adding a second (or third) stage that rescores a broad initial candidate set using a more precise signal. The pattern is always the same:
This tutorial demonstrates the following reranking strategies in Actian VectorAI DB:
  • Server-side reranking with prefetch + query — Retrieve broadly, then rerankscore with a different vector or metric.
  • Quantization rescore — Search quantized vectors fast, then rescore from originals.
  • Cross-encoder reranking — Use a dedicated cross-encoder model client-side.
  • Payload-based reranking — Boost scores using structured metadata.
  • Fusion reranking — Combine multiple retrieval signals and fuse.
  • Cascaded multistage pipelines — Chain multiple reranking stages.
  • Score threshold pruning — Cut low-confidence results after reranking.

Architecture overview

The following diagram shows how a query flows through a multistage reranking pipeline.

Environment setup

Install the Actian VectorAI Python SDK and the sentence-transformers library for embedding and cross-encoder models.

Step 1: Create a test collection and ingest data

This step uses a corpus of 25 technical documents across several topics to demonstrate how reranking improves result ordering.
Define the corpus of 25 documents, embed them, and upsert into the collection.
Running both cells prints the encoder details and confirms the collection is ready.

Before adding any reranking, establish what a single-pass vector search returns.
The single-pass search ranks all 10 results by cosine similarity alone.
The baseline puts “Transformer models” first, which is correct. But notice that “Transfer learning fine-tunes large pretrained models” ranks 4th—a cross-encoder would likely rank it higher because it directly mentions “large pretrained models” in the context of LLMs.

Step 3: Server-side reranking with prefetch

The most powerful reranking pattern in Actian VectorAI DB uses the query endpoint with prefetch. The server retrieves a broad candidate pool first, then rerankscores it.

How prefetch reranking works

The two-stage flow fetches a broad set of candidates and then rerankscores them in the final query.
This may seem redundant when using the same vector, but the key insight is that the prefetch uses the configured HNSW ef while the final stage rerankscores all prefetched candidates. To guarantee exact (brute-force) cosine similarity instead of another HNSW pass, set params=SearchParams(exact=True) on the outer query() call—demonstrated in Step 4. The pattern becomes much more powerful when the prefetch and final query use different signals — explored in the next section.

Step 4: Rerank with higher accuracy (exact rescore)

Retrieve candidates with fast approximate search, then rescore them with exact (brute-force) computation.

Why this matters

The prefetch retrieves 25 candidates using the HNSW index (fast, approximate). The final params=SearchParams(exact=True) computes exact cosine similarity over those 25 candidates. This corrects any scoring inaccuracies from the approximate index without scanning the entire collection.

Step 5: Quantization rescore

When using scalar quantization for memory savings, the compressed vectors introduce scoring noise. The rescore parameter rerankscores candidates using the original full-precision vectors.

How quantization rescore works

The three parameters below control whether and how the server rerankscores candidates after a quantized search. The pipeline:
  1. Search the int8 quantized index for limit * oversampling = 10 candidates
  2. Load the original float32 vectors for those 10 candidates
  3. Recompute exact cosine similarity
  4. Return the top 5 by exact score
The output compares rankings with and without rescoring.
Notice the rescore version places “Transfer learning” (id=11) above “Gradient boosted trees” (id=8)—correcting the quantization noise.

Step 6: Cross-encoder reranking (client-side)

A cross-encoder processes the query and each candidate together as a pair, producing a more precise relevance score than independent embeddings. This is the gold standard for reranking quality, but is too slow for first-pass retrieval.

Bi-encoder vs cross-encoder

The table below contrasts the two model types used in this pipeline. The cross-encoder sees both the query and the document together, so it can model fine-grained interactions like “does this document answer the question?” rather than just “are these texts similar?” The cross-encoder output shows both scores side by side so you can see how the ranking changes.
Notice the cross-encoder promotes “Transfer learning fine-tunes large pretrained models” to rank 2. The bi-encoder scored it lower because the embedding spaces don’t overlap perfectly with “large language models”—but the cross-encoder sees “large pretrained models” directly in context and recognizes high relevance.

Step 7: Payload-based reranking (score boosting)

Combine vector similarity with structured metadata to create a composite relevance score.

How composite scoring works

The composite score blends three normalised signals into a single value.
The weight of each signal controls how much it influences the final ranking. Adjust the weights for your domain. An e-commerce search might weight price or rating. A news search might weight recency higher. The output shows how popularity and recency shift the ranking relative to a pure vector search.

Step 8: Fusion reranking

Run two different searches (for example, with different filters or different query formulations) and fuse the results.

How multistream fusion works

The server runs three independent retrieval streams and then fuses their rankings with RRF.
Results that appear in multiple streams rank higher after fusion. A document returned by both the unfiltered stream and one of the topic-filtered streams will accumulate rank contributions from both and rank near the top.

Step 9: Client-side fusion with weighted reranking

For full control over how different signals are blended, use client-side fusion with weights.

RRF vs DBSF for reranking

The two fusion methods differ in how they normalise scores before combining them. The weights parameter in RRF controls how much each list influences the final ranking. A weight of 0.6 on the topic-filtered list biases toward ML-specific results.

Step 10: Cascaded multistage pipeline

Chain multiple reranking stages using nested prefetch. Each stage narrows and refines the candidate pool.

How the cascade works

Each nested prefetch narrows the candidate pool while increasing scoring accuracy.
Each stage increases accuracy at the cost of speed, but only over a shrinking candidate set. The final exact rescore operates on just 15 candidates—fast enough to be imperceptible.

Step 11: Rerank with score threshold pruning

After reranking, apply a score threshold to remove low-confidence results.

Threshold placement: before vs after reranking

Where you place the threshold determines which scores it evaluates. Setting the threshold on the outer query ensures it applies to the final reranked scores, not the initial approximate scores. Higher thresholds progressively trim lower-confidence results from the output.

Step 12: Full reranking pipeline

Bring everything together: server-side prefetch for broad retrieval, cross-encoder for precision reranking, and payload boosting for business signals.

The full pipeline

The four stages below show how each layer refines the candidate set before the final ranking.
The composite column reflects all three signals, producing the final ordering.

Step 13: Collection cleanup

Flush the collection to disk and optionally delete it when you no longer need the tutorial data.

reranking strategies compared

The table below summarises each strategy’s trade-offs to help you decide which to apply.

Choosing your reranking strategy

Start with the simplest option and layer on additional stages as your relevance requirements grow.

Start simple

Begin with a prefetch and exact rescore. This is the lowest-effort improvement over a raw HNSW search.

Add cross-encoder when quality matters

When precision is critical (RAG pipelines, question-answering), add a cross-encoder stage after the initial retrieval.

Add payload signals for business relevance

If your application weights non-semantic signals like popularity or recency, combine them into a composite score.

Use fusion when you have multiple retrieval paths

When you run multiple searches with different filters or query formulations, fuse the results server-side.

Actian VectorAI features used

The table below summarises every Actian VectorAI DB API surface covered in this tutorial and its role in a reranking pipeline.

Next steps

Explore the tutorials below to put reranking into practice alongside other Actian VectorAI DB capabilities.

Building multimodal systems

Combine text, image, and metadata embeddings with named vectors

Optimizing retrieval quality

Tune HNSW, quantization, and distance metrics

Predicate filters

Combine vector search with structured payload constraints

Similarity search basics

Learn the core retrieval workflow