RAG has an AI look up passages before it answers

47 minutes ago

Ask an AI model who the President of Peru is. Its answer can depend on which copy of Wikipedia it reads first. The trick behind that is called RAG, and it comes from a 2020 paper by Patrick Lewis and a team at Facebook AI Research. RAG stands for retrieval-augmented generation. Retrieval means fetching, augmented means added to, and generation means writing. The model fetches passages that match the question, adds them to the question, and writes its answer. The team asked their model who held eighty-two leadership jobs in 2018. With a 2018 copy of Wikipedia, the model got sixty-eight percent of those questions right. With a 2016 copy, the same model got four percent.

Ask

Ask about this presentation

Answers are generated from this presentation.

Chapters

  1. 0:00Handed an older Wikipedia, one AI model fell from 68% right to 4%
  2. 0:44RAG turns a closed-book exam into an open-book one
  3. 1:11With pages open, the model stopped defining the ear with itself
  4. 1:31The team cut December 2018 Wikipedia into 21 million short pieces
  5. 1:59The lookup grabs the pieces sitting closest to the question
  6. 2:25On real Google questions, an open-book model with 626 million dials beat one with 11 billion
  7. 3:18The matched shelf scored 70% and 68%, and the mismatched one 12% and 4%
  8. 4:08RAG writes from whatever page it fetches, and training still leaks in
  9. 4:46Today’s tools fetch pages their own way, and OpenAI’s also matches exact words
  10. 5:09The facts RAG uses sit on a shelf you can swap without retraining
Show transcript

Handed an older Wikipedia, one AI model fell from 68% right to 4%

Handed an older Wikipedia, one AI model fell from 68% right to 4%.

The vocabulary · 1

Who is the President of Peru?1 of 82 questions about 2018 leadersWikipediaDec 20164% rightWikipediaDec 201868% rightthe same model

Lewis et al. 2020 · Facebook AI Research, UCL, NYU · section 4.5

Ask an AI model who the President of Peru is. Its answer can depend on which copy of Wikipedia it reads first. The trick behind that is called RAG, and it comes from a 2020 paper by Patrick Lewis and a team at Facebook AI Research. RAG stands for retrieval-augmented generation. Retrieval means fetching, augmented means added to, and generation means writing. The model fetches passages that match the question, adds them to the question, and writes its answer. The team asked their model who held eighty-two leadership jobs in 2018. With a 2018 copy of Wikipedia, the model got sixty-eight percent of those questions right. With a 2016 copy, the same model got four percent.

RAG turns a closed-book exam into an open-book one

RAG turns a closed-book exam into an open-book one.

the paper’s own words for the two setups

closed bookopen book

Lewis et al. 2020 · sections 1 and 4.1

Picture the model as a student sitting an exam. A normal model sits every exam with the book closed. Everything the student knows went in during training, and when that memory runs thin, the student guesses. Those guesses are the made-up answers from a few lessons back. RAG gives the same student a shelf of books. Before answering, the student looks up the pages that match the question and writes with those pages open. The paper calls these two setups closed-book and open-book.

With pages open, the model stopped defining the ear with itself

With pages open, the model stopped defining the ear with itself.

define middle earclosed book“The middle ear is the part of the ear between the middle ear and the nose.”open book“The middle ear includes the tympanic cavity and the three ossicles.”tympanic cavity · the air space behind the eardrumossicles · 3 tiny bones

Lewis et al. 2020 · Table 3 · crossed answer marked wrong by the paper

The paper shows the difference with one request. Define the middle ear. The closed-book model defined the middle ear in terms of itself, and then sent it toward the nose. The paper marks that answer as wrong. The open-book model named the air-filled hollow behind the eardrum, and the three tiny bones inside that hollow.

The team cut December 2018 Wikipedia into 21 million short pieces

The team cut December 2018 Wikipedia into 21 million short pieces.

Wikipedia · Dec 2018Wikipedia100 words100 words100 words21 million piecesmap of meaningsclose dots say similar things

Lewis et al. 2020 · section 3

Here is how the open book works. First, the team built the shelf. The team took Wikipedia as it stood in December 2018 and cut every article into pieces of a hundred words each. That made twenty-one million pieces, and each piece is one page on the shelf. A second model then placed each piece as a point on a map of meanings, like the word map from the embeddings lesson. Pieces that say similar things land close together on that map. The pieces and their points stay fixed through training.

The lookup grabs the pieces sitting closest to the question

The lookup grabs the pieces sitting closest to the question.

Wikipedia · Dec 2018Wikipedia100 words100 words100 words21 million piecesmap of meaningsclose dots say similar thingsthe questionwhile training · 5 or 10 piecesfinal test · 50 pieces

Lewis et al. 2020 · section 3 · Appendix A

Now a question comes in. The lookup, the part of RAG that fetches pages, places the question on that same map and fetches the pieces sitting nearest to the question. Near means close in meaning. A piece can sit near the question without repeating the question's exact words. While the model was training, the lookup fetched five or ten pieces for every question. For the paper's final test, the lookup fetched fifty pieces for every question.

On real Google questions, an open-book model with 626 million dials beat one with 11 billion

On real Google questions, an open-book model with 626 million dials beat one with 11 billion.

