Skip to content

Makilesh/RAG_Explained

Repository files navigation

RAG Explained

Python License: MIT GitHub stars

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.

The Files


Contents


Get Running

Step 1: Grab the code

git clone https://github.com/Makilesh/RAG_Explained.git
cd RAG_Explained

Step 2: Install stuff

python -m venv .venv
.venv\Scripts\activate          # Windows
source .venv/bin/activate       # Mac/Linux
pip install -r requirements.txt

Step 3: (Optional) Get a free Gemini API key

  • Go to Google AI Studio
  • Copy .env.example to .env and paste your key
  • Skip this if you want to run locally

Step 4: Run it

python Complete_RAG_implementation.py

Ask it: "What do elephants use their trunks for?"

See It in Action

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.

How to Use This Repo

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.

What Makes This Different

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

The 5-Step Breakdown

This is what RAG actually does:

  1. Ingest → Load your documents (PDFs, text files, whatever)
  2. Embed → Turn text into numbers (so computers can compare them)
  3. Retrieve → Find the most relevant chunks for your question
  4. Augment → Combine your question with the retrieved info
  5. Generate → Let an LLM write a proper answer

Each step has its own section in the notebook with runnable code.

Try These Questions

Once you're running, ask:

  • "What do elephants use their trunks for?"
  • "Tell me about honey"
  • Or add your own docs to knowledge.txt and ask about those

What is RAG, Really?

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.

Issues? Questions?

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:

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors