§7.6The Whole Pipeline, Beyond Extractive QA & Conclusion

Part II NLPT pp. 69–74 · ~4 min read

  • generative qa
  • retrieval-augmented generation
  • extractive qa
  • dense passage retrieval

Evaluating the whole pipeline

We measured retriever and reader separately; now chain them. Fixing the retriever at k = 10, the reader receives multiple contexts per query (unlike the clean SQuAD-style single-context setup), so end-to-end EM/F1 drop:

0.000.250.500.360.47Reader (SQuAD-style)0.270.38Whole QA pipeline (top-1)EMF1
Figure 7-12 (recreated, illustrative). The retriever’s multiple contexts degrade end-to-end scores versus the SQuAD-style reader evaluation. Raising top_k_reader recovers some of the gap.

Going beyond extractive QA

So far the answer is always a literal span. But sometimes the answer is scattered across passages and needs synthesizing. Generative (abstractive) QA generates the answer instead of extracting it. The state of the art is retrieval-augmented generation (RAG): keep the retriever, but swap the extractive reader for a generator — a seq2seq transformer (T5 or BART) — fed by DPR .

Click a stage to see what it does. Data flows left → right; each stage transforms its input for the next.

Figure 7-13 (recreated). Retrieval-augmented generation — the reader is replaced by a generator.

Because DPR and the generator are both differentiable, the whole thing fine-tunes end-to-end (the context encoder stays frozen). There are two variants:

Two RAG variants. RAG-Token usually performs better.
How it generates
RAG-SequenceOne retrieved document for the whole answer
RAG-TokenA different document per generated token
Dotted-underlined cells have explanations — click one.
from haystack.generator.transformers import RAGenerator
from haystack.pipeline import GenerativeQAPipeline

generator = RAGenerator(model_name_or_path="facebook/rag-token-nq",
                        embed_title=False, num_beams=5)
pipe = GenerativeQAPipeline(generator=generator, retriever=dpr_retriever)
# "What is the main drawback?" -> "the price" / "no flash support" / "the cost"

RAG produces sensible, phrased answers (“the price”, “no flash support”), though subjective questions can still confuse it.

Conclusion

We built an end-to-end QA system: an extractive retriever-reader pipeline over customer reviews, compared BM25 vs DPR retrievers, boosted the reader with domain adaptation, measured everything with recall / EM / F1, and previewed generative QA with RAG.

A useful way to prioritize QA work is the hierarchy of needs — nail search first, add extraction next, and reach for generation only once the other two are exhausted:

GenerativeExtractive QASearch / Retrievalreach for lastnail first
Figure 7-14 (recreated). The QA hierarchy of needs.

The reader is useful beyond on-demand queries too — teams have used it to auto-extract product pros/cons and even do zero-shot NER via questions like “What kind of camera?”. Looking ahead, exciting frontiers include multimodal QA (over text, tables, and images — see §11.3) and QA over knowledge graphs.

That completes our tour of question answering. Next, we turn to where transformers are headed: scaling, efficiency, and new modalities.

Check yourself: whole pipeline, RAG & wrap-up

1.Why do end-to-end EM/F1 scores drop compared to the SQuAD-style reader evaluation?

2.How does generative (abstractive) QA differ from extractive QA?

3.What does RAG change about the classic retriever-reader architecture?

4.What distinguishes RAG-Token from RAG-Sequence?

5.According to the QA 'hierarchy of needs', in what order should you tackle QA?

5 questions