# RAGFlow Deep Dive

## What Is It?

**RAGFlow** is an open-source RAG (Retrieval-Augmented Generation) engine that combines deep document understanding with agentic capabilities. With **70.7k+ stars**, it's positioned as a leading platform for building enterprise AI applications with superior document parsing.

**Repository:** [infiniflow/ragflow](https://github.com/infiniflow/ragflow)

---

## The Problem It Solves

Traditional RAG systems struggle with:
- Complex document layouts (multi-column, tables, images)
- Quality degradation from poor chunking
- Hallucinations without source grounding
- Scaling to enterprise workloads

RAGFlow provides:
- **Deep document understanding** with intelligent parsing
- **Citation grounding** for traceable responses
- **Agentic workflows** for complex automation
- **Enterprise-grade** scalability

---

## Key Statistics

| Metric | Value |
|--------|-------|
| **Stars** | 70,700 |
| **Forks** | 7,700 |
| **Latest Version** | v0.23.1 |
| **License** | Apache 2.0 |
| **Released** | April 2024 |

---

## Core Philosophy

**"Quality in, Quality out"**

RAGFlow is RAG-centric (not LLM-centric), emphasizing:
- Document quality and structured extraction
- Intelligent chunking with human intervention
- Visual verification of parsed content
- Explainable retrieval with citations

---

## Key Features

### 1. Deep Document Understanding

- **Unlimited token capacity** for large documents
- **Layout recognition** (newspapers, books, resumes)
- **Table structure extraction** with preserved formatting
- **OCR** for scanned documents and images

### 2. Intelligent Chunking

| Feature | Description |
|---------|-------------|
| **Template-based** | Pre-configured for different document types |
| **Visual editing** | Double-click to modify chunks |
| **Parent-child** | Hierarchical chunking (v0.23.0+) |
| **Auto-TOC** | Document structure for context preservation |

### 3. Citation Grounding

- Every response includes source references
- Visual highlighting of where answers came from
- Reduces hallucinations through traceability

### 4. Agentic Capabilities (v0.20.0+)

- **Workflows** - Human-defined task sequences
- **Agentic Workflows** - LLM-driven automation
- **Multi-agent canvas** - Collaborative execution
- **MCP support** - Model Context Protocol integration

---

## Document Parsing

### Supported Formats

| Category | Formats |
|----------|---------|
| **Documents** | PDF, DOC, DOCX, TXT, MD |
| **Tables** | CSV, XLSX, XLS |
| **Images** | JPEG, PNG, TIF, GIF |
| **Slides** | PPT, PPTX |
| **Web** | Full web content |

### PDF Parsing Options

| Method | Description | Speed |
|--------|-------------|-------|
| **DeepDoc** | Full visual processing (OCR, TSR, DLR) | Slower |
| **Naive** | Plain-text extraction only | Fastest |
| **MinerU** | Open-source PDF conversion | Medium |
| **Docling** | Gen AI optimized processing | Medium |

---

## Vector Database Support

### Primary Options

| Database | Description |
|----------|-------------|
| **Elasticsearch** | Default, full-text + vector |
| **Infinity** | AI-native, purpose-built for RAG |

### Infinity Database Highlights

RAGFlow's proprietary AI-native database:

- **Hybrid search:** Dense vectors, sparse vectors, tensors, full-text
- **Performance:** 0.1ms latency, 15k+ QPS on million-scale
- **Features:** Phrase search, advanced ranking, tensor support

```bash
# Switch to Infinity
DOC_ENGINE=infinity docker-compose up -d
```

---

## LLM Integrations

### Supported Providers

| Provider | Models |
|----------|--------|
| **OpenAI** | GPT-4, GPT-4o, GPT-3.5 |
| **Anthropic** | Claude models |
| **Local** | Ollama, Xinference |
| **Any** | OpenAI-compatible APIs |

### Configuration

```yaml
# service_conf.yaml.template
user_default_llm: openai
OPENAI_API_KEY: sk-...
```

---

## Installation

### Requirements

| Component | Minimum |
|-----------|---------|
| **CPU** | 4 cores (x86) |
| **RAM** | 16 GB |
| **Disk** | 50 GB |
| **Docker** | 24.0.0+ |
| **Docker Compose** | v2.26.1+ |

### Quick Start

```bash
# Clone repository
git clone https://github.com/infiniflow/ragflow.git
cd ragflow/docker

# Configure memory mapping
sudo sysctl -w vm.max_map_count=262144

# CPU deployment
docker compose -f docker-compose.yml up -d

# GPU deployment
echo "DEVICE=gpu" >> .env
docker compose -f docker-compose.yml up -d
```

**Access:** http://localhost (default port 80)

### Docker Images

| Edition | Size | Description |
|---------|------|-------------|
| **Slim** | ~2GB | Without embedded models (default) |
| **Full** | ~9GB | With embedded models |

---

## Python SDK

### Installation

```bash
pip install ragflow-sdk
```

### Basic Usage

```python
from ragflow_sdk import RAGFlow

# Initialize client
rag = RAGFlow(
    api_key="YOUR_API_KEY",
    base_url="http://localhost:9380"
)

# Create dataset
dataset = rag.create_dataset(name="my_kb")

# Upload document
doc = dataset.upload_document("document.pdf")

# Parse into chunks
doc.parse()

# Create chat assistant
assistant = rag.create_chat(
    name="my_assistant",
    dataset_ids=[dataset.id]
)

# Query
response = assistant.chat("What is the main topic?")
print(response.text)
```

---

## Comparison to Alternatives

| Framework | Strengths | Best For |
|-----------|-----------|----------|
| **RAGFlow** | Document understanding, visual workflows | Complex documents, enterprise |
| **LangChain** | Maximum flexibility | Custom integrations |
| **LlamaIndex** | Precision data operations | Large text datasets |
| **Haystack** | Production stability | Testable pipelines |

### When to Choose RAGFlow

- Complex document processing (PDFs with tables, images)
- Need for visual workflow editor
- Enterprise deployment requirements
- Agentic automation needs

---

## Enterprise Features

### Data Integration (v0.22.0+)

Real-time sync from:
- AWS S3 / MinIO
- Google Drive
- Notion
- Confluence
- Discord
- JIRA

### Memory Management (v0.23.0+)

- Configurable memory types
- Session variable definition
- Context window management

### Admin Features

- Web UI dashboard
- User management
- Service monitoring

---

## Use Cases

### Legal
- Contract review and extraction
- Compliance checking
- Document analysis

### Healthcare
- Medical document processing
- Patient record analysis
- Treatment protocol assistance

### Finance
- Invoice processing
- Financial report analysis
- Audit trails

### Customer Service
- Knowledge base Q&A
- Support automation
- Issue resolution

---

## Architecture

```
┌─────────────────────────────────────────────┐
│                  RAGFlow UI                  │
├─────────────────────────────────────────────┤
│              Backend Services               │
│  ┌─────────┐ ┌─────────┐ ┌─────────────┐  │
│  │ Parser  │ │ Chunker │ │ Agent Engine│  │
│  └─────────┘ └─────────┘ └─────────────┘  │
├─────────────────────────────────────────────┤
│              Storage Layer                  │
│  ┌─────────────┐  ┌──────────┐  ┌───────┐  │
│  │ Elasticsearch│  │  MySQL   │  │ MinIO │  │
│  │  / Infinity  │  │          │  │       │  │
│  └─────────────┘  └──────────┘  └───────┘  │
└─────────────────────────────────────────────┘
```

---

## Best Practices

### Document Preparation
- Use high-quality source documents
- Ensure clear formatting
- Pre-process low-quality scans

### Chunking Strategy
- Select appropriate template for document type
- Review and manually adjust chunks if needed
- Use parent-child for hierarchical documents

### Performance Optimization
- Use Infinity for AI-native workloads
- Configure appropriate embedding models
- Monitor token usage

---

## Resources

- **Repository:** https://github.com/infiniflow/ragflow
- **Documentation:** https://ragflow.io/docs
- **Python SDK:** https://pypi.org/project/ragflow-sdk/
- **HTTP API:** https://ragflow.io/docs/dev/http_api_reference

---

*RAGFlow is the leading open-source RAG engine for complex document processing. If your documents have tables, images, or complex layouts, RAGFlow's deep understanding capabilities make it the clear choice.*
