Skip to content

VIKAS9793/SaralPolicy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SaralPolicy - Local AI Insurance Analysis

SaralPolicy Banner

Tagline: "Insurance ka fine print, ab saaf saaf."

Status: 🟒 POC/Demo (Remediation Complete) | Progress: 26/26 Issues Resolved (100%) | View Status | Implementation Report

License: MIT Python 3.9+ Tests PRs Welcome Code Style

FastAPI Ollama ChromaDB Pydantic SQLAlchemy

RAGAS OpenTelemetry Huey Indic Parler-TTS

πŸ› οΈ Tech Stack

Python FastAPI Ollama ChromaDB Pydantic SQLite OpenTelemetry HTML5 CSS3 JavaScript Material Design

πŸ”§ OSS Frameworks

Framework Purpose License Stars
RAGAS RAG Evaluation (Faithfulness, Relevancy) Apache 2.0 7k+
OpenTelemetry Metrics, Tracing, Observability Apache 2.0 1.5k+
Huey Background Task Queue (SQLite backend) MIT 5k+
Indic Parler-TTS High-Quality Hindi Neural TTS (0.9B params) Apache 2.0 AI4Bharat

🎯 What is SaralPolicy?

An AI-powered insurance document analysis system (POC/Demo) that uses local AI models to provide clear, easy-to-understand summaries in Hindi and English, with comprehensive guardrails and human-in-the-loop validation. All processing happens locally for complete privacy.

Status: 🟑 POC/Demo - See Status and Production Engineering Evaluation for details.


πŸ–ΌοΈ Application Screenshots

Main Interface

SaralPolicy Main UI Beautiful Material 3 design with drag & drop document upload

SaralPolicy Analysis View Real-time policy analysis with AI-powered insights

RAG Indexing & Knowledge Base

RAG Indexing Step 1 IRDAI knowledge base indexing with ChromaDB

RAG Indexing Step 2 Hybrid search combining BM25 + Vector embeddings

Policy Analysis Features

Policy Analysis Step 1 Comprehensive policy breakdown with key terms

Policy Analysis Step 2 Coverage details and exclusion highlights

Exclusion Detection

Policy Exclusion Detection AI-powered exclusion identification with IRDAI citations


✨ Core Features

πŸš€ Performance & Processing

  • ⚑ Optimized Document Parsing: Parallel PDF processing with ThreadPoolExecutor (4 workers)
  • πŸ“¦ Smart Caching: Document and embedding caching with MD5 hashing
  • πŸ”„ Batch Operations: Parallel embedding generation for faster RAG indexing
  • πŸ“Š Performance Monitoring: Real-time metrics tracking for all operations

πŸ€– AI & Intelligence

  • πŸ€– Local AI Analysis: Ollama + Gemma 2 2B model running locally for privacy
  • 🧠 RAG-Enhanced: Retrieval-Augmented Generation with IRDAI knowledge base (39 chunks)
  • πŸ” Hybrid Search: BM25 (keyword) + Vector (semantic) search with query caching
  • πŸ“€ Advanced Embeddings: nomic-embed-text (274MB) with connection pooling

πŸ›‘οΈ Safety & Quality

  • πŸ”’ Advanced Guardrails: Input validation, PII protection, and safety checks
  • πŸ‘₯ Human-in-the-Loop: Expert review for low-confidence analyses
  • πŸ“Š RAGAS Evaluation: Faithfulness, relevancy, precision metrics (Apache 2.0)

πŸ“„ Document Processing

  • πŸ“ Multi-Format Support: PDF, DOCX, and TXT files with drag & drop
  • πŸ”‘ Key Insights: Coverage details, exclusions, and important terms
  • ❓ Interactive Q&A: Document-specific Q&A with IRDAI augmentation

🎨 User Experience

  • 🎨 Modern UI: Beautiful Material 3 design with responsive layout
  • 🌐 Bilingual: Results in both Hindi and English
  • πŸ“Š Text-to-Speech: High-quality Hindi neural TTS (Indic Parler-TTS)
  • πŸ”’ 100% Privacy: Complete local processing, no data leaves your machine

πŸš€ Quick Start

Prerequisites

  • OS: Windows, Linux, or macOS
  • Python: 3.9 or higher
  • RAM: Minimum 8GB (16GB recommended)
  • Disk Space: ~10GB (for models and virtual environment)

