Skip to content

fix(kb): keep the requested chunk parameters when URL cleaning falls back - #10013

Open
L4XB wants to merge 2 commits into
AstrBotDevs:masterfrom
L4XB:fix/kb-clean-fallback-chunk-params
Open

L4XB wants to merge 2 commits into
AstrBotDevs:masterfrom
L4XB:fix/kb-clean-fallback-chunk-params

Conversation

@L4XB

@L4XB L4XB commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Motivation / 动机

Fixes #9999. KBHelper._clean_and_rechunk_content() fell back to self.chunker.chunk(content) in two places: when cleaning is enabled but no cleaning_provider_id is given, and when get_provider_by_id fails. Both fallbacks dropped the chunk_size / chunk_overlap requested for this upload and used the shared chunker's defaults (500/100), so a request for 128/16 was stored as 500-character chunks. Since upload_document(pre_chunked_text=...) uses those chunks as they are, the later size parameters could not correct it. The normal (cleaning disabled) path already forwarded the parameters.

Modifications / 改动点

  • Both fallback branches now call self.chunker.chunk(content, chunk_size=chunk_size, chunk_overlap=chunk_overlap); the warning log for the missing provider id names the parameters that are used.
  • New tests/test_kb_clean_rechunk_fallback.py: with a recording chunker and a provider manager whose lookup raises, both fallback paths (and the cleaning-disabled path) receive chunk_size=128, chunk_overlap=16 and produce chunks of at most 128 characters. The two fallback tests fail on master and pass with the fix.

Verification / 验证

uv run pytest tests/test_kb_clean_rechunk_fallback.py   (3 passed)
ruff check / ruff format --check on the changed files

Checklist / 检查清单

  • 我已经确认了我的更改不会引入新的错误 / I have confirmed my changes do not introduce new errors
  • 我已经添加了必要的测试 / I have added the necessary tests
  • 我已经更新了相关文档 (if needed) / I have updated the relevant documentation (if needed)

Summary by Sourcery

Keep requested chunking parameters when falling back to ordinary chunking during knowledge-base content processing.

Bug Fixes:

  • Preserve the upload-specific chunk size and overlap when content cleaning is skipped or cleaning provider lookup fails.

Enhancements:

  • Clarify fallback logging to report the chunking parameters being used.

Tests:

  • Add coverage for cleaning fallbacks and the existing cleaning-disabled path to verify requested chunk parameters are retained and chunk sizes remain bounded.

…back

_clean_and_rechunk_content() fell back to self.chunker.chunk(content)
when cleaning was enabled but no cleaning_provider_id was given, or when
the provider lookup failed. Both fallbacks dropped the chunk_size and
chunk_overlap passed for this upload and used the shared chunker's
defaults (500/100), so a request for 128/16 was stored as 500-character
chunks and later upload_document(pre_chunked_text=...) could not correct
it. The non-cleaning path already forwarded the parameters.

Forward chunk_size and chunk_overlap on both fallback paths.

Fixes AstrBotDevs#9999
sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Sep 9, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@sourcery-ai
sourcery-ai Bot dismissed their stale review September 9, 2026 20:37

Sourcery withdrew this approval because the latest commits introduced blocking findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 知识库 URL 清洗回退时丢失 chunk_size/chunk_overlap,按默认参数入库

1 participant