recallA retrieval
field guide

Sparse vs Dense Retrieval

Build this skill

Contrast sparse and dense retrieval, predict which wins for a query, and explain learned sparse retrieval.

Two ways to turn text into numbers

Keyword search and embedding search look like completely different technologies, but underneath they do the same thing: turn each text into a list of numbers and compare the lists. The difference is in what the lists look like. Keyword methods produce sparse vectors and embedding models produce dense vectors, so the two approaches are called sparse retrieval and dense retrieval.

Understanding the difference explains why each one wins in different situations, and why many good systems use both.

Sparse vectors: one slot per word

Imagine a list with one slot for every word in the whole vocabulary, which could be 100,000 or more words. To represent a page, you put a number in the slot for each word it contains (for example its BM25 weight) and leave every other slot at zero. Because a short page uses only a few dozen of those 100,000 words, almost every slot is zero. A list that is mostly zeros is called sparse.

Each slot has a clear meaning: slot 4,312 is "hostel", slot 9,870 is "fee". You can read a sparse vector and understand exactly why a page matched. That is why keyword search is easy to explain.

Dense vectors: every slot is used

An embedding is a dense vector: a much shorter list, perhaps 1,024 numbers, where every slot holds a value. No slot means a single word. Meaning is spread across all of them together, which is what lets "sick days" sit close to "medical leave".

Sparse vector (keywords)hostel: 1.79fee: 2.35(99,998 other slots = 0)Readable, exactDense vector (embedding)[0.12, -0.48, 0.33, 0.05, -0.21, 0.67, … 1,018 more ]Captures meaning

A sparse vector has a slot for every word, nearly all zero. A dense vector is short, and every number contributes to the meaning.

The code below builds both kinds for one sentence, so you can see the difference in shape.

python · runs in your browser

Expected output:

text
sparse: [0, 0, 1, 1, 1, 1, 0, 0, 0, 0]
non-zero slots: 4 of 10
dense:  [0.41, -0.12, 0.77, 0.05, -0.33]

The list comprehension walks through the vocabulary and writes 1 where the word occurs in the sentence and 0 everywhere else, so the sparse vector is always as long as the vocabulary. The dense list keeps the same short length however many words the language has.

With a real vocabulary of 100,000 words, the sparse vector would still have only four non-zero slots.

Where each one wins

The two methods fail in opposite places, which is the most useful thing to know about them.

Situation Sparse (BM25) Dense (embeddings)
Synonyms: "sick days" vs "medical leave" Misses Finds
Questions in Hindi or Telugu against English pages Misses Finds (with a multilingual model)
Exact codes: "CS3101", "Form 16A", roll numbers Finds Often misses
Rare names and new jargon Finds Can miss if the model never saw them
Explaining why something matched Easy Hard
Works with no training Yes Needs a trained model

Dense retrieval is better at meaning; sparse retrieval is better at exact text. A student asking "what is the syllabus for CS3101" needs the exact course code to match, and an embedding model may treat "CS3101" and "CS3102" as nearly identical. A student asking "can I get my paper rechecked" needs meaning, and BM25 finds nothing.

Try predicting the winner for each query below.

Learned sparse retrieval: the middle ground

There is a third option that mixes both ideas. Learned sparse retrieval uses a neural network, like an embedding model, but its output is a sparse vector over real words. The model decides which words matter and can also add related words that are not in the text. For a page about medical leave, it might give weight not only to "medical" and "leave" but also to "sick" and "absence", even though those words never appear on the page.

SPLADE is a well-known model of this kind. BGE-M3 can produce learned sparse weights alongside its dense embedding, from the same model in one pass. Learned sparse vectors keep the advantages of keywords (exact matching, readable slots, fast inverted indexes) while recovering some of the meaning-matching that plain BM25 lacks.

BM25 weights for the leave pagemedical: 2.1leave: 1.9certificate: 1.4dean: 1.2Learned sparse weights (illustrative)medical: 2.3 · leave: 2.0sick: 1.1 (added)absence: 0.9 (added)certificate: 1.2

A learned sparse model can add related words like “sick” that never appear on the page, so a query using them still matches.

Why the best systems use both

Because sparse and dense retrieval fail in different places, combining them usually beats either one alone. A hybrid system runs both searches and merges the two result lists, so a query with an exact course code is rescued by keywords and a paraphrased question is rescued by embeddings. Large search platforms such as Elasticsearch, OpenSearch and Azure AI Search support this directly.

The cost is running two searches and deciding how to combine their scores, which are on completely different scales. That is a solvable problem, and for most real collections the improvement is well worth it. When you start a new retrieval project, a reasonable default is to measure BM25 alone, dense alone and the combination on your own test questions, and let the numbers decide.

Follow your curiosity.

↑ ↓ to explore · Enter to open · Escape to close