Wikipedia · Dec 2018Wikipedia100 words100 words100 words21 million piecesmap of meaningsclose dots say similar thingsthe questionthe writer400 million dialsthe questiondraftdraftdraftanswerone piece at a timecloser pieces count for morereal Google search questions answered word for word0RAG · 626 million dials in all44.5%closed book · T5 · 11 billion dials34.5%the lookup began already trained on these questions

Lewis et al. 2020 · sections 2.2, 2.3, 2.5 · Table 1 · Appendix G

Then the writer, the part of RAG that writes the answer, takes over. The writer is a model with four hundred million dials, the numbers inside a model that training turns. The writer reads the question glued to one fetched piece, and drafts an answer. The writer does that again for each piece. Then the drafts get added up, and each draft counts for more when its piece matched the question better. The team tested RAG on real questions that people typed into Google search. RAG answered forty-four and a half percent of those questions with exactly the right words. A closed-book model called T5, with eleven billion dials, answered thirty-four and a half percent. Counting the lookup, RAG has about six hundred and twenty-six million dials in total. The lookup also had a head start. The team began the lookup from an earlier system, already trained to find answers to these same Google questions.

The matched shelf scored 70% and 68%, and the mismatched one 12% and 4%

The matched shelf scored 70% and 68%, and the mismatched one 12% and 4%.

Wikipedia · Dec 2018Wikipedia100 words100 words100 words21 million piecesmap of meaningsclose dots say similar thingsthe questionthe writer400 million dialsthe questiondraftdraftdraftanswerone piece at a timecloser pieces count for moreWikipedia · Dec 2016Wikipedia · Dec 20182016 leaders2018 leadersshelf: Dec 2016shelf: Dec 201870%4%12%68%82 leadership jobs that changed hands · same model, nothing retrained

Lewis et al. 2020 · section 4.5

Now back to the experiment from the start. The team built a second shelf from a copy of Wikipedia saved in December 2016. The team listed eighty-two leadership jobs, like President of Peru, where the person holding the job changed between 2016 and 2018. Then the team asked the same trained model who held each job, once with each shelf. With the 2016 shelf, the model named the 2016 leader seventy percent of the time. With the 2018 shelf, the model named the 2018 leader sixty-eight percent of the time. Asked for 2016 leaders from the 2018 shelf, the model got twelve percent. Asked for 2018 leaders from the 2016 shelf, the model got four percent. Between those runs, every dial in the model stayed the same. The answers moved with the shelf.

RAG writes from whatever page it fetches, and training still leaks in

RAG writes from whatever page it fetches, and training still leaks in.

Wikipedia · Dec 2018Wikipedia100 words100 words100 words21 million piecesmap of meaningsclose dots say similar thingsthe questionthe writer400 million dialsthe questiondraftdraftdraftanswerone piece at a timecloser pieces count for moreWikipedia · Dec 2016Wikipedia · Dec 20182016 leaders2018 leadersshelf: Dec 201670%4%shelf: Dec 201812%68%an out-of-date page, used anywayanswer not on any fetched page · 11.8% still righta copy-only system scores 0% here

Lewis et al. 2020 · section 4.5 · section 4.1

The open-book picture is roughly right, and here is where the picture breaks. The answer follows whatever page the lookup fetches. That four percent came from a shelf that was two years out of date, and the model wrote from the old pages anyway. RAG makes the model check the shelf. The shelf can still be wrong, and the lookup can still fetch the wrong page. The student also keeps its memory. On the Google questions where no fetched piece held the answer, RAG still got eleven point eight percent right, from what the writer learned in training. A system that can only copy words out of the fetched pages would score zero on those same questions.

Today’s tools fetch pages their own way, and OpenAI’s also matches exact words

Today’s tools fetch pages their own way, and OpenAI’s also matches exact words.

Wikipedia · Dec 2018Wikipedia100 words100 words100 words21 million piecesmap of meaningsclose dots say similar thingsthe questionthe writer400 million dialsthe questiondraftdraftdraftanswerone piece at a timecloser pieces count for moreWikipedia · Dec 2016Wikipedia · Dec 2018“…retrieve information in a knowledge base ofpreviously uploaded files through semantic andkeyword search.”OpenAI file search guidemeaning and exact words2020 lookup · meaning only

Lewis et al. 2020 · section 3 · OpenAI platform docs, file search, read 27 Sep 2026

The 2020 paper introduced the name RAG for its models. Tools today use the same look-it-up-then-write idea, each in its own way. OpenAI's file search tool, for example, fetches from files that you upload. OpenAI's guide says the tool searches by meaning and by keyword, so the tool also catches exact words. The 2020 lookup matched by meaning alone.

The facts RAG uses sit on a shelf you can swap without retraining

The facts RAG uses sit on a shelf you can swap without retraining.

2018 leaders · 68% with the 2018 shelf · 4% with the 2016 shelf

The vocabulary · 1

Wikipedia · Dec 2018Wikipedia100 words100 words100 words21 million piecesmap of meaningsclose dots say similar thingsthe questionthe writer400 million dialsthe questiondraftdraftdraftanswerone piece at a timecloser pieces count for moreWikipedia · Dec 2016Wikipedia · Dec 2018

Lewis et al. 2020 · sections 3 and 4.5

Cut a library into pages, and place every page on a map of meanings. Put the question on the same map, and fetch the closest pages. Let the writer answer with each page open, and weigh each answer by how well its page matched. The facts the model looks up live on the shelf. Swap the 2018 shelf for the 2016 one, and the same model's score on 2018 leaders fell from sixty-eight percent to four.