Concepts / Embedding-Based Retrieval

Embedding-Based Retrieval

Retrieval is about order, not just membership. Two methods can both find the same set of documents and still produce different results, because they rank those documents differently.

  • Programming

The Decision Behind Every Search Result

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. Keep the search box in mind as you read, because almost every idea here can be traced back to what happens when a query goes in and an ordered list comes out.

What Retrieval Means

Definition

Retrieval is the family of techniques that rank documents by their relevance to a query. It powers search engines, recommender systems, and log analytics, and it is not unique to RAG.

The important word in that definition 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 the documents on that answer.

Key point

Retrieval is about order, not just membership. Two methods can both find the same set of documents and still produce different results, because they rank those documents differently.

Tracing a Query Through Retrieval

Follow one query through the operation to see where each piece fits. The query and the document collection both feed into the step that computes a relevance score for each document. The scores then determine the final order of the list you see.

Querywhat the user typedCompute relevancescoreone score per document, thestep that varies by methodSort by scoremost relevant firstRanked listthe results shownDocument collectionitems that could be shownfeedsfeedsscoresorders
What steps turn a query into an ordered list of documents, and where does the relevance score get applied?

Notice which part of this pipeline changes from one retrieval method to another. The input and the final sorting are shared. The middle step, where the relevance score is computed, is the only part that differs. This is the first clue to the chapter's central lesson: the goal stays fixed while the scoring method varies.

Retrieval Beyond 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.

Retrieval coreranks documents byrelevance to a querySearch enginesRecommender systemsLog analyticsRAG pipelinesfetch material before themodel writespowerspowerspowersreused in
Which systems use the same retrieval core, and how does RAG fit alongside search engines, recommenders, and log analytics?

The practical consequence is worth remembering. 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.

Two Starting Mechanisms

The chapter introduces two common retrieval mechanisms as a starting point: term-based retrieval and embedding-based retrieval. Each one is a different answer to the scoring question raised earlier. Term-based retrieval answers it using the terms that appear in the query and the documents. Embedding-based retrieval answers it using a learned representation of the query and of each document, so that relevance is judged by how closely those representations match. This article stays at the level the chapter introduces; the mechanics are developed in later sections.

Goalrank documents by relevanceTerm-basedscores from query anddocument termsTerm-based outputsorted ranked listEmbedding-basedscores from learnedrepresentationsEmbedding-basedoutputsorted ranked listanswered byanswered bysortedsorted
How do term-based and embedding-based methods each decide that a document matches a query, and how do their scoring steps differ?

The comparison points to the central lesson of this section. Term-based and embedding-based retrieval are two answers to one question. Both produce a ranked list, and the difference lies entirely in how each computes the relevance score that the ranking depends on. The next part of the chapter takes up a broader way of grouping such methods, known as sparse versus dense retrieval.

Predict Before You Look

Before reading the answer, decide what a retrieval system actually hands back for each document it considers.

What do you think happens?

When a retrieval system considers a set of documents for a query, what does it return for them?

  • A yes or no for each document

  • An ordering of the documents from most to least relevant

  • A single document that is the answer

Reveal answer
Answer:

An ordering of the documents from most to least relevant

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, which is why ranking is the key word in the definition.

Mistakes Learners Make with Retrieval

  • Common mistake

    Treating retrieval as something that only exists inside RAG

    Why it fails

    Retrieval predates RAG and already forms the backbone of search engines, recommender systems, and log analytics.

    Do this instead

    Think of RAG as one place where a retrieval method is reused, alongside the other systems that use the same core.

  • Common mistake

    Assuming retrieval returns a yes or no for each document

    Why it fails

    The defining feature of retrieval is ranking, so the output is an ordered list rather than a set of accepted and rejected items.

    Do this instead

    Look for the ordering step. The most relevant documents come first.

  • Common mistake

    Believing every retrieval method computes relevance the same way

    Why it fails

    Methods share the goal of ranking by relevance but differ in how they compute the relevance score.

    Do this instead

    When comparing methods, focus on the scoring step, since that is where they differ.

  • Common mistake

    Treating retrieval and search as strictly different activities in this chapter

    Why it fails

    Strictly, retrieval is limited to one source while search spans several, but this chapter uses the two terms interchangeably.

    Do this instead

    Read both words as the same activity of finding and ranking relevant documents when they appear in the chapter.

Practice: Tracing a Retrieval Step

EASY

A retrieval system receives a query and a collection of five documents. Describe, in order, the steps that turn the query into the list the user sees. Then identify which single step would change if you swapped term-based retrieval for embedding-based retrieval, and explain why the final sorting step would stay the same.

Hints
  • Start with the two inputs, the query and the document collection.
  • Ask which step computes a relevance score for each document.
  • Think about what the sorting step needs in order to do its job.

Key Takeaways

  • Retrieval is the family of techniques that rank documents by their relevance to a query, and it powers search engines, recommender systems, and log analytics as well as RAG.
  • The defining output of retrieval is an ordering of documents, not a yes or no for each one.
  • Retrieval algorithms share the ranking goal but differ in how they compute relevance scores.
  • Term-based and embedding-based retrieval are two starting mechanisms, each answering the scoring question in a different way.
  • In this chapter, retrieval and search are used interchangeably to mean finding and ranking relevant documents.

Related concepts

More concepts starting with E