RAG Chatbot Setup Guide
RAG Chatbot Setup Guide
This guide will help you set up a RAG (Retrieval-Augmented Generation) chatbot that allows visitors to ask questions about Ninaโs research papers.
๐ Overview
The chatbot consists of:
- Backend service (
rag-backend/) - Handles AI queries - Frontend widget (
_includes/chatbot.html) - Chat interface on website - GitHub Actions (optional) - Auto-updates when PDFs are added
๐ Quick Start
1. Set Up Backend Locally
cd rag-backend
npm install
cp .env.example .env
# Edit .env and add your OPENAI_API_KEY
npm run ingest # Creates vector store and uploads PDFs
# Copy the VECTOR_STORE_ID to .env
npm start # Test locally
2. Deploy Backend
Choose one:
- Render.com (easiest, free tier available)
- Railway.app ($5/month, more reliable)
- Vercel/Netlify Functions (serverless)
See rag-backend/README.md for detailed deployment steps.
3. Update Chatbot Widget
Edit _includes/chatbot.html line ~180:
const API_URL = "https://your-backend-url.com/api/chat";
4. Test
- Push changes to GitHub
- Visit your site
- Click the โAskโ button (bottom right)
- Try asking: โWhat is Ninaโs research about?โ
๐ฐ Costs
OpenAI API:
- Vector Store: ~$0.10/GB/month storage
- Chat queries: ~$0.15-0.60 per 1M input tokens
- Estimated: $5-20/month for moderate traffic
Hosting:
- Render: Free tier (spins down after inactivity)
- Railway: $5/month
- Vercel/Netlify: Free tier available
Total estimated: $5-25/month
๐ง GitHub Actions (Optional)
To automatically ingest new PDFs when added:
- Go to repo Settings โ Secrets โ Actions
- Add secrets:
OPENAI_API_KEYVECTOR_STORE_ID
- Push a PDF to
/files/- it will auto-ingest!
๐ Files Created
rag-backend/- Backend service_includes/chatbot.html- Frontend widget.github/workflows/ingest-pdfs.yml- Auto-ingestion workflowRAG_SETUP.md- This file
๐ Troubleshooting
Chatbot not appearing?
- Check browser console for errors
- Verify API_URL is correct in
chatbot.html - Ensure backend is deployed and running
Backend errors?
- Check environment variables are set
- Verify vector store ID is correct
- Check OpenAI API key is valid
PDFs not ingesting?
- Ensure PDFs are text-based (not scanned images)
- Check OpenAI API key has sufficient credits
- Review ingestion logs
๐ Next Steps
- Customize chatbot styling in
chatbot.html - Adjust system prompt in
server.jsfor different tone - Add rate limiting (already included)
- Monitor costs at platform.openai.com/usage
๐ Need Help?
Check:
rag-backend/README.md- Backend documentationrag-backend/ENV_SETUP.md- Environment setup- OpenAI docs: https://platform.openai.com/docs