# RAGFlow - Kiến Trúc Hệ Thống ## 1. Tổng Quan Kiến Trúc RAGFlow sử dụng kiến trúc **Microservices** với các thành phần được container hóa bằng Docker. Hệ thống được thiết kế theo mô hình **3-tier architecture** kết hợp với **event-driven architecture** cho xử lý bất đồng bộ. ## 2. Sơ Đồ Kiến Trúc Tổng Quan ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ CLIENT LAYER │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │ │ Web App │ │ Mobile App │ │ Python SDK │ │ REST API │ │ │ │ (React/TS) │ │ (Future) │ │ Client │ │ Client │ │ │ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │ │ │ │ │ │ │ └─────────┼─────────────────┼─────────────────┼─────────────────┼──────────────────┘ │ │ │ │ └─────────────────┴────────┬────────┴─────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────────────────────┐ │ GATEWAY LAYER │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────────────────────────────────────────────────────────────────┐ │ │ │ NGINX Reverse Proxy │ │ │ │ (Load Balancing, SSL Termination) │ │ │ │ Port: 80/443 │ │ │ └─────────────────────────────────────┬───────────────────────────────────┘ │ │ │ │ └────────────────────────────────────────┼─────────────────────────────────────────┘ │ ┌──────────────────────────────┼──────────────────────────────┐ │ │ │ ▼ ▼ ▼ ┌─────────────────────────────────────────────────────────────────────────────────┐ │ APPLICATION LAYER │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────┐ │ │ │ RAGFlow Server │ │ Admin Server │ │ MCP Server │ │ │ │ (Flask/Quart) │ │ (Flask) │ │ (MCP Protocol) │ │ │ │ Port: 9380 │ │ Port: 9381 │ │ Port: 9382 │ │ │ │ │ │ │ │ │ │ │ │ ┌─────────────────┐ │ │ ┌─────────────────┐ │ │ ┌─────────────┐ │ │ │ │ │ API Blueprints │ │ │ │ Admin APIs │ │ │ │ MCP Handler │ │ │ │ │ │ - kb_app │ │ │ │ - User Mgmt │ │ │ │ - Tools │ │ │ │ │ │ - document_app │ │ │ │ - System Cfg │ │ │ │ - Resources │ │ │ │ │ │ - dialog_app │ │ │ │ - Monitoring │ │ │ └─────────────┘ │ │ │ │ │ - canvas_app │ │ │ └─────────────────┘ │ │ │ │ │ │ │ - search_app │ │ │ │ │ │ │ │ │ │ - file_app │ │ │ │ │ │ │ │ │ └─────────────────┘ │ │ │ │ │ │ │ └───────────┬───────────┘ └───────────────────────┘ └───────────────────┘ │ │ │ │ └──────────────┼───────────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────────────────────┐ │ SERVICE LAYER │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ │ │ Business Logic │ │ RAG Pipeline │ │ Agent System │ │ │ │ Services │ │ Engine │ │ Engine │ │ │ │ │ │ │ │ │ │ │ │ - UserService │ │ - Parser │ │ - Canvas │ │ │ │ - DialogService │ │ - Tokenizer │ │ - Components │ │ │ │ - DocService │ │ - Splitter │ │ - Tools │ │ │ │ - KBService │ │ - Embedder │ │ - Workflows │ │ │ │ - TaskService │ │ - Reranker │ │ │ │ │ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ │ │ │ │ │ │ │ └────────────────────┼────────────────────┘ │ │ │ │ │ ┌─────────────────────────────┼─────────────────────────────────────────────┐ │ │ │ DeepDoc Processing Engine │ │ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ │ │ PDF │ │ DOCX │ │ PPT │ │ Excel │ │ HTML │ │ │ │ │ │ Parser │ │ Parser │ │ Parser │ │ Parser │ │ Parser │ │ │ │ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │ │ │ │ │ │ │ ┌──────────────────────────────────────────────────────────────┐ │ │ │ │ │ Vision/OCR Processing (Layout Analysis) │ │ │ │ │ └──────────────────────────────────────────────────────────────┘ │ │ │ └───────────────────────────────────────────────────────────────────────────┘ │ │ │ └──────────────────────────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────────────────────┐ │ DATA LAYER │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ │ │ MySQL │ │ Redis/Valkey │ │ MinIO │ │ │ │ (Primary DB) │ │ (Cache) │ │ (Object Store) │ │ │ │ Port: 5455 │ │ Port: 6379 │ │ Port: 9000/9001 │ │ │ │ │ │ │ │ │ │ │ │ - Users │ │ - Sessions │ │ - Documents │ │ │ │ - Tenants │ │ - Cache │ │ - Files │ │ │ │ - Knowledgebase │ │ - Rate Limit │ │ - Chunks │ │ │ │ - Documents │ │ - Task Queue │ │ - Images │ │ │ │ - Dialogs │ │ │ │ │ │ │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │ │ │ │ ┌──────────────────────────────────────────────────────────────────────────┐ │ │ │ Vector Database Layer │ │ │ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ │ │ │ │ Elasticsearch │ │ Infinity │ │ OpenSearch │ │ │ │ │ │ (Default) │ │ (Alternative) │ │ (Alternative) │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ - Vector Search │ │ - Hybrid Search │ │ - Vector Search │ │ │ │ │ │ - Full-text │ │ - Full-text │ │ - Full-text │ │ │ │ │ │ - BM25 │ │ - BM25 │ │ - BM25 │ │ │ │ │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ └──────────────────────────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────────────────────┐ │ EXTERNAL SERVICES │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────────────────────────────────────────────────────────────────┐ │ │ │ LLM Providers │ │ │ │ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ │ │ │ │ │ OpenAI │ │ Claude │ │ Gemini │ │ Qwen │ │ Groq │ │ Ollama │ │ │ │ │ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ┌─────────────────────────────────────────────────────────────────────────┐ │ │ │ Data Source Connectors │ │ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ │ │Confluence│ │ Notion │ │ Slack │ │ Gmail │ │SharePoint│ │ │ │ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ┌─────────────────────────────────────────────────────────────────────────┐ │ │ │ Agent Tools & APIs │ │ │ │ ┌────────┐ ┌─────────┐ ┌────────┐ ┌────────┐ ┌─────────┐ ┌────────┐ │ │ │ │ │ Tavily │ │ Google │ │ ArXiv │ │ GitHub │ │Wikipedia│ │ Weather│ │ │ │ │ └────────┘ └─────────┘ └────────┘ └────────┘ └─────────┘ └────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ │ │ └──────────────────────────────────────────────────────────────────────────────────┘ ``` ## 3. Kiến Trúc Chi Tiết Các Thành Phần ### 3.1 API Server Architecture ``` ┌──────────────────────────────────────────────────────────────┐ │ RAGFlow API Server │ │ (ragflow_server.py) │ ├──────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────────────────────────────────────────────────┐ │ │ │ Flask/Quart Application │ │ │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐ │ │ │ │ │ CORS │ │ Session │ │ JWT Auth │ │ │ │ │ │ Middleware │ │ Middleware │ │ Middleware │ │ │ │ │ └─────────────┘ └─────────────┘ └─────────────────┘ │ │ │ └─────────────────────────────────────────────────────────┘ │ │ │ │ │ ┌───────────────────────────┼───────────────────────────────┐ │ │ API Blueprints │ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ │ kb_app │ │ doc_app │ │dialog_app│ │canvas_app│ │ │ │ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ │ │ │ │ │ │ │ │ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ │file_app │ │search_app│ │ llm_app │ │ user_app │ │ │ │ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ │ │ └───────┼────────────┼────────────┼────────────┼───────────┘ │ │ │ │ │ │ │ ┌───────┴────────────┴────────────┴────────────┴───────────┐ │ │ Service Layer │ │ │ ┌────────────────┐ ┌────────────────┐ │ │ │ │ UserService │ │ DialogService │ │ │ │ │ - register() │ │ - chat() │ │ │ │ │ - login() │ │ - stream() │ │ │ │ │ - get_user() │ │ - completion() │ │ │ │ └────────────────┘ └────────────────┘ │ │ │ │ │ │ ┌────────────────┐ ┌────────────────┐ │ │ │ │ DocumentService│ │ KBService │ │ │ │ │ - upload() │ │ - create() │ │ │ │ │ - parse() │ │ - list() │ │ │ │ │ - chunk() │ │ - delete() │ │ │ │ └────────────────┘ └────────────────┘ │ │ └──────────────────────────────────────────────────────────┘ │ │ │ │ ┌───────────────────────────┴───────────────────────────────┐ │ │ Database Layer (Peewee ORM) │ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │ │ User │ │ Tenant │ │Document │ │ Dialog │ │ │ │ │ Model │ │ Model │ │ Model │ │ Model │ │ │ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │ └──────────────────────────────────────────────────────────┘ │ │ └──────────────────────────────────────────────────────────────┘ ``` ### 3.2 RAG Pipeline Architecture ``` ┌──────────────────────────────────────────────────────────────────────────┐ │ RAG Processing Pipeline │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ INGESTION PIPELINE │ │ │ │ │ │ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ │ │ File │───▶│ Parser │───▶│Tokenizer │───▶│ Splitter │ │ │ │ │ │ Upload │ │ │ │ │ │ (Chunker)│ │ │ │ │ └──────────┘ └──────────┘ └──────────┘ └────┬─────┘ │ │ │ │ │ │ │ │ │ ┌──────────────────────────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ │ │ Embedding│───▶│ Index │───▶│ Store │ │ │ │ │ │ Model │ │ Creation │ │ (ES/Inf) │ │ │ │ │ └──────────┘ └──────────┘ └──────────┘ │ │ │ │ │ │ │ └───────────────────────────────────────────────────────────────────┘ │ │ │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ RETRIEVAL PIPELINE │ │ │ │ │ │ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ │ │ Query │───▶│ Query │───▶│ Embedding│───▶│ Hybrid │ │ │ │ │ │ Input │ │ Analysis │ │ Query │ │ Search │ │ │ │ │ └──────────┘ └──────────┘ └──────────┘ └────┬─────┘ │ │ │ │ │ │ │ │ │ ┌──────────────────────────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ │ │ Candidate│───▶│ Reranker │───▶│ Context │───▶│ LLM │ │ │ │ │ │ Chunks │ │ │ │ Building │ │ Response │ │ │ │ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │ │ │ │ │ │ └───────────────────────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────┘ ``` ### 3.3 Agent Workflow Architecture ``` ┌──────────────────────────────────────────────────────────────────────────┐ │ Agent Canvas Architecture │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ Canvas Orchestrator │ │ │ │ (canvas.py) │ │ │ └──────────────────────────────┬──────────────────────────────────────┘ │ │ │ │ │ ┌───────────────────────────┼───────────────────────────┐ │ │ │ │ │ │ │ ▼ ▼ ▼ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │ BEGIN │─────────────▶│ LLM │─────────────▶│RETRIEVAL│ │ │ │Component│ │Component│ │Component│ │ │ └─────────┘ └─────────┘ └─────────┘ │ │ │ │ │ │ │ │ ┌───────────────────┼───────────────────────┘ │ │ │ │ │ │ │ ▼ ▼ ▼ │ │ ┌─────────────┐ ┌─────────┐ ┌─────────────┐ │ │ │ CATEGORIZE │ │ MESSAGE │ │ WEBHOOK │ │ │ │ Component │ │Component│ │ Component │ │ │ └─────────────┘ └─────────┘ └─────────────┘ │ │ │ │ │ │ │ └────────────────────────┼────────────────────┘ │ │ │ │ │ ▼ │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ TOOLS INTEGRATION │ │ │ │ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ │ │ │ │ │ Tavily │ │ ArXiv │ │ GitHub │ │ Email │ │Code │ │ │ │ │ │ Search │ │ Search │ │ API │ │ Send │ │Executor│ │ │ │ │ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ │ │ └───────────────────────────────────────────────────────────────────────────┘ ``` ## 4. Data Flow Architecture ### 4.1 Document Ingestion Flow ``` ┌────────────────────────────────────────────────────────────────────────────┐ │ Document Ingestion Flow │ ├────────────────────────────────────────────────────────────────────────────┤ │ │ │ User Upload │ │ │ │ │ ▼ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ API │────▶│ File │────▶│ MinIO │────▶│ Task │ │ │ │ Endpoint │ │ Service │ │ Storage │ │ Queue │ │ │ └──────────┘ └──────────┘ └──────────┘ └────┬─────┘ │ │ │ │ │ ┌────────────────────────────────┘ │ │ │ │ │ ▼ │ │ ┌──────────────────────────────────────────────────────────────────┐ │ │ │ Background Task Processor │ │ │ │ │ │ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ │ │ Parser │───▶│Extractor │───▶│ Chunker │───▶│ Embedder │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ - PDF │ │ - Text │ │ - Token │ │ - OpenAI │ │ │ │ │ │ - DOCX │ │ - Table │ │ - Sent │ │ - BGE │ │ │ │ │ │ - HTML │ │ - Image │ │ - Page │ │ - Cohere │ │ │ │ │ └──────────┘ └──────────┘ └──────────┘ └────┬─────┘ │ │ │ │ │ │ │ │ └────────────────────────────────────────────────────────┼────────┘ │ │ │ │ │ ┌─────────────────────────────────┘ │ │ │ │ │ ▼ │ │ ┌──────────────────────────────────────────────────────────────────┐ │ │ │ Storage Layer │ │ │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │ │ │ │ MySQL │ │ Elasticsearch│ │ MinIO │ │ │ │ │ │ (Metadata) │ │ (Vectors) │ │ (Files) │ │ │ │ │ └──────────────┘ └──────────────┘ └──────────────┘ │ │ │ └──────────────────────────────────────────────────────────────────┘ │ │ │ └───────────────────────────────────────────────────────────────────────────┘ ``` ### 4.2 Query Processing Flow ``` ┌────────────────────────────────────────────────────────────────────────────┐ │ Query Processing Flow │ ├────────────────────────────────────────────────────────────────────────────┤ │ │ │ User Query: "What is the revenue for Q3 2024?" │ │ │ │ │ ▼ │ │ ┌──────────────────────────────────────────────────────────────────────┐ │ │ │ 1. QUERY UNDERSTANDING │ │ │ │ ┌──────────────┐ │ │ │ │ │ Query Parser │──▶ Extract: entities, intent, keywords │ │ │ │ └──────────────┘ │ │ │ └──────────────────────────────────────────────────────────────────────┘ │ │ │ │ │ ▼ │ │ ┌──────────────────────────────────────────────────────────────────────┐ │ │ │ 2. RETRIEVAL │ │ │ │ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ │ │ │ │ Embedding │───▶│ Hybrid │───▶│ Candidate │ │ │ │ │ │ Query │ │ Search │ │ Chunks │ │ │ │ │ └────────────┘ │ │ │ (Top 100) │ │ │ │ │ │ Vector+BM25│ └────────────┘ │ │ │ │ └────────────┘ │ │ │ └──────────────────────────────────────────────────────────────────────┘ │ │ │ │ │ ▼ │ │ ┌──────────────────────────────────────────────────────────────────────┐ │ │ │ 3. RERANKING │ │ │ │ ┌────────────┐ ┌────────────┐ │ │ │ │ │ Reranker │───▶│ Top-K │ │ │ │ │ │ Model │ │ Chunks │ │ │ │ │ │ │ │ (Top 5) │ │ │ │ │ └────────────┘ └────────────┘ │ │ │ └──────────────────────────────────────────────────────────────────────┘ │ │ │ │ │ ▼ │ │ ┌──────────────────────────────────────────────────────────────────────┐ │ │ │ 4. GENERATION │ │ │ │ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ │ │ │ │ Prompt │───▶│ LLM │───▶│ Response │ │ │ │ │ │ Builder │ │ (GPT-4) │ │ + Sources │ │ │ │ │ └────────────┘ └────────────┘ └────────────┘ │ │ │ └──────────────────────────────────────────────────────────────────────┘ │ │ │ │ │ ▼ │ │ Response: "The revenue for Q3 2024 was $X million... [source: doc.pdf]" │ │ │ └─────────────────────────────────────────────────────────────────────────────┘ ``` ## 5. Deployment Architecture ### 5.1 Docker Compose Deployment ``` ┌──────────────────────────────────────────────────────────────────────────────┐ │ Docker Compose Deployment │ ├──────────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────────────────────────────────────────────────────────────────┐ │ │ │ Docker Network │ │ │ │ (ragflow-network) │ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ │ │ │ │ ┌───────────────────────────────┼───────────────────────────────┐ │ │ │ │ │ │ │ ▼ ▼ ▼ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ nginx │ ◀──────────────▶│ ragflow- │◀──────────────────▶│ ragflow- │ │ │ │ :80/443 │ │ server │ │ admin │ │ │ └──────────┘ │ :9380 │ │ :9381 │ │ │ │ └────┬─────┘ └──────────┘ │ │ │ │ │ │ │ ┌──────────────────┼──────────────────────┐ │ │ │ │ │ │ │ │ │ ▼ ▼ ▼ │ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ │ mysql │ │ redis │ │elasticsearch│ │ │ │ │ :5455 │ │ :6379 │ │ :9200 │ │ │ │ └──────────┘ └──────────┘ └──────────┘ │ │ │ │ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ │ minio │ │ sandbox │ │ tei │ │ │ │ │:9000/9001│ │ :9385 │ │ :6380 │ │ │ │ └──────────┘ └──────────┘ └──────────┘ │ │ │ │ │ ┌────┴─────────────────────────────────────────────────────────────────┐ │ │ │ Volumes │ │ │ │ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ │ │ │ │mysql_data │ │ es_data │ │minio_data │ │ redis_data │ │ │ │ │ └────────────┘ └────────────┘ └────────────┘ └────────────┘ │ │ │ └──────────────────────────────────────────────────────────────────────┘ │ │ │ └───────────────────────────────────────────────────────────────────────────────┘ ``` ## 6. Security Architecture ``` ┌──────────────────────────────────────────────────────────────────────────────┐ │ Security Architecture │ ├──────────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────────────────────────────────────────────────────────────────┐ │ │ │ Authentication Layer │ │ │ │ │ │ │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │ │ │ │ JWT │ │ OAuth │ │ API │ │ │ │ │ │ Tokens │ │ (GitHub, │ │ Tokens │ │ │ │ │ │ │ │ OIDC) │ │ │ │ │ │ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │ │ │ │ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ │ │ │ │ ▼ │ │ ┌─────────────────────────────────────────────────────────────────────────┐ │ │ │ Authorization Layer │ │ │ │ │ │ │ │ ┌─────────────────────────────────────────────────────────────────┐ │ │ │ │ │ Multi-Tenancy Model │ │ │ │ │ │ │ │ │ │ │ │ Tenant A Tenant B Tenant C │ │ │ │ │ │ ┌──────┐ ┌──────┐ ┌──────┐ │ │ │ │ │ │ │Users │ │Users │ │Users │ │ │ │ │ │ │ │KBs │ │KBs │ │KBs │ │ │ │ │ │ │ │Docs │ │Docs │ │Docs │ │ │ │ │ │ │ └──────┘ └──────┘ └──────┘ │ │ │ │ │ │ │ │ │ │ │ └─────────────────────────────────────────────────────────────────┘ │ │ │ │ │ │ │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │ │ │ │ Role-Based │ │ Team │ │ Resource │ │ │ │ │ │ Access │ │ Permissions│ │ Ownership │ │ │ │ │ │ Control │ │ │ │ │ │ │ │ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │ │ │ │ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ │ │ │ │ ▼ │ │ ┌─────────────────────────────────────────────────────────────────────────┐ │ │ │ Encryption Layer │ │ │ │ │ │ │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │ │ │ │ RSA │ │ HTTPS │ │ Password │ │ │ │ │ │ Key Pair │ │ (TLS) │ │ Bcrypt │ │ │ │ │ │ (conf/*.pem)│ │ │ │ │ │ │ │ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │ │ │ │ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ │ │ └───────────────────────────────────────────────────────────────────────────────┘ ``` ## 7. Scalability Architecture ``` ┌──────────────────────────────────────────────────────────────────────────────┐ │ Scalability Architecture │ ├──────────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────────────────────────────────────────────────────────────────┐ │ │ │ Horizontal Scaling │ │ │ │ │ │ │ │ Load Balancer (Nginx) │ │ │ │ │ │ │ │ │ ┌──────────────────┼──────────────────┐ │ │ │ │ │ │ │ │ │ │ │ ▼ ▼ ▼ │ │ │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │ │ │ │ Server #1 │ │ Server #2 │ │ Server #N │ │ │ │ │ │ (Instance) │ │ (Instance) │ │ (Instance) │ │ │ │ │ └──────────────┘ └──────────────┘ └──────────────┘ │ │ │ │ │ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ┌─────────────────────────────────────────────────────────────────────────┐ │ │ │ Database Scaling │ │ │ │ │ │ │ │ MySQL: Elasticsearch: Redis: │ │ │ │ - Read Replicas - Cluster Mode - Sentinel │ │ │ │ - Connection Pool - Sharding - Cluster Mode │ │ │ │ - Index Partitioning │ │ │ │ │ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ┌─────────────────────────────────────────────────────────────────────────┐ │ │ │ Async Processing │ │ │ │ │ │ │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │ │ │ │ Task │───▶│ Redis │───▶│ Worker │ │ │ │ │ │ Producer │ │ Queue │ │ Consumer │ │ │ │ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │ │ │ │ │ │ │ Tasks: Document parsing, Embedding, Indexing │ │ │ │ │ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ │ │ └───────────────────────────────────────────────────────────────────────────────┘ ``` ## 8. Tóm Tắt Kiến Trúc | Layer | Components | Technology | |-------|------------|------------| | Client | Web App, SDK, API | React, Python SDK, REST | | Gateway | Reverse Proxy | Nginx | | Application | API Server, Admin | Flask/Quart | | Service | Business Logic | Python Services | | Processing | RAG, DeepDoc, Agent | Python, ML Models | | Data | Storage, Cache, Vector | MySQL, Redis, ES, MinIO | | External | LLM, Connectors, Tools | OpenAI, Claude, APIs | ### Đặc Điểm Nổi Bật 1. **Microservices**: Các service độc lập, dễ scale 2. **Event-Driven**: Xử lý async cho document processing 3. **Multi-Tenant**: Hỗ trợ nhiều tenants với data isolation 4. **Hybrid Search**: Kết hợp vector search và full-text search 5. **Pluggable**: Hỗ trợ multiple LLM providers và vector stores 6. **Containerized**: Full Docker deployment với orchestration