Anki Spaced Repetition Program

repository·main·Indexed 12 days ago

https://github.com/ankitects/anki

A spaced repetition program for efficient learning and memorization. This documentation covers the desktop version's source code, including installation on Linux, running Anki and the Anki sync server in Docker containers, and developing add-ons using the aqt package. It also details the use of Protocol Buffers (Protobuf) for communication between Rust, Python, and TypeScript components.

Tokens
179.8K
Snippets
466
Records
962
Agent score
99%

What's inside Anki

  1. Overview of Anki Add-on Architecture

    main

    Anki add-ons are implemented as Python modules that Anki loads during its startup process.

    Add-ons interact with Anki through two primary mechanisms:

    1. Hooks: Add-ons can register themselves to be notified when specific actions occur (for example, a hook that triggers when the browse screen is loaded).
    2. UI Modification: Add-ons can modify the user interface, such as adding new menu items, in response to those actions.

    While the core UI is written in Python/PyQt, certain screens (like the review screen and editor) utilize TypeScript and Svelte. To develop add-ons, familiarity with Python is required.

  2. Manage rows in the Card/Note Table

    main

    The table rows represent cards or notes matching your search.

    • Selection: Drag the mouse or hold <kbd>Ctrl</kbd> (or <kbd>Command</kbd> on Mac) to select multiple rows. When multiple rows are selected, the editor is temporarily hidden.
    • Selection Logic:
      • In Cards mode, a note is selected if any of its cards are selected.
      • In Notes mode, a card is selected if its note is selected.
    • Current Item: Clicking a row selects it as the 'current' card or note.
      • In Cards mode, the current note is the note of the current card.
      • In Notes mode, the current card is the first card of the current note.
    • Visual Indicators: Row background colors indicate status:
      1. Flagged: Uses the flag color.
      2. Suspended: Yellow.
      3. Marked (Notes mode only): Purple.
  3. Understand why Anki limits the cards you see

    main

    Anki uses a spaced repetition algorithm rather than a traditional flashcard 'cramming' approach. Instead of you deciding when to stop reviewing a card, Anki decides when you are most likely to forget it and schedules the review for that time.

    • Spaced Repetition: If you answer a card correctly, the delay until the next review grows larger (from days to months or years).
    • The 'Again' Button: If you press Again, the card will be shown again soon.
    • Efficiency: Reviewing material multiple times in a short period (cramming) is less effective than following Anki's scheduled delays.

    If you feel like you aren't seeing all your cards, it is likely because the algorithm has determined you have already mastered them or they are not yet due for review.

  4. Locate Anki user data and profile folders

    main

    Anki stores user data (notes, decks, cards, media, and backups) in specific locations depending on your operating system and Anki version.

    Windows

    • Recent versions: %APPDATA%\Anki2
    • Older versions: Documents\Anki

    macOS

    • Recent versions: ~/Library/Application Support/Anki2 (Note: The Library folder is hidden; hold the Option key while clicking the Go menu in Finder to reveal it).
    • Older versions: Documents/Anki

    Linux

    • Recent versions: ~/.local/share/Anki2 (or $XDG_DATA_HOME/Anki2 if a custom path is set).
    • Flatpak builds: ~/.var/app/net.ankiweb.Anki/data/Anki2/
    • Older versions: ~/Documents/Anki or ~/Anki

    Profile Contents

    Each profile folder contains:

    • collection.anki2: Your notes, decks, and cards.
    • collection.media: Your audio and images.
    • backups: A folder containing backups.
    • prefs.db: Program-level and profile-level preferences.

    CRITICAL: Never copy or move your collection while Anki is open, as this can cause corruption.

  5. Best practices for using shared decks

    main

    While shared decks are useful for saving time on simple factual subjects (like capital cities or flags), they should be used as a supplement rather than a replacement for external study material when learning complex subjects.

    Key considerations:

    • Context: Many shared decks lack the background explanations or context that the original creator already understood. This can make them difficult to use without external textbooks or teachers.
    • Active Learning: Creating your own decks is often more effective for complex subjects (like languages or sciences) because the process of inputting information forces you to identify key points and build a deeper understanding.
    • Language Learning: Avoid simply memorizing long lists of word-translation pairs; effective language learning requires exposure to real-world sentences and context.
  6. Manage media synchronization

    main

    Anki synchronizes sounds and images used by your notes.

    Key Media Sync Behaviors

    • Detection: Anki detects when media is added, removed, or replaced in your media folder. It cannot detect if you have edited the contents of an existing file. To sync edits, you must replace the file.
    • Merging: Media changes are always merged, even during one-way (Upload/Download) syncs.
    • Deletion Safety: To prevent accidental loss, deletions only sync to other devices if they are made after the device is fully in sync. If you delete files before a sync completes, they may be re-downloaded from AnkiWeb during the next sync.
    • Restoring Deleted Media: If you accidentally deleted media, go to preferences and log out. The next sync will attempt to restore deleted files if they are still available on AnkiWeb.
    • Filesystem Note: If running Anki from a USB flash drive, use an NTFS filesystem. Anki may fail to detect media changes on FAT32 filesystems.
  7. Handle asynchronous Webview communication in Anki 2.1

    main

    The transition to QtWebEngine introduces several asynchronous behaviors that differ from the old QtWebKit implementation:

    • Communication: AnkiWebView() provides a pycmd(str) function in JavaScript which calls the onBridgeCmd(str) method in Python.
    • JavaScript Evaluation: JavaScript is now evaluated asynchronously. To get a result from a JS expression, use ankiwebview.evalWithCallback().
    • Editor Saves: editor.saveNow() now requires a callback. If your add-on performs actions in the browser, call editor.saveNow() first and execute your logic within the callback.
    • Page Actions: Actions like mw.web.triggerPageAction(QWebEnginePage.Copy) are asynchronous and should be rewritten using JavaScript or a delay.
    • Scroll Position: Methods like setScrollPosition() are no longer supported directly and must be implemented via JavaScript.
    • Key Events: WebEngine does not provide keyPressEvent(). To handle custom shortcuts, use setStateShortcuts() to fire a hook for adjusting shortcuts based on state.
  8. Use Oneofs in Protobuf

    main

    All fields within a oneof block are implicitly optional. The same caveats regarding default values in Python and Typescript apply to oneof fields.

    In Python, you can use WhichOneof("field_name") to determine which specific field in the oneof group is currently set. It returns the name of the set field as a string.

    message Foo {
        oneof bar {
          string name = 1;
          int32 number = 2;
        }
    }
    message = Foo(name="")
    assert message.WhichOneof("bar") == "name"
  9. Configure FSRS Desired Retention

    main

    Desired retention controls the probability that you will remember a card when it is scheduled for review. The default value is 0.90.

    Impact on Workload

    Adjusting this value has an exponential impact on your daily review workload:

    • Higher Retention: Increasing retention (e.g., to 0.95 or 0.97) significantly shortens intervals, meaning you must review cards much more frequently.
    • Lower Retention: Decreasing retention reduces workload but increases the number of cards you forget, which can be demotivating and may eventually increase workload if forgetting becomes too frequent.

    Recommendations

    • Keep the value between the Compute Minimum Recommended Retention and 0.97.
    • Use the Compute minimum recommended retention (CMRR) tool to find a baseline that balances learning efficiency and workload.