# hkuds/rag-anything architecture

> Architecture diagram of the GitHub repository hkuds/rag-anything, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hkuds/rag-anything
- Repository: https://github.com/hkuds/rag-anything
- Video tour (about a minute): https://gitdiagram.com/hkuds/rag-anything/video

## Overview

#### Purpose and Entry Points
RAG-Anything is a Python 3.10 multimodal document RAG library built on LightRAG. It ingests documents or pre-parsed content, derives text and modality-specific semantic representations, indexes them through LightRAG, and answers text or VLM-enhanced queries. Primary public API: `RAGAnything` and configuration exports in `raganything/__init__.py`; orchestration resides in `raganything/raganything.py`.

#### Core Orchestration and LightRAG Boundary
`RAGAnything` owns pipeline coordination while delegating persistence, embeddings, graph construction, vector retrieval, and baseline query modes to an injected or internally constructed LightRAG instance. Callers supply LLM, embedding, and optional vision-model functions; this keeps provider choice outside the library. Configuration and shared domain abstractions are in `raganything/config.py`, `raganything/base.py`, and `raganything/raganything.py`.

#### Ingestion and Parser Boundary
Document ingestion accepts PDFs, Office files, images, text, audio/video, folders, or direct `content_list` insertion. The parser layer normalizes parser-specific output into the flat content-list contract, preserving page/order, captions, footnotes, paths, and structure. MinerU, Docling, and PaddleOCR are selectable external parser backends; MinerU output includes v2-to-legacy normalization. Key paths: `raganything/parser.py`, `raganything/mineru_content.py`, `raganything/batch_parser.py`.

#### Content Routing and Processing
The processor splits normalized content into text chunks and modality work, retaining source-document identity and hierarchy. Text flows to LightRAG insertion; image, table, equation, generic, audio, and video items route to dedicated processors that generate descriptions and entities/chunks for the same knowledge base. Main paths: `raganything/processor.py`, `raganything/modalprocessors.py`, `raganything/modalprocessors_audio.py`, `raganything/modalprocessors_video.py`.

#### Multimodal Enrichment and Graph Indexing
Modality processors use caller-provided caption/VLM functions to interpret non-text assets, then create indexed chunks and graph entities/relationships through LightRAG. This is the critical integration boundary: RAG-Anything enriches content and preserves cross-modal/document relationships, while LightRAG owns the graph/vector backends. Prompts and language-specific prompt management are centralized in `raganything/prompt.py`, `raganything/prompt_manager.py`, and `raganything/prompts_zh.py`.

#### Query Paths
`aquery`/`query` forward text retrieval modes—hybrid, local, global, naive—to LightRAG. When enabled, query logic identifies retrieved image context, loads/encodes assets, and sends text plus images to the vision model. `aquery_with_multimodal` accepts caller-provided tables, equations, or other modal context alongside retrieval. Query assembly is in `raganything/query.py`; public coordination remains in `raganything/raganything.py`.

#### Batch, Reliability, and Runtime Dependencies
Batch operations parallelize folder ingestion with dry-run/incremental behavior: `raganything/batch.py` and `raganything/batch_parser.py`. Resilience and callbacks provide operational hooks around asynchronous work: `raganything/resilience.py`, `raganything/callbacks.py`. Runtime infrastructure is Python asyncio plus LightRAG storage backends (file-based by default, externally configurable alternatives such as Neo4j). External services/tools include LLM/embedding/VLM APIs (OpenAI-compatible, Ollama, vLLM, LM Studio, MiniMax examples), MinerU/Docling/PaddleOCR, LibreOffice for Office conversion, faster-whisper for audio, SceneDetect and ffmpeg for video, and optional CDN/object-storage URL mapping via `raganything/asset_urls.py`.

