FastAPI + React application for document Q&A using PageIndex tree-based retrieval (vectorless RAG).
- PDF upload and asynchronous indexing via PageIndex
- Flow-based trace panel showing query mapping and retrieved chunks
- Tree-structured retrieval over document sections
- Multi-model chat routing with Gemini-first defaults
- Friendly handling for common upstream errors (
InsufficientCredits,LimitReached)
- Backend: FastAPI, Uvicorn, PageIndex SDK, OpenAI-compatible clients
- Frontend: React, TypeScript, Vite
- Python dependency management:
pyproject.toml
.
├── main.py # FastAPI backend
├── pyproject.toml # Python dependencies
├── frontend/
│ ├── src/App.tsx # Main UI and chat flow
│ ├── src/index.css # UI styling
│ └── package.json # Frontend scripts/deps
└── README.md
- Python 3.11+
- Node.js 18+
- npm
Create a .env file in the project root:
PAGEINDEX_API_KEY=your_pageindex_key
GEMINI_API_KEY=your_gemini_key
# Optional: only needed if selecting OpenRouter models from the UI
OPENROUTER_API_KEY=your_openrouter_key# From project root
python -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -e .Run backend:
uvicorn main:app --reloadBackend runs on http://127.0.0.1:8000.
cd frontend
npm install
npm run devFrontend runs on http://127.0.0.1:5173.
- Start backend from project root
- Start frontend from
frontend/ - Open the frontend URL
- Upload PDF and wait for
Index Ready - Ask questions in chat
GET /api/health- Basic service health and client availability
POST /api/upload- Upload PDF, returns
doc_idand processing status
- Upload PDF, returns
GET /api/upload-status/{doc_id}- Poll indexing status and fetch generated tree when complete
POST /api/chat- Run tree search + grounded answer generation
402 InsufficientCredits: PageIndex credits exhausted429 LimitReached: PageIndex usage limit hit400 Document index is not ready yet: chat sent before indexing completed
Frontend production build:
cd frontend
npm run buildBackend syntax check:
python -m py_compile main.py- If
.envkeys were changed, restart backend so keys reload - If upload succeeds but chat fails, ensure
Index Readyappears before asking - If Gemini model errors occur, select a supported Gemini option in the model picker
- If CORS/network errors appear, verify backend is running on port 8000
- Never commit
.envor API keys - Rotate keys if exposed
- Restrict CORS origins before deploying to production
Add your preferred license here (for example, MIT)