- 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.
- 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.Step 2: Baseline single-pass search
Before adding any reranking, establish what a single-pass vector search returns.Step 3: Server-side reranking with prefetch
The most powerful reranking pattern in Actian VectorAI DB uses thequery 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.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 withexact (brute-force) computation.
Why this matters
The prefetch retrieves 25 candidates using the HNSW index (fast, approximate). The finalparams=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. Therescore 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:
- Search the int8 quantized index for
limit * oversampling = 10candidates - Load the original float32 vectors for those 10 candidates
- Recompute exact cosine similarity
- Return the top 5 by exact score
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.
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.
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.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.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.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