From 8ee9d1be3680602d17fe51c79694c7e01da462ef Mon Sep 17 00:00:00 2001 From: Bryan Nathan Date: Thu, 29 Oct 2026 06:57:52 +0800 Subject: [PATCH 1/3] fix: recognize unspaced CJK memory sentence boundaries Preserve the ASCII whitespace requirement while allowing CJK sentence terminators to end memory chunks without intervening spaces. Add regressions for punctuation, supported closing quotes, default chunk sizes and decimal compatibility. Fixes #2130 --- .../services/memory/consolidator/chunker.py | 6 +- tests/services/memory/test_chunker.py | 55 +++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/deeptutor/services/memory/consolidator/chunker.py b/deeptutor/services/memory/consolidator/chunker.py index e0f9b6128..89dcbaca9 100644 --- a/deeptutor/services/memory/consolidator/chunker.py +++ b/deeptutor/services/memory/consolidator/chunker.py @@ -21,9 +21,9 @@ Boundary = Literal["paragraph", "sentence"] # Paragraph boundary: one or more blank lines. _PARA_BOUNDARY = re.compile(r"\n\s*\n+") -# Sentence boundary: terminal punctuation followed by space/newline. -# Covers ASCII (.!?) and CJK (。!?). -_SENT_BOUNDARY = re.compile(r"[.!?。!?](?:[\")»」』]+)?(?=\s|$)") +# ASCII sentence punctuation needs whitespace/end-of-text (not e.g. a decimal point). +# CJK sentences commonly follow 。!? immediately, without intervening whitespace. +_SENT_BOUNDARY = re.compile(r'[.!?][")»」』]*(?=\s|$)|[。!?][")»」』]*') @dataclass(frozen=True) diff --git a/tests/services/memory/test_chunker.py b/tests/services/memory/test_chunker.py index 795bec0c5..9ef1ee0e3 100644 --- a/tests/services/memory/test_chunker.py +++ b/tests/services/memory/test_chunker.py @@ -74,6 +74,61 @@ def test_sentence_boundary_used_when_configured() -> None: assert chunk.text[-1].isspace() or chunk.text.rstrip()[-1] in ".!?" +@pytest.mark.parametrize("punctuation", ["。", "!", "?"]) +@pytest.mark.parametrize("closing_quote", ["", "」", "』", '"']) +def test_cjk_sentences_without_spaces_end_at_boundaries( + punctuation: str, closing_quote: str +) -> None: + sentences = [ + f"学习数学需要练习{punctuation}{closing_quote}", + f"理解概念也很重要{punctuation}{closing_quote}", + f"每天复习能够巩固知识{punctuation}{closing_quote}", + ] + text = "".join(sentences) + chunks = chunk_with_boundary( + text, + budget=4, + overlap_ratio=0.0, + min_chunk_chars=1, + max_chunk_chars=14, + boundary="sentence", + ) + assert [chunk.text for chunk in chunks] == sentences + assert "".join(chunk.text for chunk in chunks) == text + assert all(chunk.end - chunk.start <= 14 for chunk in chunks) + + +def test_cjk_sentence_boundaries_with_default_chunk_sizes() -> None: + text = "学习数学需要练习。理解概念也很重要。每天复习能够巩固知识。" * 5000 + chunks = chunk_with_boundary( + text, + budget=20, + overlap_ratio=0.1, + min_chunk_chars=1000, + max_chunk_chars=64000, + boundary="sentence", + ) + assert all(chunk.text.endswith("。") for chunk in chunks) + assert chunks[0].start == 0 + assert chunks[-1].end == len(text) + assert all(chunk.end - chunk.start <= 64000 for chunk in chunks) + assert all(left.end >= right.start for left, right in zip(chunks, chunks[1:])) + + +def test_ascii_period_inside_number_is_not_a_sentence_boundary() -> None: + text = "Value is 3.14. Next sentence." + chunks = chunk_with_boundary( + text, + budget=4, + overlap_ratio=0.0, + min_chunk_chars=1, + max_chunk_chars=20, + boundary="sentence", + ) + assert chunks[0].text == "Value is 3.14." + assert "".join(chunk.text for chunk in chunks) == text + + def test_budget_caps_chunk_count() -> None: text = ("paragraph body. " * 20 + "\n\n") * 30 # ~ 10k chars chunks = chunk_with_boundary( From 093a55fa1a0b4decd90359152dceda75ad5c9cde Mon Sep 17 00:00:00 2001 From: "Bingxi Zhao (Frank)" <13051345080@163.com> Date: Sat, 31 Oct 2026 17:24:07 +0800 Subject: [PATCH 2/3] docs: acknowledge development-branch contributors Co-authored-by: hydraxman <8344245+hydraxman@users.noreply.github.com> --- CONTRIBUTORS.md | 20 ++++++++++++++++++++ README.md | 2 ++ 2 files changed, 22 insertions(+) create mode 100644 CONTRIBUTORS.md diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md new file mode 100644 index 000000000..104cec73e --- /dev/null +++ b/CONTRIBUTORS.md @@ -0,0 +1,20 @@ +# Contributors + +Thank you to everyone who contributes code, fixes, tests, translations, documentation, and feedback to DeepTutor. Git history preserves original authors and coauthors; the [GitHub contributors page](https://github.com/HKUDS/DeepTutor/graphs/contributors) also records contributions to the default branch. + +## Contributions integrated into dev after v1.7.0 + +This list acknowledges contributions on the development branch before the next release reaches the default branch. It supplements the project's existing contributor history. + +- [@0x-IHRR](https://github.com/0x-IHRR) — [#2128](https://github.com/HKUDS/DeepTutor/pull/2128). +- [@amartinawi](https://github.com/amartinawi) — [#2169](https://github.com/HKUDS/DeepTutor/pull/2169). +- [@bercedev](https://github.com/bercedev) — [#2167](https://github.com/HKUDS/DeepTutor/pull/2167). +- [@Eapp1e](https://github.com/Eapp1e) — [#2197](https://github.com/HKUDS/DeepTutor/pull/2197), [#2215](https://github.com/HKUDS/DeepTutor/pull/2215). +- [@Frank-zhu2000](https://github.com/Frank-zhu2000) — [#2127](https://github.com/HKUDS/DeepTutor/pull/2127). +- [@hydraxman](https://github.com/hydraxman) — [#2131](https://github.com/HKUDS/DeepTutor/pull/2131). +- [@kevin9327](https://github.com/kevin9327) — [#2225](https://github.com/HKUDS/DeepTutor/pull/2225). +- [@KKandLL-Forever](https://github.com/KKandLL-Forever) — [#2149](https://github.com/HKUDS/DeepTutor/pull/2149). +- [@Rimcat-JA](https://github.com/Rimcat-JA) — [#2232](https://github.com/HKUDS/DeepTutor/pull/2232). +- [@rudycelekli](https://github.com/rudycelekli) — [#2198](https://github.com/HKUDS/DeepTutor/pull/2198), [#2199](https://github.com/HKUDS/DeepTutor/pull/2199), [#2200](https://github.com/HKUDS/DeepTutor/pull/2200), [#2226](https://github.com/HKUDS/DeepTutor/pull/2226), [#2227](https://github.com/HKUDS/DeepTutor/pull/2227), [#2228](https://github.com/HKUDS/DeepTutor/pull/2228), [#2233](https://github.com/HKUDS/DeepTutor/pull/2233), [#2234](https://github.com/HKUDS/DeepTutor/pull/2234), [#2235](https://github.com/HKUDS/DeepTutor/pull/2235), [#2236](https://github.com/HKUDS/DeepTutor/pull/2236), [#2237](https://github.com/HKUDS/DeepTutor/pull/2237), [#2238](https://github.com/HKUDS/DeepTutor/pull/2238), [#2239](https://github.com/HKUDS/DeepTutor/pull/2239), [#2240](https://github.com/HKUDS/DeepTutor/pull/2240). +- [@sriv144](https://github.com/sriv144) — [#2153](https://github.com/HKUDS/DeepTutor/pull/2153). +- [@x-labb](https://github.com/x-labb) — [#2219](https://github.com/HKUDS/DeepTutor/pull/2219). diff --git a/README.md b/README.md index d6ab7b9e9..53ae1b3c7 100644 --- a/README.md +++ b/README.md @@ -1229,6 +1229,8 @@ We want DeepTutor to keep iterating and improving — and ultimately to become a We hope DeepTutor becomes a gift for the community. 🎁 +See the [development-branch contributor list](CONTRIBUTORS.md) for recently integrated contributions. + Contributors From 3b750ec003b8c8e3da011ae18aede591b9d84457 Mon Sep 17 00:00:00 2001 From: "Bingxi Zhao (Frank)" <13051345080@163.com> Date: Sat, 31 Oct 2026 18:36:27 +0800 Subject: [PATCH 3/3] test(partners): await archived export messages before asserting --- web/tests/partner-archives-markdown.spec.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/tests/partner-archives-markdown.spec.tsx b/web/tests/partner-archives-markdown.spec.tsx index eb70a5c13..d9a21899c 100644 --- a/web/tests/partner-archives-markdown.spec.tsx +++ b/web/tests/partner-archives-markdown.spec.tsx @@ -1,4 +1,4 @@ -import { cleanup, fireEvent, render, screen, within } from "@testing-library/react"; +import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react"; import { afterEach, beforeEach, expect, it, vi } from "vitest"; import { fromMarkdown } from "mdast-util-from-markdown"; @@ -161,10 +161,11 @@ it("renders assistant Markdown with the real chat renderer and keeps user text l expect(user).toHaveClass("whitespace-pre-wrap"); expect(user.querySelector("strong")).toBeNull(); expect(container.querySelectorAll("table")).toHaveLength(1); - expect(onMessagesChange).toHaveBeenLastCalledWith([ + // Export messages are reported by an effect after the history request settles. + await waitFor(() => expect(onMessagesChange).toHaveBeenLastCalledWith([ { role: "user", content: userText }, { role: "assistant", content: markdown }, - ]); + ])); }); it.each([