1. Setup Environment

# Clone the repository
git clone https://github.com/VIKAS9793/SaralPolicy.git
cd SaralPolicy

# Create virtual environment
python -m venv venv
venv\Scripts\activate  # Windows
# source venv/bin/activate  # Linux/Mac

# Upgrade pip
python -m pip install --upgrade pip

2. Install Dependencies

cd backend
pip install -r requirements.txt

3. Install and Setup Ollama

# Download and install Ollama from https://ollama.ai/download
# Pull required models
ollama pull gemma2:2b
ollama pull nomic-embed-text

# Start Ollama service (keep running in background)
ollama serve

4. Environment Configuration

# Copy environment template
copy .env.example .env  # Windows
# cp .env.example .env  # Linux/Mac

# Edit .env and add your HuggingFace token (optional, for Indic Parler-TTS)
# HF_TOKEN=hf_your_token_here

5. Index IRDAI Knowledge Base

python scripts/index_irdai_knowledge.py

6. Run the Application

python main.py

7. Open in Browser

Visit http://localhost:8000 to access the Material 3 web interface.


πŸ“ Project Structure

SaralPolicy/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py                          # Main FastAPI application
β”‚   β”œβ”€β”€ requirements.txt                 # All dependencies (pinned versions)
β”‚   β”œβ”€β”€ .env.example                     # Environment template (safe to commit)
β”‚   β”œβ”€β”€ .env                             # Your secrets (NEVER commit)
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ config.py                    # Validated configuration (Pydantic)
β”‚   β”‚   β”œβ”€β”€ dependencies.py              # Dependency Injection Container
β”‚   β”‚   β”œβ”€β”€ routes/                      # API Endpoints
β”‚   β”‚   β”œβ”€β”€ services/                    # Business Logic Services
β”‚   β”‚   β”‚   β”œβ”€β”€ ollama_llm_service.py    # Local LLM via Ollama
β”‚   β”‚   β”‚   β”œβ”€β”€ rag_service.py           # RAG with ChromaDB
β”‚   β”‚   β”‚   β”œβ”€β”€ policy_service.py        # Policy analysis orchestration
β”‚   β”‚   β”‚   β”œβ”€β”€ guardrails_service.py    # Input/output validation
β”‚   β”‚   β”‚   β”œβ”€β”€ tts_service.py           # Text-to-speech orchestration
β”‚   β”‚   β”‚   β”œβ”€β”€ indic_parler_engine.py   # Hindi neural TTS (Apache 2.0)
β”‚   β”‚   β”‚   β”œβ”€β”€ rag_evaluation_service.py    # RAGAS evaluation
β”‚   β”‚   β”‚   β”œβ”€β”€ observability_service.py     # OpenTelemetry metrics
β”‚   β”‚   β”‚   └── task_queue_service.py        # Huey task queue
β”‚   β”‚   β”œβ”€β”€ middleware/                  # Security middleware
β”‚   β”‚   β”œβ”€β”€ prompts/                     # Versioned prompt registry
β”‚   β”‚   β”œβ”€β”€ models/                      # Data models
β”‚   β”‚   └── db/                          # Database layer
β”‚   β”œβ”€β”€ tests/                           # All tests (197 passing)
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   β”œβ”€β”€ chroma/                      # ChromaDB persistent storage
β”‚   β”‚   └── irdai_knowledge/             # IRDAI regulatory documents
β”‚   β”œβ”€β”€ scripts/                         # Utility scripts
β”‚   β”œβ”€β”€ static/                          # Frontend assets (CSS, JS)
β”‚   └── templates/                       # HTML templates
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ SETUP.md                         # Installation guide
β”‚   β”œβ”€β”€ TROUBLESHOOTING.md               # Common issues & solutions
β”‚   β”œβ”€β”€ SYSTEM_ARCHITECTURE.md           # Detailed architecture
β”‚   β”œβ”€β”€ STATUS.md                        # Current status
β”‚   β”œβ”€β”€ setup/                           # Additional setup guides
β”‚   β”œβ”€β”€ reports/                         # Technical reports
β”‚   β”œβ”€β”€ adr/                             # Architectural decisions
β”‚   └── product-research/                # Strategic documents (16 docs)
β”œβ”€β”€ assets/                              # Screenshots and banners
β”œβ”€β”€ .gitignore                           # Git ignore (includes .kiro/, .env)
β”œβ”€β”€ README.md                            # This file
β”œβ”€β”€ CONTRIBUTING.md                      # Contribution guidelines
└── LICENSE                              # MIT License

