From 6a192c5ed5448174b955c5a4655871c26575906f Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Tue, 30 Dec 2025 15:17:57 +0800 Subject: [PATCH 1/2] Allow zero chunk overlap --- astrbot/core/knowledge_base/chunking/recursive.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/astrbot/core/knowledge_base/chunking/recursive.py b/astrbot/core/knowledge_base/chunking/recursive.py index 3f4aabb57..e5cf1b3f0 100644 --- a/astrbot/core/knowledge_base/chunking/recursive.py +++ b/astrbot/core/knowledge_base/chunking/recursive.py @@ -149,8 +149,10 @@ def _split_by_character( 分割后的文本块列表 """ - chunk_size = chunk_size or self.chunk_size - overlap = overlap or self.chunk_overlap + if chunk_size is None: + chunk_size = self.chunk_size + if overlap is None: + overlap = self.chunk_overlap result = [] for i in range(0, len(text), chunk_size - overlap): end = min(i + chunk_size, len(text)) From fa4d35b57935912ddfbc7722bcdd259bc5a98e3f Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Tue, 30 Dec 2025 15:21:25 +0800 Subject: [PATCH 2/2] Validate recursive chunking bounds --- astrbot/core/knowledge_base/chunking/recursive.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/astrbot/core/knowledge_base/chunking/recursive.py b/astrbot/core/knowledge_base/chunking/recursive.py index e5cf1b3f0..3882b0871 100644 --- a/astrbot/core/knowledge_base/chunking/recursive.py +++ b/astrbot/core/knowledge_base/chunking/recursive.py @@ -153,6 +153,12 @@ def _split_by_character( chunk_size = self.chunk_size if overlap is None: overlap = self.chunk_overlap + if chunk_size <= 0: + raise ValueError("chunk_size must be greater than 0") + if overlap < 0: + raise ValueError("chunk_overlap must be non-negative") + if overlap >= chunk_size: + raise ValueError("chunk_overlap must be less than chunk_size") result = [] for i in range(0, len(text), chunk_size - overlap): end = min(i + chunk_size, len(text))