Information Retrieval and Retrieval-Augmented Generation

Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 11

60 cards

Introduction

  1. What are factoid questions?
    Information needs that can be met with facts expressed in short texts, e.g. “Where is the Louvre Museum located?”.
  2. How can an instruction-tuned LLM answer factoid questions without retrieval, and where is that knowledge stored?
    By conditional generation from the question: it has seen the facts in pretraining. Such factual knowledge seems to be stored in the large feedforward layers of the transformer.
  3. What is a hallucination?
    A response that is not faithful to the facts of the world: the model makes up a reasonable-sounding answer. LLMs sometimes do this even when the correct facts are stored in their parameters, apparently when the feedforward layers fail to recall them.
  4. What does it mean for a system to be calibrated, and why does it matter for hallucination?
    Its confidence in an answer correlates highly with the probability that the answer is correct. A calibrated system could hedge when likely wrong; LLMs are poorly calibrated and often give wrong answers with complete certainty.
  5. What three problems arise from answering questions using only an LLM’s parameters?
    Hallucination (often wrong, hard to detect), no access to proprietary data (personal email, medical records, company documents), and static knowledge (no information after the model was trained).
  6. What is retrieval-augmented generation (RAG)?
    Using information retrieval to fetch documents likely to contain relevant information, then having an LLM generate an answer conditioned on those documents and the question.
  7. What are the benefits of grounding answers in retrieved documents?
    Answers are based on facts from a curated collection, can be shown together with their source passages (so users can check them), and retrieval works over any proprietary data.

11.1 Information retrieval

  1. What is ad hoc retrieval?
    A user poses a query to a retrieval system, which returns an ordered set of documents from some collection.
  2. Define document, collection, term and query in IR.
    A document is whatever unit of text is indexed and retrieved (web page, paper, passage). A collection is the set of documents used to satisfy requests (possibly the whole web). A term is a word (or phrase) in the collection. A query is a user’s information need expressed as a set of terms.
  3. What are the two classes of IR systems?
    Sparse retrieval, representing queries and documents as word-count vectors weighted by tf-idf or BM25, and dense retrieval, representing them as embeddings computed by language models.
  4. What is the vector space model of IR, and what is the bag-of-words assumption?
    A document is represented as a vector of counts of the words it contains (Salton, 1971). Bag of words: treat the document as an unordered set of words, ignoring positions and keeping only frequencies.
  5. What is a term-document matrix?
    A matrix with a row per vocabulary word and a column per document; each cell counts how often the word occurs in the document. Each document is a column vector.
  6. What does a term-document matrix reveal about similar documents?
    Similar documents have similar words, so their column vectors are similar: Shakespeare’s comedies have many fool and wit, few battle, unlike the histories.
  7. Why do IR systems use term weights instead of raw counts?
    Raw counts overweight frequent words and ignore how discriminative a word is; tf-idf and BM25 weight terms by frequency in the document and rarity across the collection.
  8. Define the term frequency used in tf-idf.
    Log-scaled count: \(\text{tf}_{t,d} = 1 + \log_{10}\text{count}(t, d)\) if the count is positive, else 0. A word occurring 100 times isn’t 100 times more relevant (tf goes 1, 2, 3, 4 for counts 1, 10, 100, 1000).
  9. Define document frequency and inverse document frequency.
    \(\text{df}_t\) is the number of documents containing term \(t\). \(\text{idf}_t = \log_{10}\frac{N}{\text{df}_t}\) for \(N\) documents: high for terms in few documents, 0 for terms in every document.
  10. Why is idf useful?
    Terms that occur in only a few documents discriminate those documents from the rest; terms that occur everywhere (good, sweet in Shakespeare) aren’t helpful.
  11. Define tf-idf.
    \(\text{tf-idf}(t, d) = \text{tf}_{t,d} \cdot \text{idf}_t\).
  12. How does the classic tf-idf model score a document against a query?
    By the cosine between their tf-idf vectors, \(\text{score}(q, d) = \frac{q \cdot d}{|q||d|}\), assuming documents with words similar to the query are more relevant. Only terms in both contribute to the dot product.
  13. For the query “sweet love”, why does “Sweet sweet nurse! Love?” outscore “Sweet sorrow”?
    The first document contains both query terms (sweet twice), while the second lacks love, which has the higher idf; its tf-idf cosine is much higher (≈ .75 vs ≈ .08).
  14. What is a common simplification of tf-idf cosine scoring?
    Dropping the idf term for the document (keeping it only for the query), which sometimes performs better.
  15. What is BM25?
    A tf-idf variant (Okapi BM25): \(\sum_{t \in q}\log\frac{N}{\text{df}_t}\cdot\frac{\text{tf}_{t,d}}{k\big(1 - b + b\frac{|d|}{|d_{avg}|}\big) + \text{tf}_{t,d}}\). Parameter \(k\) balances term frequency against idf; \(b\) controls document-length normalization.
  16. What do the BM25 parameters \(k\) and \(b\) do at their extremes?
    \(k = 0\): no term frequency, just binary presence (plus idf); large \(k\): raw term frequency. \(b = 1\): full scaling by document length; \(b = 0\): no length scaling. Typical: \(k\) in [1.2, 2], \(b = 0.75\).
  17. What is a stop list, and why is it less used now?
    A list of high-frequency (mostly function) words removed from queries and documents. It makes phrase search hard (“to be or not to be” → “not”), and idf already downweights such words, so modern IR rarely uses it.
  18. What is an inverted index?
    The data structure for finding documents containing query terms: a dictionary of terms (with document frequencies) each pointing to a postings list of document IDs, optionally with counts or positions.
    love  {2} → 1 [1] → 3 [1]
    nurse {2} → 1 [1] → 4 [1]
    sweet {3} → 1 [2] → 2 [1] → 3 [1]
    Format: term {document frequency} → doc id [count in doc] → …
  19. Summarize how a ranked retrieval system works.
    Indexing: build an inverted index over the collection. Retrieval: use it to find candidate documents containing query terms, score each by tf-idf or BM25 cosine with the query, sort by score, and return the top N.

