FREE STUDY NOTES · DP-800

Hybrid search and reciprocal rank fusion (RRF) in SQL Server and Azure SQL

How to combine full-text and vector search results with reciprocal rank fusion in T-SQL, and why RRF uses ranks rather than raw scores.

From Ultra Transcenders DP-800 by Tony Rough (coming December 2026)

Hybrid search runs a keyword query and a vector query over the same rows and merges the two ranked lists. Because the two scores live on incompatible scales, the merge is usually done by position with reciprocal rank fusion.

Why scores can’t simply be added

CONTAINSTABLE and FREETEXTTABLE return RANK from 0 to 1000 where higher is better, while vector distances are small numbers where lower is better. Adding or averaging them mixes units and directions. Reciprocal rank fusion (RRF) ignores raw scores and uses each document’s position: every list contributes 1 / (k + rank), the contributions are summed per document, and the sum is sorted descending. Documents near the top of both lists win. Azure AI Search documents that RRF performs best with a small constant such as k = 60, and that this k is unrelated to the number of nearest neighbours. Weighting is applied by multiplying a list’s contribution. Figure 14.1 shows how the two ranked lists are merged.

The search text feeds a keyword list (FREETEXTTABLE or CONTAINSTABLE, higher RANK is better) and a vector list (VECTOR_SEARCH, lower distance is better), and each list is numbered by position. Reciprocal rank fusion adds 1/(k + rank) from each list, with k typically 60, to produce the merged top results, which can optionally be sent as JSON in a RAG prompt with sp_invoke_external_rest_endpoint.
Figure 14.1: Hybrid search merged with reciprocal rank fusion

RRF in T-SQL

DECLARE @q  NVARCHAR(400) = N'waterproof hiking boots';
DECLARE @qv VECTOR(1536)  = AI_GENERATE_EMBEDDINGS(@q USE MODEL EmbeddingModel);

WITH kw AS (
    SELECT ft.[KEY] AS product_id,
           ROW_NUMBER() OVER (ORDER BY ft.[RANK] DESC) AS rnk
    FROM FREETEXTTABLE(dbo.Products, description, @q) AS ft
),
vec AS (
    SELECT v.product_id, ROW_NUMBER() OVER (ORDER BY v.distance) AS rnk
    FROM (SELECT TOP (50) WITH APPROXIMATE p.product_id, r.distance
          FROM VECTOR_SEARCH(TABLE = dbo.Products AS p, COLUMN = embedding,
                             SIMILAR_TO = @qv, METRIC = 'cosine') AS r
          ORDER BY r.distance) AS v
)
SELECT TOP (10)
       COALESCE(kw.product_id, vec.product_id) AS product_id,
       ISNULL(1.0 / (60 + kw.rnk), 0) + ISNULL(1.0 / (60 + vec.rnk), 0) AS rrf_score
FROM kw
FULL OUTER JOIN vec ON kw.product_id = vec.product_id
ORDER BY rrf_score DESC;

The keyword list is ranked by full-text RANK, the vector list by ascending distance (the approximate search sits in a subquery because ROW_NUMBER needs the subquery pattern), and a full outer join keeps products found by only one method, which contribute zero from the other list. To favour semantics, multiply the vector term (for example by 2); to favour exact terms, weight the keyword term.

Other re-ranking options

The SQL vector FAQ describes re-ranking by combining vector search with full-text search (which provides BM25-style ranking), by additional SQL business logic, or by a semantic re-ranking model (a cross-encoder) that scores each candidate passage against the query. Filters such as stock status or region belong in the WHERE clause of each branch so that both lists rank only eligible rows.

Common trap: Normalising nothing and adding RANK to distance to build a hybrid score - full-text rank is 0-1000 higher-is-better and vector distance is lower-is-better; merge by position with RRF (1/(k + rank), k typically 60) or normalise both before weighting.

Get the whole book

This note is one section of Ultra Transcenders DP-800: Developing AI-Enabled Database Solutions, an independent study guide that explains every topic the exam covers by technology, with comparison tables, diagrams and the common traps, plus a glossary linked to Microsoft Learn.

Amazon.co.ukKindle: coming soonPaperback: coming soon
Amazon.comKindle: coming soonPaperback: coming soon

Due on Amazon in December 2026, in Kindle and paperback editions.

About the book · DP-800 terms in the glossary · All DP-800 study notes

More DP-800 study notes