Search

Search papers and lessons

Open-Domain Question Answering

Level 3 · 12 min read

Open-domain question answering finds the answer to a question anywhere in a large collection of text by first retrieving a few relevant passages and then reading them to extract the answer.

On this page

  • Colour = topic mix
  • Discrete math
  • Neural network basics
  • Calculus
  • Probability
  • Linear algebra
  • Algorithms
  • ReadReady to readNot yet

TL;DR

Open-domain question answering is the task of answering a natural-language question when the answer lives somewhere in a very large collection of text, such as all of Wikipedia, and the system is not told which document to use. It works in two stages. A retriever searches the collection and returns a short list of passages that are likely to contain the answer, and a reader looks at those passages and picks out the answer span. Retrieval has to be fast enough to search millions of passages, and reading has to be accurate enough to ignore the passages that only look relevant.

Builds on: Inverted Index, Bi-Encoder · Leads to: Retrieval-Augmented Generation, dense passage retrieval

Where it's used

Search engines answering questions directly. When a search box shows a short answer above the links, a retriever has found the page and a reader has pulled out the sentence that answers the question. The same two-stage design sits behind many "answer box" features.

Research benchmarks on Wikipedia. The 2017 DrQA system answered questions from about five million Wikipedia articles, using a keyword-based retriever and a neural reader. Later benchmarks such as Natural Questions and TriviaQA use the same setup, and they are the standard tests for new retrievers.

Grounding chatbots in documents. A company's help desk or a legal team can index its own documents and ask the system questions. Retrieved passages can be shown next to the answer, so a person can check where it came from. Retrieval-augmented generation is the modern form of this idea, where a language model writes the answer from the retrieved text.

How it works

We trace one tiny corpus of three short documents. Each document is a passage:

  • D1: "Paris is the capital of France."
  • D2: "The Seine flows through Paris."
  • D3: "Berlin is the capital of Germany."

The question is "capital of France".

  1. Index the passages. Lowercase the words and record which passages contain each word. The Inverted Index for the three passages is:

    • capital: D1, D3
    • france: D1
    • of: D1, D3
    • paris: D1, D2

    Check: a word that appears in no passage has no entry, so a search for it returns nothing.

  2. Retrieve by word overlap. For the query, count how many of its words each passage contains. D1 contains capital, of and france, so its count is 3. D3 contains capital and of, so its count is 2. D2 contains none, so its count is 0. Check: the index lets us visit only the passages that appear in some query word's list, here D1 and D3.

  3. Keep the top passages. Keep the kk best-scoring passages. With k=2k = 2 we keep D1 and D3. Check: a larger kk gives the reader more chances to find the answer, but it also gives the reader more distractors.

  4. Read the passages. The reader looks at each passage and scores every possible answer span. In D1 the span "Paris" fits the question, because it is the capital of France. In D3 the best span is "Berlin", which is the capital of Germany and does not match France. Check: the reader must notice the word France in the question and prefer the span that answers about France.

  5. Pick the answer. Compare the best span scores across passages and return the highest. Here it is "Paris" from D1. Check: the answer comes with its passage, so a person can verify it.

A bi-encoder can replace step 2 with vector search. It embeds the query and each passage as vectors ahead of time, then scores passages by a dot product. That finds passages with matching meaning even when the words differ, such as "French capital" for "capital of France".

flowchart LR
  Q[Question] --> R[Retriever: find top k passages]
  C[(Collection of passages)] --> R
  R --> P[k passages]
  P --> RD[Reader: extract answer span]
  Q --> RD
  RD --> A[Answer with its passage]

The math

Definition: Open-domain question answering

Given a question qq and a collection of passages D={d1,…,dN}\mathcal{D} = \{d_1, \dots, d_N\}, find a span aa inside some passage in D\mathcal{D} that answers qq. The system is not given the passage in advance, so it must search D\mathcal{D} first.

Step 2 in symbols: scoring passages

A retriever assigns each passage a score s(q,d)s(q, d). In the word-overlap version, with W(q)W(q) the set of query words and W(d)W(d) the set of words in passage dd,

s(q,d)=∣ W(q)∩W(d) ∣.s(q, d) = \big|\, W(q) \cap W(d) \,\big|.

The vertical bars mean the size of the set, so this is the number of shared words. In the example W(q)={capital,of,france}W(q) = \{\text{capital}, \text{of}, \text{france}\}, s(q,D1)=3s(q, D1) = 3 and s(q,D3)=2s(q, D3) = 2.

In the bi-encoder version, the score is the dot product of two embeddings,

s(q,d)=u⊤v,u=fq(q),v=fd(d),s(q, d) = \mathbf{u}^\top \mathbf{v}, \qquad \mathbf{u} = f_q(q), \quad \mathbf{v} = f_d(d),

where fqf_q and fdf_d are the query and passage encoders from the Bi-Encoder. Because v\mathbf{v} depends only on dd, it is computed once for the whole collection.

Step 3 in symbols: the top-kk set

The retriever returns

Tk(q)=the k passages d∈D with the largest s(q,d).\mathcal{T}_k(q) = \text{the } k \text{ passages } d \in \mathcal{D} \text{ with the largest } s(q, d).

When D\mathcal{D} has millions of passages, finding these exactly is slow, so systems use approximate search over the vectors, which skips most passages and accepts a small chance of missing a good one.

Step 4 in symbols: scoring answer spans

A passage of nn words has a start score SiS_i and an end score EjE_j for each word position ii and jj, produced by the reader's network. A span from ii to jj with i≤ji \le j scores

score(i,j)=Si+Ej.\text{score}(i, j) = S_i + E_j.

The reader considers only spans with j≥ij \ge i, because an answer cannot end before it starts.

Step 5 in symbols: choosing the answer

Over all retrieved passages and all valid spans, the answer is

a^=arg⁡max⁡d∈Tk(q)  max⁡i≤j  [ s(q,d)+scored(i,j) ].\hat{a} = \arg\max_{d \in \mathcal{T}_k(q)}\;\max_{i \le j}\; \bigl[\, s(q, d) + \text{score}_d(i, j) \,\bigr].

Here arg⁡max⁡\arg\max means the argument that gives the largest value, and s(q,d)s(q, d) is the retrieval score of passage dd. The walkthrough compared reader scores alone and so left s(q,d)s(q, d) out. Example 3 adds it, as many systems do, so the passage's relevance counts as well as the span's fit. This is a maximum over a finite set, so no optimisation is needed at answer time.

Worked examples

Example
Example 1: the word-overlap retriever by hand

Corpus: D1 = "Paris is the capital of France." D2 = "The Seine flows through Paris." D3 = "Berlin is the capital of Germany." Query: "capital of France". Score each passage and pick the top one.

  1. Query words: W(q)={capital,of,france}W(q) = \{\text{capital}, \text{of}, \text{france}\}.
  2. D1 words include capital, of and france. Shared count: 33.
  3. D2 words are the, seine, flows, through, paris. Shared count: 00.
  4. D3 words include capital and of, but not france. Shared count: 22.
  5. Ranking: D1 with 33, then D3 with 22, then D2 with 00.
  6. Interpretation: the top passage is D1, and the reader will find "Paris" there. D2 is never useful for this query, and the index let us skip it entirely.
Example
Example 2: the bi-encoder retriever with toy vectors

Suppose the query encoder gives u=(0.9,0.1)\mathbf{u} = (0.9, 0.1) and the passage encoder, applied in advance, gives v1=(0.8,0.2)\mathbf{v}_1 = (0.8, 0.2) for D1, v2=(0.3,0.9)\mathbf{v}_2 = (0.3, 0.9) for D2 and v3=(0.1,0.9)\mathbf{v}_3 = (0.1, 0.9) for D3. Find the scores and the top passage.

  1. Score D1: 0.9×0.8+0.1×0.2=0.72+0.02=0.740.9 \times 0.8 + 0.1 \times 0.2 = 0.72 + 0.02 = 0.74.
  2. Score D2: 0.9×0.3+0.1×0.9=0.27+0.09=0.360.9 \times 0.3 + 0.1 \times 0.9 = 0.27 + 0.09 = 0.36.
  3. Score D3: 0.9×0.1+0.1×0.9=0.09+0.09=0.180.9 \times 0.1 + 0.1 \times 0.9 = 0.09 + 0.09 = 0.18.
  4. Ranking: D1 at 0.740.74, D2 at 0.360.36, D3 at 0.180.18.
  5. Interpretation: the top passage is D1, the same as the word-overlap version. The vectors are fixed for the whole collection, so only the query needs encoding at search time.
Example
Example 3: a two-stage run with the reader's scores

A retriever returns the top three passages for the question "Who wrote Nineteen Eighty-Four?". Their retrieval scores are 12.412.4, 11.911.9 and 7.27.2. The reader gives the best span in each passage a score, and the answer is the span with the highest reader score after adding the retrieval score in its passage.

  1. Passage A, retrieval score 12.412.4, best span "George Orwell" with reader score 2.12.1. Combined: 12.4+2.1=14.512.4 + 2.1 = 14.5.
  2. Passage B, retrieval score 11.911.9, best span "Orwell's essays" with reader score 0.80.8. Combined: 11.9+0.8=12.711.9 + 0.8 = 12.7.
  3. Passage C, retrieval score 7.27.2, best span "1949" with reader score 1.51.5. Combined: 7.2+1.5=8.77.2 + 1.5 = 8.7.
  4. The highest combined score is 14.514.5, from passage A. The answer is "George Orwell".
  5. Interpretation: passage C contains a true fact, the year of the book, but it answers a different question, so the reader score is lower. Passage B mentions the author but not the answer span, so its best span scores lower. Combining the two scores lets the system prefer the passage that is both relevant and answers the question.

Try it: suppose passage B's reader score rose to 3.53.5 and nothing else changed. Which span becomes the answer, and why might this be a mistake?

Answer: 11.9+3.5=15.411.9 + 3.5 = 15.4, which beats 14.514.5, so "Orwell's essays" becomes the answer. It is a mistake because the span is not the author's name, so a higher reader score on a wrong span means the reader is answering a different question. This is why spans should be judged against the question, not only by how confident the reader is.

Common mistakes and tradeoffs

It is tempting to think that open-domain question answering is just keyword search. In fact the retriever only narrows the search. A passage can contain every query word and still not answer the question, so the reader has to check meaning, not word counts.

It is tempting to think that retrieving more passages always helps. In fact a larger kk raises the chance that the answer is in the set, but it also adds distractors and makes reading slower. The best kk is found by measuring answer accuracy on held-out questions.

It is tempting to think that a language model answers these questions without retrieval. In fact a model can answer from what it memorised during training, which is called closed-book answering. That method cannot be checked against a source, and it cannot use documents added after training. Open-domain systems keep the evidence visible.

When to use it: when the answer exists in a large text collection, the collection changes or is too large to memorise, and you need to show where the answer came from.

When not to use it: when the answer needs reasoning over many documents, or when the collection is small enough to read in full. Then a single long-context reader or a summary may be simpler.

Alternatives: word-overlap retrieval with TF-IDF is simple, cheap and strong on rare words, while dense retrieval captures meaning. A Cross-Encoder can rerank the short list with a more careful comparison, at a higher cost per passage.

History

Early question-answering systems in the 1960s and 1970s worked on small, hand-built databases, and their answers were limited to the stored facts. Retrieval-based systems for large text collections came out of information retrieval, where keyword indexes had been the standard tool for decades.

In 2017 the DrQA system combined a TF-IDF retriever with a neural reader and answered questions from Wikipedia, which made the two-stage design the standard approach. In 2020 Karpukhin and colleagues showed that a dense bi-encoder retriever, trained on question and passage pairs, could beat the word-overlap retriever on open-domain benchmarks, which made dense retrieval the default for new systems. The approach caught on because the retrieved passages give a checkable answer, which mattered as language models began to produce fluent but unsupported text.

Recap

  • An open-domain question has its answer somewhere in a large collection, and the system does not know where.
  • A retriever scores passages, using word overlap or embeddings with a dot product, and keeps the top kk.
  • A reader scores answer spans in those passages with start and end scores, and the best span across passages is the answer.
  • The two stages trade speed against accuracy: the retriever must be fast over millions of passages, and the reader must be accurate on a few.
  • Read next: Retrieval-Augmented Generation, where a language model writes the answer from the retrieved passages, and the dense passage retrieval paper for the dense retriever in practice.

Check yourself

QuestionRecall: what are the two stages of an open-domain question answering system, and what does each one return?Show answer

The retriever searches the whole collection and returns a short list of likely passages. The reader looks at those passages and returns the answer span, usually with the passage it came from.

QuestionComputation: a query has the words {river,bank,flood}\{\text{river}, \text{bank}, \text{flood}\}. Passage P has the words {bank,flood,warning}\{\text{bank}, \text{flood}, \text{warning}\} and passage Q has {river,boat}\{\text{river}, \text{boat}\}. Using word overlap, which passage scores higher and by how much?Show answer

P shares bank\text{bank} and flood\text{flood}, so its score is 22. Q shares river\text{river}, so its score is 11. P scores higher, by 2−1=12 - 1 = 1.

QuestionWhy: why does a bi-encoder allow the passage vectors to be computed once, before any question arrives?Show answer

The score is the dot product of the query vector and the passage vector, and the passage vector depends only on the passage. Nothing inside the encoders couples the query and the passage, so every passage can be encoded in advance and stored, and only the query needs encoding at search time.

QuestionApplied: a support team finds that the system returns the right passage most of the time, but often shows a wrong span from it. They can change either the retriever or the reader. Which should they look at first, and why?Show answer

They should look at the reader, because the right passage is already being found. The error is in choosing the span, so the reader's scoring of spans, such as its start and end scores on a validation set of questions, is the place to start. Changing the retriever would not fix a wrong span inside a passage that was already correct.

Sources

  • Karpukhin et al. (2020), Dense Passage Retrieval for Open-Domain Question Answering: arXiv:2004.04906
  • Chen, Fisch, Weston, Bordes (2017), Reading Wikipedia to Answer Open-Domain Questions: arXiv:1704.00051
  • Question answering: Wikipedia