learning-it by example

Back to the video

RAG for Beginners: The Idea, Then 37 Lines of Python

I asked a model five questions about a cafe, and it got none right, until I gave it the facts.

Video #293 ยท RAG and vector search

Steps in the video

  1. 0:00 A model that knows nothing about a made-up cafe
  2. 0:28 The idea in four steps
  3. 1:01 Where the idea comes from
  4. 1:28 Setup
  5. 1:51 The facts and the questions
  6. 2:15 The pipeline
  7. 2:45 Ask both ways
  8. 3:31 What this does not show
  9. 3:57 Mistakes to avoid
  10. 4:22 My take and next steps
  11. 4:48 Recap

Files

  • compare.py (11 lines)
  • facts.py (19 lines)
  • rag.py (37 lines)

Download the code (zip)

Tested with

Python 3.12.15 | ollama==0.6.3

What this does not show

Eight made-up facts, five easy questions and one question the facts cannot answer; one seed, one small model (llama3.2), two facts retrieved. An answer counts as right if it contains one expected word. Run on one laptop; your counts may differ.

Sources

Learning IT by Example.