Skip to content

Commit 5771c7c

Browse files
Create recommender/state.py
1 parent 92eaaf6 commit 5771c7c

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎recommender/state.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# recommender/state.py
2+
from pydantic import BaseModel, Field
3+
from typing import List, Optional
4+
5+
class SessionState(BaseModel):
6+
"""
7+
The immutable token tracking contract passed across the inference pipeline.
8+
Enforces structural context bounds on raw clickstream sequences.
9+
"""
10+
session_id: str
11+
raw_item_history: List[int] = Field(default_factory=list)
12+
processed_tensor_input: Optional[List[float]] = None
13+
top_k_recommendations: List[int] = Field(default_factory=list)
14+
prediction_confidence: List[float] = Field(default_factory=list)
15+
16+
# Operational Observability
17+
sequence_length: int = 0
18+
inference_latency_ms: float = 0.0
19+
fallback_triggered: bool = False
20+
execution_trace: List[str] = Field(default_factory=list)
21+
22+
def log_trace(self, message: str) -> "SessionState":
23+
return self.model_copy(update={"execution_steps": list(self.execution_trace) + [message]})

0 commit comments

Comments
 (0)