Menu

System Architecture

Relevant source files

This document provides a high-level overview of RAGFlow's system architecture, describing how the major components are organized, how they communicate, and the deployment model. This serves as an entry point for understanding the system's structure before diving into specific subsystems.

For detailed information about individual services and their responsibilities, see Core Services and Components. For storage backend specifics, see Data Storage and Infrastructure. For deployment procedures, see Deployment and Configuration.

Architectural Style

RAGFlow follows a multi-tier architecture with clear separation between presentation, application logic, data processing, and storage layers. The system is designed for containerized deployment using Docker Compose, with each major component running as an independent service.

Key architectural characteristics:

  • Asynchronous Processing: Background task execution separated from API serving via task_executor.py
  • Pluggable Storage: Document engine abstraction allows switching between Elasticsearch, OpenSearch, and Infinity
  • Multi-Tenancy: Tenant-scoped data isolation enforced at the service layer
  • Horizontal Scalability: Stateless API services enable horizontal scaling; background workers can be scaled independently

Sources: README.md136-141 docker/docker-compose-base.yml1-300 api/ragflow_server.py1-120

System Topology

Key Service Endpoints:

ServicePortPurposeImplementation
RAGFlow Server9380Main REST API, chat, dataset managementapi/ragflow_server.py
Admin API9381System administration endpointsconf/service_conf.yaml4-6
MCP Server9382Model Context Protocol interfaceconf/service_conf.yaml1-3
Document Store9200 (ES) / 9201 (OS) / 23817 (Infinity)Vector + full-text searchrag/utils/es_conn.py rag/utils/infinity_conn.py
MySQL5455Relational metadatadocker/.env95
MinIO9000 (API) / 9001 (Console)Object storage for filesdocker/.env106
Redis6379Cache, queue, distributed locksdocker/.env118
TEI6380Local embedding generationdocker/.env161
Sandbox9385Secure code executiondocker/.env228

Sources: docker/.env1-245 conf/service_conf.yaml1-142 docker/docker-compose-base.yml1-300

Component Interaction Patterns

Data Flow Characteristics:

  1. Synchronous API Path: ragflow_server.py handles HTTP requests, performs validation, queries MySQL/Redis, and returns responses immediately
  2. Asynchronous Processing Path: Heavy operations (parsing, embedding, indexing) are queued to Redis and consumed by task_executor.py
  3. Retrieval Path: Chat requests trigger synchronous hybrid search against the document store, followed by LLM generation
  4. State Management: MySQL stores metadata and configuration; Redis stores transient state (task queues, locks, caches); MinIO stores raw files; Document store holds searchable chunks

Sources: api/ragflow_server.py50-61 rag/svr/task_executor.py (referenced in diagrams), rag/utils/redis_conn.py1-240

Configuration Architecture

Configuration Hierarchy:

LevelFilePurposeExample Variables
Docker Environmentdocker/.envContainer-level settings, ports, passwordsDOC_ENGINE, MYSQL_PASSWORD, ES_PORT
Service Configurationdocker/service_conf.yaml.templateApplication settings with variable substitutionragflow.host, mysql.max_connections
Compose Orchestrationdocker/docker-compose.ymlService topology, volumes, networksService definitions, profiles
Python Settingscommon.settings moduleRuntime configuration loaded from YAML/envsettings.ES, settings.MYSQL
Dynamic Settingsapi/db/runtime_config.pyDatabase-stored system configurationSystem-level toggles

Key Configuration Patterns:

  • Variable Substitution: service_conf.yaml.template uses ${VAR_NAME} syntax, populated from .env at container startup
  • Profile-Based Deployment: Docker Compose profiles (elasticsearch, infinity, sandbox) enable/disable service groups via COMPOSE_PROFILES
  • Singleton Connections: Connection classes (rag/utils/es_conn.py43-83 rag/utils/infinity_conn.py131-159) use @singleton decorator to ensure single instance per process

Sources: docker/.env1-245 docker/service_conf.yaml.template1-142 docker/README.md1-200 api/settings.py1-16

Deployment Architecture

RAGFlow is deployed as a collection of Docker containers orchestrated by Docker Compose. The deployment separates concerns into infrastructure services (databases, storage) and application services (API, workers).

