Foundations — Reranking and hybrid search
This page builds — from nothing — every symbol, letter and piece of notation that the parent note throws at you. If the parent wrote , , or and you blinked, this is where each one is earned.
0. The stage: what are we even counting?
Before any formula, fix the actors. We have:
- A query — the question you type. It is made of terms (words): .
- A pile of documents — for us, small chunks of text. We call one of them (or ).
- A corpus — the whole collection of documents. Its total count is .
Look at the figure: the query on the left is broken into terms, and each term is a searchlight that may or may not land on a given document. Relevance is just "how brightly do the searchlights land?"
1. The counting symbols: , , ,
1.1 — "add up a bunch of things"
The big Greek "S" (, sigma) means sum. When you see read it as a sentence: "start at , work out the something for , then for , … up to , and add all those numbers together." The is just a counter that walks through the terms.
1.2 — term frequency (how often a word appears)
reads: "how many times does term appear inside document ?" If says "cat" five times, then .
- Picture: a highlighter passing over , ticking each hit.
- Why we need it: a word mentioned often is probably central to the document. (With a catch we handle in D2 — diminishing returns.)
1.3 and — length and average length
The bars mean the length of — its word count. It is not absolute value here; it is a "size of" measure.
= average document length = the mean word count across the whole corpus.
Why both? A long document racks up word-hits just by being long, not by being more relevant. Comparing to tells us "is this document unusually long?" so we can cancel that unfair advantage. That's the fraction inside BM25.
2. Rareness: , , , and IDF
Some words are everywhere ("the"), some are rare and precious ("photosynthesis"). We need a symbol for rareness.
- :: total documents in the corpus.
- :: document frequency — how many documents contain term at least once.
If is small (the word lives in few docs), the word is rare and discriminating. The ratio is large for rare words, small for common ones.
2.1 Why (the natural logarithm)?
is the natural logarithm — a function that squashes big numbers. , , . Notice: multiplying by 10 only adds about 2.3 to .
The figure shows flattening: doubling the input barely nudges the output once you're out on the right. That gentleness is exactly why IDF uses it.
3. Vectors: , , , the dot product, and
Keyword matching can't see that "car" and "automobile" mean the same thing. For meaning, we turn text into vectors — lists of numbers — and compare directions.
3.1 What is a vector here?
A bi-encoder (a neural net) reads a piece of text and spits out a fixed list of numbers, say 768 of them. That list is a point/arrow in space.
- :: the query's vector (bold = it's a whole list, not one number).
- :: a document's vector.
- :: "the space of lists of real numbers." is the embedding dimension (e.g. 768). is the symbol for real numbers; the exponent means " of them."
3.2 The dot product
The dot means: multiply matching entries, then add them up. Geometrically, the dot product is large and positive when the two arrows point the same way, zero when they're perpendicular, negative when opposite. It measures alignment.
3.3 The norm — length of an arrow
The double bars mean the length (magnitude) of the arrow: This is just the Pythagorean theorem generalised to dimensions.
3.4 Putting them together: cosine similarity
The raw dot product mixes two things: direction and how long the arrows are. We only care about direction (meaning), not length. So we divide out the lengths:
4. Ranks and fusion: , , and the RRF sum
After each retriever runs, it produces an ordered list: best document first. The position in that list is a rank.
- :: the position of document in retriever 's list. Rank = best.
- :: which retriever we mean (BM25, or dense). The RRF sum runs over both.
- :: a smoothing constant (commonly ) — not the same as top-, and not BM25's . Notation collides in this field; watch the subscripts.
The figure plots against rank: a steep drop near the top, then a long flat tail — which is precisely why the top few positions dominate and deep positions barely matter.
5. The map of prerequisites
Read it top to bottom: symbols on the left become scores, scores become ranked lists, ranked lists fuse, and the fused shortlist gets one expensive final judge before reaching the language model.
6. Where each foundation lives in the vault
- Sparse counting (, IDF, ) → BM25 and TF-IDF
- Vectors, dot product, cosine → Embeddings and Bi-encoders
- The joint scorer that replaces separate encoding → Cross-encoders and Sentence Transformers
- Where the ranked lists actually get searched fast → Vector Databases and ANN Search
- Why we keep the final list small → Lost in the Middle - LLM context limits
- How we score whether the pipeline worked → Evaluation - Recall@k and MRR
- The whole assembled system → Retrieval-Augmented Generation (RAG)
- This foundation's parent → Reranking and hybrid search (index 4.4.14)
Equipment checklist
Test yourself — cover the right side and answer aloud.