πŸ”§ Technical Details

Core Infrastructure

Component Technology Version
Backend FastAPI 0.115.6
AI Model Ollama + Gemma 2 2B Local
Embeddings nomic-embed-text 274MB
Vector DB ChromaDB 0.5.23
Validation Pydantic 2.10.3
Database SQLAlchemy + SQLite 2.0.36
UI Material Design 3 HTML/CSS/JS

OSS Frameworks (No API Keys Required)

Framework Purpose License Fallback
RAGAS RAG evaluation (faithfulness, relevancy) Apache 2.0 Heuristic scoring
OpenTelemetry Metrics, tracing, observability Apache 2.0 Built-in metrics
Huey Background task queue (SQLite backend) MIT Synchronous execution
Indic Parler-TTS High-quality Hindi neural TTS (0.9B params) Apache 2.0 gTTS β†’ pyttsx3

Text-to-Speech Performance

Hardware ~100 chars ~500 chars
CPU (default) 2-5 min 5-10 min
GPU (CUDA) 5-15 sec 15-45 sec
GPU (Apple M1/M2) 10-30 sec 30-90 sec

Note: Neural TTS on CPU is slow but produces high-quality Hindi speech. For faster responses, the system falls back to gTTS automatically.


πŸ—οΈ System Architecture

graph TB
    subgraph FE["🎨 FRONTEND"]
        UI["Material 3 Web UI"]
    end

    subgraph API["⚑ API LAYER"]
        FAST["FastAPI Server"]
    end

    subgraph CORE["πŸ”§ CORE SERVICES"]
        DOC["Document Service"]
        RAG["RAG Service"]
        LLM["Ollama LLM<br/>gemma2:2b"]
        POLICY["Policy Service"]
    end

    subgraph STORAGE["πŸ’Ύ STORAGE"]
        CHROMA["ChromaDB"]
        IRDAI["IRDAI Knowledge<br/>39 chunks"]
    end

    subgraph SAFETY["πŸ›‘οΈ SAFETY"]
        GUARD["Guardrails"]
        EVAL["RAGAS Evaluation"]
        HITL["Human-in-the-Loop"]
    end

    subgraph AUX["πŸ“Š AUXILIARY"]
        TTS["TTS Service<br/>Indic Parler-TTS"]
        TRANS["Translation<br/>Argos Translate"]
    end

    UI --> FAST
    FAST --> DOC
    FAST --> POLICY
    POLICY --> RAG
    POLICY --> LLM
    RAG --> CHROMA
    IRDAI --> CHROMA
    POLICY --> GUARD
    POLICY --> EVAL
    EVAL --> HITL
    FAST --> TTS
    FAST --> TRANS
Loading

πŸ“– Full Architecture: See SYSTEM_ARCHITECTURE.md


πŸ§ͺ Testing

cd backend

# Run all tests (197 tests)
python -m pytest tests/ -v

# Run specific test categories
python -m pytest tests/test_security.py -v          # Security tests
python -m pytest tests/test_oss_frameworks.py -v    # OSS framework tests
python -m pytest tests/test_hallucination_detection.py -v  # Hallucination tests

# Run with coverage
python -m pytest tests/ --cov=app --cov-report=html

Test Categories

Category Tests Description
Configuration 23 Config validation, environment handling
Security 15 Input sanitization, PII protection, CORS
Error Paths 23 Graceful degradation, fallback handling
Hallucination 15 Detection accuracy, grounding validation
OSS Frameworks 28 RAGAS, OpenTelemetry, Huey integration
Integration 20+ End-to-end workflow tests
Total 197 All passing

πŸ”’ Privacy & Security

  • 100% Local Processing: All AI analysis happens on your machine
  • No Cloud APIs: Zero data sent to external services
  • No API Keys Required: Core functionality works offline
  • Advanced Guardrails: Input validation, PII protection, safety checks
  • HITL Validation: Expert review for quality assurance
  • Secure Secrets: .env file in .gitignore, never committed

