Learn / Lessons

The RAG pipeline

How does a question travel through your files to an answer with sources? The method is called retrieval augmented generation. Find the passages that matter.

Chapters

  1. 0:00Introduction
  2. 0:05The idea: Find, then answer
  3. 0:16Prepare: Cut into pieces
  4. 0:28Meaning as numbers: Embeddings
  5. 0:38The store: A vector database
  6. 0:47Sharpen: Search, then rerank
  7. 0:55Put together: The request
  8. 1:03Trust, carefully: Check the answer
  9. 1:13Yours: Keep it private
  10. 1:21Wrap up
Read the transcript

Introduction

How does a question travel through your files to an answer with sources?

The idea: Find, then answer

The method is called retrieval augmented generation. Find the passages that matter. Give them to the model with your question. It answers from what it was given.

Prepare: Cut into pieces

First, your documents are turned into text. The text is cut into small passages. Keep headings and page numbers with them. Good pieces make good answers.

Meaning as numbers: Embeddings

An embedding model turns each passage into a list of numbers. Similar meanings land close together. Your question gets the same treatment.

The store: A vector database

The numbers go into a vector database, such as Qdrant. It searches millions of passages quickly and returns the nearest ones.

Sharpen: Search, then rerank

Search casts a wide net. A reranker then reads each candidate against your question, and puts the best first.

Put together: The request

The best passages go into the prompt. Ask the model to answer only from them, and to cite each one it uses.

Answer using only these sources.
Cite each one, like [1].
[1] ...passage...
[2] ...passage...
Question: what changed this year?

Trust, carefully: Check the answer

Open the cited passage. Make sure it really says that. Test with questions you know the answers to. And re index when your files change.

Yours: Keep it private

Everything can run on your own hardware. Control who can search which files. And back up the database with your other data.

Wrap up

Find the right passages, then let the model answer with sources.

Sources

More lessons