feat: add seconds-based time window support for Thompson Sampling #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implements sliding time window functionality for Thompson Sampling to support non-stationary content optimization. Enables content marketers to focus AI recommendations on recently active content while maintaining backward compatibility.
Implementation Details
New Storage Methods
getAllArmsDataWithWindow($experiment_uuid, $time_window_seconds)- Filters arms by activity timestampgetAllArmsData()methodNew Manager Methods
getThompsonScoresWithWindow($experiment_uuid, $time_window_seconds)- Thompson Sampling with time filteringgetThompsonScores()now uses new method internallyDatabase Optimizations
rl_experiment_totals(experiment_uuid, updated)rl_arm_data(experiment_uuid, updated, arm_id, turns, rewards, created)Technical Benefits
Database Schema Changes
BREAKING CHANGE: Requires fresh installation or manual index updates
New indexes replace old separate indexes:
rl_experiment_totals:experiment_uuid+updated→experiment_updated(experiment_uuid, updated)rl_arm_data:experiment_uuid+updated→covering_time_window(experiment_uuid, updated, arm_id, turns, rewards, created)Testing Performed
Use Cases Enabled
Content Types Benefiting:
Content Types Unchanged:
Related Issues & PRs
Resolves: #2
Paired with: dxpr/ai_sorting#6 (UI integration)
Related: dxpr/ai_sorting#5 (UI issue)
Deployment Notes
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com