RAG Basics: Build a Retrieval-Augmented Generation Pipeline
Intermediate · 45 minutes · 100 points
In this hands-on lab, you will build a foundational Retrieval-Augmented Generation (RAG) pipeline from scratch using Python. RAG combines a retrieval system with a language model to answer questions grounded in a specific document corpus. You will create a simple document store, implement vector embeddings using sentence-transformers, build a retrieval function using cosine similarity, and wire everything together into a working question-answering system — all without external API calls.
What you’ll learn
- Understand the core components of a RAG pipeline: document store, embedder, retriever, and generator
- Use sentence-transformers to generate vector embeddings for documents and queries
- Implement cosine-similarity-based retrieval to find the most relevant document chunks
- Build a simple prompt-based answer generator that augments context with retrieved documents
- Persist and verify each component as a Python script inside the container
How this lab works
- Start the lab: One click starts a container on your computer with a real terminal: nothing to install by hand, nothing to clean up.
- Work through 5 tasks: Each task says what to build or fix. You do it yourself, in a real terminal, with hints when you get stuck.
- Check your work: Check my work runs each task’s checks in your container and says what passed and what to fix.
- Finish and keep going: 100 points, your progress saved, and the next lab to try.
What it runs on
- Runs: A container on your computer, with a real terminal
- Image: python:3.12-slim
What you need
- A free LearnXops account
- The LearnXops desktop app for macOS, Windows or Linux
- Docker Desktop installed and running
- Stable internet connection (for downloading model weights on first run)
Topics: rag, retrieval-augmented-generation, nlp, embeddings, sentence-transformers, vector-search, cosine-similarity, python, ai, llm
Create a free account to start this lab.