Ever wondered how ChatGPT could answer questions about your documents? That's RAG. This tutorial breaks it down into simple, runnable code that actually works.
what_is_RAG.md- Start here if RAG is new to youHow_does_RAG_work.ipynb- Interactive notebook (run each cell)Complete_RAG_implementation.py- The full system (ready to run)knowledge.txt- Your test dataRAG_knowledge.md- Advanced stuff and FAQs
- Quick Start
- See It in Action
- How to Use This Repo
- What Makes This Different
- The 5-Step Breakdown
- What is RAG?
- Resources
Step 1: Grab the code
git clone https://github.com/Makilesh/RAG_Explained.git
cd RAG_ExplainedStep 2: Install stuff
python -m venv .venv
.venv\Scripts\activate # Windows
source .venv/bin/activate # Mac/Linux
pip install -r requirements.txtStep 3: (Optional) Get a free Gemini API key
- Go to Google AI Studio
- Copy
.env.exampleto.envand paste your key - Skip this if you want to run locally
Step 4: Run it
python Complete_RAG_implementation.pyAsk it: "What do elephants use their trunks for?"
Here's what happens when you run it:
$ python Complete_RAG_implementation.py
✅ Loaded documents: 9 chunks
Enter your question: What do elephants use their trunks for?
Retrieved: Elephants use their trunks for smelling, breathing, trumpeting, drinking, and grabbing things.
Augmented Prompt:
Based on this info: Elephants use their trunks for smelling, breathing, trumpeting, drinking, and grabbing things.
Answer the question: What do elephants use their trunks for?
Use Gemini API for generation? (y/n, default n): y
Final Answer (Gemini):
Elephants use their trunks for smelling, breathing, trumpeting, drinking, and grabbing things.Never touched RAG before?
Read what_is_RAG.md → Open How_does_RAG_work.ipynb → Run each cell and watch what happens
Just want to see it work?
Run Complete_RAG_implementation.py right now. It works out of the box.
Building something real?
Check RAG_knowledge.md for production tips, common pitfalls, and how to scale.
No fluff. No 500-line enterprise boilerplate. Just:
- Real code that runs in 5 minutes
- Actual explanations of why each line exists
- Works offline (uses local models if you skip the API)
- Your choice: Gemini API for quality, or free local model
Built with: LangChain, FAISS, Sentence Transformers, Google Gemini
This is what RAG actually does:
- Ingest → Load your documents (PDFs, text files, whatever)
- Embed → Turn text into numbers (so computers can compare them)
- Retrieve → Find the most relevant chunks for your question
- Augment → Combine your question with the retrieved info
- Generate → Let an LLM write a proper answer
Each step has its own section in the notebook with runnable code.
Once you're running, ask:
- "What do elephants use their trunks for?"
- "Tell me about honey"
- Or add your own docs to
knowledge.txtand ask about those
Full explanation in what_is_RAG.md →
You know how ChatGPT sometimes makes stuff up? RAG fixes that by letting it "look up" answers in your documents before responding.
Without RAG: LLM guesses based on training data
With RAG: LLM reads your actual documents, then answers
It's like giving someone an open-book exam instead of making them memorize everything.
Open an issue. I actually read them.
Or fork it and make it better. That works too.
If this helped you build something, drop a star ⭐
Resources that helped build this: