Coverage for src/qdrant_loader/core/chunking/strategy/markdown/splitters/fallback.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-08 06:05 +0000

1"""Fallback splitter implementation extracted from `section_splitter`.""" 

2 

3import re 

4 

5from qdrant_loader.core.chunking.strategy.markdown.splitters.base import BaseSplitter 

6 

7 

8class FallbackSplitter(BaseSplitter): 

9 """Simple fallback splitter for when other strategies fail.""" 

10 

11 def split_content(self, content: str, max_size: int) -> list[str]: 

12 """Simple chunking implementation based on fixed size. 

13 

14 Args: 

15 content: Content to split 

16 max_size: Maximum chunk size 

17 

18 Returns: 

19 List of content chunks 

20 """ 

21 chunks: list[str] = [] 

22 

23 paragraphs = re.split(r"\n\s*\n", content) 

24 current_chunk = "" 

25 

26 for para in paragraphs: 

27 if len(current_chunk) + len(para) <= max_size: 

28 current_chunk += para + "\n\n" 

29 else: 

30 if current_chunk: 

31 chunks.append(current_chunk.strip()) 

32 current_chunk = para + "\n\n" 

33 

34 if current_chunk: 

35 chunks.append(current_chunk.strip()) 

36 

37 return chunks 

38 

39 

40__all__ = ["FallbackSplitter"]