AI State of the Art
SOTA/Retrieval Augmented Generation (RAG)/28 min
Section 139

Advanced RAG: HyDE, Self-querying, Correction

Listen as a podcast →

Beyond Basic RAG

A reminder of the arrangement, set out in full in RAG: principle and architecture. RAG stands for retrieval-augmented generation. The principle has two steps: first you search a store for relevant documents, then you hand them to the language model (the large language model, almost always shortened to LLM) so that it writes its answer leaning on them.

Two steps, therefore two distinct ways to fail. Either the search did not bring back the right document, in which case no amount of good writing can rescue the answer. Or the search did its job and it is the writing that betrays the texts supplied. This page is almost entirely about the first problem.

Every technique below acts on one point only: what goes into the search engine, or what is done with what comes out. None of them makes the model a better writer.

Two pipelines compared. On the left, Naive RAG: the query and document indexing feed straight into a retrieval step, then an augmentation and generation step, then the response. On the right, Advanced RAG: the same chain but with a Pre-Retrieval stage wrapping indexing and the query, then Retrieval, then an extra Post-Retrieval stage before augmentation and generation.
Advanced RAG is not a different chain, it is the same chain with two added intervention points. Upstream you rework the question and the index: that is where HyDE, multiple rephrasing and stepping back live. Downstream you re-sort and recompose the passages before handing them to the model.Source : Leonie Monigatti, Advanced Retrieval-Augmented Generation (after the taxonomy of Gao et al.)
When to Move to Advanced RAG

Measure first, and measure the two steps separately. That is the subject of Evaluating a RAG system, and the measures of ranking quality (recall@K, MRR, NDCG) are defined in Measuring a ranking.

The decision rule is simple, though no universal threshold exists: if your retrieval numbers are good and the answer still disappoints, the problem lies in the writing and nothing on this page will help. If the relevant documents never reach the model, then and only then are the techniques below worth the trouble.

HyDE: Searching With a Fake Document

HyDE stands for hypothetical document embeddings.

Precise Zero-Shot Dense Retrieval without Relevance Labels (Gao et al., 2022)

The Problem

Your question is: "How does photosynthesis work?" Short, interrogative, written from the point of view of someone who does not know. The document holding the answer says: "Photosynthesis is a biochemical process by which plants convert..."

But dense retrieval (the kind that compares vectors rather than words, see Dense, sparse and hybrid retrieval) rests on textual resemblance. And a question does not resemble an answer: not in length, not in phrasing, not in vocabulary. You are looking for a book by describing the gap it leaves on the shelf.

The Trick

Ask the model to write a fake document itself, one that would answer the question, then search for the documents that resemble that fake document rather than the question.

  1. Question: "How does photosynthesis work?"
  2. The model writes: "Photosynthesis is a biochemical process by which plants use light energy to..."
  3. Compute the vector representation of the written text, not of the question
  4. Search the store for documents close to that vector

The model acts as a translator between the language of questions and the language of documents. The fake document may contain errors without doing harm: it is never shown to the user, it only steers the search. The facts come from the real documents retrieved.

Diagram of how HyDE works. On the left, three instruction plus query pairs, for example write a passage to answer the question paired with how long does it take to remove a wisdom tooth. These pairs go into a GPT model that produces a generated document. That generated document, not the question, is sent to the Contriever dense retriever, which returns the real documents from the corpus on the right.
The key detail: what enters the search engine (here Contriever) is not the user's question but the document invented by the model, in orange. The real retrieved documents, in blue, are on the right.Source : HyDE paper, Gao et al. 2022 (figure 2), via Zilliz
Why This Can Work

It is counterintuitive: a fictional and possibly false document serves the search better than the real question. The reason is that dense retrieval measures closeness of form, not of truth. A false but well-turned text has the shape of an answer; the question does not.

The Gao et al. paper addresses one particular case, the one where you have no labelled examples of what counts as relevant for this corpus, that is what zero-shot means in its title. That is where the method earns its keep: when you do have labelled examples, you can simply train the retriever.

