From 481192300dc23c872d5a68b490f1cdfe5bcd3cd7 Mon Sep 17 00:00:00 2001 From: Stephen Hu <812791840@qq.com> Date: Tue, 9 Dec 2025 09:58:34 +0800 Subject: [PATCH] Fix:[ERROR][Exception]: list index out of range (#11826) ### What problem does this PR solve? https://github.com/infiniflow/ragflow/issues/11821 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- rag/prompts/generator.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rag/prompts/generator.py b/rag/prompts/generator.py index e8ad77032..9fc30dc33 100644 --- a/rag/prompts/generator.py +++ b/rag/prompts/generator.py @@ -781,7 +781,10 @@ async def run_toc_from_text(chunks, chat_mdl, callback=None): # Merge structure and content (by index) prune = len(toc_with_levels) > 512 - max_lvl = sorted([t.get("level", "0") for t in toc_with_levels if isinstance(t, dict)])[-1] + max_lvl = "0" + sorted_list = sorted([t.get("level", "0") for t in toc_with_levels if isinstance(t, dict)]) + if sorted_list: + max_lvl = sorted_list[-1] merged = [] for _ , (toc_item, src_item) in enumerate(zip(toc_with_levels, filtered)): if prune and toc_item.get("level", "0") >= max_lvl: