A Retrieval-Augmented Generation (RAG) system for analyzing 3M+ Reddit posts from r/Canada
Built for AI Hackathon in the North 2026
Features β’ Demo β’ Architecture β’ Setup β’ Tech Stack
Verity is an AI-powered platform that helps users understand Canadian public discourse by analyzing millions of Reddit posts. Using advanced RAG (Retrieval-Augmented Generation) technology with Groq's ultra-fast LLM inference, it retrieves relevant discussions and generates insightful answers backed by real community conversations.
- π Semantic Search - Vector similarity search across 2.97M+ Reddit posts
- β‘ Lightning Fast - Powered by Groq's llama-3.3-70b-versatile for sub-second responses
- π€ AI Insights - Context-aware answer generation with source attribution
- π Real-time Stats - Live API usage tracking and dataset statistics
- π¨ Beautiful UI - Modern React interface with gradient glassmorphic design
π https://shams0026-canadaconvo-backend.hf.space
Try these endpoints:
- π API Docs: /docs
- β€οΈ Health Check: /api/v1/health
- π Stats: /api/v1/stats
curl -X POST "https://shams0026-canadaconvo-backend.hf.space/api/v1/query" \
-H "Content-Type: application/json" \
-d '{
"query": "What are Canadians saying about healthcare?",
"top_k": 10
}'
|
|
|
|
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FRONTEND (React + Vite) β
β ββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Chat β β Message β β Source β β
β β Interface ββ β Display ββ β Cards β β
β ββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β β
β API Client (services/api.ts) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β HTTPS
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BACKEND (FastAPI on HF Space) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β API Layer (/api/v1) β β
β β /query | /health | /stats β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β RAG Engine β β
β β ββββββββββββββ ββββββββββββββ ββββββββββββββ β β
β β β Embed ββ β Retrieve ββ β Generate β β β
β β β Query β β Context β β Response β β β
β β ββββββββββββββ ββββββββββββββ ββββββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Groq API β β ChromaDB β β Embeddings β β
β β (Primary) β β Vector DB β β Service β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Step-by-Step:
- Query Embedding β Convert user query to 384-dim vector using sentence-transformers
- Vector Search β Find top-K similar posts from 2.97M embeddings in ChromaDB
- Context Building β Structure retrieved posts into a comprehensive prompt
- LLM Generation β Groq's llama-3.3-70b generates insights from context
- Response Formatting β Return answer with source citations and metadata
| Technology | Purpose | Version |
|---|---|---|
| FastAPI | Web framework | 0.104.1 |
| ChromaDB | Vector database | 0.4.18 |
| Groq API | LLM inference (Primary) | llama-3.3-70b-versatile |
| Gemini API | LLM inference (Fallback) | gemini-2.5-flash |
| sentence-transformers | Text embeddings | all-MiniLM-L6-v2 (384-dim) |
| Uvicorn | ASGI server | Latest |
| Pydantic | Data validation | 2.x |
| Hugging Face Spaces | Deployment | Docker SDK |
| Technology | Purpose | Version |
|---|---|---|
| React | UI framework | 19.2 |
| TypeScript | Type safety | 5.9 |
| Vite | Build tool | 7.2.4 |
| Tailwind CSS | Styling | 3.4.1 |
| Lucide React | Icons | Latest |
- Python scripts for ETL
- Pandas & NumPy for data processing
- ChromaDB persistent vector store (16GB)
- Pre-computed embeddings for 2.97M posts
- Source: r/Canada subreddit
- Total Posts: 2,972,749
- Time Period: Historical discussions
- Embedding Dimensions: 384
- Vector Database Size: 16GB
- Metadata: Titles, scores, comments, years
{
"total_posts": 2972749,
"embedding_dimension": 384,
"vector_db_size": "16GB",
"model": "all-MiniLM-L6-v2",
"database": "ChromaDB"
}- Python 3.12+
- Node.js 18+
- Git
- 8GB+ RAM (for running locally with full dataset)
# 1. Clone repository
git clone https://github.com/Shams261/Verity.git
cd Verity/canadaconvo-backend
# 2. Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Configure environment
cp .env.example .env
# Edit .env and add your API keys:
# - GROQ_API_KEY=your_groq_key_here
# - HACKATHON_API_KEY=your_gemini_key_here (optional fallback)
# 5. Start server
python app.pyBackend will be running at http://localhost:8000
API Documentation: http://localhost:8000/docs
# 1. Navigate to frontend
cd ../canadaconvo-frontend
# 2. Install dependencies
npm install
# 3. Configure API endpoint (if needed)
# Create .env.local with:
# VITE_API_URL=http://localhost:8000/api/v1
# 4. Start development server
npm run devFrontend will be running at http://localhost:5173
# LLM Configuration
GROQ_API_KEY=your_groq_api_key_here
GROQ_MODEL=llama-3.3-70b-versatile
USE_GROQ=true
# Fallback LLM (optional)
HACKATHON_API_KEY=your_gemini_api_key_here
GEMINI_MODEL=gemini-2.5-flash
# Embeddings
EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
EMBEDDING_DIM=384
# RAG Settings
RETRIEVAL_TOP_K=50
RERANK_TOP_K=20
# Server
HOST=0.0.0.0
PORT=8000# Backend API URL
VITE_API_URL=https://shams0026-canadaconvo-backend.hf.space/api/v1https://shams0026-canadaconvo-backend.hf.space/api/v1
POST /query
Submit a natural language query to analyze Canadian discourse.
Request:
{
"query": "What are Canadians saying about housing affordability?",
"top_k": 20
}Response:
{
"query": "What are Canadians saying about housing affordability?",
"answer": "Based on analyzing discussions from r/Canada...",
"sources": [
{
"id": "post_123",
"title": "Housing crisis discussion",
"text": "Post content...",
"score": 1250,
"year": "2023",
"num_comments": 342
}
],
"metadata": {
"num_sources": 20,
"cached": false,
"api_calls_used": 4,
"api_calls_remaining": 999999
}
}GET /health
Check service status.
Response:
{
"status": "healthy",
"service": "CanadaConvo",
"version": "1.0.0"
}GET /stats
Get system statistics.
Response:
{
"total_posts": 2972749,
"api_calls_used": 4,
"api_calls_remaining": 999999,
"embedding_model": "all-MiniLM-L6-v2",
"llm_provider": "Groq",
"llm_model": "llama-3.3-70b-versatile",
"using_groq": true
}Verity/
βββ canadaconvo-backend/ # Python FastAPI Backend
β βββ app/
β β βββ api/ # API endpoints
β β β βββ v1/
β β β βββ endpoints/
β β β βββ query.py # POST /query
β β β βββ health.py # GET /health, /stats
β β βββ core/ # Core business logic
β β β βββ rag_engine.py # Main RAG implementation
β β βββ db/ # Database clients
β β β βββ chroma_client.py # ChromaDB integration
β β βββ models/ # Pydantic models
β β β βββ query.py # Request/Response models
β β β βββ post.py # Post model
β β βββ services/ # External services
β β β βββ embedding_service.py # Embeddings
β β β βββ groq_service.py # Groq API client
β β β βββ gemini_service.py # Gemini API client
β β βββ utils/ # Utilities
β β βββ data_loader.py # Data management
β βββ config/
β β βββ settings.py # Configuration
β βββ data/ # Data files (16GB+)
β β βββ processed/
β β β βββ embeddings.npy # Pre-computed embeddings
β β β βββ metadata.parquet # Post metadata
β β βββ chroma/ # ChromaDB persistent storage
β βββ scripts/ # Data processing scripts
β β βββ 02_clean_data.py
β β βββ 03_generate_embeddings.py
β β βββ 04_build_indexes.py
β βββ .env # Environment variables (gitignored)
β βββ .env.example # Template for env vars
β βββ Dockerfile # Docker configuration
β βββ requirements.txt # Python dependencies
β βββ app.py # Server entry point
β βββ README.md # Backend documentation
β
βββ canadaconvo-frontend/ # React + TypeScript Frontend
β βββ src/
β β βββ components/
β β β βββ ChatInterface.tsx # Main chat UI
β β β βββ MessageDisplay.tsx # Message rendering
β β β βββ SourceCard.tsx # Citation cards
β β β βββ StatsPanel.tsx # Header stats
β β βββ services/
β β β βββ api.ts # API client
β β βββ types/
β β β βββ index.ts # TypeScript types
β β βββ App.tsx # Root component
β β βββ main.tsx # Entry point
β β βββ index.css # Global styles
β βββ public/ # Static assets
β βββ package.json
β βββ tsconfig.json
β βββ vite.config.ts # Vite configuration
β βββ tailwind.config.js # Tailwind config
β
βββ .gitignore # Git ignore rules
βββ README.md # This file
1. USER INPUT
ββ User types: "What issues concern Canadians most?"
2. FRONTEND
ββ POST /api/v1/query
3. BACKEND API
ββ Receives QueryRequest
4. RAG ENGINE
ββ Embedding Generation
β ββ Convert query to 384-dim vector
β
ββ Vector Search
β ββ Find top 20 similar posts in ChromaDB
β
ββ Context Building
β ββ Structure prompt with retrieved posts
β
ββ LLM Generation
β ββ Groq API generates insights
β
ββ Response Formatting
ββ Return {answer, sources, metadata}
5. FRONTEND DISPLAY
ββ Render AI answer
ββ Show source cards
ββ Display metadata
6. USER SEES RESULT
ββ Comprehensive answer with citations
| Metric | Value |
|---|---|
| Dataset Size | 2.97M posts |
| Embedding Dimension | 384 |
| First Query | ~3-5s (with Groq) |
| Cached Query | <1s |
| Vector Search | ~100ms |
| LLM Inference | ~2-3s (Groq) |
| Default Top-K | 20 posts |
Uses sentence-transformers to convert text into 384-dimensional vectors, enabling semantic understanding beyond keyword matching.
Leverages Groq's ultra-fast LLM infrastructure for sub-second response generation with llama-3.3-70b-versatile.
Every answer includes citations to original Reddit posts, ensuring transparency and verifiability.
Frequently asked questions are cached to provide instant responses and reduce API costs.
Live dashboard showing:
- Total posts in dataset (2.97M)
- API usage tracking
- Active LLM provider (Groq/Gemini)
The backend is deployed on Hugging Face Spaces using Docker:
title: Verity Backend API
emoji: π
sdk: docker
app_port: 7860Secrets Configuration:
GROQ_API_KEY- Your Groq API keyHACKATHON_API_KEY- Gemini API key (optional)HF_TOKEN- Hugging Face token for dataset access
The frontend can be deployed on:
- Vercel (Recommended)
- Netlify
- GitHub Pages
- Any static hosting service
Environment Variable:
VITE_API_URL=https://shams0026-canadaconvo-backend.hf.space/api/v1- β All API keys stored in environment variables
- β
.envfiles gitignored - β No hardcoded credentials in code
- β Secrets managed via HF Space settings
Backend allows requests from:
localhost:3000(React dev)localhost:5173(Vite dev)*.vercel.app(Vercel deployments)*.hf.space(HF Space frontend)
We welcome contributions! Here's how:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
feat:New featurefix:Bug fixdocs:Documentation changesstyle:Code style changesrefactor:Code refactoringtest:Test additions/changeschore:Build process or tool changes
Problem: ChromaDB collection not found
Solution: Ensure data files are downloaded
The app will auto-download on first runProblem: Groq API errors
Solution: Check your GROQ_API_KEY in .env
Verify you have API credits remainingProblem: Out of memory
Solution: Reduce RETRIEVAL_TOP_K in config
Or increase available RAM (8GB+ recommended)Problem: API connection refused
Solution: Verify VITE_API_URL in .env.local
Check backend is runningProblem: Build errors
Solution: Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm installThis project was created for the AI Hackathon in the North 2026.
The AI Collective - Thunder Bay
- The AI Collective - Thunder Bay - For organizing the AI Hackathon in the North
- Hackathon Organizers - For providing API access and resources
- r/Canada Community - For the rich discussion dataset
- Groq - For ultra-fast LLM inference
- ChromaDB - For efficient vector storage
- Sentence Transformers - For high-quality embeddings
- FastAPI - For the excellent Python web framework
- React Team - For the amazing frontend library
- Hugging Face - For hosting infrastructure
Built with β€οΈ for the AI Hackathon in the North 2026
For questions, suggestions, or feedback:
- GitHub Issues: Create an issue
- Repository: Shams261/Verity
If you find this project useful, please consider giving it a β!