What HyDE Costs

  • One extra model call, before you even search. The time taken to write the fake document adds in full to the response time.
  • A dependence on what the model knows. If the subject is wholly foreign to it, the fake document will be off target and will steer the search the wrong way. That covers niche domains, a company's internal jargon, anything postdating the model's training.

Self-Querying: Separating Meaning From Constraint

A question often mixes two things of different natures: a subject, and conditions to be met. Self-querying means having the model produce a structured query from the user's sentence.

An Example

Question: "What are the 2024 financial reports on renewable energy?"

What the model produces:

  • Semantic part, sent to the search engine: "renewable energy financial performance"
  • Filter part, applied to the metadata: type = "financial report" AND year = 2024

What the model has grasped is that "2024" is not a theme but a condition, a 2023 document is not "somewhat" 2024, it is excluded. Searching for "2024" by resemblance of meaning would have no reliable effect; turning it into a filter gives an exact result.

Two conditions for this to work: your documents actually carry the metadata in question (a filled-in publication date, a document type), and the model knows the list of available fields, which you describe in its instructions.

Note what the model really does here: it does not "understand" the store, it produces text in a query format. That text is then executed by the database, which is exact.

Rephrasing the Question

Multiple Rephrasing

A single phrasing catches a single facet of the need. So you ask the model for several variants of the same question:

  1. "How does photosynthesis work?"
  2. "What is the biochemical mechanism of photosynthesis?"
  3. "How do plants convert light into energy?"

You run the search on each, then merge the lists obtained. The most common merging method is reciprocal rank fusion, shortened to RRF: each document earns, for every list it appears in, a score that is higher the better it is ranked there, and those scores are added up. A document found by every variant therefore rises mechanically above a document found by only one.

The point is to make retrieval less sensitive to how the question happens to be worded. The cost is direct: as many searches as variants, plus the model call that produces them. Expect response time to roughly double or triple depending on whether the searches run in parallel or one after another.

Stepping Back

For a very specific question, retrieval often fails because no document deals with precisely that case. The trick, called step-back prompting, is to have the question first rephrased into a more general one.

  • Question: "Boiling point of ethanol at 2000 m altitude?"
  • Step-back question: "How does atmospheric pressure affect boiling points?"

No document will give the first answer; many give the second. You thereby recover the general principle, which the model then applies to the particular case.

Take a Step Back: Evoking Reasoning via Abstraction in Large Language Models (Zheng et al., 2023)
Where to Start

If you try only one thing, try multiple rephrasing with RRF merging: it is little code, and it almost never makes results worse, since all you do is add candidates to the list before sorting. The other techniques on this page require a judgement about your corpus.

Decoupling Search From Reading

Search Small, Supply Wide

Splitting documents into pieces (the subject of Chunking strategies) poses a dilemma. A small piece is found precisely, because it talks about one thing only; but read on its own it is often unintelligible, lacking whatever came before it. A large piece carries its context, but its vector representation blends several subjects, which blurs the search.

The fix separates the two uses. You index small pieces, a sentence or two, so the search is precise. Then, once a piece is found, you give the model a widened window: the piece plus its neighbouring sentences. Search on the fine grain, read on the coarse one.

Climbing Back to the Parent Document

When several small pieces from the same document come back together, that is a clue: it is probably no coincidence, the whole document is on topic. You then replace those scattered pieces with the parent document, or with the section containing them, which spares the model a string of disjointed fragments.

Corrective RAG: Checking Before Using

Basic RAG makes a silent assumption: whatever the engine brought back is usable. CRAG, for corrective retrieval-augmented generation, lifts that assumption by inserting a judgement.

  1. Run the search normally.
  2. An evaluator grades each document brought back: relevant, doubtful, off topic.
  3. Relevant: use it.
  4. Doubtful: refine, split the document and keep only the passages that bear on the question.
  5. Off topic: do not use it. Rephrase the question, or go looking elsewhere, for instance on the web.

What this changes is not the quality of the search but the quality of the failure case: instead of answering confidently from bad documents, the system notices it has nothing good and goes looking another way.

