By ··11 min read

What improved a website's RAG search: hybrid search, RRF, reranker

A baseline that stored nothing, keyword plus vector search, Reciprocal Rank Fusion, a reranker and a query rewrite that fires 12 times in 100. The numbers for each step on a real 1,400-page site.

I was asked to build a question-answering search for a marketing website of about 1,400 pages, the kind of tool where a visitor types “Who is the CEO?” and gets the right page back. The first run of the crawler fetched and extracted 500 pages in 42 seconds, then wrote 0 pages and 0 chunks (pieces of page text) to the database. Its summary line ended webUnmatched: 500: nothing was stored, so nothing could be found. That run turned out to be the most useful thing I did, because it gave me a number to beat.

The short version

The rest of this post is that order, with the score after each step. Retrieval-augmented generation (RAG) is the pattern where a model answers from text a search step found for it. The search step is where most of the quality is won or lost, so that is the part I measured.

Measure a naive version first

The benchmark was small on purpose. I wrote 30 questions a visitor might ask, in their words, and for each one I recorded the page on the site that holds the answer. A question counted as answered when the right page was in the top five results of at least one of the searches.

The crawler I started from fetched each page’s HTML and pulled the text out. It only kept that text for pages it could match to an entry in the content management system (CMS), and without access to the CMS it matched none: that is what webUnmatched counted. It would have found nothing to keep anyway. This site builds its text in the browser, so the HTML the crawler received was a shell with no words in it.

Two rows. A raw HTML fetch gives nothing to extract and 0 chunks. Rendering the page in a browser first gives 5,028 chunks from all but 3 of about 1,400 pages.
The first crawl read the page before the browser had built it

For the benchmark I set the CMS matching aside and opened each page in a browser first. All but 3 of the roughly 1,400 pages produced text, 5,028 chunks of it. A chunk is a piece of a page, small enough to be searched and shown on its own.

The first table already says something. Limiting the crawl to 500 pages scored 12 of 30, because the case studies and solution pages sat past the cap. Crawling everything scored 24, and 24 became the line to beat.

Run Questions answered (right page in top 5)
Original crawler, as it was 0 / 30
With browser rendering, 500 pages 12 / 30
With browser rendering, whole site 24 / 30

The baseline ran two kinds of search, both inside the same graph database (Neo4j), which stores pages and chunks as records linked to each other.

Keyword search looks for the words in the question. It is exact, so it is good at names and product terms, and it is blind to rewording: ask for “extra developers” and it will not find a page that says “staff augmentation”.

Vector search turns the question and every chunk into a list of numbers (an embedding) that captures meaning, then returns the chunks whose numbers sit closest. It handles rewording well and is weaker on a precise name.

On the 30 questions the right page came first 18 times for keyword search and 11 times for vector search. Neither was enough alone, and they failed on different questions.

The rest of this post builds the pipeline below one stage at a time, with the score after each stage.

A question goes to keyword search and vector search, the two lists are merged with RRF, a reranker reorders the top 30, and if the best score is under 0.9 the question is reworded and searched again.
Where the post ends up: two searches, one merge, a reranker and a rewrite that runs only when the results look weak.

Two things that did not help, then one that did

I added metadata to each page in the graph: breadcrumbs, tags, keywords and links to parent pages. The score went from 24 to 23, and keyword search put the right page first 15 times instead of 18.

The cause was a short searchable summary for each page, packed with its tags and keywords. Those summaries took 52 of the 150 top-five keyword results across the 30 questions, matching questions they did not answer. A question about learning matched a webinar about machine learning.

Taking the tags and keywords out of the summary left the score at 23. The metadata was not the problem; the text underneath it was.

The chunker cut every 2,000 characters, and 82% of the cuts landed mid-sentence. Text from neighbouring page elements was also glued together, so a heading and the line under it became one word:

Jane DoeChief Executive Officer

A search for “chief executive” cannot match that. I changed the chunker to split at paragraphs, list items and headings, keep chunks under about 1,200 characters, end them between sentences, and repeat the section heading at the start of a continued chunk. Mid-sentence endings fell from 82% to 29% and glued words from about 19,000 to about 6,000. The score went to 26, and “Who is the CEO?” went from rank 15 to rank 2.

Step (same 30 questions) Answered Keyword: first / top 5 Vector: first / top 5
Baseline 24 18 / 22 11 / 22
Add metadata to the search text 23 15 / 22 13 / 21
Take tags and keywords back out 23 16 / 22 14 / 20
Split text properly 26 15 / 25 16 / 22

Merge by position with Reciprocal Rank Fusion

Many right pages now sat at rank 2 in one list or the other. The fix needed no model: combine the two lists.

The tempting way is to add the scores. It does not work, because the two searches score on different scales. Keyword scores have no fixed range: they grow with how many of the question’s words a chunk contains and how rare those words are. Vector similarity sits between 0 and 1, so adding the two lets keyword search drown out vector search.

A position means the same thing in both lists. Reciprocal Rank Fusion gives each page 1 / (60 + rank) from every list it appears in and adds the results. The 60 is the constant from the original paper by Cormack, Clarke and Buettcher, and it is still the usual default. It stops rank 1 from counting overwhelmingly more than rank 2 or 3.

A case study page ranked 2 by keyword search and 3 by vector search scores 0.0320 and takes first place. A page ranked 1 by keyword search and missing from vector search scores 0.0164.
The case study's ranks are from one benchmark question; the second page stands for any page only one search found

This is a cut-down version of the function that shipped. The real one returns pages with their matching text instead of scores.

