Advanced level · Module 9: Text Summarization and Question Answering · Lesson 3 of 3
A Retrieve-then-Read Document QA Pipeline
Learners combine BM25 retrieval from the Intermediate level with the extractive reader to answer questions over a folder of documents, citing the source passage for every answer.
In this lesson you will
- Build a retrieve-then-read QA pipeline
- Evaluate retrieval and reading separately
Key concepts
passage chunkingBM25 retrievalreadersource citationretrieval recall@k
The lesson
Documents are too long for a reader model, so split them into passages of a few sentences. For each question, BM25 retrieves the top passages, the extractive reader finds candidate answers in each and the best-scoring answer is returned with its document and passage.
Evaluate the two stages separately. Retrieval recall@5 asks whether the passage containing the answer is in the top five. Reader exact match asks whether the answer is found when the right passage is given. Most failures come from retrieval.
Always show the source passage with the answer, so the user can check it. This differs from generative assistants built with retrieval-augmented generation, which are covered in the AI programme. An extractive pipeline only returns text that exists in the documents.
Step by step
- Chunk the document folder into passages.
- Connect BM25 retrieval to the QA reader.
- Evaluate recall@5 and end-to-end exact match on the question set.
- Display answers with their source document and passage.
Answering questions over a folder of public documents
A retrieve-then-read pipeline that answers only from the documents and shows the source passage for every answer.
Prepare documents
Public reports and notices are converted to text, cleaned and split into passages of three to five sentences, each recorded with its document title and page.
data officer
Index passages
A BM25 index is built over all passages; it is rebuilt whenever documents are added.
system
Retrieve
For each question, BM25 returns the five most relevant passages.
system
Read
An extractive QA model finds the best answer span in each passage and gives a score.
system
Answer or decline
If the best score is above the threshold, the answer is shown with its source passage; otherwise the reply is 'not found in these documents'.
system
Check and improve
Staff review a weekly sample of questions, answers and declines, and record wrong answers for the evaluation set.
document owner
Wrong answers and unanswered questions are added to the test set; retrieval and the score threshold are re-evaluated before any change goes live.
Why it works
Extractive QA can only return text that exists in the documents, but it can still pick the wrong passage, so every answer shows its source. Personal or confidential documents are not included. Generative assistants that compose answers are covered in the AI programme.
Practice activity
Build and evaluate a document QA pipeline over public institutional documents.
Expected result: A working pipeline with stage-wise evaluation and answers that always cite their source.
Check your understanding
-
Why evaluate retrieval separately from reading?
Show answer
To know whether failures come from finding the passage or from extracting the answer.
-
Why show the source passage with each answer?
Show answer
So that users can check the answer themselves.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.