Main entry points: [`raganything/raganything.py`](https://github.com/hkuds/rag-anything/blob/main/raganything/raganything.py) (RAGAnything), [`raganything/parser.py`](https://github.com/hkuds/rag-anything/blob/main/raganything/parser.py) (Parser facade), [`raganything/processor.py`](https://github.com/hkuds/rag-anything/blob/main/raganything/processor.py) (Content processor), [`raganything/modalprocessors.py`](https://github.com/hkuds/rag-anything/blob/main/raganything/modalprocessors.py) (Image/table/equation processors)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core API"]
  node_public_api["Public exports<br/>Python API<br/>[__init__.py]"]
  node_orchestrator["RAGAnything<br/>pipeline coordinator<br/>[raganything.py]"]
  node_domain_config["Config &amp; domain abstractions<br/>shared models<br/>[config.py]"]
  node_resilience_callbacks["Resilience &amp; callbacks<br/>runtime hooks<br/>[resilience.py]"]
end

subgraph group_ingestion["Ingestion"]
  node_parser["Parser facade<br/>content normalizer<br/>[parser.py]"]
  node_mineru_normalizer["MinerU normalization<br/>parser adapter<br/>[mineru_content.py]"]
  node_batch_ingestion["Batch ingestion<br/>parallel folder pipeline<br/>[batch.py]"]
  node_batch_parser["Batch parser<br/>batch parsing<br/>[batch_parser.py]"]
end

subgraph group_enrichment["Multimodal Enrichment"]
  node_content_processor["Content processor<br/>routing pipeline<br/>[processor.py]"]
  node_visual_modal_processors["Image/table/equation processors<br/>modal enrichment<br/>[modalprocessors.py]"]
  node_audio_processor["Audio processor<br/>modal enrichment"]
  node_video_processor["Video processor<br/>modal enrichment"]
  node_prompts["Prompt management<br/>prompt layer<br/>[prompt_manager.py]"]
end

subgraph group_query["Query"]
  node_query_assembly["Query assembly<br/>multimodal query<br/>[query.py]"]
end

subgraph group_external["External Boundaries"]
  node_lightrag[("LightRAG<br/>retrieval and index backend")]
  node_model_providers{{"LLM, embedding &amp; vision functions<br/>caller-provided models"}}
  node_parser_backends{{"Parser backends<br/>external tools"}}
  node_media_tools["Media &amp; conversion tools<br/>external tools"]
end

node_public_api -->|"exports"| node_orchestrator
node_domain_config -->|"configures"| node_orchestrator
node_orchestrator -->|"ingests documents"| node_parser
node_orchestrator -->|"inserts content lists"| node_content_processor
node_batch_ingestion -->|"parallelizes parsing"| node_batch_parser
node_batch_ingestion -->|"submits ingestion"| node_orchestrator
node_batch_parser -->|"uses"| node_parser
node_parser -->|"normalizes MinerU"| node_mineru_normalizer
node_parser -->|"delegates parsing"| node_parser_backends
node_parser -.->|"converts media sources"| node_media_tools
node_parser -->|"normalized content list"| node_content_processor
node_content_processor -->|"indexes text chunks"| node_lightrag
node_content_processor -->|"routes visual items"| node_visual_modal_processors
node_content_processor -->|"routes audio"| node_audio_processor
node_content_processor -->|"routes video"| node_video_processor
node_visual_modal_processors -->|"indexes enriched chunks and graph links"| node_lightrag
node_audio_processor -->|"indexes enrichment"| node_lightrag
node_video_processor -->|"indexes enrichment"| node_lightrag
node_visual_modal_processors -->|"uses caption/VLM"| node_model_providers
node_audio_processor -->|"uses models"| node_model_providers
node_video_processor -->|"uses models"| node_model_providers
node_prompts -->|"supplies prompts"| node_visual_modal_processors
node_orchestrator -->|"aquery/query"| node_query_assembly
node_query_assembly -->|"retrieves hybrid/local/global/naive"| node_lightrag
node_query_assembly -->|"sends text and image context"| node_model_providers
node_resilience_callbacks -.->|"wraps async operations"| node_orchestrator

click node_public_api "https://github.com/hkuds/rag-anything/blob/main/raganything/__init__.py"
click node_orchestrator "https://github.com/hkuds/rag-anything/blob/main/raganything/raganything.py"
click node_domain_config "https://github.com/hkuds/rag-anything/blob/main/raganything/config.py"
click node_parser "https://github.com/hkuds/rag-anything/blob/main/raganything/parser.py"
click node_mineru_normalizer "https://github.com/hkuds/rag-anything/blob/main/raganything/mineru_content.py"
click node_batch_ingestion "https://github.com/hkuds/rag-anything/blob/main/raganything/batch.py"
click node_batch_parser "https://github.com/hkuds/rag-anything/blob/main/raganything/batch_parser.py"
click node_content_processor "https://github.com/hkuds/rag-anything/blob/main/raganything/processor.py"
click node_visual_modal_processors "https://github.com/hkuds/rag-anything/blob/main/raganything/modalprocessors.py"
click node_audio_processor "https://github.com/hkuds/rag-anything/blob/main/raganything/modalprocessors_audio.py"
click node_video_processor "https://github.com/hkuds/rag-anything/blob/main/raganything/modalprocessors_video.py"
click node_prompts "https://github.com/hkuds/rag-anything/blob/main/raganything/prompt_manager.py"
click node_query_assembly "https://github.com/hkuds/rag-anything/blob/main/raganything/query.py"
click node_resilience_callbacks "https://github.com/hkuds/rag-anything/blob/main/raganything/resilience.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_public_api,node_orchestrator,node_domain_config,node_resilience_callbacks toneBlue
class node_parser,node_mineru_normalizer,node_batch_ingestion,node_batch_parser toneAmber
class node_content_processor,node_visual_modal_processors,node_audio_processor,node_video_processor,node_prompts toneMint
class node_query_assembly toneRose
class node_lightrag,node_model_providers,node_parser_backends,node_media_tools toneIndigo
```

## Components

### Core API

- [Public exports](https://github.com/hkuds/rag-anything/blob/main/raganything/__init__.py): Python API · Exports RAGAnything and configuration. · `raganything/__init__.py`
- [RAGAnything](https://github.com/hkuds/rag-anything/blob/main/raganything/raganything.py): pipeline coordinator · Coordinates ingestion, indexing, and query flows. · `raganything/raganything.py`
- [Config & domain abstractions](https://github.com/hkuds/rag-anything/blob/main/raganything/config.py): shared models · `raganything/config.py`
- [Resilience & callbacks](https://github.com/hkuds/rag-anything/blob/main/raganything/resilience.py): runtime hooks · Provides asynchronous reliability handling and operational callbacks. · `raganything/resilience.py`

### Ingestion

- [Parser facade](https://github.com/hkuds/rag-anything/blob/main/raganything/parser.py): content normalizer · Converts source documents into the flat content-list contract. · `raganything/parser.py`
- [MinerU normalization](https://github.com/hkuds/rag-anything/blob/main/raganything/mineru_content.py): parser adapter · Normalizes MinerU v2 output to the legacy content shape. · `raganything/mineru_content.py`
- [Batch ingestion](https://github.com/hkuds/rag-anything/blob/main/raganything/batch.py): parallel folder pipeline · Supports dry-run and incremental folder processing. · `raganything/batch.py`
- [Batch parser](https://github.com/hkuds/rag-anything/blob/main/raganything/batch_parser.py): batch parsing · `raganything/batch_parser.py`

### Multimodal Enrichment

- [Content processor](https://github.com/hkuds/rag-anything/blob/main/raganything/processor.py): routing pipeline · Splits text chunks and routes normalized modal items. · `raganything/processor.py`
- [Image/table/equation processors](https://github.com/hkuds/rag-anything/blob/main/raganything/modalprocessors.py): modal enrichment · Creates descriptions, chunks, and semantic entities for visual content. · `raganything/modalprocessors.py`
- [Audio processor](https://github.com/hkuds/rag-anything/blob/main/raganything/modalprocessors_audio.py): modal enrichment · `raganything/modalprocessors_audio.py`
- [Video processor](https://github.com/hkuds/rag-anything/blob/main/raganything/modalprocessors_video.py): modal enrichment · `raganything/modalprocessors_video.py`
- [Prompt management](https://github.com/hkuds/rag-anything/blob/main/raganything/prompt_manager.py): prompt layer · Centralizes prompts and language-specific prompt selection. · `raganything/prompt_manager.py`

### Query

- [Query assembly](https://github.com/hkuds/rag-anything/blob/main/raganything/query.py): multimodal query · Builds retrieval queries and attaches retrieved image context for VLM calls. · `raganything/query.py`

### External Boundaries

- **LightRAG**: retrieval and index backend · Owns persistence, embeddings, graph construction, vector retrieval, and baseline query modes.
- **LLM, embedding & vision functions**: caller-provided models · Provider selection remains outside the library.
- **Parser backends**: external tools · MinerU, Docling, and PaddleOCR parse source documents.
- **Media & conversion tools**: external tools · LibreOffice, faster-whisper, SceneDetect, and ffmpeg support source conversion.

## Connections

- Public exports → RAGAnything: exports
- Config & domain abstractions → RAGAnything: configures
- RAGAnything → Parser facade: ingests documents
- RAGAnything → Content processor: inserts content lists
- Batch ingestion → Batch parser: parallelizes parsing
- Batch ingestion → RAGAnything: submits ingestion
- Batch parser → Parser facade: uses
- Parser facade → MinerU normalization: normalizes MinerU
- Parser facade → Parser backends: delegates parsing
- Parser facade → Media & conversion tools: converts media sources
- Parser facade → Content processor: normalized content list
- Content processor → LightRAG: indexes text chunks
- Content processor → Image/table/equation processors: routes visual items
- Content processor → Audio processor: routes audio
- Content processor → Video processor: routes video
- Image/table/equation processors → LightRAG: indexes enriched chunks and graph links
- Audio processor → LightRAG: indexes enrichment
- Video processor → LightRAG: indexes enrichment
- Image/table/equation processors → LLM, embedding & vision functions: uses caption/VLM
- Audio processor → LLM, embedding & vision functions: uses models
- Video processor → LLM, embedding & vision functions: uses models
- Prompt management → Image/table/equation processors: supplies prompts
- RAGAnything → Query assembly: aquery/query
- Query assembly → LightRAG: retrieves hybrid/local/global/naive
- Query assembly → LLM, embedding & vision functions: sends text and image context
- Resilience & callbacks → RAGAnything: wraps async operations