rrf.ts
const RRF_K = 60;
function fuse(lists: string[][]): [string, number][] {
const scores = new Map<string, number>();
for (const list of lists) {
list.forEach((page, index) => {
scores.set(page, (scores.get(page) ?? 0) + 1 / (RRF_K + index + 1));
});
}
return [...scores].sort((a, b) => b[1] - a[1]);
}
const keyword = ["blog-post", "case-study"];
const vector = ["other-1", "other-2", "case-study"];
console.log(fuse([keyword, vector]).slice(0, 3));

Run it with node --experimental-strip-types rrf.ts. The case study wins:

[
[ 'case-study', 0.03200204813108039 ],
[ 'blog-post', 0.01639344262295082 ],
[ 'other-1', 0.01639344262295082 ]
]

On the benchmark the fused list put the right page first for 19 of 30 questions, up from 16 for the best single search. Three questions whose right page sat between rank 2 and rank 5 in both lists moved to first, and one more question was answered, making 27 of 30.

Fusion has a cost, and I saw it. When only one search finds a page, that page gets half the credit: the “Who is the CEO?” page was rank 2 in keyword search and fell to rank 14 in the fused list, because vector search did not return it in its top 50. A weak second rank is not always enough either. One case study, rank 2 in keyword search and 16 in vector search, finished fifth behind four pages that both searches found.

Rerank the top 30

A reranker is a second, slower reader. Search compares the question to each chunk separately, ahead of time. A reranker reads the question together with each candidate page and scores how well that page answers it, from 0 to 1. Run it only on the best candidates, because it costs a model call.

I took the top 30 pages from the fused list, sent each one with the text that matched on it, and re-sorted by the reranker’s score. The model was Qwen3-Reranker-8B, called through OpenRouter. A quick test on three questions showed the effect: one expected page moved from 30th to 3rd. A question about an office the company does not have scored 0.27 at best, against 1.00 for real answers, which later gave me a clean line for saying “not found”.

For the final graph I also changed the crawl. Text repeated across many pages (boilerplate) was removed, a model wrote a context sentence for each chunk plus a summary and likely questions for each page, and I switched the embedding model. So the numbers below compare stages inside one run, not against the table above.

Each stage is scored on 90 answerable questions from a 100-question set, two ways: whether the expected page came first, and whether a model judge (which reads the top result and says whether it answers the question) agreed.

Stage, 90 questions Expected page first Top result answers (judged)
Keyword search 58 54
Vector search 60 73
Fused with RRF 70 69
Reranked (final settings, with the rewrite below) 75 85

The judged column explains why the expected-page count alone is too strict. Vector search puts the listed page first only 60 times, but its first result answers the question 73 times, because other pages on a site often answer it too. Reranking was the only stage that raised both columns by a clear margin.

Rewrite the question only when it is needed

Some questions use words the site never uses. A rewrite step asks a model for up to three other wordings, searches all of them, fuses the lists and reranks again. It is aimed at that vocabulary gap, and it adds a model call and several searches to every query.

The reranker score tells you when it is needed. If the best page scores under 0.9, the search is unsure, so rewrite then. If not, skip it. I compared three modes on the same 90 questions:

Mode Never rewrite Rewrite when best score is under 0.9 Always rewrite
Questions rewritten (of 100) 0 12 100
Expected page first / top 5 73 / 87 75 / 89 74 / 89
Top result answers (judged) 83 85 84
Average search time 2.9 s 3.9 s 11.2 s
Model cost per search $0.0015 $0.0017 $0.0019

The gaps in quality are one or two questions out of 90, which is within the run-to-run noise I saw elsewhere in the benchmark, so I would not claim the gated mode is more accurate. What the table does show is the cost: always rewriting is nearly four times slower than never rewriting, with no gain. The gated mode matched the others on quality while rewriting only 12 questions. The times are higher than a single user would see, because six searches ran at once.

The gate is a few lines in the search function:

src/search/site-search.ts
results = await rerankPages(results);
if (rewriteWhenWeak && results[0].score! < rewriteBelowScore!) {
const later = await rewriteQuery();
variants.push(...later.queries);
stages.expanded = fuse([...lists, ...later.lists]);
results = await rerankPages(stages.expanded);
}

An extra search over named entities (people, platforms, industries) did not earn its place. On its own it put the right page first for only 22 of 90 questions. Its list was also fused in before reranking, and later analysis showed that the list the reranker received put the right page first for 53 questions, against 70 for keyword and vector search alone.

How to check it worked on your site

  1. Write 30 questions in your visitors’ words, and for each one note the page that answers it. Add a few the site cannot answer.
  2. Score the dumbest version that runs, and keep the number.
  3. Change one thing, re-score, and keep a table like the ones above. If a change lowers the number, find out why before keeping it.
  4. Score with a judge as well as an expected URL, or you will count correct answers as misses.

If your search runs on Sitecore Search, the wait between publishing and finding a page is a separate problem. I timed every hop from a SitecoreAI publish to a searchable document.

What comes next

A search that returns the right page is not yet an answer, so I added a step that writes a short answer from the top three pages and cites each sentence. The first version asked a second model to check every sentence, and it threw away 30 answers that were correct. The replacement makes the answering model quote the exact words it used, and plain code checks that each quote appears in the source page. That deserves its own post.

Takeaways

  • Score a naive baseline first. Mine was 0 of 30, and it told me the crawler was the problem, not the search.
  • Fix the text before you tune the search. Chunk boundaries moved the score more than any metadata did.
  • Combine keyword and vector search by rank position, not by score.
  • Rerank a short list, not the whole index.
  • Gate the expensive step on a signal you already have. Rewriting 12 questions in 100 took about a third of the time of rewriting them all, at the same quality.
  • Keep a changelog of numbers. Two of my ideas did not help, and only the table showed it.