This project presents the development and implementation of an intelligent Insurance Retrieval-Augmented Generation (RAG) system that provides instant, accurate answers to insurance policy queries through advanced semantic analysis and multi-document processing capabilities.
The Insurance RAG Assistant addresses critical challenges in insurance information retrieval by combining semantic query optimization with multi-document RAG architecture. The system automatically analyzes query complexity and intent, dynamically adjusting search parameters without manual tuning. Key innovations include intelligent K-value optimization that adapts retrieval depth based on query patterns, plan-specific filtering for targeted searches, and a hybrid architecture supporting both REST API integration and real-time chat interfaces.
The system demonstrates significant improvements in query processing efficiency and accuracy through automatic semantic pattern detection, achieving optimal document retrieval across four insurance plan types (Activ Assure, Activ Secure, Activ Health, Activ One). The implementation leverages Azure OpenAI services with FAISS vector indexing and Django REST framework, providing a scalable solution for insurance document processing and query resolution.
Key Contributions:
1.1 Overall Architecture
The system implements a three-tier architecture with intelligent query processing:
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Streamlit β β Django REST β β Document β
β Frontend βββββΆβ API Backend βββββΆβ Processing β
β β β β β β
β - Chat Interfaceβ β - Query Analysis β β - PDF Ingestion β
β - Plan Selectionβ β - Semantic K Opt β β - Chunking β
β - Results Displayβ β - RAG Pipeline β β - FAISS Index β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βΌ
ββββββββββββββββββββ
β Semantic Query β
β Analyzer β
β β
β - Pattern Detect β
β - K Optimization β
β - Complexity β
β Assessment β
ββββββββββββββββββββ
1.2 Core Components
Backend (Django REST API)
views.py
: REST API endpoints and request handlingsemantic_query_analyzer.py
: Intelligent query pattern detectioningestion.py
: PDF processing and vector index creationutils.py
: Shared utilities and helper functionsprompt_config.py
: LLM prompt templates and configurationslogging_config.py
: Comprehensive logging systemFrontend (Streamlit)
insurance_chat.py
: Interactive chat interface with plan selection2.1 Document Ingestion Process
# Document processing workflow PDF Files β Text Extraction β Chunking β Embedding Generation β FAISS Index
2.2 Vector Index Creation
2.3 Chunking Strategy
3.1 Query Pattern Detection
The system implements embedding-based similarity analysis to classify queries into patterns:
3.2 Dynamic K-Value Optimization
# Automatic optimization logic Query Input β Pattern Detection β Complexity Assessment β K-Value Calculation
Algorithm Features:
4.1 Retrieval Process
4.2 Generation Process
5.1 Core Technologies
5.2 Configuration Management
AZURE_OPENAI_API_KEY=your_api_key_here AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/ AZURE_OPENAI_API_VERSION=2024-02-15-preview AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=gpt-4 AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME=text-embedding-ada-002
6.1 REST API Endpoints
POST /api/build-index/
: Vector index creation from PDF documentsPOST /api/query/
: Enhanced query processing with semantic analysisGET /api/plan_names/
: Available insurance plan retrievalGET /api/test-connection/
: System health check6.2 Enhanced Query Endpoint
POST /api/query/ { "q": "What documents are required for a cashless claim?", "k": "4", "plan_name": "Activ Assure,Activ Secure,Activ Health,Activ One" }
1.1 Query Processing Capabilities
1.2 Semantic Analysis Performance
"k_optimization": { "user_requested": 4, "system_calculated": 7, "pattern_detected": "procedural_info", "confidence": 0.8142491852568631, "reasoning": "Detected 'procedural_info' query pattern" }
Query Pattern Recognition:
2.1 Multi-Document RAG Performance
2.2 Example Query Results
{ "answer": "For a cashless claim under the Activ Secure insurance plan...", "source_docs": [ { "plan_name": "Activ Health", "source_file": "Activ Health.pdf", "page_number": 35, "content_preview": "(iv) Payment receipt of any change in the travel booking..." } ], "total_docs_found": 7, "plans_searched": ["Activ Assure", "Activ Secure", "Activ Health", "Activ One"] }
3.1 Architecture Benefits
3.2 Integration Capabilities
4.1 Use Case Coverage
4.2 System Advantages
5.1 Technical Constraints
5.2 Domain and Data Limitations
5.3 Functional Limitations
5.4 Response Quality Issues
The Insurance RAG Assistant successfully demonstrates advanced semantic query processing capabilities in the insurance domain. The system's intelligent K-value optimization and multi-document RAG architecture provide significant improvements over traditional keyword-based search systems.
Key Achievements:
Technical Innovation:
The semantic query analyzer represents a significant advancement in RAG system design, automatically adapting retrieval parameters based on query complexity and intent. This eliminates a major pain point in traditional RAG implementations where users must manually tune search parameters.