Coverage for /home/admin/Documents/AI/applications/lexigram-dev/lexigram/experimental/ai/lexigram-ai-rag/src/lexigram/ai/rag/preprocessing/base.py: 93%

15 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-25 07:19 +0800

1""" 

2Base preprocessor class for document preprocessing. 

3""" 

4 

5from __future__ import annotations 

6 

7from abc import ABC, abstractmethod 

8from typing import TYPE_CHECKING, Any 

9 

10if TYPE_CHECKING: 

11 from lexigram.ai.rag.preprocessing.document import PreprocessedDocument 

12else: 

13 # Forward declaration 

14 class PreprocessedDocument: 

15 content: str 

16 metadata: Any 

17 raw_content: str | None = None 

18 preprocessing_stats: dict[str, Any] = {} 

19 

20 

21class AbstractPreprocessor(ABC): 

22 """Base class for all document preprocessors. 

23 

24 All preprocessors should inherit from this class 

25 to ensure consistent interface and behavior. 

26 """ 

27 

28 def __init__(self, name: str): 

29 """Initialize preprocessor. 

30 

31 Args: 

32 name: Name of the preprocessor. 

33 """ 

34 self.name = name 

35 

36 @abstractmethod 

37 async def preprocess( 

38 self, 

39 content: str, 

40 **kwargs, 

41 ) -> PreprocessedDocument: 

42 """Preprocess document content. 

43 

44 Args: 

45 content: Document content to preprocess. 

46 **kwargs: Additional preprocessing parameters. 

47 

48 Returns: 

49 Preprocessed document with extracted information. 

50 """ 

51 

52 def __repr__(self) -> str: 

53 """String representation of preprocessor.""" 

54 return f"{self.__class__.__name__}(name='{self.name}')"