11.2 Evaluating IR systems

  1. Define precision and recall for a set of retrieved documents.
    Precision = relevant returned / all returned (\(|R|/|T|\)). Recall = relevant returned / all relevant documents in the collection (\(|R|/|U|\)).
  2. Why aren’t plain precision and recall enough for ranked retrieval?
    They ignore order: we want metrics that prefer systems ranking relevant documents higher.
  3. Define precision and recall at rank \(k\).
    Precision\(_k\) = relevant documents in top \(k\) / \(k\); Recall\(_k\) = relevant documents in top \(k\) / total relevant documents.
  4. How do precision and recall behave as you go down a ranked list?
    Recall never decreases (it rises at each relevant document); precision jumps up at relevant documents and down otherwise. They are plotted as a precision-recall curve.
  5. What is interpolated precision, and why use it?
    Precision at recall level \(r\) is set to the maximum precision at any recall ≥ \(r\): \(\text{IntPrecision}(r) = \max_{i \ge r}\text{Precision}(i)\). It allows averaging over queries at 11 standard recall levels (0, .1, …, 1) and smooths the curve, giving systems the benefit of the doubt.
  6. What does the shape of a precision-recall curve tell you about a system?
    Higher precision at all recall levels is better; systems high on the left favor precision, those high on the right favor recall.
  7. What is average precision (AP), and mean average precision (MAP)?
    AP: average of the precision values measured at the ranks where relevant documents occur, \(\frac{1}{|R_r|}\sum_{d \in R_r}\text{Precision}_r(d)\). MAP: the mean of AP over a set of queries.
  8. Compute AP if relevant documents appear at ranks 1, 3 and 4 (and those are all the relevant ones).
    Precisions at those ranks: 1/1, 2/3, 3/4. AP = (1 + .667 + .75)/3 ≈ .81.

11.3 Dense retrieval

  1. What is the vocabulary mismatch problem?
    Sparse methods like tf-idf and BM25 only work when query and document share exact words, so the user must guess the words the answer’s writer used. Dense embeddings handle synonymy and solve this.
  2. How does a cross-encoder (full-interaction) model score a query–document pair?
    Feed both to one encoder, “query [SEP] document”, so self-attention sees all tokens of both, then a linear layer on the [CLS] output predicts a relevance score. Documents are usually split into passages (e.g. ~100-token chunks) to fit the window.
  3. Why can’t the cross-encoder be used to search a whole collection?
    Every new query would require running every document in the collection through the encoder jointly with it, which is far too expensive; it is used only for reranking.
  4. What is a bi-encoder?
    Separate encoders for queries and documents: each document is encoded once in advance (e.g. its [CLS] vector) and stored; a new query is encoded and scored against all documents by dot product, \(\text{score} = z_q \cdot z_d\).
    encoder(q [SEP] d)scorequery + doc togetheraccurate, slowenc_Q(q)enc_D(d)z_q · z_ddocs precomputedfast, less accurate
  5. Why is a bi-encoder less accurate than a cross-encoder?
    Its relevance decision can’t exploit interactions between query tokens and document tokens; each side is compressed into a vector independently.
  6. What is a common way to combine cheap and expensive retrieval methods?
    Rank with a cheap first pass (e.g. BM25), then rerank only the top N documents with an expensive model like a full cross-encoder.
  7. How does ColBERT score a query against a document?
    Encode query and document separately into one contextual vector per token (document vectors can be precomputed); for each query token find the most similar document token (MaxSim) and sum: \(\text{score}(q, d) = \sum_{i=1}^{N}\max_{j} E_{q_i}\cdot E_{d_j}\).
  8. How are neural retrievers like ColBERT trained, and where do training examples come from?
    End-to-end with a cross-entropy loss on triples (query, positive document, negative document). Positives from datasets with gold relevant passages (e.g. MS MARCO), negatives sampled from an existing system’s top results; without labels, relevance-guided supervision iteratively harvests passages that do or don’t contain short answer strings.
  9. How is efficient search done with dense vectors?
    Finding the document vectors with the highest dot product with the query is a nearest neighbor search problem, solved with approximate nearest neighbor libraries like Faiss. (Sparse retrieval uses the inverted index.)

