feat(profile): user-profile feature registry + builder (phase A)
Centralizes user-level features (completion_rate_30d, dismiss_rate_30d, mean_dwell_ms_30d, preferred_hour, tip_volume_30d) in a TS registry that owns both definition and SQL aggregation, since the data lives in the TS-owned SQLite tables (tip_views/tip_feedback). Lazy TTL refresh keeps recommend latency bounded; values persist in user_profile_features (KV). ml/serving accepts profile_features on /score + /generate but does not yet consume them — extending the bandit feature vector changes D and resets every user's learned state, so that's a deliberate phase-B step. Includes ml/features/profile_schema.py as a contract mirror with a sync test that diffs name sets against registry.ts. ADR-0011 records the data-locality reasoning (registry in TS, not Python as the issue originally suggested). Phase B (deferred): event-driven incremental updates, bandit consumption with state migration, admin per-user profile page, staleness alerts. Refs #81. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -152,6 +152,11 @@ class ScoreRequest(BaseModel):
|
||||
user_id: str
|
||||
candidates: list[Candidate]
|
||||
context: Context = Context()
|
||||
# User-level features computed by the API (#81 phase A). Accepted, logged,
|
||||
# but not yet consumed by the bandit — extending the feature vector
|
||||
# changes `D` and resets every user's learned state, which is a deliberate
|
||||
# follow-up (phase B), not a side effect of this PR.
|
||||
profile_features: Optional[dict] = None
|
||||
|
||||
|
||||
class ScoreResponse(BaseModel):
|
||||
@@ -184,6 +189,9 @@ class GenerateRequest(BaseModel):
|
||||
context: PromptContext = PromptContext()
|
||||
n: int = 3
|
||||
prompt_version: Optional[str] = None # None → server default (env DEFAULT_PROMPT_VERSION)
|
||||
# User-level features (#81 phase A). Accepted by the contract; not yet
|
||||
# injected into the prompt — that's a #84-style prompt-design decision.
|
||||
profile_features: Optional[dict] = None
|
||||
|
||||
|
||||
class TipCandidate(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user