# RERA Professional AI Legal Assistant

A high-performance RAG (Retrieval-Augmented Generation) system built to parse, index, and query Real Estate Regulatory Authority (RERA) documentation, including rules, regulations, and tribunal judgements.

##  Features

- **Professional Architecture**: Industry-standard directory structure for scalability and maintainability.
- **Hybrid OCR Engine**: Seamlessly handles both digital and scanned (image-based) PDF documents using PyMuPDF and Tesseract.
- **FAISS Vector Store**: High-speed local similarity search for document retrieval.
- **LCEL RAG Chain**: Utilizes LangChain Expression Language for robust, predictable AI pipelines.
- **FastAPI Integration**: Production-ready REST API with Pydantic validation and health monitoring.
- **Persistence Layer**: Smart indexing that only processes new documents once and persists the state locally.

## 🛠 Tech Stack

- **Backend**: FastAPI (Python 3.10+)
- **LLM**: Google Gemini 2.5 Flash
- **Vector DB**: FAISS (Local)
- **Document Processing**: PyMuPDF (fitz) + Tesseract OCR
- **Orchestration**: LangChain (LCEL)

##  Project Structure

```text
├── app/
│   ├── api/          # FASTful API endpoints
│   ├── core/         # Global configuration & settings
│   ├── services/     # Core business logic (RAG & AI)
│   ├── utils/        # Helper utilities (OCR & Document Processing)
├── Data/             # PDF Document Repository
├── main.py           # Application Entry Point
├── faiss_index/      # Persistent Vector Database (Generated)
└── .env              # Environment Configuration
```

## Quick Start

### 1. Prerequisites
- Python 3.10 or higher.
- [Tesseract OCR Engine](https://github.com/UB-Mannheim/tesseract/wiki) installed on your system.

### 2. Installation
```powershell
# Clone the repository and navigate to the root
# Install dependencies
pip install -r requirements.txt
```

### 3. Configuration
Create a `.env` file in the root directory:
```env
GEMINI_API_KEY=your_google_api_key_here
FAISS_INDEX_PATH=faiss_index
DATA_DIR=Data
MODEL_NAME=gemini-2.5-flash
```

### 4. Running the Application
```powershell
python main.py
```
The application will automatically scan the `Data/` directory, perform OCR where necessary, and start the API server on `http://localhost:8080`.

##  API Usage

### Send a Legal Query
**Endpoint**: `POST /ai/chat`
**Body**:
```json
{
  "message": "What are the rules regarding delivery of possession?"
}
```

### Check Service Status
**Endpoint**: `GET /ai/status`

---
*Developed for professional RERA legal assistance.*
