1"""Context pruning for memory entries — trims to fit token budgets.
2
3Provides pluggable scoring strategies (recency, hybrid) and a greedy
4pruning algorithm to keep high-value entries within a token limit.
5"""
6
7from __future__ import annotations
8
9from typing import TYPE_CHECKING
10
11if TYPE_CHECKING:
12 from lexigram.ai.memory.pruning.pruner import DynamicContextPruner
13 from lexigram.ai.memory.pruning.scorer import (
14 HybridScorerImpl,
15 RecencyScorerImpl,
16 RelevanceScorerProtocol,
17 )
18 from lexigram.ai.memory.pruning.types import PruningResult, PruningStrategy
19
20_LAZY_IMPORTS: dict[str, str] = {
21 "DynamicContextPruner": "lexigram.ai.memory.pruning.pruner",
22 "HybridScorerImpl": "lexigram.ai.memory.pruning.scorer",
23 "RecencyScorerImpl": "lexigram.ai.memory.pruning.scorer",
24 "RelevanceScorerProtocol": "lexigram.ai.memory.pruning.scorer",
25 "PruningResult": "lexigram.ai.memory.pruning.types",
26 "PruningStrategy": "lexigram.ai.memory.pruning.types",
27}
28
29
30def __getattr__(name: str) -> object:
31 if name in _LAZY_IMPORTS:
32 import importlib
33
34 module = importlib.import_module(_LAZY_IMPORTS[name])
35 value = getattr(module, name)
36 globals()[name] = value
37 return value
38 msg = f"module {__name__!r} has no attribute {name!r}"
39 raise AttributeError(msg)
40
41
42def __dir__() -> list[str]:
43 return sorted(set(__all__) | set(_LAZY_IMPORTS.keys()))
44
45
46__all__ = list(_LAZY_IMPORTS.keys())