How hudasharings/ragflow works
1. Repository shape
- This is a full-stack RAG/agent platform, not a single service.
- The main boundaries are: web UI, Python backend/API, document intelligence and retrieval pipeline, agent orchestration, sandboxed code execution, and deployment/integration tooling.
2. User-facing web application
- web/ is a React + TypeScript + Vite frontend.
- It contains the primary product surfaces: chats, datasets/knowledge bases, documents, files, agents, memories, search, user settings, and admin views.
- The frontend is mostly a stateful console for configuring pipelines and viewing results/logs rather than just a chat UI.
3. API and application layer
- api/ is the main backend entry point, with api/ragflow_server.py wiring the server.
- api/apps/ is organized by domain: chat, documents, files, knowledge bases, connectors, LLM settings, users, tenants, memory, search, plugins, MCP, evaluation, and system config.
- This layer acts as the HTTP boundary and translates UI/API requests into service calls and async tasks.
4. Domain services and persistence
- api/db/services/ and api/db/joint_services/ implement the business logic behind those API modules.
- api/db/db_models.py defines the persistent model boundary; the codebase clearly separates route handlers from data/service logic.
- The backend uses a relational database for metadata and workflow state, while external stores handle documents and indexes.
5. Core RAG engine
- rag/ is the runtime inference and retrieval core.
- It contains pipeline primitives for parsing, splitting, tokenizing, hierarchical merging, advanced RAG, app-specific flows, and LLM wrappers.
- rag/prompts/ and rag/nlp/ show that generation is tightly coupled with prompt templates, query rewriting, ranking, and language-aware retrieval logic.
6. Document understanding pipeline
- deepdoc/ is the document intelligence subsystem.
- It includes parsers for PDF, DOCX, PPT, Excel, HTML, Markdown, JSON, text, OCR, layout recognition, and table structure recognition.
- This is the ingestion front door for unstructured content; its output feeds chunking, metadata extraction, and retrieval index construction.
7. External data source connectors
- common/data_source/ implements many connectors to third-party systems such as Google Drive, Confluence, GitHub, GitLab, Jira, Slack, Teams, Notion, Dropbox, Box, SharePoint, Gmail, IMAP, WebDAV, Airtable, Asana, Discord, and others.
- These connectors are a separate ingestion path from local file upload.
- Their role is to pull remote content into the same document parsing/indexing pipeline used for uploaded files.
8. Storage and indexing backends
- rag/utils/, common/doc_store/, and api/db/ show the main persistence boundaries.
- The platform supports Elasticsearch or Infinity for document/vector retrieval, MinIO/S3-like object storage for file blobs, Redis for caching/coordination, and MySQL for application state.
- The README and docker assets confirm that these are first-class runtime dependencies, not optional extras.
9. Agent orchestration and tool execution
- agent/ defines the workflow/agent canvas and reusable components such as loop, switch, iteration, retrieval, message, variable assignment/aggregation, and LLM nodes.
- agent/tools/ provides tool adapters for web search, SQL execution, crawling, code execution, academic search, finance/data sources, email, and retrieval.
- agent/templates/ and the canvas UI in web/src/pages/agent/ indicate that agents are built as editable graphs and serialized as DSL/JSON workflows.
10. Sandboxed code execution
- sandbox/ is a separate execution subsystem for running user/code-tool workloads safely.
- It has its own executor manager service, container runtime configuration, seccomp profile, and base images.
- This is a hard security boundary: code execution is intentionally isolated from the main backend.
11. Admin and operations plane
- admin/server/ and admin/client/ form a dedicated admin service and CLI, separate from the main product API.
- It handles user/role/service management and operational tasks.
- This is distinct from end-user RAG flows and should be drawn as an internal ops plane.
12. SDKs, integrations, and external surfaces
- sdk/python/ exposes a client SDK for automation and external applications.
- mcp/ provides MCP client/server support, and plugin/ plus intergrations/ add embedding points for chat platforms, browser extensions, and Firecrawl.
- These are outbound/integration boundaries, letting third-party systems consume or extend RAGFlow without using the web UI.
13. Primary runtime data flow
- The main flow is: user configures a knowledge base or agent in the web app → API persists metadata and launches processing → document/content ingestion parses source material → chunks and embeddings are stored/indexed → retrieval and reranking are performed at query time → LLM response is generated with citations and references returned to the UI.
- Agent flows add another layer: graph-defined tool calls, branching, loops, and optional sandboxed code execution happen before or during retrieval/generation.
14. Deployment model
- The repo is designed for containerized deployment.
- docker/ and helm/ define the production topology: web-facing reverse proxy, backend service, database, object storage, search engine, Redis, and sandbox executor.
- Dockerfile*, GitHub workflows, and the source-launch instructions show that local dev and production share the same service boundaries, just different packaging.
15. What to draw in an architecture diagram
- Draw the frontend, main API/backend, admin service, sandbox, and external stores as separate boxes.
- Show two ingestion paths into the backend: uploaded files and external connectors.
- Show the backend fanning out to document parsing, RAG indexing, agent orchestration, and admin/state services.
- Show Elasticsearch/Infinity, MySQL, MinIO/S3, Redis, and LLM providers as external dependencies of the backend and pipeline layers.
Main entry points: apps Domain Apps · flow RAG Core · ragflow_server.py API Server · services Services
Components 24
Web UI
React console for chat, datasets, agents, search, memory, files, and admin views.
- Product UI · Main end-user application surfaces and navigation.
web/src/pages - Agent Canvas · Editable graph canvas, forms, run sheets, logs, and shared agent views.
web/src/pages/agent - Datasets · Knowledge base management, documents, chunking, parsing, and testing screens.
web/src/pages/dataset - Chats · Chat experiences, sessions, assistants, and next-generation chat views.
web/src/pages/next-chats - Search UI · Search, retrieval documents, previews, and embedded search experiences.
web/src/pages/next-search - Admin UI · Dedicated admin views for users, roles, monitoring, services, and whitelists.
web/src/pages/admin
Backend API
Python HTTP layer, domain apps, and persistence services.
- API Server · Backend application startup and routing boundary.
api/ragflow_server.py - Domain Apps · Domain-oriented API modules for chat, documents, files, KBs, connectors, LLMs, search, memory, and system config.
api/apps - Services · Service layer implementing domain behavior and task coordination.
api/db/services - DB Models · Relational data model boundary for application state and workflow metadata.
api/db/db_models.py
RAG Engine
Retrieval, parsing, chunking, prompting, and model wrappers.
- DeepDoc · Document parsing, OCR, layout, and table understanding.
deepdoc - RAG Core · Core runtime for parsing, splitting, tokenizing, hierarchical merging, and app-specific RAG flows.
rag/flow - LLM Wrappers · Chat, embedding, rerank, OCR, sequence-to-text, and TTS model interfaces.
rag/llm - Prompts · Prompt and template library used across retrieval, generation, summarization, and citation flows.
rag/prompts - NLP · Query rewriting, tokenization, synonym handling, search logic, and term weighting.
rag/nlp
Agent Runtime
Graph-based workflows, tools, and execution orchestration.
- Agent DSL · Graph/canvas runtime that serializes agent workflows and pipeline definitions.
agent/canvas.py - Components · Reusable workflow nodes such as loop, switch, iteration, retrieval, message, variables, and LLM.
agent/component - Tools · Adapters for web search, SQL, crawling, code execution, academic and finance sources.
agent/tools
Ops & Integrations
Admin service, SDKs, MCP, plugins, deployment, and sandboxing.
- Sandbox Exec · Containerized and seccomp-restricted code execution service.
sandbox/executor_manager - Admin Service · Separate admin server and CLI for user, role, and service management.
admin/server - Python SDK · Programmatic client for chat, dataset, document, agent, memory, and session operations.
sdk/python/ragflow_sdk - MCP & Plugins · MCP client/server support plus plugin and embedding extension points.
mcp - Data Connectors · Third-party source connectors for drive, docs, code, tickets, chat, email, and web sources.
common/data_source
Other components
- Storage Backends · Document/vector stores, object storage, cache, and database backends.
Connections 27
- Product UI → API Server: API requests · UI calls backend endpoints for all product flows.
- Agent Canvas → Domain Apps: save/run graphs · Canvas and run sheets persist and execute agent workflows.
- Datasets → Domain Apps: manage KBs · Dataset screens manage documents, parsing, chunking, and retrieval setup.
- Chats → Domain Apps: chat sessions · Chat UI drives conversations, assistants, and message history.
- Search UI → Domain Apps: search queries · Search views request retrieval and document previews.
- Admin UI → Admin Service: admin ops · Admin UI uses the separate administration backend.
- API Server → Domain Apps: routes to domains · Server entrypoint wires HTTP modules by domain.
- Domain Apps → Services: business logic · Request handlers delegate to domain services.
- Services → DB Models: persist state · Services read and write application metadata and workflow state.
- Domain Apps → DeepDoc: ingest files · Document and file flows trigger parsing and document understanding.
- Domain Apps → Data Connectors: sync sources · Connector flows pull remote content into the ingestion pipeline.
- DeepDoc → RAG Core: parsed content · Document intelligence output feeds chunking and retrieval preparation.
- RAG Core → LLM Wrappers: embed/rerank/llm · Core RAG runtime depends on model wrappers for generation and ranking.
- RAG Core → Prompts: prompting · Retrieval and generation use shared prompt templates.
- RAG Core → NLP: query rewrite · Core retrieval uses NLP helpers for query analysis and search logic.
- Agent DSL → Components: compose nodes · Canvas workflows are built from reusable component nodes.
- Agent DSL → Tools: invoke tools · Agent graphs call external tools and connectors during execution.
- Tools → Sandbox Exec: code tools · Untrusted code execution is delegated to the sandbox subsystem.
- Components → RAG Core: retrieval steps · Agent workflows can embed retrieval and generation subflows.
- Domain Apps → Agent DSL: workflow API · Backend exposes agent creation, save, run, and log endpoints.
- Domain Apps → Admin Service: ops endpoints · Administrative functionality is separated from end-user flows.
- Python SDK → API Server: programmatic access · SDK speaks to the main backend API.
- MCP & Plugins → API Server: integration surface · MCP and plugins extend or consume backend capabilities.
- RAG Core → Storage Backends: indexes/blobs · Retrieval depends on vector/document stores and object storage.
- Services → Storage Backends: app state · Backend services use relational and cache storage for persistent state.
- Data Connectors → Storage Backends: raw assets · Ingested content is staged in object and document stores.
- Admin Service → Storage Backends: admin data · Admin service manages operational metadata and user/role state.