|
| 1 | +# Architecture Overview |
| 2 | + |
| 3 | +This document provides a detailed architecture diagram of the Azure Search OpenAI demo application, showing the complete RAG (Retrieval Augmented Generation) flow and all components. |
| 4 | + |
| 5 | +## System Architecture |
| 6 | + |
| 7 | +```mermaid |
| 8 | +graph TB |
| 9 | + %% User Interface Layer |
| 10 | + User[👤 User] --> WebApp[🌐 React Frontend<br/>TypeScript/Vite] |
| 11 | + |
| 12 | + %% Application Layer |
| 13 | + WebApp --> Backend[🐍 Python Backend<br/>Quart API] |
| 14 | + |
| 15 | + %% Authentication (Optional) |
| 16 | + Backend --> Auth{🔐 Authentication<br/>Enabled?} |
| 17 | + Auth -->|Yes| EntraID[🏢 Microsoft Entra ID<br/>Azure AD] |
| 18 | + Auth -->|No| ProcessRequest[Process Request] |
| 19 | + EntraID --> ProcessRequest |
| 20 | + |
| 21 | + %% Core RAG Flow |
| 22 | + ProcessRequest --> RAGFlow{📋 Request Type} |
| 23 | + RAGFlow -->|Chat| ChatApproach[💬 Chat Approach<br/>chatreadretrieveread.py] |
| 24 | + RAGFlow -->|Ask| AskApproach[❓ Ask Approach<br/>retrievethenread.py] |
| 25 | + RAGFlow -->|Vision| VisionApproach[👁️ Vision Approach<br/>GPT-4V enabled] |
| 26 | + |
| 27 | + %% Search and Retrieval |
| 28 | + ChatApproach --> QueryRewrite[🔄 Query Rewriting<br/>OpenAI API] |
| 29 | + QueryRewrite --> SearchIndex[🔍 Azure AI Search<br/>Vector + Keyword Search] |
| 30 | + AskApproach --> SearchIndex |
| 31 | + VisionApproach --> SearchIndex |
| 32 | + VisionApproach --> VisionAPI[👁️ Azure AI Vision<br/>Image Analysis] |
| 33 | + |
| 34 | + %% Document Storage and Processing |
| 35 | + SearchIndex --> BlobStorage[💾 Azure Blob Storage<br/>Document Storage] |
| 36 | + DocProcessor[📄 Document Processor<br/>prepdocs.py] --> BlobStorage |
| 37 | + DocProcessor --> SearchIndex |
| 38 | + DocProcessor --> FormRecognizer[📋 Azure AI Document Intelligence<br/>Text Extraction] |
| 39 | + DocProcessor --> OpenAIEmbedding[🧮 Azure OpenAI<br/>Embedding Generation] |
| 40 | + |
| 41 | + %% AI Processing |
| 42 | + ChatApproach --> OpenAI[🤖 Azure OpenAI Service<br/>GPT Models] |
| 43 | + AskApproach --> OpenAI |
| 44 | + VisionApproach --> OpenAI |
| 45 | + OpenAIEmbedding --> SearchIndex |
| 46 | + |
| 47 | + %% Response Generation |
| 48 | + OpenAI --> ResponseProcessor[📝 Response Processing<br/>Citations & Sources] |
| 49 | + ResponseProcessor --> WebApp |
| 50 | + |
| 51 | + %% Optional Features |
| 52 | + Backend --> ChatHistory{💭 Chat History<br/>Enabled?} |
| 53 | + ChatHistory -->|Cosmos DB| CosmosDB[🌌 Azure Cosmos DB<br/>Persistent Storage] |
| 54 | + ChatHistory -->|Browser| BrowserStorage[🖥️ Browser Storage<br/>Local Storage] |
| 55 | + ChatHistory -->|Disabled| NoHistory[No Storage] |
| 56 | + |
| 57 | + Backend --> Speech{🎤 Speech<br/>Enabled?} |
| 58 | + Speech -->|Yes| SpeechService[🗣️ Azure Speech Service<br/>STT/TTS] |
| 59 | + Speech -->|No| NoSpeech[No Speech] |
| 60 | + |
| 61 | + %% Monitoring and Observability |
| 62 | + Backend --> AppInsights[📊 Azure Application Insights<br/>Monitoring & Telemetry] |
| 63 | + OpenAI --> AppInsights |
| 64 | + SearchIndex --> AppInsights |
| 65 | + |
| 66 | + %% Deployment Infrastructure |
| 67 | + WebApp --> ContainerApps[📦 Azure Container Apps<br/>Default Hosting] |
| 68 | + Backend --> ContainerApps |
| 69 | + ContainerApps --> ContainerRegistry[📋 Azure Container Registry<br/>Container Images] |
| 70 | + |
| 71 | + %% Alternative Deployment |
| 72 | + WebApp -.-> AppService[🌐 Azure App Service<br/>Alternative Hosting] |
| 73 | + Backend -.-> AppService |
| 74 | + |
| 75 | + %% Security and Access Control |
| 76 | + Backend --> AccessControl{🛡️ Access Control<br/>Enabled?} |
| 77 | + AccessControl -->|Yes| SecurityFilter[🔒 Security Filters<br/>OID/Groups based] |
| 78 | + AccessControl -->|No| PublicAccess[Public Access] |
| 79 | + SecurityFilter --> SearchIndex |
| 80 | + |
| 81 | + %% Styling |
| 82 | + classDef userInterface fill:#e1f5fe |
| 83 | + classDef application fill:#f3e5f5 |
| 84 | + classDef azureService fill:#fff3e0 |
| 85 | + classDef storage fill:#e8f5e8 |
| 86 | + classDef optional fill:#fce4ec |
| 87 | + classDef security fill:#ffebee |
| 88 | + |
| 89 | + class User,WebApp userInterface |
| 90 | + class Backend,ProcessRequest,RAGFlow,ChatApproach,AskApproach,VisionApproach,ResponseProcessor application |
| 91 | + class OpenAI,SearchIndex,FormRecognizer,OpenAIEmbedding,VisionAPI,AppInsights,ContainerApps,ContainerRegistry,AppService,SpeechService azureService |
| 92 | + class BlobStorage,CosmosDB,BrowserStorage storage |
| 93 | + class ChatHistory,Speech,NoHistory,NoSpeech,VisionApproach optional |
| 94 | + class Auth,EntraID,AccessControl,SecurityFilter,PublicAccess security |
| 95 | +``` |
| 96 | + |
| 97 | +## Key Components |
| 98 | + |
| 99 | +### Frontend Layer |
| 100 | +- **React Frontend**: Modern web application built with TypeScript and Vite |
| 101 | +- **User Interface**: Provides Chat and Ask interfaces for different interaction modes |
| 102 | + |
| 103 | +### Backend Layer |
| 104 | +- **Python API**: Quart-based asynchronous web framework |
| 105 | +- **RAG Approaches**: Different strategies for retrieval and generation |
| 106 | + - Chat: Multi-turn conversations with context |
| 107 | + - Ask: Single-turn Q&A |
| 108 | + - Vision: Image-aware processing with GPT-4V |
| 109 | + |
| 110 | +### Azure Services |
| 111 | +- **Azure OpenAI Service**: Core AI model hosting (GPT-4, GPT-3.5, Ada embeddings) |
| 112 | +- **Azure AI Search**: Vector and keyword search with semantic ranking |
| 113 | +- **Azure Blob Storage**: Document storage and content management |
| 114 | +- **Azure AI Document Intelligence**: Text extraction from various document formats |
| 115 | +- **Azure Container Apps**: Primary hosting platform (scalable, serverless) |
| 116 | +- **Azure Application Insights**: Monitoring, logging, and telemetry |
| 117 | + |
| 118 | +### Optional Components |
| 119 | +- **Microsoft Entra ID**: Authentication and authorization |
| 120 | +- **Azure Cosmos DB**: Persistent chat history storage |
| 121 | +- **Azure AI Vision**: Image analysis for vision-enabled scenarios |
| 122 | +- **Azure Speech Service**: Speech-to-text and text-to-speech capabilities |
| 123 | + |
| 124 | +### Data Flow |
| 125 | + |
| 126 | +1. **Document Ingestion**: Documents are processed by `prepdocs.py`, which extracts text using Azure AI Document Intelligence and generates embeddings using Azure OpenAI |
| 127 | +2. **User Query**: User submits a question through the React frontend |
| 128 | +3. **Authentication** (Optional): User identity is verified against Microsoft Entra ID |
| 129 | +4. **Query Processing**: Backend determines the appropriate RAG approach based on request type |
| 130 | +5. **Search & Retrieval**: Query is executed against Azure AI Search to find relevant documents |
| 131 | +6. **AI Generation**: Retrieved content is combined with the user query and sent to Azure OpenAI for response generation |
| 132 | +7. **Response**: AI-generated response with citations is returned to the user |
| 133 | + |
| 134 | +### Security Features |
| 135 | +- **Access Control**: Optional row-level security based on user identity |
| 136 | +- **Security Filters**: OID and group-based filtering of search results |
| 137 | +- **Private Endpoints**: Network isolation capabilities for enhanced security |
| 138 | + |
| 139 | +## Deployment Options |
| 140 | + |
| 141 | +The application supports two primary deployment modes: |
| 142 | +- **Azure Container Apps** (Default): Serverless container hosting with automatic scaling |
| 143 | +- **Azure App Service**: Traditional PaaS hosting option |
| 144 | + |
| 145 | +Both options use Azure Container Registry for container image management and Azure Application Insights for monitoring. |
0 commit comments