Skip to content

retronoob99/stack-overflow-ai-assistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

39 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Stack Overflow AI Assistant

A full-stack RAG-based AI assistant grounded in 500K real Stack Overflow questions and 1.2M answers. Ask any programming question and get a synthesized answer with real Stack Overflow sources.

πŸ”— Live Demo: stack-overflow-ai-assistant.vercel.app


πŸ“Έ Screenshots

image

🧠 How It Works

User Query
    ↓
Guardrail Check (tech or not?)
    ↓
Embed query β†’ Search FAISS (498K vectors)
    ↓
Fetch real SO answers by question_id
    ↓
Build context β†’ Groq LLaMA 3.1
    ↓
Synthesized answer + Source cards

Five Response Paths

Path Trigger Response
greeting "hi", "hello" Friendly intro message
rag Tech + found in dataset Answer + 3 source cards
general Tech + not in dataset LLM answer from own knowledge
no_answers Found questions but no answers LLM general answer
rejected Non-tech query Polite rejection message

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Frontend (Vercel)                  β”‚
β”‚         React + Tailwind CSS + Marked.js        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚ POST /chat
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           Backend (HuggingFace Spaces)          β”‚
β”‚                  FastAPI                        β”‚
β”‚                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚            RAG Pipeline                 β”‚   β”‚
β”‚  β”‚  Guardrail β†’ FAISS β†’ AnswerFetcher      β”‚   β”‚
β”‚  β”‚  ContextBuilder β†’ Groq LLaMA 3.1        β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           Data (HuggingFace Datasets)           β”‚
β”‚  questions.index  β”‚  questions_docs.pkl         β”‚
β”‚  answers_cleaned.parquet                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“Š Dataset

File Size Description
questions_cleaned.parquet ~320 MB 498,643 cleaned SO questions
answers_cleaned.parquet ~600 MB 1,199,928 cleaned SO answers
top_tags.parquet ~1 KB Top 30 SO tags with counts
questions.index ~730 MB FAISS IVFFlat index
questions_docs.pkl ~400 MB LangChain Documents with metadata

Data Source: Google BigQuery public Stack Overflow dataset
Stratified sampling: Top 30 programming tags, 500K questions total


🎯 Model Performance

Metric Score
Top-1 Accuracy 65.1%
Top-3 Accuracy 84.7%
Top-5 Accuracy 90.0%
Score Ranking Accuracy 38.3%
Overall Accuracy 79.9%

πŸ› οΈ Tech Stack

ML / Data

  • sentence-transformers β€” all-MiniLM-L6-v2 embeddings (384 dims)
  • FAISS β€” IVFFlat index for semantic search
  • LangChain β€” Document ingestion and pipeline
  • Groq β€” LLaMA 3.1 8B for answer generation
  • Google BigQuery β€” Data extraction

Backend

  • FastAPI β€” REST API
  • HuggingFace Spaces β€” Deployment (Docker)
  • HuggingFace Hub β€” Data storage

Frontend

  • HTML/CSS/JavaScript β€” Chat interface
  • Tailwind CSS β€” Styling
  • Marked.js β€” Markdown rendering
  • Vercel β€” Deployment

πŸš€ Running Locally

Prerequisites

Backend Setup

# Clone the repo
git clone https://github.com/retronoob99/stack-overflow-ai-assistant
cd stack-overflow-ai-assistant/backend

# Install dependencies
pip install -r requirements.txt

# Create .env file
echo "GROQ_API_KEY=your_groq_key_here" > .env
echo "VECTOR_STORE_PATH=../data/vector_store" >> .env
echo "ANSWERS_PATH=../data/answers_cleaned.parquet" >> .env

# Run the backend
python app.py

Frontend Setup

# Open index.html directly in browser
# Or use Live Server in VS Code

# Update API URL in index.html to localhost
# Find: fetch("https://...hf.space/chat"
# Replace with: fetch("http://localhost:7860/chat"

Download Data

from huggingface_hub import hf_hub_download

# Download FAISS index
hf_hub_download(
    repo_id="retronoob99/stackoverflow-ai-data",
    filename="questions.index",
    repo_type="dataset",
    local_dir="data/vector_store"
)

# Download documents
hf_hub_download(
    repo_id="retronoob99/stackoverflow-ai-data",
    filename="questions_docs.pkl",
    repo_type="dataset",
    local_dir="data/vector_store"
)

# Download answers
hf_hub_download(
    repo_id="retronoob99/stackoverflow-ai-data",
    filename="answers_cleaned.parquet",
    repo_type="dataset",
    local_dir="data"
)

πŸ“ Project Structure

stack-overflow-ai-assistant/
β”‚
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app.py                  ← FastAPI app + endpoints
β”‚   β”œβ”€β”€ rag_pipeline.py         ← RAG logic (AnswerFetcher, ContextBuilder, LLMCaller, Guardrail)
β”‚   β”œβ”€β”€ utils.py                ← EmbeddingManager, VectorStore, RAGRetriever
β”‚   β”œβ”€β”€ Dockerfile              ← HuggingFace Spaces deployment
β”‚   └── requirements.txt
β”‚
β”œβ”€β”€ frontend/
β”‚   └── index.html              ← Full chat UI (HTML + CSS + JS)
β”‚
β”œβ”€β”€ notebook/
β”‚   β”œβ”€β”€ vector_indexing_pipeline.ipynb   ← One-time embedding + FAISS setup
β”‚   └── Data_Cleaning_EDA.ipynb          ← Data cleaning pipeline
β”‚
└── README.md

πŸ”Œ API Endpoints

POST /chat

// Request
{
    "query": "How do I reverse a list in Python?",
    "top_k": 5
}

// Response
{
    "answer": "You can reverse a list using [::-1]...",
    "is_relevant": true,
    "is_tech": true,
    "sources": [
        {
            "rank": 1,
            "question_id": 3940128,
            "title": "How do I reverse a list or loop over it backwards?",
            "primary_tag": "python",
            "top_answers": ["To get a new reversed list..."]
        }
    ],
    "path": "rag"
}

GET /health

{
    "status": "ok",
    "pipeline_ready": true,
    "total_vectors": 498643,
    "total_answers": 1199928,
    "model": "all-MiniLM-L6-v2",
    "score_threshold": 0.5
}

πŸ“– Related Research


πŸ™ Acknowledgements


πŸ“„ License

MIT License β€” feel free to use, modify and build on this project.