Implement: SM-2 review engine — scheduling, due cards, and rating #16

Open
opened 2026-08-20 15:31:53 +02:00 by gaetan · 0 comments
Owner

Wayfinder map: #1
Dependencies: #13 (project scaffolding), #15 (database layer)

Description

Implement the SM-2 spaced repetition algorithm: query due cards, apply ratings, update scheduling. This is the core learning engine.

Tasks

  • Create internal/review/ package
  • Implement SM-2 algorithm:
    • new_interval = old_interval * ease_factor * adjustment
    • Adjustment factors: Again=0, Hard=1.2, Good=2.5, Easy=4.0
    • Ease factor adjustment: ease_factor = ease_factor + (0.1 - (5 - rating) * (0.08 + (5 - rating) * 0.02))
    • If rating is "Again", reset interval to 1 day
  • Rating enum/types:
    • Again (0) — card not remembered, reset to 1 day
    • Hard (1.2) — partial recall
    • Good (2.5) — full recall
    • Easy (4.0) — easy, increase interval more
  • Query due cards: WHERE next_review <= now
  • Prioritization: new cards first, then by next_review ascending
  • Max 10 new cards per day (configurable)
  • Interval cap at 30 days
  • Update progress after each rating
  • Session management: get next card, rate card, check session complete
  • Unit tests for SM-2 algorithm with known inputs/outputs

Acceptance criteria

  • SM-2 formula produces correct intervals for known inputs
  • Due cards are returned in correct priority order
  • Max 10 new cards per day is enforced
  • Interval capped at 30 days
  • Rating updates progress correctly
  • Unit tests pass with verified SM-2 calculations
**Wayfinder map:** #1 **Dependencies:** #13 (project scaffolding), #15 (database layer) ## Description Implement the SM-2 spaced repetition algorithm: query due cards, apply ratings, update scheduling. This is the core learning engine. ## Tasks - [ ] Create `internal/review/` package - [ ] Implement SM-2 algorithm: - `new_interval = old_interval * ease_factor * adjustment` - Adjustment factors: Again=0, Hard=1.2, Good=2.5, Easy=4.0 - Ease factor adjustment: `ease_factor = ease_factor + (0.1 - (5 - rating) * (0.08 + (5 - rating) * 0.02))` - If rating is "Again", reset interval to 1 day - [ ] Rating enum/types: - `Again` (0) — card not remembered, reset to 1 day - `Hard` (1.2) — partial recall - `Good` (2.5) — full recall - `Easy` (4.0) — easy, increase interval more - [ ] Query due cards: `WHERE next_review <= now` - [ ] Prioritization: new cards first, then by next_review ascending - [ ] Max 10 new cards per day (configurable) - [ ] Interval cap at 30 days - [ ] Update progress after each rating - [ ] Session management: get next card, rate card, check session complete - [ ] Unit tests for SM-2 algorithm with known inputs/outputs ## Acceptance criteria - SM-2 formula produces correct intervals for known inputs - Due cards are returned in correct priority order - Max 10 new cards per day is enforced - Interval capped at 30 days - Rating updates progress correctly - Unit tests pass with verified SM-2 calculations
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
gaetan/knowledgify#16
No description provided.