Corrective Retrieval Augmented Generation (Yan et al., 2024)
Two panels. On the left, the problem: two questions go through a retriever, one brings back accurate documents and the generator answers correctly, the other brings back inaccurate documents and the generator answers wrongly. On the right, the CRAG mechanism: after retrieval, a retrieval evaluator labels the documents Correct, Ambiguous or Incorrect. Correct triggers knowledge refinement that decomposes, filters and recomposes the passages; Incorrect triggers a query rewrite and a web search; generation then uses internal knowledge, external knowledge, or both.
The left panel shows why CRAG exists: an engine that brings back the wrong document mechanically produces a wrong answer. The right panel shows the fix: an evaluator grades the documents as correct, ambiguous or incorrect, and each verdict triggers a different action, from simply filtering the passages to falling back on a web search.Source : Corrective RAG paper (figures 1 and 2), via Cobus Greyling
Self-RAG: The Evaluator Built Into the Model

In CRAG the evaluator is a separate piece bolted around the model. Self-RAG moves that judgement inside the model: it is trained to emit, as it writes, special markers signalling that it needs to look something up, or grading whether a retrieved passage is relevant and whether the sentence it has just written is properly supported by that passage.

The difference is one of location, not of nature: judgement added from outside, versus judgement learned and built in. The second route requires training the model specifically, which puts it out of reach of anyone who does not train their own models.

Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflection (Asai et al., 2023)

Adaptive RAG: Not Treating Every Question Alike

A factual question and a question requiring three sources to be cross-referenced do not need the same effort. The idea of Adaptive RAG is to add a router at the head of the chain that estimates how hard the question is and picks the strategy:

  • Simple question: one search, one passage, answer. Or even, if the answer is common knowledge, no search at all.
  • Intermediate question: one search, then reranking to sharpen the order, see Reranking.
  • Multi-hop question: break it into sub-questions and search several times, each answer feeding the next question.

The point is not only to save money: it is to avoid degrading the easy questions. A heavy arrangement applied to "what is the VAT rate in France" adds delay, expense and opportunities to go wrong, and contributes nothing.

The weak spot is obviously the router: it must estimate a question's difficulty before having searched, and therefore before knowing whether the store even holds the answer.

Adaptive-RAG: Learning to Adapt Retrieval-Augmented Large Language Models through Question Complexity (Jeong et al., 2024)

Good Practice

Complexity Always Costs; Improvement Does Not Always Come

Every technique on this page adds at least one model call, hence delay and expense, and one more place where the system can go wrong. A simple, well-tuned RAG (chunking suited to the documents, a good representation model, reranking) regularly beats a sophisticated RAG that is poorly calibrated.

None of these techniques is good in the abstract: each corrects one specific weakness. HyDE addresses the gap in form between question and document; self-querying addresses exact constraints; stepping back addresses questions that are too narrow. Applying HyDE to a date-filtering problem will achieve nothing.

The sequence to follow:

  1. Start simple: basic RAG, with careful chunking and a good representation model.
  2. Measure the two steps separately. On the retrieval side, the ranking measures of Measuring a ranking; on the writing side, faithfulness to the documents supplied and relevance of the answer, covered in Evaluating a RAG system.
  3. Work out which of the two steps is failing. It is the only way to avoid working for nothing.
  4. Add one technique, measure again, and keep it only if the gain is visible.
  5. Repeat. Every addition must justify what it costs.

There is no universally good configuration, because the right technique depends on your documents and your questions. Sophistication is no guarantee of quality; only measurement settles the matter.

Check your understanding0 / 5

1. Your retrieval numbers (recall@K, MRR) are good, yet your RAG system's final answers still disappoint. What should you do?

2. With HyDE, the fake document the model writes may contain factual errors. Why is that not a deal-breaker?

3. In the question about 2024 financial reports on renewable energy, how does self-querying handle the year 2024?

4. What does Corrective RAG (CRAG) actually change compared with basic RAG?

5. If you were to try only one technique from this page, which one does it recommend, and why?