Skip to content

Knowledge: puzzle selection, a random order, a quality filter and facets (draft-1, cjus/chessgui#575) - #30

Merged
cjus merged 1 commit into
mainfrom
claude/puzzle-selection
Nov 14, 2026
Merged

cjus merged 1 commit into
mainfrom
claude/puzzle-selection

Conversation

@cjus

@cjus cjus commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Closes #29. Part of cjus/chessgui#575 (the puzzle trainer). Draft until chessdb has served it (below).

What changes

spec/knowledge.md, cnp::knowledge and a conformance session change together (rule 1):

  • Capability puzzleSelection: offers the three fields and the operation below. A client sends none of them to a node without it.
  • knowledge/puzzles takes order (easiest, the default, or random), seed (0 to 4294967295, only with random) and quality (reliable). The answer says the seed it used and, when asked, the quality thresholds.
  • knowledge/puzzleFacets (new): the node's rating bands, the total in each, and each theme's counts per band, optionally under quality.
  • Session conformance/knowledge/selection.jsonl (requires: knowledge.puzzleSelection): a random pass names its seed and repeats from it, the seed range, quality's thresholds, facets, and six refusals.
  • Recorded in a new "Changes" section of the knowledge spec.

Versioning (rule 2): only optional fields, a method and a capability, so no new major version and no new contract name; contract stays draft-1.

Why this shape (measured, #29)

On the real file (6,193,530 puzzles, imported by chessdb main, 20-row pages, warm cache, one machine):

Strategy Common theme and band Rare combination
hash sort of the filtered set 1.2 to 6.2 s 0.8 to 3.2 s
random OFFSET 0.2 to 6.0 s up to 6.9 s
scan forward from a random start 0.1 to 1 ms 0.3 to 1.1 s

So random is a scan from a seeded start in the node's storage order, wrapping, not a sort. The spec says it is not a shuffle and why (a page is neighbours in storage order; the start is only even over matches when they aren't clustered, which holds for Lichess's file, ordered by an id unrelated to rating and theme: I read that from its first rows, I haven't tested the evenness).

reliable leaves the thresholds to the node and the answer names them; chessdb's are measured at plays >= 100, popularity >= 80 and rating deviation <= 110 (70.7% of the puzzles).

Decisions I made, for review

  • A named preset (quality: "reliable") rather than three threshold fields, so a node can tune it; the answer carries the numbers.
  • seed is a u32, so a JSON number is exact in every client.
  • Facets bands are the node's, and a client must use the answer's.
  • Left out on purpose: several themes in one request, excluding a theme, the puzzles of the day (all listed under "Not in draft 1"), and skipping puzzles the player solved (the node doesn't know progress; the client filters).

Checks (run locally on this commit)

cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test (the knowledge spec's examples parse, and every session file reads and sends valid messages), RUSTDOCFLAGS=-D\ warnings cargo doc --workspace --no-deps, cargo deny check: all pass.

Not done / why this is a draft

  • No node serves it yet. chessdb will, in its own PR against this branch; I'll mark this ready and merge once that has run the new session against the real binary.
  • Not measured: a cold cache, a slower disk, or the facets kept up to date as an import runs and resumes.

🤖 Generated with Claude Code

…ets (draft-1, cjus/chessgui#575)

knowledge/puzzles takes order (easiest or random), seed and quality (reliable); the
answer names the seed and the thresholds used. knowledge/puzzleFacets counts puzzles
by theme and rating band, so a client can offer a choice without finding out that a
combination is empty. New capability puzzleSelection. All optional: a node without it,
or a request that doesn't send it, is unchanged.

The design is measured, not guessed: on the real Lichess puzzles file (6,193,530
puzzles, chessdb main) a hash sort of the filtered set took 0.8 to 6.2 s and a random
offset up to 6.9 s, while a forward scan from a random start took 0.1 to 1 ms for common
themes. So random is a scan from a seeded start in the node's storage order, wrapping,
and the spec says it is not a shuffle. Facets take 68 to 78 s to group at request time,
so the spec has them kept as the node imports.

Spec, types (cnp::knowledge) and a conformance session (knowledge-selection) change
together.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cjus

cjus commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

chessdb has now served this: cjus/chessdb#41 (draft, pinned to this branch's cef3bde). Run on the real binary over the real Lichess puzzles file (6,193,530 puzzles):

  • knowledge-selection passes against it, with the rest of the conformance run: 23 passed, 52 skipped (voice), 0 failed.
  • knowledge/puzzleFacets answers in 1 to 2 ms, and its counts equal an independent count of the CSV (4,376,768 reliable puzzles).
  • A random pick takes 1 to 2 ms for common themes; a random page of 20 takes 1 to 3 ms; the cells with 20 puzzles or fewer take up to 1.3 s because the scan reaches the end of the table.
  • The spec as written held up: nothing needed changing in this PR. One thing it says that chessdb makes concrete: puzzleFacets' counts are exactly what knowledge/puzzles reaches for that theme, band and quality (chessdb tests that for every cell).

I'll mark this ready for review and merge it once you've looked at the design decisions in the description (the reliable preset, a u32 seed, the node's own bands), or tell me to go ahead.

@cjus
cjus marked this pull request as ready for review November 14, 2026 14:10
@cjus
cjus merged commit e26375c into main Nov 14, 2026
2 checks passed
@cjus
cjus deleted the claude/puzzle-selection branch November 14, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

knowledge/puzzles: quality filter, varied order and facets for a puzzle trainer (cjus/chessgui#575)

1 participant