> For AI agents: the complete documentation index is available at https://open-spaced-repetition.github.io/ts-fsrs/llms.txt, the full documentation bundle is available at https://open-spaced-repetition.github.io/ts-fsrs/llms-full.txt.

# Optimizer overview

FSRS ships default model weights, but you can retrain them from your own review logs so the intervals match the people you serve. The Optimizer runs on `@open-spaced-repetition/binding`, which converts review-log CSV into training items, estimates parameters, and reports how well the result predicts held-out reviews. The trained weights plug straight back into `DefaultScheduler` or a custom `defineScheduler` through `weights`. See [Model](https://open-spaced-repetition.github.io/ts-fsrs/guide/model.md) for what weights mean and [Scheduler](https://open-spaced-repetition.github.io/ts-fsrs/guide/scheduler.md) for where they are applied.

Use the same `modelVersion` (`'FSRS-7'` by default, or `'FSRS-6'`) for CSV conversion, training, evaluation, and scheduling. Pass it as the fourth argument to `convertCsvToFsrsItems` and in the training/evaluation options, then call `DefaultScheduler({ version: modelVersion, weights })`. FSRS-7 produces 34 weights and preserves fractional and same-day intervals normalized by the actual local study-day duration; FSRS-6 produces 21 weights and uses whole study days. Same-day follow-up reviews can therefore contribute to FSRS-7 training.

:::warning Beta
The Optimizer is currently in beta, and its API methods may change at any time.
:::


For your Agent

Implement or explain FSRS weight training

Copy Prompt

Use the current ts-fsrs Optimizer contract for this task: [describe the task].

1. Read https://open-spaced-repetition.github.io/ts-fsrs/guide/optimizer/index.md and https://open-spaced-repetition.github.io/ts-fsrs/guide/optimizer/train-evaluate.md for the runtime choices and the review-log pipeline.
2. Convert review-log CSV with convertCsvToFsrsItems; pass the day the next day starts and a timezone or UTC offset.
3. Train with computeParameters(items, { enableShortTerm, modelVersion }) and use the returned weights in DefaultScheduler or a custom defineScheduler.
4. Report fit with evaluateWithTimeSeriesSplits; keep review logs, ratings, and state transitions accurate.
5. Prefer the napi-rs binding in Node and the wasip1 wasm build in a browser Worker.
6. Use the current public API and add focused tests for the training path you implement.

## One package, two runtimes

The binding ships one API, and loading resolves the build for your environment automatically: it searches for an available native package and, in a browser or Worker, falls back to a WebAssembly build. Install the package your environment needs:

Native module (Node, servers, and CLIs):


```sh [npm]
npm install @open-spaced-repetition/binding
```

```sh [yarn]
yarn add @open-spaced-repetition/binding
```

```sh [pnpm]
pnpm add @open-spaced-repetition/binding
```

```sh [bun]
bun add @open-spaced-repetition/binding
```

```sh [deno]
deno add npm:@open-spaced-repetition/binding
```

WASI Preview 1 (wasip1) WebAssembly:


```sh [npm]
npm install @open-spaced-repetition/binding-wasm32-wasip1
```

```sh [yarn]
yarn add @open-spaced-repetition/binding-wasm32-wasip1
```

```sh [pnpm]
pnpm add @open-spaced-repetition/binding-wasm32-wasip1
```

```sh [bun]
bun add @open-spaced-repetition/binding-wasm32-wasip1
```

```sh [deno]
deno add npm:@open-spaced-repetition/binding-wasm32-wasip1
```

wasm32-wasi WebAssembly:


```sh [npm]
npm install @open-spaced-repetition/binding-wasm32-wasi
```

```sh [yarn]
yarn add @open-spaced-repetition/binding-wasm32-wasi
```

```sh [pnpm]
pnpm add @open-spaced-repetition/binding-wasm32-wasi
```

```sh [bun]
bun add @open-spaced-repetition/binding-wasm32-wasi
```

```sh [deno]
deno add npm:@open-spaced-repetition/binding-wasm32-wasi
```

```ts
import { computeParameters } from '@open-spaced-repetition/binding'
```

Your environment resolves the matching build: a server or CLI uses the native module, and a browser or Web Worker uses a wasm build.

:::note COOP/COEP and threading
WebAssembly runs threadless or threaded. Threadless wasm needs no Cross-Origin-Opener-Policy or Cross-Origin-Embedder-Policy headers and reports progress through Worker messages rather than shared memory. A threaded build requires the page to be `crossOriginIsolated`, that is, served with COOP and COEP headers.
:::

## The review-log pipeline

Training follows a short pipeline, each step a binding call:

1. `convertCsvToFsrsItems` turns review-log CSV into a list of `FSRSItem`s.
2. `computeParameters` trains weights from those items and returns the weight array.
3. `evaluateWithTimeSeriesSplits` measures how well the parameters predict held-out reviews.

You can also ask the binding to recommend learning and relearning steps with `computeOptimalSteps`. Walk through each call in [Train and evaluate](https://open-spaced-repetition.github.io/ts-fsrs/guide/optimizer/train-evaluate.md), or run a real training in the trainer on the [Playground](https://open-spaced-repetition.github.io/ts-fsrs/playground.md) page.
