The Retrieval Problem — Finding the Needle in Billions of Haystacks

Every time you type into a search box and get useful results in milliseconds from billions of documents, a remarkable amount of engineering is hiding behind the cursor. Information retrieval is the science of finding relevant information in a large collection, and it's one of the oldest, most practical, and — in the age of RAG — most suddenly-relevant-again fields in computing. This series builds search from first principles, and it starts with why "just find the matching documents" is far harder than it sounds.

This series is the classical-retrieval companion to the vector-search material this blog already covers: before embeddings and semantic search, there is the foundational problem of matching queries to documents at scale, and the elegant structures (the inverted index, BM25) that solved it. Understanding classical IR is understanding what RAG retrieval is built on — and why modern systems blend the old and the new. Post 1 frames the problem.

“Search” sounds like one task but is really two, and conflating them causes most confusion about how search engines work:

Both are hard, for a reason that defines the field: scale meets relevance. You must search enormous collections (billions of documents) fast (milliseconds), while returning results that are actually relevant (a human-judgment quality). Speed pulls toward simple, precomputable structures; relevance pulls toward nuanced understanding of meaning. The entire field is the tension between these two, and every technique — the index (post 2), the ranking functions (post 4), the evaluation metrics (post 5) — is a move in that tension.

Why the obvious approach fails

The naive idea — scan every document for the query terms — fails immediately and instructively:

These two failures map to the field’s two great inventions: the inverted index (post 2) solves the speed problem by precomputing where every term appears, and ranking functions plus text analysis (posts 3–4) attack the relevance problem by scoring how well documents match and by bridging vocabulary gaps. Modern semantic/vector search (post 7) attacks the relevance problem from the other side, matching by meaning rather than words — but it stands on the same framing this post sets up.

The classic IR pipeline

Putting it together, a search system is a pipeline with an offline half and an online half — a structure worth holding in mind for the whole series:

Offline (indexing time), done once per document: - Ingest and parse documents from the collection. - Analyze the text — break it into terms and normalize them (post 3), so “Running,” “running,” and “runs” are treated consistently. - Build the index — construct the inverted index (post 2) mapping each term to the documents containing it, so lookups are instant.

Online (query time), done per search: - Analyze the query the same way the documents were analyzed (critical — the query and documents must speak the same normalized vocabulary). - Retrieve candidates — use the inverted index to instantly find documents containing the query terms. - Rank the candidates by a relevance score (post 4), and return the top results.

This offline-index / online-retrieve split is the architectural heart of search, and it’s exactly why search is fast: the expensive work (reading and indexing every document) happens once, ahead of time, so queries only touch a compact precomputed structure. It’s also the same shape as RAG retrieval — index your documents offline, retrieve relevant ones at query time to feed an LLM — which is why classical IR is suddenly foundational knowledge again. The vocabulary and structures this series builds are precisely what a retrieval system, classical or neural, is made of.

The throughline: information retrieval is finding relevant information in a large collection, and “search” is really two problems — matching (which documents are relevant?) and ranking (in what order?) — unified by the field’s defining tension, scale meets relevance (search billions of documents in milliseconds while returning genuinely relevant results). The naive scan fails twice: too slow (forcing a precomputed index so queries never touch raw documents) and too literal (exact term matching is a poor proxy for the meaning the user wants). Those failures birthed the field’s inventions — the inverted index (speed) and ranking + text analysis (relevance), with semantic/vector search attacking relevance by meaning. It all runs on the offline-index / online-retrieve pipeline that makes search fast and that RAG retrieval reuses directly.

Key takeaways

Further reading

Sources & References