Skip to content

Commit f7c9cc2

Browse files
committed
RDBC-1068 Fix OverlapTokens supported-methods set to match server/C#
Overlap tokens are only consumed by the two paragraph chunking methods (PlainTextSplitParagraphs, MarkDownSplitParagraphs) on the server. The Python set wrongly allowed PlainTextSplit/PlainTextSplitLines (silently ignored by the server) and omitted MarkDownSplitParagraphs (spurious client-side rejection of a valid config). Also makes the validation message derive from the set so it can't drift again.
1 parent 1ab9583 commit f7c9cc2

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

ravendb/documents/operations/ai/chunking_options.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ class ChunkingMethod(Enum):
1111
HTML_STRIP = "HtmlStrip"
1212

1313

14-
# Methods that support overlap tokens
14+
# Methods that support overlap tokens. Mirrors the server (TextChunker.cs) and the C#/Node clients:
15+
# only the two *paragraph* methods consume OverlapTokens; every other method ignores it.
1516
METHODS_SUPPORTING_OVERLAP_TOKENS = {
16-
ChunkingMethod.PLAIN_TEXT_SPLIT,
17-
ChunkingMethod.PLAIN_TEXT_SPLIT_LINES,
1817
ChunkingMethod.PLAIN_TEXT_SPLIT_PARAGRAPHS,
18+
ChunkingMethod.MARK_DOWN_SPLIT_PARAGRAPHS,
1919
}
2020

2121

@@ -84,10 +84,8 @@ def validate(self, source: str, errors: List[str]) -> None:
8484
errors.append(f"{source}: OverlapTokens cannot be greater than MaxTokensPerChunk.")
8585

8686
if self.overlap_tokens > 0 and self.chunking_method not in METHODS_SUPPORTING_OVERLAP_TOKENS:
87-
errors.append(
88-
f"{source}: OverlapTokens is only supported for PlainTextSplit, "
89-
f"PlainTextSplitLines, and PlainTextSplitParagraphs chunking methods."
90-
)
87+
supported = ", ".join(sorted(method.value for method in METHODS_SUPPORTING_OVERLAP_TOKENS))
88+
errors.append(f"{source}: OverlapTokens is only supported for the following chunking methods: {supported}.")
9189

9290
@staticmethod
9391
def are_equal(left: Optional["ChunkingOptions"], right: Optional["ChunkingOptions"]) -> bool:

ravendb/tests/embeddings_generation_tests/test_chunking_options.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ def test_no_chunking_marker_bypasses_budget_validation(self):
4545
options.validate("source", errors)
4646
self.assertEqual([], errors)
4747

48+
def test_overlap_allowed_only_on_paragraph_methods(self):
49+
# Matches the server / C# / Node clients: overlap is consumed only by the two paragraph methods.
50+
for method in (ChunkingMethod.PLAIN_TEXT_SPLIT_PARAGRAPHS, ChunkingMethod.MARK_DOWN_SPLIT_PARAGRAPHS):
51+
errors = []
52+
ChunkingOptions(method, 100, 10).validate("source", errors)
53+
self.assertEqual([], errors, method)
54+
55+
def test_overlap_rejected_on_non_paragraph_methods(self):
56+
for method in (
57+
ChunkingMethod.PLAIN_TEXT_SPLIT,
58+
ChunkingMethod.PLAIN_TEXT_SPLIT_LINES,
59+
ChunkingMethod.MARK_DOWN_SPLIT_LINES,
60+
ChunkingMethod.HTML_STRIP,
61+
):
62+
errors = []
63+
ChunkingOptions(method, 100, 10).validate("source", errors)
64+
self.assertEqual(1, len(errors), method)
65+
self.assertIn("OverlapTokens", errors[0])
66+
4867

4968
if __name__ == "__main__":
5069
unittest.main()

0 commit comments

Comments
 (0)