A high-performance document question-answering service built with FastAPI and LangChain, implementing Retrieval-Augmented Generation (RAG) for intelligent document analysis.
- API Docs: https://hackrx-rag-app.onrender.com/docs
- GitHub Repository: https://github.com/sujeetgund/fastapi-rag-service.git
This service allows users to upload documents via URL and ask multiple questions about the content. Using advanced RAG techniques with LangChain, it provides accurate, context-aware answers by retrieving relevant document sections and generating responses.
- Document Processing: Support for various document formats (PDF, DOC, TXT, etc.)
- Multi-Question Support: Process multiple questions in a single request
- RESTful API: Clean, well-documented FastAPI endpoints
- RAG Pipeline: Advanced retrieval-augmented generation for accurate answers
- Dockerized: Easy deployment with Docker support
- Type Safety: Full Pydantic model validation
- Error Handling: Comprehensive exception handling and logging
- FastAPI: Modern, fast web framework for building APIs
- LangChain: Framework for developing applications with language models
- Pydantic: Data validation and settings management
- Docker: Containerization for easy deployment
- UV: Fast Python package installer and resolver
fastapi-rag-service/
├── api/
│ └── routes.py # API endpoint definitions
├── core/
│ ├── config.py # Configuration settings
│ ├── exceptions.py # Custom exception classes
│ └── security.py # Security and authentication
├── models/
│ └── schemas.py # Pydantic models and schemas
├── services/
│ ├── document_service.py # Document processing logic
│ └── qa_service.py # Question-answering service
├── .dockerignore
├── .gitignore
├── .python-version
├── Dockerfile # Docker configuration
├── main.py # FastAPI application entry point
├── pyproject.toml # Project metadata and dependencies
├── README.md
├── requirements.txt # Python dependencies
└── uv.lock # UV lock file
The input structure for the primary /hackrx/run endpoint.
| Field | Type | Description | Example |
|---|---|---|---|
| documents | str | URL of the document to process | "https://example.com/document.pdf" |
| questions | List[str] | List of questions to answer | ["What is the main topic?", "What are the key findings?"] |
The output structure from the RAG pipeline.
| Field | Type | Description | Example |
|---|---|---|---|
| answers | List[str] | Generated answers in the same order as questions | ["The main topic is...", "The key findings are..."] |
- Python 3.9+
- Docker (optional)
- UV package manager (recommended)
- Clone the repository
git clone https://github.com/sujeetgund/fastapi-rag-service.git
cd fastapi-rag-service- Install dependencies
Using UV (recommended):
uv syncUsing pip:
pip install -r requirements.txt- Run the application
uvicorn main:app --reloadThe API will be available at http://localhost:8000
- Build the Docker image
docker build -t fastapi-rag-service .- Run the container
docker run -p 8000:8000 fastapi-rag-servicePOST /hackrx/run
Process a document and answer questions about its content.
curl -X POST "http://localhost:8000/hackrx/run" \
-H "Content-Type: application/json" \
-d '{
"documents": "https://example.com/research-paper.pdf",
"questions": [
"What is the main research question?",
"What methodology was used?",
"What are the key conclusions?"
]
}'{
"answers": [
"The main research question focuses on investigating the impact of machine learning algorithms on data processing efficiency.",
"The study employed a mixed-methods approach combining quantitative analysis with qualitative interviews.",
"The key conclusions indicate that ML algorithms can improve processing efficiency by up to 40% while maintaining data accuracy."
]
}Visit http://localhost:8000/docs to access the interactive Swagger UI documentation.
Configuration settings can be modified in core/config.py:
- API settings
- Model parameters
- Document processing options
- Security configurations
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.