Fix: Correct pagination and early termination bugs in chunk_list() (#11692)
Summary
This PR fixes two critical bugs in
chunk_list()method that prevent processing large documents (>128 chunks) in GraphRAG and other workflows.Bugs Fixed
Bug 1: Incorrect pagination offset calculation
Location:
rag/nlp/search.pylines 530-531Problem: The loop variable
pwas used directly as offset, causing incorrect pagination:```python
BEFORE (BUGGY):
for p in range(offset, max_count, bs): # p = 0, 128, 256, 384… es_res = self.dataStore.search(…, p, bs, …) # p used as offset
Fix: Use page number multiplied by batch size:
AFTER (FIXED):
for page_num, p in enumerate(range(offset, max_count, bs)): es_res = self.dataStore.search(…, page_num * bs, bs, …)
Bug 2: Premature loop termination
Location: rag/nlp/search.py lines 538-539
Problem: Loop terminates when any page returns fewer than 128 chunks, even when thousands more remain:
BEFORE (BUGGY):
if len(dict_chunks.values()) < bs: # Breaks at 126 chunks even if 3,000+ remain break
Fix: Only terminate when zero chunks returned:
AFTER (FIXED):
if len(dict_chunks.values()) == 0: break
Enhancement: Add max_count parameter to GraphRAG
Location: graphrag/general/index.py line 60
Added max_count=10000 parameter to chunk loading for both LightRAG and General GraphRAG paths to ensure all chunks are processed.
Testing
Validated with a 314-page legal document containing 3,207 chunks:
Before fixes:
- Only 2-126 chunks processed
- GraphRAG generated 25 nodes, 8 edges
After fixes:
- All 3,209 chunks processed ✅
- GraphRAG processing complete dataset
Impact
These bugs affect any workflow using chunk_list() with large documents, particularly:
- GraphRAG knowledge graph generation
- RAPTOR hierarchical summarization
- Document processing pipelines with >128 chunks
Related Issue
Fixes #11687
Checklist
- Code follows project style guidelines
- Tested with large documents (3,207+ chunks)
- Both bugs validated by Dosu bot in issue #11687
- No breaking changes to API
Co-authored-by: Kevin Hu kevinhu.sh@gmail.com
Document | Roadmap | Twitter | Discord | Demo
📕 目录
💡 RAGFlow 是什么?
RAGFlow 是一款领先的开源检索增强生成(RAG)引擎,通过融合前沿的 RAG 技术与 Agent 能力,为大型语言模型提供卓越的上下文层。它提供可适配任意规模企业的端到端 RAG 工作流,凭借融合式上下文引擎与预置的 Agent 模板,助力开发者以极致效率与精度将复杂数据转化为高可信、生产级的人工智能系统。
🎮 Demo 试用
请登录网址 https://demo.ragflow.io 试用 demo。
🔥 近期更新
🎉 关注项目
⭐️ 点击右上角的 Star 关注 RAGFlow,可以获取最新发布的实时通知 !🌟
🌟 主要功能
🍭 “Quality in, quality out”
🍱 基于模板的文本切片
🌱 有理有据、最大程度降低幻觉(hallucination)
🍔 兼容各类异构数据源
🛀 全程无忧、自动化的 RAG 工作流
🔎 系统架构
🎬 快速开始
📝 前提条件
🚀 启动服务器
确保
vm.max_map_count不小于 262144:克隆仓库:
进入 docker 文件夹,利用提前编译好的 Docker 镜像启动服务器:
服务器启动成功后再次确认服务器状态:
出现以下界面提示说明服务器启动成功:
在你的浏览器中输入你的服务器对应的 IP 地址并登录 RAGFlow。
在 service_conf.yaml.template 文件的
user_default_llm栏配置 LLM factory,并在API_KEY栏填写和你选择的大模型相对应的 API key。好戏开始,接着奏乐接着舞!
🔧 系统配置
系统配置涉及以下三份文件:
SVR_HTTP_PORT、MYSQL_PASSWORD、MINIO_PASSWORD等。请务必确保 .env 文件中的变量设置与 service_conf.yaml.template 文件中的配置保持一致!
如果不能访问镜像站点 hub.docker.com 或者模型站点 huggingface.co,请按照 .env 注释修改
RAGFLOW_IMAGE和HF_ENDPOINT。如需更新默认的 HTTP 服务端口(80), 可以在 docker-compose.yml 文件中将配置
80:80改为<YOUR_SERVING_PORT>:80。把文档引擎从 Elasticsearch 切换成为 Infinity
RAGFlow 默认使用 Elasticsearch 存储文本和向量数据. 如果要切换为 Infinity, 可以按照下面步骤进行:
停止所有容器运行:
Note:
-v将会删除 docker 容器的 volumes,已有的数据会被清空。设置 docker/.env 目录中的
DOC_ENGINE为infinity.启动容器:
🔧 源码编译 Docker 镜像
本 Docker 镜像大小约 2 GB 左右并且依赖外部的大模型和 embedding 服务。
🔨 以源代码启动服务
安装
uv和pre-commit。如已经安装,可跳过本步骤:下载源代码并安装 Python 依赖:
通过 Docker Compose 启动依赖的服务(MinIO, Elasticsearch, Redis, and MySQL):
在
/etc/hosts中添加以下代码,目的是将 conf/service_conf.yaml 文件中的所有 host 地址都解析为127.0.0.1:如果无法访问 HuggingFace,可以把环境变量
HF_ENDPOINT设成相应的镜像站点:如果你的操作系统没有 jemalloc,请按照如下方式安装:
启动后端服务:
安装前端依赖:
启动前端服务:
以下界面说明系统已经成功启动:
开发完成后停止 RAGFlow 前端和后端服务:
📚 技术文档
📜 路线图
详见 RAGFlow Roadmap 2025 。
🏄 开源社区
🙌 贡献指南
RAGFlow 只有通过开源协作才能蓬勃发展。秉持这一精神,我们欢迎来自社区的各种贡献。如果您有意参与其中,请查阅我们的 贡献者指南 。
🤝 商务合作
👥 加入社区
扫二维码添加 RAGFlow 小助手,进 RAGFlow 交流群。