Environment Variables

# backend/.env (NEVER commit this file)
HF_TOKEN=hf_your_token_here  # Optional: For Indic Parler-TTS
OLLAMA_HOST=localhost:11434  # Default Ollama endpoint

πŸ“š Documentation

Quick Links

Product Research (16 Documents)

# Document Description
1 Executive Summary Problem, solution, market opportunity (β‚Ή1,200 Cr)
2 Product Vision Long-term vision and strategy
3 Business Case Market sizing (515M policies), revenue models
4 Competitive Analysis Competitor landscape, differentiation
5 Product Roadmap Feature timeline, milestones
6 PRD Functional requirements, user stories
7 Requirements Technical specifications
8 Architecture System design, data flow
9 Explainability AI transparency, evaluation metrics
10 User Journey UX flows, interaction design
11 Privacy & Compliance IRDAI, DPDP Act 2023
12 Testing Strategy QA plans, coverage
13 Go-to-Market Launch plan, pricing
14 Risk Register Risk identification, mitigation
15 Ethical AI AI ethics, bias mitigation
16 Metrics & KPIs Success metrics, North Star

πŸ“Š API Endpoints

Endpoint Method Purpose
/ GET Serve frontend UI
/upload POST Upload policy document
/analyze POST Analyze uploaded policy
/rag/ask POST Ask question via RAG
/rag/stats GET RAG service statistics
/tts POST Generate audio summary
/translate POST Hindi ↔ English translation

🎯 POC Goals

  • Validate Core Concept: Does local AI analysis provide value?
  • Test Accuracy: Are summaries and insights accurate?
  • User Experience: Is the Material 3 interface intuitive?
  • Guardrails Effectiveness: Are safety checks working?
  • HITL Integration: How often is expert review needed?
  • Market Fit: Is there demand for privacy-first insurance analysis?

πŸ‘€ Author

Vikas Sahani
Product Manager & Main Product Lead

Engineering Team:

  • Kiro (AI Co-Engineering Assistant)
  • Antigravity (AI Co-Assistant & Engineering Support)

🀝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md before submitting.

# Quick start for contributors
git checkout -b feature/AmazingFeature
git commit -m 'feat: add AmazingFeature'
git push origin feature/AmazingFeature
# Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see LICENSE for details.


πŸ™ Acknowledgments

  • IRDAI for insurance regulatory guidelines
  • Ollama for local LLM infrastructure
  • Google for Gemma models
  • ChromaDB for vector database
  • FastAPI community for excellent framework
  • AI4Bharat for Indic Parler-TTS Hindi speech synthesis
  • HuggingFace for model hosting and transformers library

πŸ“š Citations

If you use SaralPolicy or its components in your research, please cite:

Indic Parler-TTS (Hindi Text-to-Speech)

@inproceedings{sankar25_interspeech,
  title     = {{Rasmalai : Resources for Adaptive Speech Modeling in IndiAn Languages with Accents and Intonations}},
  author    = {Ashwin Sankar and Yoach Lacombe and Sherry Thomas and Praveen {Srinivasa Varadhan} and Sanchit Gandhi and Mitesh M. Khapra},
  year      = {2025},
  booktitle = {{Interspeech 2025}},
  pages     = {4128--4132},
  doi       = {10.21437/Interspeech.2025-2758},
}

@misc{lacombe-etal-2024-parler-tts,
  author = {Yoach Lacombe and Vaibhav Srivastav and Sanchit Gandhi},
  title = {Parler-TTS},
  year = {2024},
  publisher = {GitHub},
  howpublished = {\url{https://github.com/huggingface/parler-tts}}
}

@misc{lyth2024natural,
  title={Natural language guidance of high-fidelity text-to-speech with synthetic annotations},
  author={Dan Lyth and Simon King},
  year={2024},
  eprint={2402.01912},
  archivePrefix={arXiv},
}

Model: ai4bharat/indic-parler-tts (Apache 2.0, 0.9B parameters)


πŸ“ž Support

Found a security issue? Please email vikassahani17@gmail.com instead of using the public issue tracker.


Made with ❀️ to make insurance understandable for everyone
"Because everyone deserves to understand what they're paying for."


This is a POC/demo system. For production deployment, see the Production Engineering Evaluation and Remediation Plan.