A document question answering system with FastAPI backend and React frontend that allows you to upload documents (PDF, DOCX, TXT) and ask natural language questions about them.
- Document upload and processing (PDF, DOCX, TXT)
- Document chunking and embedding generation
- Hybrid search (vector + keyword) for accurate information retrieval
- OpenAI embeddings with e5 model fallback
- React UI for document upload and question asking
doc-qa-demo/
│
├─ api/ # FastAPI code
│ ├─ ingest.py # parses & chunks docs
│ ├─ embed.py # wraps OpenAI + fallback e5
│ ├─ retrieve.py # hybrid search
│ └─ main.py # /ask endpoint
└─ web/ # React UI
-
Create and activate a Python virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install required packages from requirements.txt to avoid dependency conflicts:
cd api pip install -r requirements.txtNote: If you're using TensorFlow, there may be compatibility issues with protobuf versions. The requirements.txt file specifies protobuf<5.0.0 to ensure compatibility with TensorFlow.
-
Set your OpenAI API key as an environment variable:
export OPENAI_API_KEY=your-api-key-here # On Windows: set OPENAI_API_KEY=your-api-key-here
-
Run the FastAPI server:
uvicorn main:app --reload
The API will run on http://localhost:8000
-
Install Node.js dependencies:
cd web npm install -
Run the React development server:
npm start
The UI will run on http://localhost:3000
- Open http://localhost:3000 in your browser
- Upload one or more documents using the document uploader
- Ask questions about the uploaded documents
- View the results showing the most relevant document chunks
GET /: Root endpoint to check if API is runningPOST /documents/upload: Upload a document for processingPOST /ask: Ask a question about the documentsGET /documents: List all uploaded documents
- Python 3.8+
- Node.js 14+
- OpenAI API key (optional, e5 model will be used as fallback)
If you encounter dependency conflicts with protobuf and TensorFlow, you can fix them by installing specific versions:
pip uninstall protobuf -y
pip install protobuf>=3.20.3,<5.0.0For other dependency issues, try installing the requirements.txt file with the --no-deps flag and then manually installing the conflicting packages:
pip install -r requirements.txt --no-deps
pip install package-name==specific-version