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 rescore with a different vector or metric.
  • 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 “Transfer learning” first, which is reasonable. Notice that “Transformer models use multihead self-attention enabling LLMs” ranks 4th even though it is the most directly relevant result for a question about large language models. A cross-encoder would likely rank it higher.

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 rescores it.

How prefetch reranking works

The two-stage flow fetches a broad set of candidates and then rescores 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 rescores 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: hnsw_ef sweep — accuracy vs speed

Different hnsw_ef values trade retrieval speed for recall accuracy. Run the same query with increasing hnsw_ef to see how much the candidate set changes.

Expected output

All hnsw_ef values return 100% recall on this small 25-doc corpus. Differences become visible at larger scale.

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?”

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.

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.

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 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: 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


Step 11: Rerank with score threshold pruning

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

Threshold placement: before vs after reranking

Use score_threshold on points.search() with params=SearchParams(exact=True) for precise threshold pruning after the retrieval phase.

Step 12: 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


Next steps