vieveksharmaa/multi-source-rag
๐ Multi-Source RAG with Citations
Ingest YouTube videos, PDFs, Word docs, web pages, GitHub repos, and live web search โ get answers with exact citations back to the source, timestamp, and page number.
Built with LangChain + LangGraph. Every provider (LLM, embeddings, vector store, web search) swaps via a single .env line. Runs entirely free by default.
๐ Live Demo: huggingface.co/spaces/vieveksharmaa/multi-source-rag ๐ฆ GitHub: github.com/vieveksharmaa/multi-source-rag
Table of Contents
- What Is RAG?
- Architecture
- Local Setup
- LLM Providers
- Embedding Providers
- Vector Stores
- Web Search Providers
- Source Types
- Deployment
- Environment Variables Reference
- API Reference
- Troubleshooting
- Tech Stack
1. What Is RAG?
RAG (Retrieval-Augmented Generation) grounds an LLM's answer in real documents rather than training data. Instead of hallucinating, the model reads the relevant passages first, then answers from them โ with citations.
Why multi-source? Most RAG apps handle one source type. This app handles six simultaneously:
2. Architecture
โโโโโโโโโโโโโโโโโโโโโโโ
โ User Query โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โโโโโโโโโโโโผโโโโโโโโโโโ
โ Query Router โ LLM decides: needs live web?
โโโโโโโโโโฌโโโโโโโโโโโโโ
(parallel fan-out)
โโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโโโโผโโโโโโโโโโโ โโโโโโโโโโโโโโผโโโโโโโโโโโโ
โ Vector Retrieval โ โ Web Search โ
โ (ChromaDB / Qdrant / โ โ (DuckDuckGo / Tavily) โ
โ Pinecone) โ โโโโโโโโโโโโโโฌโโโโโโโโโโโโ
โโโโโโโโโโโโฌโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโผโโโโโโโโโโโ
โ Document Grader โ Filters irrelevant chunks
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โโโโโโโโโโโโผโโโโโโโโโโโ
โ Answer Generator โ Writes answer with [1][2] citations
โโโโโโโโโโโโโโโโโโโโโโโIngestion pipeline:
Source URL / File
โ
Source Loader (YouTube transcript / PDF parser / web scraper / GitHub walker)
โ
Text Splitter (RecursiveCharacterTextSplitter, 1000 chars, 200 overlap)
โ
Embeddings (HuggingFace / OpenAI / Ollama / Gemini / NVIDIA)
โ
Vector Store (ChromaDB / Qdrant / Pinecone)3. Local Setup
Prerequisites
- Python 3.11
git- A free Groq API key (60 seconds to get)
Step 1 โ Clone
git clone https://github.com/vieveksharmaa/multi-source-rag.git
cd multi-source-ragStep 2 โ Virtual environment
# Windows
python -m venv .venv
.venv\Scripts\activate
# macOS / Linux
python3.11 -m venv .venv
source .venv/bin/activateStep 3 โ Install dependencies
pip install -r requirements.txtStep 4 โ Configure
cp .env.example .envSet at minimum:
GROQ_API_KEY=your_key_here # Free at https://console.groq.comEverything else has a working free default.
Step 5 โ Run
python main.pyOpen http://localhost:8000. The first ingest downloads the HuggingFace embedding model (~80 MB, cached after that).
Step 6 โ Test it
- Paste any YouTube URL in the sidebar โ click Ingest
- Ask a question about the video
- Answer appears with
[1] [YouTube] Title @ 2:34citations
4. LLM Providers
Set LLM_PROVIDER= in .env to switch. Supported: `groq` ยท `gemini` ยท `openai` ยท `anthropic` ยท `nvidia` ยท `ollama`
4.1 Groq โ Default
Runs Llama/Gemma on custom LPU hardware โ 10โ20ร faster than a GPU server. Free with generous rate limits.
LLM_PROVIDER=groq
GROQ_API_KEY=gsk_... # https://console.groq.com
GROQ_MODEL=llama-3.1-8b-instant
# or: llama-3.3-70b-versatile4.2 Google Gemini
Free tier: 15 req/min, 1M tokens/day. Good for longer contexts.
LLM_PROVIDER=gemini
GOOGLE_API_KEY=AIza... # https://aistudio.google.com
GEMINI_MODEL=gemini-1.5-flash
# or: gemini-1.5-proUncomment in requirements.txt: langchain-google-genai>=2.0.0
4.3 OpenAI
Industry standard. GPT-4o is the highest quality option. Paid only.
LLM_PROVIDER=openai
OPENAI_API_KEY=sk-... # https://platform.openai.com
OPENAI_MODEL=gpt-4o-mini
# or: gpt-4oUncomment in requirements.txt: langchain-openai>=0.2.0
4.4 Anthropic Claude โ Supported
Claude models via the Anthropic API. Excellent at following instructions and producing well-structured answers with citations.
LLM_PROVIDER=anthropic
ANTHROPIC_API_KEY=sk-ant-... # https://console.anthropic.com
ANTHROPIC_MODEL=claude-3-5-haiku-20241022
# or: claude-3-5-sonnet-20241022 # higher quality
# or: claude-opus-4-6 # best qualityUncomment in requirements.txt: langchain-anthropic>=0.3.0
Model comparison:
4.5 NVIDIA NIM (free, 100+ models)
One API endpoint with 100+ open-source models. Free tier, no credit card.
LLM_PROVIDER=nvidia
NVIDIA_API_KEY=nvapi-... # https://build.nvidia.com
NVIDIA_MODEL=meta/llama-3.1-8b-instructPopular models: meta/llama-3.3-70b-instruct ยท deepseek-ai/deepseek-r1 ยท qwen/qwen2.5-72b-instruct Full catalogue: build.nvidia.com/explore/discover
4.6 Ollama (Local)
Run models entirely on your own machine. No API key, no cost, no data leaves your computer.
ollama pull llama3 # 4.7GBLLM_PROVIDER=ollama
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_MODEL=llama3Uncomment in requirements.txt: langchain-ollama>=0.2.0
5. Embedding Providers
Set EMBEDDING_PROVIDER= in .env. Supported: `huggingface` ยท `openai` ยท `gemini` ยท `nvidia` ยท `ollama`
โ ๏ธ If you change embedding provider after ingesting, delete ./data/chroma_db/ and re-ingest. Vectors from different models are incompatible.5.1 HuggingFace (Local) โ Default
Downloads and runs a small model locally. No API key. Free forever.
EMBEDDING_PROVIDER=huggingface
HUGGINGFACE_EMBEDDING_MODEL=BAAI/bge-small-en-v1.55.2 OpenAI Embeddings
Best commercial quality. ~$0.02/1M tokens.
EMBEDDING_PROVIDER=openai
OPENAI_API_KEY=sk-...
OPENAI_EMBEDDING_MODEL=text-embedding-3-small5.3 Google Gemini Embeddings
Free tier. Pairs well with Gemini LLM.
EMBEDDING_PROVIDER=gemini
GOOGLE_API_KEY=AIza...5.4 NVIDIA NIM Embeddings
Purpose-built for retrieval Q&A. No local memory usage.
EMBEDDING_PROVIDER=nvidia
NVIDIA_API_KEY=nvapi-...
NVIDIA_EMBEDDING_MODEL=nvidia/nv-embedqa-e5-v55.5 Ollama Embeddings (Local)
ollama pull nomic-embed-textEMBEDDING_PROVIDER=ollama
OLLAMA_EMBEDDING_MODEL=nomic-embed-text6. Vector Stores
Set VECTOR_STORE= in .env. Supported: `chroma` ยท `qdrant` ยท `pinecone`
6.1 ChromaDB โ Default
Zero setup. Persists to disk. Fast for up to ~100K vectors.
VECTOR_STORE=chroma
CHROMA_PERSIST_DIR=./data/chroma_db6.2 Qdrant
High-performance. Runs locally via Docker or on Qdrant Cloud (free 1GB tier).
docker run -p 6333:6333 qdrant/qdrantVECTOR_STORE=qdrant
QDRANT_URL=http://localhost:6333Uncomment in requirements.txt: langchain-qdrant>=0.1.0 and qdrant-client>=1.9.0
6.3 Pinecone
Fully managed, serverless. Free tier: 1 index, 2GB.
VECTOR_STORE=pinecone
PINECONE_API_KEY=pcsk_...
PINECONE_INDEX=rag-indexUncomment in requirements.txt: langchain-pinecone>=0.2.0 and pinecone-client>=4.0.0
Dimension guide (must match embedding model):
7. Web Search Providers
Set WEB_SEARCH_PROVIDER= in .env. Triggered automatically when a query needs live data.
8. Source Types
GitHub note: Set GITHUB_TOKEN=ghp_... for private repos or to avoid rate limits.
YouTube note: Cloud platforms (HuggingFace, Render) may have YouTube block transcript requests. Run locally if this is an issue.
9. Deployment
9.1 Hugging Face Spaces โ Recommended (free)
16GB RAM, persistent storage, no sleep on public spaces.
- Push to GitHub
- Create a Space at huggingface.co/new-space โ SDK: Docker, Hardware: CPU Basic
- Add HF as a remote and push:
git remote add hf https://huggingface.co/spaces/YOUR_HF_USERNAME/multi-source-rag
git push hf main- Add secrets: Space โ Settings โ Variables and Secrets โ add
GROQ_API_KEY(or your chosen provider key)
Your app runs at https://YOUR_HF_USERNAME-multi-source-rag.hf.space
Redeploy:
git add . && git commit -m "update" && git push hf main9.2 Railway
$5 free credit/month. Auto-deploys from GitHub. No sleep.
- railway.app โ New Project โ Deploy from GitHub
- Settings โ Variables โ add your
.envvalues - Start Command:
uvicorn main:app --host 0.0.0.0 --port $PORT
9.3 Render
Free tier available but only 512MB RAM (embedding model is tight) and ephemeral filesystem.
- render.com โ New Web Service โ connect GitHub repo
- Build Command:
pip install -r requirements.txt - Start Command:
uvicorn main:app --host 0.0.0.0 --port $PORT - Add environment variables in Dashboard โ Environment
Recommendation: Use HuggingFace Spaces instead โ same cost ($0), 32ร more RAM.
9.4 Fly.io
Free: 3 VMs + 3GB persistent volume. Docker-based.
fly auth login
fly launch
fly secrets set GROQ_API_KEY=gsk_...
fly volumes create rag_data --size 1
fly deploy9.5 Self-Hosted VPS
Best for production. Hetzner starts at ~โฌ4/month.
sudo apt update && sudo apt install -y python3.11 python3.11-venv git
git clone https://github.com/vieveksharmaa/multi-source-rag.git
cd multi-source-rag
python3.11 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env && nano .env
uvicorn main:app --host 0.0.0.0 --port 8000Use systemd to run as a background service and Nginx + Certbot for HTTPS.
Platform Comparison
10. Environment Variables Reference
# โโ LLM โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
LLM_PROVIDER=groq # groq | gemini | openai | anthropic | nvidia | ollama
GROQ_API_KEY=gsk_... # https://console.groq.com (free)
GROQ_MODEL=llama-3.1-8b-instant
GOOGLE_API_KEY=AIza... # https://aistudio.google.com (free tier)
GEMINI_MODEL=gemini-1.5-flash
OPENAI_API_KEY=sk-... # https://platform.openai.com (paid)
OPENAI_MODEL=gpt-4o-mini
ANTHROPIC_API_KEY=sk-ant-... # https://console.anthropic.com
ANTHROPIC_MODEL=claude-3-5-haiku-20241022
NVIDIA_API_KEY=nvapi-... # https://build.nvidia.com (free, no credit card)
NVIDIA_MODEL=meta/llama-3.1-8b-instruct
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_MODEL=llama3
# โโ Embeddings โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
EMBEDDING_PROVIDER=huggingface # huggingface | openai | gemini | nvidia | ollama
HUGGINGFACE_EMBEDDING_MODEL=BAAI/bge-small-en-v1.5
OPENAI_EMBEDDING_MODEL=text-embedding-3-small
NVIDIA_EMBEDDING_MODEL=nvidia/nv-embedqa-e5-v5
OLLAMA_EMBEDDING_MODEL=nomic-embed-text
# โโ Vector Store โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
VECTOR_STORE=chroma # chroma | qdrant | pinecone
CHROMA_PERSIST_DIR=./data/chroma_db
QDRANT_URL=http://localhost:6333
QDRANT_API_KEY=
QDRANT_COLLECTION=rag_documents
PINECONE_API_KEY=pcsk_...
PINECONE_INDEX=rag-index
PINECONE_ENVIRONMENT=us-east-1-aws
# โโ Web Search โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
WEB_SEARCH_PROVIDER=duckduckgo # duckduckgo | tavily | serpapi
TAVILY_API_KEY=tvly-...
WEB_SEARCH_MAX_RESULTS=5
# โโ GitHub โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
GITHUB_TOKEN=ghp_... # Optional โ needed for private repos / high rate limits
# โโ App โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
APP_NAME="Multi-Source RAG"
DEBUG=false
MAX_CHUNK_SIZE=1000
CHUNK_OVERLAP=200
TOP_K_RESULTS=5
TEMPERATURE=0.111. API Reference
Interactive docs at http://localhost:8000/docs.
POST /ingest
{ "source": "https://www.youtube.com/watch?v=VIDEO_ID" }Response:
{ "status": "ok", "source_type": "youtube", "chunks_added": 23 }POST /ingest/file
Form data: file โ PDF, DOCX, TXT, MD
POST /query
{ "query": "What is the main argument?" }Response:
{
"answer": "The main argument is... [1][2]",
"citations": [
{ "number": 1, "source_type": "youtube", "title": "...", "url": "...", "extra": "@ 5:20" }
]
}GET /health
Returns current provider config.
GET /config
Returns LLM provider, model, embedding provider, vector store, chunk settings.
DELETE /store/clear
Wipes all indexed data.
GET /debug/retrieve?q=your+query
Shows raw retrieval results with similarity scores โ useful for debugging.
GET /debug/store
Shows all chunks currently in the vector store.
12. Troubleshooting
First ingest is slow (30โ60 sec) The HuggingFace model downloads on first use (~80โ130 MB). Cached after that. Docker builds pre-download it so cloud deploys don't have this delay.
"YouTube transcripts are blocked" YouTube blocks cloud provider IPs. Options: use a PDF/URL source instead, or run locally where your home IP isn't blocked.
Answers about wrong topic / stale data Click Clear All in the sidebar, then re-ingest your sources.
"Context does not contain information about..." Either ingestion returned 0 chunks (check the response) or the query is too vague. Use GET /debug/retrieve?q=your+query to see exactly what gets retrieved.
ChromaDB error after changing embedding model
rm -rf ./data/chroma_db/Then re-ingest.
Groq rate limit
GROQ_MODEL=gemma2-9b-it # different quota pool
# or switch provider entirely
LLM_PROVIDER=anthropic
LLM_PROVIDER=geminiGitHub clone fails The loader tries main โ master โ default branch automatically. If it still fails, the repo may be private โ set GITHUB_TOKEN in .env.
Out of memory on cloud The default embedding model needs ~300 MB RAM. Switch to an API-based embedder: EMBEDDING_PROVIDER=gemini or EMBEDDING_PROVIDER=nvidia.
