Coverage for /home/admin/Documents/AI/applications/lexigram-dev/lexigram/experimental/ai/lexigram-ai-memory/src/lexigram/ai/memory/exceptions.py: 80%

20 statements  

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

1"""Exceptions for lexigram-ai-memory.""" 

2 

3from __future__ import annotations 

4 

5from lexigram.contracts.ai.exceptions import AIMemoryError as _ContractsAIMemoryError 

6from lexigram.contracts.ai.memory import ConsolidationError 

7 

8 

9class MemorySystemError(_ContractsAIMemoryError): 

10 """Base exception for memory operations.""" 

11 

12 _code: str = "LEX_ERR_MEM_005" 

13 

14 

15class MemoryStoreError(MemorySystemError): 

16 """Raised when a backend store operation fails.""" 

17 

18 _code: str = "LEX_ERR_MEM_006" 

19 

20 def __init__(self, message: str, store: str | None = None) -> None: 

21 """Initialise with optional store name context. 

22 

23 Args: 

24 message: Human-readable description. 

25 store: Name of the store that raised the error. 

26 """ 

27 super().__init__(message) 

28 self.store = store 

29 

30 

31class MemoryCapacityError(MemorySystemError): 

32 """Raised when a memory store is at capacity and cannot accept new entries.""" 

33 

34 _code: str = "LEX_ERR_MEM_008" 

35 

36 def __init__(self, message: str, capacity: int | None = None) -> None: 

37 """Initialise with optional capacity context. 

38 

39 Args: 

40 message: Human-readable description. 

41 capacity: Maximum capacity that was exceeded. 

42 """ 

43 super().__init__(message) 

44 self.capacity = capacity 

45 

46 

47class EmbeddingError(MemorySystemError): 

48 """Raised when generating or storing an embedding fails.""" 

49 

50 _code: str = "LEX_ERR_MEM_009" 

51 

52 

53class FactExtractionError(MemorySystemError): 

54 """Raised when entity/fact extraction from text fails.""" 

55 

56 _code: str = "LEX_ERR_MEM_010" 

57 

58 

59__all__ = [ 

60 "ConsolidationError", 

61 "EmbeddingError", 

62 "FactExtractionError", 

63 "MemoryCapacityError", 

64 "MemoryStoreError", 

65 "MemorySystemError", 

66]