"""Configuration model for the context window management system.
This module defines :class:`ContextWindowConfig`, a Pydantic model that
controls how the context window manager operates. Configuration includes:
- Maximum token limits (model-specific)
- Capacity thresholds for triggering optimization
- Prioritization strategies (relevance, recency, hybrid)
- Minimum importance scores for content retention
The config can be instantiated with defaults or loaded from BaseConfig
for integration with the broader Babylon configuration system.
See Also:
:class:`~babylon.intelligence.rag.context_window.manager.ContextWindowManager`:
The manager that uses this configuration.
:class:`~babylon.config.base.BaseConfig`:
Source of default values when using :meth:`from_base_config`.
"""
from pydantic import BaseModel, ConfigDict
from babylon.config.base import BaseConfig
[docs]
class ContextWindowConfig(BaseModel):
"""Configuration for the Context Window Management system.
Attributes:
max_token_limit: Maximum number of tokens allowed in the context window
capacity_threshold: Percentage of capacity at which optimization should trigger
prioritization_strategy: Strategy for content prioritization (relevance, recency, hybrid)
min_content_importance: Minimum importance score for content to be kept in context
"""
model_config = ConfigDict(frozen=True)
max_token_limit: int = 150000 # Default to 150k tokens
capacity_threshold: float = 0.75 # Default to 75% capacity
prioritization_strategy: str = "hybrid" # Options: relevance, recency, hybrid
min_content_importance: float = 0.2 # Minimum importance score to keep content
[docs]
@classmethod
def from_base_config(cls) -> "ContextWindowConfig":
"""Create context window config from BaseConfig."""
return cls(
max_token_limit=getattr(BaseConfig, "CONTEXT_WINDOW_MAX_TOKENS", 150000),
capacity_threshold=getattr(BaseConfig, "CONTEXT_WINDOW_THRESHOLD", 0.75),
prioritization_strategy=getattr(
BaseConfig, "CONTEXT_WINDOW_PRIORITY_STRATEGY", "hybrid"
),
min_content_importance=getattr(BaseConfig, "CONTEXT_WINDOW_MIN_IMPORTANCE", 0.2),
)