Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
F

fsrs-rs

> 编程语言
Open source

FSRS for Rust, including Optimizer and Scheduler

400 stars0 likes2 views
WebsiteGitHub

About

FSRS for Rust, including Optimizer and Scheduler

FSRS for Rust

The Free Spaced Repetition Scheduler (FSRS) is a modern spaced repetition algorithm. It springs from MaiMemo's DHP model, which is a variant of the DSR model proposed by Piotr Wozniak.

FSRS-rs is a Rust implementation of FSRS. It also provides simulation capabilities and basic scheduling functionality.

For more information about the algorithm, please refer to the wiki page of FSRS.


Quickstart

Add the crate

Add FSRS to your project:

bash
cargo add fsrs

The scheduling example below also uses chrono to track review times:

toml
chrono = { version = "0.4", default-features = false, features = ["std", "clock"] }

Run cargo run --example to see the complete samples (schedule, migrate, optimize, cost_adr).

Schedule reviews

rust
use chrono::{Duration, Utc};
use fsrs::{FSRS, MemoryState};

let fsrs = FSRS::default();
let desired_retention = 0.9;
let previous_state: Option = None;
let elapsed_days = 0;

let next_states = fsrs.next_states(previous_state, desired_retention, elapsed_days)?;
let review = next_states.good;

let interval_days = review.interval.round().max(1.0) as u32;
let due = Utc::now() + Duration::days(interval_days as i64);

Replace previous_state/elapsed_days with a stored MemoryState and the number of days since the prior review when scheduling existing cards. Full example: examples/schedule.rs.

Optimize parameters from review logs

…

Feed the optimizer a vector of FSRSItem instances built from your review history; the returned parameters can then be persisted or supplied to schedulers. Full example: examples/optimize.rs.

Train and use a single-user Cost ADR policy

fsrs-rs also includes a CPU/Rayon single-user optimizer for the FSRS-6 and FSRS-7 Cost ADR policy. It searches a 15-parameter cost-conditioned desired-retention policy and evaluates it against a fixed 16-point desired-retention baseline portfolio. The report includes hypervolume, same-target time-saved AUC, relative same-target time-saved AUC, and memory-span coverage.

bash
cargo run --release --example cost_adr

The example accepts command-line overrides for quick experiments:

bash
cargo run --release --example cost_adr -- --days 90 --deck 2000 --pop 8 --gen 5

By default, the example uses the same simulation scale as srs-simulator: 1825 days, a 10000-card deck, 10 new cards per day, a 9999-review limit, and a 720-minute daily cost limit. Its training defaults come from CostAdrTrainingConfig::default(). Cost ADR derives separate training-simulation and evaluation seeds from the base seed so the default report does not reuse the same simulator rollout seeds for training and evaluation.

The example trains a per-user CostAdrPolicy, shows which fields should be persisted with the user's FSRS parameters, and demonstrates the runtime scheduling loop with CostAdrPolicy::next_states, which returns the post-rating MemoryState, cost-conditioned desired retention, and next interval for each answer button. Use simulate_with_cost_adr_policy when you already have a CostAdrPolicy and want the simulator to recompute per-card desired retention after each review in an offline simulation.

Migrate from SM-2 style data

rust
use fsrs::{FSRS, FSRSItem, FSRSReview};

let fsrs = FSRS::default();
let sm2_retention = 0.9;
let ease_factor = 2.5;
let interval = 10.0;

let initial_state = fsrs.memory_state_from_sm2(ease_factor, interval, sm2_retention)?;

let reviews = vec![
    FSRSReview { rating: 3, delta_t: 5.0 },
    FSRSReview { rating: 4, delta_t: 10.0 },
];

let memory_state = fsrs.memory_state(
    FSRSItem { reviews },
    Some(initial_state),
)?;

Use memory_state_from_sm2 when you only have the latest SM-2 ease/interval; pass the result as the starting point while you replay any partial review history. Full example: examples/migrate.rs.

Online development

You can use .

Local development

add

bash
#!/bin/sh
cargo fmt
cargo clippy -- -D warnings
git add .

to .git/hooks/pre-commit, then chmod +x .git/hooks/pre-commit

Bindings

  • c
  • python
  • nodejs
  • dart
  • php

Q&A

  • What is the difference between fsrs-rs and rs-fsrs

    If you only want to schedule cards, use [lang]-fsrs or the bindings.

    If you need to optimize, use this crate or its bindings.

  • Why use two crates instead of one?

    Calculating the weights involves tensor operations so the data types are different (Tensor vs Vec/Slice). If we were to use one crate, this would mean using cfg to change the variable type, which would be tedious. Because of this, instead we publish two separate crates.

    Another reason is, it would be hard to port to other languages while using Tensors.

    This crate now uses scalar and SIMD Rust kernels for inference and analytic gradients for training. It has no Burn dependency or generic tensor-backend API; FSRS-6 and FSRS-7 are selected from the parameter count.

  • What about the name?

    Before this crate was made, go-fsrs and other libraries already existed, so the name rs-fsrs was chosen.

    Then we wanted to port the torch version to Rust so that everyone could optimize on their own devices (tch-rs uses libtorch which is too heavy). Since the algorithm is called fsrs, we add an -rs on the end.

Acknowledgements

Thank you to everyone who has contributed time, ideas, and care to this project. Special thanks to:

  • Jarrett Ye — core algorithm, training, benchmarking, and documentation.
  • Damien Elmes — training API robustness, progress handling, and dependency upkeep.
  • Luc Mcgrady — simulator features, per-card parameters, and scheduling enhancements.
  • Asuka Minato — CI/tooling, bindings, and documentation updates.
  • Expertium — scheduler/simulator tuning and parameter naming refinements.

Issues· 15 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustfsrsmachine-learningrustspaced-repetition-algorithm

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言