Sparse versus Dense Retrieval
Retrieval is the family of techniques that rank documents by their relevance to a query, and it is not unique to RAG; it also powers search engines, recommender systems, and log analytics.
A Hidden Decision Behind Every Result List
Suppose you type a few words into a search box and get back a list of results. Somewhere behind that list is a decision the system had to make for every item it could show you: how well does this item match what I asked for? Retrieval is the name for the family of techniques that make that decision and act on it. This article introduces the idea, shows where it sits in the larger picture, and sets up the two mechanisms that the rest of this chapter builds on.
Before reading on, pause and ask yourself a simple question: if a system had to order three documents for one query, what would it need to know about each document? Keep your answer in mind. The rest of the article shows how the answer fits into a single repeating operation.
Retrieval as Ranking by Relevance
Retrieval is the family of techniques that rank documents by their relevance to a query. It is not unique to RAG; it also powers search engines, recommender systems, and log analytics.
At its core, retrieval works by ranking documents based on their relevance to a given query. The important word is ranking. Retrieval does not simply hand back a yes or no for each document. It orders the documents so that the most relevant ones come first. Every retrieval method has to answer the same underlying question, which is how relevant each document is to the query, and then sort on the answer.
Read the diagram from the top. The query and the document collection both feed into the step that computes a relevance score for each document, and the scores determine the final order. The part that changes from one retrieval method to another is the middle step, where the score is computed. Everything before and after that step is shared across methods, which is why the scoring step is the place to look when you want to understand how two retrieval methods differ.
Why Retrieval Is Not Only About RAG
It is easy to associate retrieval with retrieval-augmented generation (RAG), because RAG pipelines depend on fetching relevant material before a language model writes its answer. But retrieval is not unique to RAG. Information retrieval is an old idea, and it already forms the backbone of search engines, recommender systems, and log analytics. These systems existed long before RAG did.
A search engine that returns a ranked list of pages for a typed query, a recommender that orders items for a user, and a log analytics tool that surfaces the most relevant log entries for a question all rely on the same basic idea of ranking items by relevance. A RAG pipeline is one more consumer of ranked results: it takes the top-ranked material and passes it to a language model.
The practical consequence is useful to remember. Many retrieval algorithms were developed for traditional retrieval systems, and those same algorithms can also be reused inside RAG. When you meet a retrieval method in a RAG setting, it may have a long history in search and recommendation work behind it.
Retrieval Versus Search
Two words appear constantly in this area, and they are not quite the same. Retrieval is typically limited to one database or system. Search involves retrieval across various systems. The difference is one of scope: retrieval describes finding relevant items within a single source, while search describes the wider act of looking across several sources.
Two Starting Mechanisms
The source introduces two common retrieval mechanisms as a starting point. Each one is a different answer to the scoring question raised earlier: how well does this document match the query? The two are described below, and the comparison that follows lines them up side by side.
Same Goal, Different Scoring Methods
The comparison points to the central lesson of this section. The goal stays fixed while the scoring method varies. Term-based and embedding-based retrieval are two answers to one question, and the next section of the chapter takes up a broader way of grouping such methods, known as sparse versus dense retrieval. Notice that both methods start from the same query and the same documents. They diverge only at the scoring step, and the final sorted list is produced the same way for both.
Ranking Three Documents for One Query
A query arrives and the system holds three candidate documents, A, B, and C. A scoring method assigns each document a relevance score (the numbers below are illustrative, not from a real system). Produce the ranked result list.
- 1Identify the shared inputs
The query and the three documents are the same no matter which retrieval method is used. Only the scoring step is method-specific.
- 2Compute a score for each document
Suppose the scoring step gives A a score of 0.42, B a score of 0.87, and C a score of 0.15. A higher score means the document is judged more relevant to the query.
- 3Sort by score
Retrieval orders the documents rather than marking each as yes or no. Sorting from highest to lowest gives B, then A, then C.
- 4Consider a different method
If a different scoring method were used on the same query and documents, it could produce different numbers and therefore a different order, even though the sorting step is identical.
The ranked list is B, A, C under this illustrative scoring method. The result depends entirely on the scoring step, which is where term-based and embedding-based methods differ.
Mistakes Learners Make About Retrieval
Common mistake Treating retrieval as something that only exists inside RAG systems.
Why it failsRetrieval is a family of techniques that also powers search engines, recommender systems, and log analytics. These systems existed before RAG did.
Do this insteadThink of RAG as one consumer of ranked results, alongside other applications that share the same retrieval core.
Common mistake Thinking retrieval returns a yes or no for each document.
Why it failsRetrieval ranks documents so that the most relevant come first. It does not simply classify each one.
Do this insteadLook for the ordering of results, and remember that the score is what determines that order.
Common mistake Assuming retrieval and search mean different things inside this chapter.
Why it failsRetrieval is typically limited to one database or system, while search spans several. This chapter, however, uses the two terms interchangeably.
Do this insteadWhen the chapter says retrieval or search, read both as the same activity of finding and ranking relevant documents.
Common mistake Believing that two retrieval methods must produce the same order for the same query.
Why it failsRetrieval algorithms differ in how they compute relevance scores, so the same query and documents can yield different scores and different rankings.
Do this insteadCompare methods at the scoring step, since that is where they diverge.
Checking Your Understanding
A team builds a search feature for product manuals and later adds a RAG assistant that reads the same manuals. A colleague says the RAG assistant needs a completely different retrieval core. Using what you have learned, explain whether that claim is accurate, and identify which step of the pipeline would be the most likely place for the two systems to differ.
Hints
- Ask whether RAG is the only application that depends on ranked retrieval.
- Think about which step of the query-to-results pipeline is method-specific.
What do you think happens?
If two methods receive the same query and the same three documents, what must they share, and what may they disagree on?
Reveal answer
They share the query, the documents, and the sorting of results by score. They may disagree on the relevance scores themselves, which means they may disagree on the final order.
Retrieval algorithms differ in how they compute relevance scores. The goal of ranking by relevance stays fixed, while the scoring step varies.
Key Takeaways from Retrieval
- 1Retrieval is the family of techniques that rank documents by their relevance to a query.
- 2Retrieval is not limited to RAG; it also powers search engines, recommender systems, and log analytics.
- 3Retrieval and search are used interchangeably in this chapter, both describing the act of finding and ranking relevant documents.
- 4Term-based and embedding-based retrieval are two starting mechanisms, and they differ mainly in how they compute relevance scores.
- 5Sparse versus dense retrieval is the broader comparison the next section introduces, building on these scoring differences.
At a glance
- Retrieval ranks documents by their relevance to a query rather than returning a yes or no for each one.
- Retrieval is not unique to RAG and also powers search engines, recommender systems, and log analytics.
- Term-based and embedding-based retrieval are two starting mechanisms that answer the same scoring question in different ways.
- Retrieval algorithms differ in how they compute relevance scores, and the sorting of results is shared across methods.
- Sparse versus dense retrieval is the broader comparison introduced next in the chapter.