11.4 Retrieval-augmented generation

  1. What are the two components of a RAG system?
    The retriever, which finds relevant passages in a document collection, and the generator (historically the “reader”), an LLM that answers conditioned on the retrieved passages and the user prompt.
  2. Give the basic RAG algorithm.
    (1) Retrieve the top-k passages \(R(q) = d_1 \ldots d_k\) for query \(q\); (2) build a prompt with the passages and the question (“Based on these texts, answer this question: …”); (3) call the LLM, which generates \(p(x_i \mid R(q); \text{instruction}; q; x_{<i})\).
    questionretrieverpromptLLMquestion goes into the prompt toodocuments
    Retrieve, then generate an answer grounded in the passages.
  3. What is agent-based RAG?
    The system decides when to call retrieval and from which collection (web, private data…), instead of always retrieving for every turn.
  4. How can RAG deal with noisy or insufficient retrieved passages?
    Add a reranker to reorder passages after retrieval, or use multi-hop retrieval: append the first-stage documents to the query and retrieve again.
  5. How can the LLM or the retriever be trained for RAG?
    Instruction-tune the LLM on questions annotated with retrieved passages and correct answers; or use test-time compute to have it reflect on which passages were useful; or train the retriever and LLM end-to-end on question–answer data, since the IR engine wasn’t optimized for feeding an LLM.
  6. What are knowledge citations, and how are they most simply generated?
    Evidence for factual statements, like numbered references to URLs or literature. Simplest: instruct the model in the prompt to answer only from the provided search results and cite them for every factual claim.

11.5 Datasets

  1. Along which dimensions do question-answering datasets vary?
    The questions’ origin (natural information-seeking vs probing/testing), answer format (multiple choice vs free form), whether passages are provided (open vs closed book), and prompting setup (zero-shot vs few-shot).
  2. Name natural information-seeking QA datasets.
    Natural Questions (Google queries with long paragraph and short span answers from Wikipedia), MS MARCO (Bing queries with human answers and passages, for retrieval ranking and QA), DuReader (Chinese), TyDi QA (typologically diverse languages).
  3. What is the TyDi QA task?
    Given a question and a Wikipedia article’s passages in one of several typologically diverse languages, (a) select the passage containing the answer (or NULL) and (b) mark the minimal answer span (or NULL).
  4. Why is MMLU a probing rather than an information-seeking dataset?
    Its questions come from exams for humans (GRE, medical licensing, AP…), designed to test knowledge, not to reflect people’s information needs.
  5. What is the difference between reading comprehension, open-book and closed-book QA?
    Reading comprehension: extract the answer from a given document. Open-book QA: answer given one or more documents (e.g. via RAG). Closed-book QA: answer directly from the LM with no retrieval.

11.6 Evaluating question answering

  1. How are question-answering systems evaluated?
    Multiple-choice (e.g. MMLU): exact match, the % of predictions matching the gold answer exactly. Free-text answers (e.g. Natural Questions): token F1, treating prediction and gold as bags of tokens, computing F1 per question and averaging.

Historical notes

  1. How did the 1961 BASEBALL system answer questions?
    It parsed the question (with a cascade of finite-state transducers), mapped words to meaning fragments (“Where” → Place = ?), and matched the resulting attribute-value query against a structured database of games.
  2. How did Protosynthex (1964) choose answer sentences?
    It retrieved candidate sentences by frequency-weighted term overlap with the question, then dependency-parsed them and picked the one whose structure best matched the question (“What do worms eat?” matches “worms eat grass”, not “birds eat worms”).
  3. What meaning representation did 1970s QA systems like LUNAR use?
    Predicate calculus / logical forms, as natural language interfaces to databases (LUNAR: lunar geology samples).
  4. What role did TREC play in QA history?
    The US Text REtrieval Conference evaluations (since 1992) provided testbeds for IR; its QA track (1999) drove many factoid and non-factoid QA systems.
  5. Where did RAG first come from?
    Retrieval augmentation was first introduced to improve language-model word prediction (Khandelwal et al., 2019), then quickly applied to question answering.

Source