This project provides an Anki Addon and a standalone CLI tool to automatically generate rich language learning flashcards using Large Language Models (LLMs) like Google Gemini. By providing a target word and the sentence where you found it, the tool extracts its context-specific definition, uncovers its grammatical type, and generates relevant example sentences.
- Context-Aware Definitions: Resolves word ambiguity by analyzing the context you saw the word in.
- Auto-Generated Examples: Automatically populates the card with multiple usage examples.
- Anki Addon: Seamless UI to generate and add cards straight into your daily deck.
- CLI Interface: Generate and insert cards via terminal (using AnkiConnect).
- Customizable Card Template: Map the output fields (
word,context,definition,type,synonyms,examples) to your own Anki Note format!
- Python 3.9+ (if using the CLI standalone)
- A Google Gemini API Key
- Locate your Anki Addons folder. Open Anki and go to Tools -> Add-ons -> View Files.
- Copy this entire project directory (
polar-orion) into the addons folder. Let's rename it to something recognizable likecontextual_flashcards. - Restart Anki.
- Open Anki.
- Go to Tools -> Contextual Flashcards.
- Click on the Settings button.
- Go to the Basic tab and enter your Google Gemini API Key. (You can get one from Google AI Studio).
- In the Anki Settings tab, ensure the mapping of outputs fits your Note Type. The generator outputs the following internal properties:
word: The target word.context: The sentence where you saw it.definition: The meaning of the word in that specific context.type: The grammatical type (noun, verb, etc).synonyms: A list of synonyms for the word in this context.examples: A list of 1-3 example sentences.
If you don't have a template ready, go to Tools -> Manage Note Types -> Add in Anki and create a new Note Type (e.g., based on "Basic") with the following fields:
WordContextDefinitionTypeSynonymsExamples
Then in the Addon settings, map word -> Word, context -> Context, synonyms -> Synonyms, etc.
- While studying or browsing, if you find a word you want to study, go to Anki's Tools -> Contextual Flashcards.
- Enter the Word and paste the Context.
- Select your target language and click "Generate".
- After reviewing the generated content in the preview box, click "Add to Anki".
To use the CLI, Anki must be running and have the AnkiConnect addon installed (Addon Code: 2055492159).
Configure your CLI tools by saving your settings to ~/.anki_context_flashcard_config.json:
{
"gemini_api_key": "YOUR_API_KEY",
"default_model": "gemini",
"default_language": "English",
"deck_name": "Default",
"note_type": "Language",
"field_mapping": {
"word": "Word",
"definition": "Definition",
"context": "Context",
"type": "Type",
"synonyms": "Synonyms",
"example1": "Example 1",
"example2": "Example 2",
"example3": "Example 3"
}
}Run the script from your terminal:
python ./cli.py --word "aberration" --context "She is normally calm and level headed, so this outburst is an aberration." --lang "Spanish"- Support for Local LLM inference (e.g., via LM Studio / Ollama).