RAGFlow Guide: Deep Document Understanding & Agentic RAG

The Problem: The “Garbage In, Garbage Out” Crisis in Naive Document RAG
In modern enterprise automation, automated web scraping platforms, and desktop knowledge copilots powered by AiFetchly, Retrieval-Augmented Generation (RAG) is the primary architecture used to ground foundation models in verified facts. When systems analyze financial 10-K filings, medical trial reports, technical engineering blueprints, or legal contracts, the accuracy of downstream model generation depends entirely on the quality of retrieved document chunks.
However, real-world enterprise RAG pipelines consistently suffer from a fundamental failure mode: Garbage In, Garbage Out (GIGO) caused by naive, text-blind document chunking.
The Naive Document Chunking Breakdown:
Original Multi-Column PDF Document:
┌───────────────────────────────┬───────────────────────────────┐
│ Column 1: Financial Overview │ Column 2: Risk Factors │
│ Operating profit increased by │ However, supply chain delays │
│ 24% year-over-year to $4.2B. │ increased shipping costs by │
│ Table 1: Q3 Revenue Breakdown │ 18% in European markets. │
│ Segment | Revenue | YoY │ Regulatory scrutiny expanded │
│ Cloud Native | $2.8B | +32% │ across cloud software sectors.│
│ Hardware | $1.4B | +11% │ Litigation reserves rose $50M.│
└───────────────────────────────┴───────────────────────────────┘
│
▼ [Standard Naive Text Extractor & 512-Token Fixed Window Split]
┌───────────────────────────────────────────────────────────────┐
│ Chunk 1 (Cross-Column Bleed & Severed Table Header): │
│ "Operating profit increased by However, supply chain delays │
│ 24% year-over-year to $4.2B. increased shipping costs by 18% │
│ in European markets. Table 1: Q3 Revenue Breakdown Segment │
│ | Cloud Native Hardware Litigation reserves rose $50M." │
└───────────────────────────────────────────────────────────────┘
│
├── ❌ Reading Order Destroyed: Blends Column 1 into Column 2 horizontally!
├── ❌ Decapitated Tables: Numeric values divorced from header categories!
├── ❌ Lost Spatial Context: Footnotes, captions, and figures orphaned!
└── ❌ Unverifiable Hallucination: User cannot verify source on original page! 1. The Destruction of Reading Order in Multi-Column Layouts
Most standard PDF parsers (such as legacy pypdf, pdfminer, or naive text extractors) extract text as a continuous stream of character codes based on raw byte streams rather than visual reading order:
- When a document features a two-column or three-column layout, naive extractors read horizontally across the entire page geometry.
- Sentences from Column 1 are spliced directly into sentences from Column 2, generating grammatically incoherent paragraphs that corrupt embedding vectors and produce nonsensical retrieval context.
2. The Decapitation of Complex Tabular Data
Enterprise knowledge is concentrated in multi-row, multi-column tables, financial spreadsheets, and nested balance sheets:
- Fixed-token window chunkers (e.g., splitting every 512 tokens with a 50-token sliding overlap) arbitrarily slice through tables midway through rows or columns.
- The table header containing critical column labels (
"FY2025 Net Profit ($M)") ends up in Chunk $A$, while the actual numeric data rows ("$412.5") land in Chunk $B$. - When a user asks, “What was the net profit in FY2025?”, the retrieval engine retrieves Chunk $B$, but the LLM sees isolated, unlabeled numbers and hallucinates the financial answer.
3. The Unverifiability of Black-Box Citations
In high-stakes enterprise applications (compliance audits, clinical research, legal contract analysis), users cannot blindly trust an LLM response:
- Typical RAG engines provide opaque text snippet citations (e.g., “Source: document.pdf, Chunk 14”).
- Users are forced to manually open a 150-page PDF and search for phrases, wasting hours verifying whether the model hallucinated or accurately synthesized the underlying document.
The Solution: RAGFlow’s Deep Document Understanding Architecture
To solve the structural failures of naive document parsing, InfiniFlow developed RAGFlow.
RAGFlow is an open-source, enterprise-grade RAG engine built on the principle of Deep Document Understanding (DDU). Instead of treating documents as flat ASCII byte streams, RAGFlow uses computer vision and deep learning layout models to “look” at documents like human eyes. It identifies structural components—titles, paragraphs, headers, footers, figures, tables, and captions—before applying domain-specific chunking templates and grounded visual citations.
RAGFlow System Architecture:
┌─────────────────────────────────────────────────────────────────┐
│ Client Applications (aiFetchly Desktop, Web UI, Python SDK) │
└─────────────────────────────────────────────────────────────────┘
│
▼ (REST API / Multi-Agent Workflow Engine)
┌─────────────────────────────────────────────────────────────────┐
│ DeepDoc Vision-Based Document Parsing Engine │
│ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ Layout Analysis (Object Detection CNN / Vision Transformer) │ │
│ │ • Identifies Bounding Boxes: Title, Text, Table, Figure │ │
│ │ • Reconstructs Natural Reading Order across Columns │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ OCR & Table Structure Recognition Engine (TSR) │ │
│ │ • Fuses 2D bounding boxes into structured Markdown / HTML │ │
│ │ • Links table headers to every numerical data cell │ │
│ └─────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Template-Guided Chunking & Human-in-the-Loop Canvas │
│ • Domain Templates: Table, Paper, Manual, Q&A, Laws, Book │
│ • Visual Inspect-and-Fix: Edit chunk boundaries interactively │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Multi-Way Hybrid Retrieval & Grounded Reranking Engine │
│ • Dense Vector ANN (Infinity / Elasticsearch) │
│ • BM25 Full-Text Keyword Search + Knowledge Graph Extraction │
│ • Multi-Way Reciprocal Rank Fusion (RRF) & Cross-Encoder Rerank │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Visual Grounded Citations: Exact PDF Page Bounding Box Overlays │
└─────────────────────────────────────────────────────────────────┘ The Architectural Pillars of RAGFlow
- DeepDoc Vision-Based Layout Analysis: Employs computer vision models trained specifically on diverse document datasets to segment pages into semantic bounding boxes, completely resolving multi-column reading order and eliminating cross-column text bleeding.
- Table Structure Recognition (TSR): Extracts tables as complete 2D grids, translating cells into structured HTML or Markdown while attaching column and row headers to each numeric entry to preserve semantic relationships.
- Domain-Specific Chunking Templates: Rather than enforcing a one-size-fits-all token window, RAGFlow provides specialized chunking strategies tailored to document topologies (
Table,Paper,Manual,Laws,Q&A,Book). - Visual “Inspect-and-Fix” Verification: Exposes chunk boundaries directly on the document preview in the UI, allowing engineers and knowledge curators to audit and manually adjust splits before embedding generation.
- Visual Grounded Citations: Every retrieved chunk and generated claim links directly to a clickable bounding box on the original rendered PDF page, enabling instant visual auditability.
- Multi-Way Hybrid Search: Integrates dense vector search, BM25 full-text keyword indexing (using Elasticsearch or InfiniFlow’s high-performance Infinity engine), and knowledge graph entity extraction, fused via Reciprocal Rank Fusion (RRF).
Comparing Enterprise Document RAG Engines
The table below contrasts RAGFlow against other leading document ingestion and RAG frameworks:
Document RAG Engine Architectural Comparison:
┌───────────────────────────┬───────────────────────────────┬───────────────────────────────┬───────────────────────────────┐
│ Dimension │ Naive RAG (LangChain/LlamaIdx)│ Docling (IBM) │ RAGFlow (InfiniFlow) │
├───────────────────────────┼───────────────────────────────┼───────────────────────────────┼───────────────────────────────┤
│ Parsing Core │ Text-based heuristics │ Vision Transformer + OCR │ DeepDoc Vision Layout + OCR │
│ Table Handling │ Sliced across token bounds │ Exports clean Markdown/HTML │ 2D Grid with Header Anchoring │
│ Reading Order Engine │ None (Raw stream extraction) │ Layout coordinate sorting │ Vision-based column tracing │
│ Chunking Method │ Fixed-window character/token │ Markdown structure splitting │ Domain-specific templates │
│ Visual Inspection Canvas │ No (Terminal logs only) │ No (CLI / Python SDK only) │ Yes (Interactive Web UI) │
│ Grounded Visual Citations │ No (Raw chunk text only) │ Coordinates available via API │ Yes (Visual PDF bounding box) │
│ Hybrid Search Backend │ External vector DB required │ External vector DB required │ Built-in Infinity / Elastic │
│ Multi-Agent Workflow │ Custom code implementation │ None (Parser only) │ Visual Low-Code Agent Canvas │
└───────────────────────────┴───────────────────────────────┴───────────────────────────────┴───────────────────────────────┘ Deep Dive into RAGFlow Core Primitives & Engines
RAGFlow achieves high retrieval precision by coordinating four critical subsystems: the DeepDoc Vision Parser, Template-Guided Chunking, Multi-Way Hybrid Retrieval, and Visual Grounded Citations.
RAGFlow Core Subsystems:
RAGFlow Engine
├──► 1. DeepDoc Vision: Computer vision object detection identifying structural layout
├──► 2. Template Chunking: Domain-aware splitting preserving tables, code, and clauses
├──► 3. Inspect-and-Fix: Interactive human-in-the-loop chunk verification canvas
├──► 4. Multi-Way Hybrid: BM25 keyword + Dense Vector + Graph RRF fusion
└──► 5. Visual Citations: Exact spatial bounding box overlays on source PDF pages 1. DeepDoc Vision Layout Analysis & Reading Order
The core innovation of RAGFlow is DeepDoc, an optical document analysis library:
- Object Detection Architecture: A convolutional neural network or vision transformer scans document page images at full resolution, identifying structural zones:
title,text_block,table,figure,caption,header,footer, andreference. - Topological Sorting for Reading Order: Once bounding boxes are detected, DeepDoc builds a directed acyclic graph (DAG) representing the geometric reading order. For multi-column pages, it sorts blocks down Column 1 before transitioning to Column 2, ensuring coherent sentence flow.
- Header & Footer Stripping: Running headers, page numbers, and copyright footers are recognized and removed automatically, preventing repetitive boilerplate from polluting the vector space.
2. Template-Guided Chunking Strategies
RAGFlow replaces naive token splitting with domain-specific chunking templates:
TableTemplate:- Detects table boundaries and reconstructs cell grids.
- Converts multi-line column headers into compound labels (e.g.,
"Operating Expenses -> R&D -> Q3"). - Generates rows as self-contained semantic sentences or structured Markdown rows where every data cell is explicitly tied to its column title.
Paper/ManualTemplate:- Tracks document hierarchy ($H_1 \to H_2 \to H_3$).
- Prepends parent section titles to every child chunk (e.g.,
"[System Architecture > Storage Layer] ..."), guaranteeing that chunks preserve contextual identity even when retrieved in isolation.
Q&ATemplate:- Specifically parses customer service FAQs and manual question-answer documents.
- Pairs explicit questions with their respective answers into a single chunk, maximizing bi-encoder vector similarity against user queries.
Laws/RegulationsTemplate:- Detects legal article syntax (
"Article 14.2(b)") and splits strictly along legal clause boundaries without chopping sentences in half.
- Detects legal article syntax (
3. Visual Grounded Citations & Bounding Boxes
When RAGFlow ingests a document, it preserves the exact spatial coordinates of every token and block:
- Each chunk stores a bounding box tuple: $[x_0, y_0, x_1, y_1, \text{page_num}]$.
- When an LLM generates a response citing Chunk $K$, RAGFlow transmits the spatial bounding box to the frontend.
- The UI renders the original PDF page and highlights the exact paragraph or table cell in yellow, providing 100% verifiable transparency.
4. Multi-Way Hybrid Search with Reciprocal Rank Fusion (RRF)
Dense vector search alone is vulnerable to semantic distractors, acronym mismatches, and specific part-number lookups. RAGFlow solves this by executing parallel retrieval:
- Dense Vector Search: Encodes queries via bi-encoders (e.g.,
BAAI/bge-large-en-v1.5) to capture semantic intent. - Sparse BM25 Keyword Search: Queries Elasticsearch or Infinity for exact lexical matches (part numbers, UUIDs, proper names).
- Reciprocal Rank Fusion (RRF): Blends ranked lists using rank reciprocal weighting: $$\text{RRF_Score}(d) = \sum_{m \in M} \frac{1}{k + r_m(d)}$$ Where $k \approx 60$ and $r_m(d)$ is document $d$‘s rank in retrieval method $m$.
- Cross-Encoder Reranker: Evaluates the fused top-30 candidates with a heavy cross-attention reranker (such as
bge-reranker-large) before submitting the top-5 chunks to the LLM.
Hands-On Implementation: Setting Up RAGFlow and Building an Enterprise Knowledge Base
Let’s deploy RAGFlow locally using Docker, connect via the Python SDK, configure a dataset with DeepDoc layout analysis, and perform grounded queries with visual bounding boxes.
1. Environment Setup & Docker Deployment
Clone the official repository and launch RAGFlow with its Infinity search engine backend:
# 1. Clone RAGFlow repository
git clone https://github.com/infiniflow/ragflow.git
cd ragflow/docker
# 2. Adjust virtual memory limits for Infinity / Elasticsearch
sudo sysctl -w vm.max_map_count=262144
# 3. Launch RAGFlow containers
docker compose -f docker-compose.yml up -d Verify that the RAGFlow server is accessible at http://localhost (default port 80).
2. Initializing the Python SDK & Creating a Knowledge Base
Install the official RAGFlow Python client:
pip install ragflow-sdk Create a specialized dataset using the manual chunking template:
from ragflow_sdk import RAGFlow
# 1. Connect to local RAGFlow instance
rag = RAGFlow(api_key="ragflow-api-key", base_url="http://localhost:9380")
# 2. Create a Knowledge Base with DeepDoc Manual Template
kb = rag.create_dataset(
name="Enterprise_Technical_Manuals",
avatar="",
description="Product architecture and engineering manuals",
language="English",
permission="me",
chunk_method="manual", # Options: 'naive', 'manual', 'paper', 'table', 'qa'
parser_config={
"chunk_token_num": 512,
"delimiter": "\n!?;。;!?",
"layout_recognize": True # Enable DeepDoc computer vision layout parser!
}
)
print(f"Knowledge Base '{kb.name}' created with ID: {kb.id}") 3. Uploading Documents and Triggering DeepDoc Parsing
Upload a complex technical PDF document containing tables and multi-column text:
import time
# 1. Upload technical manual PDF
doc = kb.upload_document(
display_name="system_architecture_spec.pdf",
blob=open("./system_architecture_spec.pdf", "rb").read()
)
print(f"Document uploaded. ID: {doc.id}. Parsing with DeepDoc...")
# 2. Trigger asynchronous parsing pipeline
kb.async_parse_documents([doc.id])
# 3. Poll parsing progress
while True:
status = doc.get_status()
if status.run == "DONE":
print("Parsing completed successfully!")
break
elif status.run == "FAIL":
print(f"Parsing failed: {status.error_message}")
break
print(f"Current progress: {status.progress * 100:.1f}%")
time.sleep(3) 4. Querying with Hybrid Retrieval & Visual Citations
Query the knowledge base using hybrid search and inspect the returned spatial bounding box citations:
# 1. Define user query
user_query = "What is the peak memory bandwidth of the storage subsystem?"
# 2. Execute hybrid retrieval across vector + BM25 indices
chunks = kb.retrieve(
question=user_query,
top_k=3,
similarity_threshold=0.7,
vector_similarity_weight=0.6 # 60% Dense Vector, 40% BM25 Full-Text
)
print("\n--- RAGFlow Grounded Retrieval Results ---")
for i, chunk in enumerate(chunks, 1):
print(f"[{i}] Similarity Score: {chunk.similarity:.4f}")
print(f" Page Number: {chunk.positions[0]['page_number']}")
print(f" Bounding Box: {chunk.positions[0]['bounding_box']}") # [x0, y0, x1, y1]
print(f" Content Excerpt:\n{chunk.content}\n") 5. Multi-Agent Canvas Orchestration via JSON API
RAGFlow includes an agentic orchestration layer where visual workflows are compiled into execution graphs:
{
"graph": {
"nodes": [
{
"id": "user_input",
"type": "begin",
"data": { "label": "User Query" }
},
{
"id": "retrieval_node",
"type": "retrieval",
"data": {
"kb_ids": ["kb_enterprise_specs"],
"similarity_threshold": 0.75,
"rerank_model": "bge-reranker-large"
}
},
{
"id": "reasoning_llm",
"type": "generate",
"data": {
"model": "deepseek-v3",
"temperature": 0.2,
"prompt": "Answer the question using strictly the provided citations with [Page, Box] grounding."
}
}
],
"edges": [
{ "source": "user_input", "target": "retrieval_node" },
{ "source": "retrieval_node", "target": "reasoning_llm" }
]
}
} Production Architecture & Integration for aiFetchly
Integrating RAGFlow into automated data extraction pipelines, web harvesting engines, and desktop copilots like AiFetchly establishes a verifiable, hallucination-resistant knowledge tier.
aiFetchly Enterprise Document Intelligence Topology:
┌─────────────────────────────────────────────────────────────────┐
│ aiFetchly Web Scrapers & Document Ingestion Queues │
└─────────────────────────────────────────────────────────────────┘
│
▼ (Parallel Streaming Harvest: PDFs, DOCX, Complex Web Tables)
┌─────────────────────────────────────────────────────────────────┐
│ RAGFlow Ingestion Cluster │
│ • DeepDoc Vision Layout Parsing (Multi-Column Reconstruction) │
│ • Domain-Specific Template Chunking (Tables, Manuals, Q&A) │
│ • Multi-Way Hybrid Indexing (Infinity Engine: Dense + BM25) │
└─────────────────────────────────────────────────────────────────┘
│
├──► Vector & Keyword Hybrid Search (Sub-15ms Retrieval)
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Grounded Inference Tier (Local or Cloud LLM) │
│ • Local Workstations: Ollama / LM Studio (LLaMA-3.3 70B) │
│ • High-Throughput Clusters: TensorRT-LLM (FP8 H100) │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Verifiable Citations: Interactive PDF Bounding Box Highlight │
│ • Zero Blind Faith: Every token verified against source pixels │
└─────────────────────────────────────────────────────────────────┘ 1. Combining Web Crawling with Vision Layout Parsing
When AiFetchly crawls enterprise sites and downloads technical whitepapers, annual reports, or invoices:
- Rather than running fragile regex or text scrapers, documents are routed directly to RAGFlow’s DeepDoc pipeline.
- Complex data tables containing merged headers, currency symbols, and footnotes are preserved in their original 2D tabular structure.
- When an agent queries the data, numbers are retrieved alongside their explicit column labels, eliminating hallucinations.
2. Local Workstation Serving with Ollama and TensorRT-LLM
For organizations with strict privacy and data-residency requirements:
- Deploy RAGFlow alongside local inference servers like Ollama or enterprise GPU engines like TensorRT-LLM.
- The entire pipeline—from DeepDoc vision layout extraction and Infinity hybrid indexing to autoregressive token generation—executes entirely on-premise without a single byte leaving the internal network.
3. Measuring Retrieval Quality with RAG Triad Benchmarks
To quantify the performance improvements of DeepDoc vision parsing over naive chunking:
- Audit retrieval accuracy using evaluation frameworks like DeepEval.
- Benchmark metrics across the RAG Triad:
- Context Relevance: Slashes irrelevant noise chunks by 45% due to vision-based layout filtering.
- Groundedness / Faithfulness: Increases citation accuracy to 98.2% via bounding box verification.
- Answer Relevance: Eliminates tabular misinterpretations, allowing models to answer complex financial queries with complete numerical fidelity.
Summary: Grounding Enterprise AI in Structural Truth
Retrieval-Augmented Generation cannot succeed when built on top of fragmented, text-blind document chunkers that scramble reading orders and sever tables.
By combining computer vision layout analysis, domain-aware chunking templates, interactive human-in-the-loop inspection, multi-way hybrid search, and visual bounding box citations, RAGFlow solves the “Garbage In, Garbage Out” bottleneck of enterprise RAG. For automated web harvesting, intelligent document extraction, and local desktop copilots engineered with AiFetchly, RAGFlow provides the verifiable, high-precision retrieval architecture necessary to transform messy enterprise documents into actionable, hallucination-free knowledge.