Retrieval
A model answers from what it learned in training, unless you give it the right text when it answers. That is retrieval-augmented generation, or RAG, shown here step by step on a clinical record.
A model does not know your patient. Retrieval finds the parts of a record that bear on a question and hands them to the model with the question, so the answer can come from the record and point back to it. This module follows one clinical note through the three steps.
Chunks and meaning¶
First the note is split into chunks: short passages that each make sense on their own. Each chunk is turned into a list of numbers, called an embedding, that places it on a map by meaning.
Step through it and watch where each chunk lands. Chunks that mean similar things sit close together, even when they share few words.
Finding the right chunks¶
A question is turned into an embedding the same way and lands on the same map. The chunks nearest to it are pulled out and passed to the model.
Try each question, then try the third: "Any history of kidney disease?" The closest chunk is a two-year-old line that rules kidney disease out. Similar is not the same as relevant, and the search cannot tell the difference.
Answering with sources¶
Now compare the answer with and without retrieval. Without it, the model writes a fluent, plausible answer that is wrong for this patient. With it, the answer is built from the retrieved chunks and cites them. Tap a citation to check the chunk it came from.
What to take away¶
Retrieval gives a model the right text to work from, and citations let you check its answer against the record. Retrieval can still pull the wrong chunk, so a citation is where your checking starts. To build one yourself, the Building a RAG system course does it step by step in notebooks.
Where next
How AI works: Module 4: Agents
Back to your lesson: Building a RAG system, Module 2: Documents, chunking and embeddings
Back to your lesson: Building a RAG system, Module 3: Retrieval
Back to your lesson: Building a RAG system, Module 4: Generation with citations
A shared question channel is on the way. When it opens, each answer will be written once and shared with everyone taking the course.