An AI-powered semantic search and Q&A tool for GitHub codebases โ plus an ML-based issue auto-triage system. Ask natural-language questions about any repo and get grounded answers with file/line citations.
- What This Is
- Architecture
- Folder Structure
- Prerequisites
- Part 1 โ API Keys & Accounts
- Part 2 โ Database Setup (pgvector)
- Part 3 โ Backend Setup
- Part 4 โ Frontend Setup
- Part 5 โ Training the Issue Classifier
- Part 6 โ GitHub Webhook Setup
- Part 7 โ Running Everything Locally
- Part 8 โ Deployment
- Cost Breakdown
- Interview Talking Points
Two features in one project:
- RAG-powered code Q&A โ index any GitHub repo's Python files (parsed by function/class using the
astmodule), embed them, store in pgvector, and answer natural-language questions grounded in the actual code with citations. - ML-based issue auto-triage โ a scikit-learn classifier (TF-IDF + Logistic Regression) trained on historical labeled GitHub issues, automatically labels new issues as
bug,feature_request,question, orduplicatevia a webhook.
flowchart TD
A["๐ฆ GitHub Repo"] --> B["โ๏ธ AST parser<br/>(function/class chunks)"]
B --> C["๐ข sentence-transformers<br/>embeddings"]
C --> D["๐๏ธ pgvector (PostgreSQL)"]
E["๐ฌ User question"] --> F["๐ Embed + search pgvector"]
F -->|"top-5 chunks"| G["โจ Gemini LLM"]
G -->|"grounded answer + citations"| E
H["๐ New GitHub Issue"] --> I["๐ท๏ธ TF-IDF + LogisticRegression"]
I -->|"category + confidence"| J["๐ค Auto-label via GitHub API"]
style A fill:#181717,color:#fff
style B fill:#64748B,color:#fff
style C fill:#4285F4,color:#fff
style D fill:#336791,color:#fff
style E fill:#0EA5E9,color:#fff
style F fill:#4285F4,color:#fff
style G fill:#4285F4,color:#fff
style H fill:#181717,color:#fff
style I fill:#F59E0B,color:#000
style J fill:#181717,color:#fff
codemind/
โโโ README.md
โโโ frontend/ # Next.js app
โ โโโ package.json
โ โโโ next.config.js
โ โโโ tailwind.config.js
โ โโโ postcss.config.js
โ โโโ tsconfig.json
โ โโโ .env.local.example
โ โโโ app/
โ โโโ layout.tsx
โ โโโ globals.css
โ โโโ page.tsx # Connect/index a repo
โ โโโ chat/page.tsx # Chat UI
โโโ backend/ # Python FastAPI app
โโโ requirements.txt
โโโ .env.example
โโโ main.py # API routes
โโโ db.py # Postgres/pgvector connection
โโโ schema.sql # Table definitions
โโโ indexer.py # Clone, AST parse, chunk, embed
โโโ chat.py # Retrieval + LLM generation
โโโ webhook.py # Issue auto-triage webhook
โโโ classifier/
โโโ fetch_training_data.py # Pull labeled issues from GitHub
โโโ train.py # Train TF-IDF + LogisticRegression
โโโ predict.py # Load model, predict category
- Node.js 18+ and Python 3.10+
- PostgreSQL with the ability to install extensions (local install, or a free-tier managed Postgres from Render/Railway/Supabase โ all support pgvector)
- Free Gemini API key from ai.google.dev
- GitHub Personal Access Token
- Git installed locally
Gemini API key:
- Go to
ai.google.devโ Get API key โ sign in โ Create API key โ copy it
GitHub Personal Access Token:
- GitHub โ Settings โ Developer settings โ Personal access tokens โ Fine-grained tokens โ Generate new token
- Permissions needed: Issues: Read & write, Contents: Read-only
- Copy the token
GitHub Webhook Secret: just generate any random string yourself (used to verify webhook authenticity):
openssl rand -hex 20Option A โ Local Postgres:
# Install pgvector extension (Mac via Homebrew)
brew install pgvector
# Create the database
createdb codemindOption B โ Free managed Postgres (Render, Railway, or Supabase โ all support pgvector):
- Create a free Postgres instance on any of these
- Copy the connection string they give you
Either way, once you have a DATABASE_URL, run the schema:
cd backend
python db.pyThis enables the vector extension and creates all tables (repos, code_chunks, issue_predictions).
cd backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
# Fill in DATABASE_URL, GEMINI_API_KEY, GITHUB_TOKEN, GITHUB_WEBHOOK_SECRETRun the API server:
uvicorn main:app --reload --port 8000Visit http://localhost:8000 โ you should see {"status": "ok", "service": "CodeMind API"}.
cd frontend
npm install
cp .env.local.example .env.local
# Set NEXT_PUBLIC_API_URL=http://localhost:8000
npm run devVisit http://localhost:3000 โ enter a repo like psf/requests (a smaller, well-known Python repo, good for testing) and click Index Repository.
cd backend/classifier
python fetch_training_data.py # pulls labeled issues from a public repo
python train.py # trains and saves issue_classifier.joblibYou'll see a classification_report printed showing precision/recall per category โ this tells you how well the model performs before trusting it in production. The trained model is saved as issue_classifier.joblib in the classifier/ folder, which predict.py loads automatically.
To train on a different repo's issues, edit the repo name at the bottom of fetch_training_data.py.
To enable auto-triage on your own repo:
- Go to your repo โ Settings โ Webhooks โ Add webhook
- Payload URL:
https://your-backend-url.com/webhook/issues - Content type:
application/json - Secret: the same value you set as
GITHUB_WEBHOOK_SECRET - Which events: select Issues only
- Save
Now every new issue opened on that repo will trigger the classifier and auto-apply a label if confidence is high enough.
# Terminal 1 โ backend
cd backend
source venv/bin/activate
uvicorn main:app --reload --port 8000
# Terminal 2 โ frontend
cd frontend
npm run devTest flow:
- Visit
localhost:3000โ index a repo (e.g.,psf/requests) - Wait for indexing to complete โ redirected to chat
- Ask: "How does this library handle retries?"
- See a grounded answer with file/line citations
Test the webhook locally (needs a public URL โ use ngrok):
ngrok http 8000Use the ngrok HTTPS URL as your webhook's Payload URL temporarily while testing.
- Push the
backend/folder to a GitHub repo - Create a new Web Service on Render/Railway, point it at your repo
- Set build command:
pip install -r requirements.txt - Set start command:
uvicorn main:app --host 0.0.0.0 --port $PORT - Add all environment variables from
.envin the platform's dashboard - Deploy โ you'll get a live URL like
https://codemind-backend.onrender.com
Use their free-tier Postgres, enable the vector extension via their SQL console, then run schema.sql against it.
cd frontend
npm install -g vercel
vercel login
vercelSet NEXT_PUBLIC_API_URL to your deployed backend URL in Vercel's environment variables, then:
vercel --prodChange the Payload URL to your real deployed backend: https://your-backend.onrender.com/webhook/issues
| Resource | Free Tier | Cost |
|---|---|---|
| Vercel (frontend) | 100GB bandwidth/mo | $0 |
| Render/Railway (backend + Postgres) | Free tier available | $0 |
| Gemini API | Free tier | $0 |
| sentence-transformers | Runs locally, no API | $0 |
| scikit-learn | Local training, no API | $0 |
Total: $0/month for personal/demo use.
- Why AST parsing instead of naive text chunking: code has structure โ chunking by function/class (not arbitrary word counts) keeps each embedding semantically coherent and enables precise file/line citations.
- Why pgvector instead of a dedicated vector DB: one database handles both structured data and vector search โ simpler infra, no extra service to manage.
- Why a classical ML model (not an LLM) for issue triage: it's a well-defined, small-output classification task โ TF-IDF + Logistic Regression trains in seconds, costs nothing per prediction, and is easy to retrain as label definitions evolve. Using an LLM here would be slower and costlier for no real accuracy benefit.
- Where training data came from: pulled real historical labeled issues via the GitHub API โ no manual labeling needed, a production-realistic way to bootstrap a dataset.
- Confidence thresholding: the webhook only auto-applies a label above a confidence threshold, otherwise leaves it for a human โ avoiding confidently wrong auto-labels.
- Support multi-language parsing via
tree-sitter(currently Python-only viaast) - Add streaming responses in the chat UI
- Add a feedback mechanism (๐/๐) to track answer quality
- Re-train the classifier periodically as new labeled issues accumulate
- Add authentication so multiple users can index their own private repos
Built as a developer-focused RAG + ML project combining semantic code search with automated issue triage.