learning-it by example

Back to the video

RAG From Scratch in Python: Chunk, Embed, Retrieve (Local)

Build a working RAG system in plain Python with Ollama, and see exactly what it retrieves. No framework, no vector database, no API key.

Video #02 ยท RAG and vector search

Steps in the video

  1. 0:00 Build RAG in plain Python
  2. 0:16 What RAG is
  3. 0:47 Setup with Ollama
  4. 1:07 The documents
  5. 1:22 Chunk and embed
  6. 1:43 Find the closest chunks
  7. 2:06 Answer from the chunks
  8. 2:26 Running it
  9. 3:04 Check retrieval first
  10. 3:28 The chunk size trap
  11. 4:05 What this does not show
  12. 4:38 Four mistakes to avoid
  13. 5:00 My take and next steps
  14. 5:32 Recap

Files

  • notes.txt (22 lines)
  • rag.py (54 lines)
  • truncation.py (25 lines)

Download the code (zip)

Tested with

Python 3.12.15 | ollama==0.6.3

What this does not show

Seven made-up notes, a tiny embedding model (all-minilm) and a few questions on one laptop: not a benchmark. The truncation trap is shown with one example in Ollama. The advice pages were read as search results; the output on screen is the evidence.

Sources

Learning IT by Example.