RAG Chatbot lets users upload PDFs and ask questions answered with document-grounded AI.
- Frontend: Next.js, TypeScript, Tailwind CSS, Framer Motion
- Backend: FastAPI, LangChain, OpenAI, Pinecone
- Frontend deployment: Vercel
- Backend deployment: Render free tier
.
|-- frontend/
| |-- app/
| |-- lib/api.ts
| |-- .env.local.example
| `-- vercel.json
`-- backend/
|-- main.py
|-- ingest.py
|-- query.py
|-- models.py
|-- requirements.txt
|-- .env.example
`-- render.yaml
cd frontend
npm install
copy .env.local.example .env.local
npm run devSet frontend/.env.local:
NEXT_PUBLIC_API_URL=http://localhost:8000The frontend runs at http://localhost:3000 by default.
cd backend
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
copy .env.example .env
uvicorn main:app --reloadSet backend/.env:
OPENAI_API_KEY=your_openai_api_key
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_INDEX_NAME=your_pinecone_index_name
FRONTEND_URL=http://localhost:3000The backend runs at http://localhost:8000 by default.
- Create or log in to a Pinecone account.
- Create a new index.
- Use these index settings:
- Dimensions:
1536 - Metric:
cosine - Vector type: dense
- Dimensions:
- Use a serverless/free-tier compatible cloud and region.
- Copy the index name into
PINECONE_INDEX_NAME. - Copy your Pinecone API key into
PINECONE_API_KEY.
The dimension must be 1536 because the backend uses OpenAI text-embedding-3-small.
- Push this project to GitHub.
- Go to Render and create a new Blueprint or Web Service.
- If using Blueprint, point Render to
backend/render.yaml. - If creating a Web Service manually, use:
- Root directory:
backend - Runtime: Python
- Build command:
pip install -r requirements.txt - Start command:
uvicorn main:app --host 0.0.0.0 --port $PORT
- Root directory:
- Add these Render environment variables:
OPENAI_API_KEYPINECONE_API_KEYPINECONE_INDEX_NAMEFRONTEND_URL
- Set
FRONTEND_URLto your Vercel production URL after the frontend is deployed, for example:
FRONTEND_URL=https://your-project.vercel.app- Deploy the service.
- After deployment, test:
https://your-render-service.onrender.com/health
Expected response:
{"status":"ok","version":"1.0.0"}- Go to Vercel and import the GitHub repository.
- Set the frontend root directory to
frontend. - Add this Vercel environment variable:
NEXT_PUBLIC_API_URL=https://your-render-service.onrender.com- Deploy the frontend.
- Copy the Vercel production URL.
- Go back to Render and set backend
FRONTEND_URLto that Vercel URL. - Redeploy or restart the Render backend so CORS uses the new value.
frontend/vercel.json includes a placeholder rewrite:
{
"rewrites": [
{
"source": "/api/:path*",
"destination": "RENDER_URL/api/:path*"
}
]
}Before relying on /api/... rewrites, replace RENDER_URL with your actual Render backend URL. The current frontend API utility uses NEXT_PUBLIC_API_URL, so setting that environment variable is the required deployment step.
Render backend:
OPENAI_API_KEY=your_openai_api_key
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_INDEX_NAME=your_pinecone_index_name
FRONTEND_URL=https://your-project.vercel.appVercel frontend:
NEXT_PUBLIC_API_URL=https://your-render-service.onrender.comLocal frontend:
NEXT_PUBLIC_API_URL=http://localhost:8000Frontend:
cd frontend
npm run lint
npm run build
npm run devBackend:
cd backend
uvicorn main:app --reloadUpload test:
POST /upload
multipart/form-data field: file
Expected shape:
{"success":true,"doc_id":"...","filename":"...","chunk_count":1,"message":"PDF uploaded and ingested successfully"}Query test:
POST /query
{"question":"What is this document about?","doc_id":"..."}
Expected shape:
{"success":true,"answer":"...","sources":[{"page":1,"text":"..."}],"doc_id":"..."}