Profile-Based Configuration:

The system uses Docker Compose profiles to enable/disable components based on deployment requirements. Profiles are set via COMPOSE_PROFILES in docker/.env20:

ProfilePurposeServices Enabled
elasticsearchUse Elasticsearch as document storees01 (port 1200)
infinityUse Infinity as document storeinfinity (port 23817)
opensearchUse OpenSearch as document storeopensearch01 (port 1201)
cpuCPU-only processingRAGFlow container with CPU support
gpuGPU-accelerated processingRAGFlow container with GPU support
sandboxEnable code executorsandbox-executor-manager (port 9385)
tei-cpu / tei-gpuLocal embedding serviceText Embeddings Inference

Container Process Architecture:

The main RAGFlow container runs multiple Python processes:

  1. ragflow_server.py (PID 1): HTTP API server handling client requests
  2. task_executor.py: Background worker for document processing, embedding generation, and advanced indexing
  3. Progress updater thread: Updates document parsing progress in database

Process separation ensures that long-running tasks (document parsing, RAPTOR clustering, GraphRAG entity extraction) do not block API responsiveness.

Sources: docker/docker-compose-base.yml1-300 docker/.env1-245 api/ragflow_server.py46-120 docker/README.md13-22

Data Persistence

All persistent data is stored in Docker volumes, ensuring data survives container restarts:

VolumePurposeContent
mysql_dataRelational metadataUsers, tenants, datasets, chat sessions, task records
minio_dataObject storageRaw uploaded files (PDF, DOCX, images, etc.)
redis_dataCache and queue dataTask queues, distributed locks, LLM response cache
esdata01 / infinity_data / osdata01Document storeIndexed text chunks, vector embeddings, full-text indexes

Storage Sizing Considerations:

  • Document Store: Largest volume; size depends on number of documents and embedding dimensions. Estimated at ~1-2KB per chunk.
  • MinIO: Stores original files; size depends on upload volume
  • MySQL: Relatively small; primarily metadata and configuration
  • Redis: Ephemeral data; limited by maxmemory setting (docker/docker-compose-base.yml204 sets 128MB default)

Sources: docker/docker-compose-base.yml277-295

Technology Stack Summary

LayerTechnologiesPurpose
FrontendReact, UmiJS, Tailwind CSS, Ant DesignWeb UI for knowledge base and chat management
API ServerFlask, Quart (async), Python 3.10-3.12REST API and Server-Sent Events
Task ProcessingPython multiprocessing, Redis queuesAsynchronous background job execution
Document ProcessingDeepDoc (ONNX models), pdfplumber, python-docxOCR, layout analysis, chunking
Vector SearchElasticsearch 8.11+ OR Infinity OR OpenSearch 2.19+Hybrid vector + keyword search
Relational DBMySQL 8.0.39User, tenant, dataset metadata
Object StorageMinIO (S3-compatible)File uploads
Cache/QueueRedis (Valkey 8)Distributed locks, task queues, LLM caching
LLM IntegrationOpenAI, Anthropic, Cohere, Ollama, etc. (15+ providers)Chat, embedding, reranking
Graph ProcessingNetworkX, graspologicEntity resolution, community detection
ML/DLscikit-learn, UMAP, XGBoost, ONNX RuntimeClustering, chunking, OCR
ContainerizationDocker, Docker ComposeService orchestration

Python Package Dependencies:

Key packages from pyproject.toml9-154:

  • Web: flask==3.0.3, quart==0.20.0, flask-cors==5.0.0
  • Search: elasticsearch==8.12.1, infinity-sdk==0.6.6, opensearch-py==2.7.1
  • Database: pymysql>=1.1.1, peewee==3.17.1, valkey==6.0.2
  • Storage: minio==7.2.4, boto3==1.34.140
  • LLM: openai>=1.45.0, anthropic==0.34.1, cohere==5.6.2, ollama>=0.5.0
  • ML: scikit-learn==1.5.0, umap_learn==0.5.6, xgboost==1.6.0
  • Document: pdfplumber==0.10.4, python-docx>=1.1.2, openpyxl>=3.1.0
  • NLP: nltk==3.9.1, tiktoken==0.7.0

Sources: pyproject.toml1-199 README.md1-401