RAGFlow 教學:開源 RAG 引擎怎麼裝、怎麼餵文件、怎麼讓 AI 不亂講
把公司一整櫃的 PDF 丟給 AI,然後它開始一本正經地胡說八道——這大概是每個想做企業知識庫的人都遇過的場面。RAGFlow 用「深度文件理解」加上可追溯引用來治這個病。這篇從 Docker 安裝、建知識庫、設模型,一路講到怎麼讓答案附上出處。
Introduction: When AI Misreads PDFs
I've come across a real case where a company wanted to build an internal knowledge base by feeding over 300 product manuals in PDF format into an RAG system. However, the AI would incorrectly connect numbers in tables to other text segments and mistake copyright notices at the end of pages for actual content references. When asked about the power of a specific model, it would confidently provide an incorrect answer that actually belonged to a different model. The engineer in charge sighed, saying the problem wasn't with the model being dumb, but rather that the files weren't being properly read into the system.
This is where RAG truly faces challenges - not in connecting models, but in accurately segmenting complex files with tables and scanned documents into pieces that the model can handle. RAGFlow specializes in this aspect. This article will guide you through setting it up, feeding it files, and enabling it to provide sources for its answers.
What is RAGFlow
RAGFlow is an open-source RAG (Retrieve, Augment, Generate) engine developed by InfiniFlow, with its code publicly available on GitHub. If you're still unsure what RAG is, it's best to start with our What is RAG article - simply put, it's a technology that allows AI to search your data repository before answering questions, rather than relying on memory or making things up.
What sets RAGFlow apart from other RAG tools is its "DeepDoc" deep document understanding capability. Unlike general tools that simply extract text from PDFs, which can become disorganized when the layout is complex, RAGFlow understands the structure of the document - identifying titles, tables, paragraphs, and even handling scanned documents (image-based PDFs) through OCR. It supports a wide range of formats including Word, presentations, Excel, plain text, images, scanned documents, structured data, and web pages.
Another key feature is traceable references. When answering, it will mark the source of the information, allowing you to see which part of which document the answer comes from, significantly reducing the chance of being misled by the AI. It also integrates with platforms like Dify that are working on agent orchestration, supporting the creation of visual workflows that combine RAG, tools, and MCP.
Use Cases
- Enterprise Internal Knowledge Base: Feed product manuals, SOPs, and contract templates into it, and employees can ask questions in natural language, with answers provided along with their sources.
- Customer Service FAQ Backend: Connect it with frequently asked questions and technical documents to serve as the brain for chatbots.
- Research and Analysis: For complex documents like legal cases, financial reports, and academic papers that require precise references, DeepDoc's strengths are particularly useful.
- Personal Second Brain: Throw in your accumulated notes and e-books, and it becomes a conversational knowledge base.
To understand how to set up an RAG system as a whole, you can refer to our RAG Implementation Guide alongside this article.
Getting Started: First-Time Setup
RAGFlow is deployed using Docker, and while the process isn't difficult, it does have some system requirements. Let's take a look.
1. Confirm System Requirements
The official recommendation is for a CPU with at least 4 cores, at least 16GB of RAM, and at least 50GB of hard drive space, with Docker 24 or above and Docker Compose v2.26 or above. The RAM requirement is crucial - it needs to run a vector search engine, and insufficient RAM will cause it to freeze, so don't try to run it on a small machine with only 4GB of RAM.
2. Pull the Project and Start
After cloning the project from GitHub, navigate into the docker directory and start it:
bash
git clone https://github.com/infiniflow/ragflow.git
cd ragflow/docker
docker compose up -d
The first run will download several images, so grab a cup of coffee and wait. Once it's done, use docker ps to confirm that all containers are up and running.
3. Open the Backend and Set Up the Model
After the service starts, open http://your-host-IP (default port 80) in your browser. Register an account and log in, then go to the settings to fill in the API key for your model - this step cannot be skipped. RAGFlow does not come with a model; you need to tell it which LLM (for answering) and which embedding model (for converting text into vectors) to use. You can fill in OpenAI, cloud models from various providers, or even connect to a local Ollama.
4. Build a Knowledge Base and Feed Files
Create a Knowledge Base and upload your PDFs and Word documents into it. The key part comes next: after uploading, you need to select a chunking template (chunk method). RAGFlow provides multiple templates corresponding to different file types - general documents, academic papers, books, legal documents, presentations, tables, Q&A pairs, etc. Choosing the right template significantly affects the quality of the chunking. After selecting the template, press parse, and it will run DeepDoc to break down the files into segments.
5. Check the Chunking Results
This is one of RAGFlow's most useful features: after parsing, it will visualize the chunking results for you, allowing you to see what each segment looks like and where it corresponds to in the original text. If you find that the chunking is poor - for example, if tables are cut off - you can manually adjust it. Don't be afraid of the trouble; this step directly affects the accuracy of the answers later on.
6. Build a Chat Assistant and Test Q&A
Once the chunking is satisfactory, build a Chat and hang the knowledge base on it, and you can start asking questions. When it answers, it will attach the source references, and clicking on them will jump to the original text segment.
Advanced Tips
Use templates according to file types: Don't put legal contracts and product briefs into the same knowledge base using the same template. The layouts are too different, and the chunking logic isn't the same. Build separate bases and choose appropriate templates for each, and the accuracy will significantly improve.
Make good use of hybrid search: RAGFlow performs both vector search and BM25 keyword search, followed by re-ranking. Pure vector search often fails to catch "exact nouns, material numbers, article numbers," which keyword search can complement. It's enabled by default, but you can adjust the weights.
Connect to Ollama to run local models: For those concerned about data privacy and not wanting to send company files to the cloud, you can point both the LLM and the embedding model to a local Ollama, running the entire suite offline. The trade-off is that you'll need better hardware.
Use API to integrate into your system: RAGFlow provides an API that you can use as a backend search layer, with your own interface on the frontend, or integrated into existing customer service systems. For more complex workflows, you can also use its agent orchestration feature, similar in concept to AI Agent Development.
Common Errors and Notes
- Insufficient RAM: 16GB is the minimum, not a recommendation. Running below this will cause containers to crash repeatedly, a common issue for newcomers.
- Forgetting to set the embedding model: Many people only set up the LLM for answering and forget the embedding model, resulting in files not being correctly vectorized, and thus answering poorly. Both need to be set.
- Carelessly choosing or not checking chunking templates: Using the default template for a complex PDF and then complaining about poor answers - the problem likely lies in the chunking. You must look at the visualization results and adjust if they're bad.
- Believing references guarantee 100% accuracy: Traceable references allow for verification, not a guarantee of correctness. References reduce the risk of hallucinations, but models can still misread segments. For critical scenarios, please manually verify the sources. To understand more about why AI might provide incorrect information, see What is AI Hallucination.
- Not considering data privacy: Using cloud models means your file segments will be sent to the model providers. For sensitive data, please use local model solutions.
TheAI Academy Review
Among the many tools that can connect to RAG, most focus on how to connect models or store vectors, assuming files can be cleanly read into the system. In practice, file parsing is where 90% of projects fail. RAGFlow focuses its efforts on DeepDoc and chunking visualization, directly addressing this dirtiest of jobs. For teams wanting to build enterprise knowledge bases and being driven crazy by tables and scanned documents, this focus is very appropriate.
After doing RAG for a long time, you'll understand a phrase: the quality of answers isn't won by how strong the model is, but by whether the files have been properly read into the system. RAGFlow bets on this, and it's the right bet.
Note that it's an engineering-oriented tool that requires Docker knowledge, a decent machine, and isn't a cloud service that you can simply install and use. If you're an individual looking to simply try RAG, the threshold might be too high; but if you're looking to self-host, control, and handle complex files, it's worth spending an afternoon to set up and play with.
Data Sources
Frequently Asked Questions
RAGFlow 是免費的嗎?自架要錢嗎?
RAGFlow 本身是開源的,你自己用 Docker 部署在自己的伺服器上,軟體不用付費。但要花的成本有兩塊:一是硬體(建議 16GB 記憶體以上的機器),二是模型費用——你接的雲端 LLM 跟嵌入模型 API 是另外算錢的。如果全部改用本地 Ollama 模型,理論上可以做到零 API 費用,代價是需要更好的硬體。官方另外也有提供雲端版的付費方案,不想自己架的人可以考慮。
我不太會寫程式,裝得起來嗎?
RAGFlow 的安裝主要靠 Docker,只要照著指令 clone 專案、跑 docker compose up,不太需要寫程式。但你得對命令列、Docker 有基本概念,遇到容器起不來、記憶體不足時要能自己 debug,所以說它是工程取向的工具。完全沒碰過終端機的純新手,門檻會偏高,建議先找會 Docker 的同事協助第一次部署。
為什麼一定要選切塊模板?用預設不行嗎?
可以用預設,但結果往往不理想。RAGFlow 的切塊模板是針對不同文件型態設計的——論文、書本、法律、簡報、表格各有對應邏輯。版面複雜的文件用錯模板,會把表格切斷、把標題跟內文混在一起,直接拖垮回答準確度。花一分鐘選對模板、解析後看一下視覺化結果,是性價比最高的一步,別省。
RAGFlow 跟 Dify、LangChain 這類工具差在哪?
定位不同。LangChain 是開發框架,給工程師寫程式組 RAG 流程用;Dify 偏向 LLM 應用開發平台,涵蓋面廣。RAGFlow 則把重心壓在「文件理解與檢索品質」這一段,DeepDoc 深度解析跟切塊視覺化是它的招牌。如果你的痛點是「文件讀不乾淨、答案不準」,RAGFlow 對症;如果你要的是完整的應用編排平台,可能要搭配或改用 Dify 那類工具。