Skip to content
tezvyn:
Menu

RAG: Giving Language Models an Open-Book Exam

Source: arXivMediumHow cards are made

Retrieval-Augmented Generation (RAG) gives a language model an open-book exam instead of forcing it to memorize everything. It combines a model's reasoning ability with a searchable external knowledge base. This grounds LLM responses in specific, up-to-date information, like a support bot using a product manual. The footgun is forgetting that the quality of the retrieved information directly limits the quality of the final answer.

The mental model

Retrieval-Augmented Generation (RAG) stops treating a language model as a closed-book exam where it must recall every fact from memory. Instead, it gives the model an open-book exam for every query. It combines the model's built-in knowledge (parametric memory) with an external, searchable knowledge base (non-parametric memory), allowing it to generate answers grounded in specific, verifiable information.

How it works

When a user submits a prompt, the RAG process unfolds in two main stages: 1. Retrieval: The system first uses a "retriever" component to search an external knowledge base (like a vector index of Wikipedia or company documents) for information relevant to the prompt. It pulls the most relevant text chunks. 2. Generation: These retrieved text chunks are then combined with the original prompt and passed as context to a generator model (a standard LLM). The LLM synthesizes an answer based on both the user's question and the provided factual documents, effectively "citing" its sources as it generates the response.

When to use it

• Grounding in current or private data: When you need an LLM to answer questions based on information it wasn't trained on, like today's news, internal company wikis, or product documentation. • Reducing hallucinations: By providing factual context for every generation, RAG makes it much harder for the model to invent facts. It also allows for providing source attribution. • Avoiding costly fine-tuning: Updating a knowledge base is far cheaper and faster than retraining or fine-tuning a massive language model every time new information becomes available.

When not to use it

• Latency-critical applications: The retrieval step adds a small delay. If absolute minimum latency is required and factual grounding is not, a standard LLM might be faster. • Purely creative tasks: For tasks like writing a poem or brainstorming fictional ideas, the constraints of factual retrieval may be unnecessary or even counter-productive.

One canonical example

A user asks a financial chatbot, "How did our new product line perform in Q3?" A standard LLM would likely respond that it doesn't have access to that information. A RAG system would: 1. Retrieve: Search the company's internal database and pull the relevant section from the Q3 earnings report. 2. Generate: The LLM receives the prompt and the report text, then generates: "According to the Q3 earnings report, the new product line generated $15M in revenue, exceeding projections by 20% due to strong market adoption."

Interview question

What is the fundamental way Retrieval-Augmented Generation (RAG) improves a language model's factual accuracy?

  • a.A) It continuously updates the model's internal knowledge base with new information.
  • b.B) It provides the model with relevant external documents to synthesize answers from.Correct
  • c.C) It allows the model to learn and incorporate user feedback directly into its responses.
  • d.D) It trains the model on a much larger and more diverse dataset than traditional LLMs.
Why?

The core mechanism of RAG is to retrieve relevant external documents and provide them as context to the language model during generation, effectively giving it an 'open-book' for factual queries. This grounds the LLM's responses in specific, verifiable information. Option A is incorrect because RAG uses an external knowledge base and does not directly update the LLM's internal memory.

Just read this? Test yourself on what you have been reading.

Read the original → arxiv.org

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on llm — each one lists the topics its interview covers.

See open roles