Study-Ocean-AI_Mentor / COLAB_GUIDE.md
Mohit Raj
Sync from GitHub via hub-sync
030f984 verified
|
Raw History Blame Contribute Delete
3.49 kB

πŸŽ“ Study Ocean RAG β€” Google Colab Guide

Your laptop stays cool. Colab's T4 GPU does all the heavy lifting.


πŸ“‹ One-Time Setup (First Time Only)

1. Upload ZIP to Google Drive

  1. Go to drive.google.com
  2. Create a folder: MyDrive/StudyOcean/
  3. Upload StudyOceanPDFs.zip into that folder
  4. ⏳ Wait for upload to complete (6 GB β€” may take 15–30 min on slow wifi)

2. Get a Gemini API Key (Free)

  1. Go to aistudio.google.com/apikey
  2. Click Create API Key
  3. Copy the key β€” you'll paste it into the notebook

3. Open the Notebook in Colab

  1. Go to colab.research.google.com
  2. Click File β†’ Upload notebook
  3. Upload StudyOcean_RAG_Colab.ipynb from this folder

4. Set T4 GPU Runtime

This is critical β€” without it, ingestion will be very slow!

  1. In Colab: Runtime β†’ Change runtime type
  2. Set Hardware accelerator = T4 GPU
  3. Click Save

πŸš€ Running the Pipeline

First Time (Fresh Ingestion)

Run cells in order: Steps 1 β†’ 2 β†’ 3 β†’ 4 β†’ 5 β†’ 6 β†’ 7 β†’ 8 β†’ 9 β†’ 10

Step What it does Time
1 Verify T4 GPU + mount Drive 30s
2 Install packages 2–3 min
3 Configure settings (paste API key here!) instant
4 Extract PDFs from ZIP 5–10 min
5 Ingest PDFs & build vector store 30–60 min
6 Save vector store to Drive 2–5 min
7 Test retrieval instant
8 Build RAG chain instant
9 Test full pipeline 5s
10 Launch Gradio chat UI instant

Future Sessions (Vector Store Already Built)

Run cells: Steps 1 β†’ 2 β†’ 3 β†’ 11 β†’ 8 β†’ 10

Step What it does Time
11 Load saved vector store from Drive 1–2 min
8 Build RAG chain instant
10 Launch Gradio chat UI instant

πŸ’» Running Locally (After Ingestion)

Once the vector store is built, you can run the chat locally:

Option A β€” Download via Colab (Step 12)

  • Run Step 12 in the notebook
  • It downloads vector_store_export.zip to your computer
  • Extract it to: Study_Ocean Rag/data/vector_store/

Option B β€” Download from Google Drive

  • Go to Drive β†’ StudyOcean/vector_store/
  • Download the folder
  • Place it at: Study_Ocean Rag/data/vector_store/

Then run locally:

# Make sure .env has your GOOGLE_API_KEY
python main.py chat    # Web UI at http://localhost:7860
# OR
python main.py ask     # Terminal Q&A

⚑ Performance on T4 GPU

Task CPU (your laptop) T4 GPU (Colab)
Embedding batch size 64 256
~10,000 chunks ~45 min ~8 min
~50,000 chunks ~4 hours ~35 min
~100,000 chunks ~8 hours ~70 min

❓ Troubleshooting

"ZIP not found" error β†’ Update ZIP_DRIVE_PATH in Step 3 to match your actual Drive path

"CUDA not available"
β†’ You forgot to set T4 GPU runtime! Runtime β†’ Change runtime type β†’ T4 GPU

Colab session disconnects during ingestion
β†’ The vector store saves in batches. Re-run from Step 5 β€” FAISS will rebuild from scratch. Save to Drive often.

"Invalid API key"
β†’ Make sure you pasted the full Gemini API key in Step 3

Gradio link doesn't work
β†’ Gradio public links expire after 72 hours. Re-run Step 10 to get a new link.