Overview
Auto Tagger provides a public API for extending and integrating with the plugin. This reference documents all public classes, interfaces, and methods.Plugin Class
AutoTaggerPlugin
Main plugin class that extends Obsidian’sPlugin base class.
Location: src/main.ts:34
Current plugin settings
The TF-IDF model instance used for tag suggestions
Methods
Called when the plugin is loaded. Initializes the model, settings tab, and registers event handlers.Lifecycle:
- Loads settings from disk
- Creates TagModel instance
- Registers settings tab
- Scans vault when layout is ready
- Registers editor-change event
- Registers active-leaf-change event
- Adds commands
Called when the plugin is unloaded. Cleans up timers and active notices.
Loads settings from disk and merges with defaults.
Saves current settings to disk.
Clears the cache of suggestions shown per file. Useful after rescanning or when tags have been manually changed.
Interfaces
AutoTaggerSettings
Plugin configuration interface. Location:src/main.ts:16
Debounce delay in milliseconds before checking for tag suggestions after typing
Where to insert accepted tags:
first-line: Insert as inline tags on the first content linefrontmatter: Insert in YAML frontmatter tags arrayinline-end: Insert at the end of the current line
Minimum confidence score for showing suggestions (range: 0.005 - 0.1)
Maximum number of tags to suggest at once (range: 1 - 10)
Whether to automatically suggest tags while editing
TagSuggestion
Represents a single tag suggestion with its confidence score. Location:src/model.ts:15
The suggested tag name (without the # prefix)
Confidence score based on TF-IDF cosine similarity and co-occurrence boost
ModelStats
Statistics about the learned tag model. Location:src/model.ts:20
Total number of markdown files scanned in the vault
Number of documents that contain at least one tag
Number of unique tags found across all documents
Number of unique words in the model’s vocabulary
TagModel Class
The TF-IDF engine that learns from existing tags and suggests new ones. Location:src/model.ts:29
Properties
Read-only property indicating whether the model has completed scanning and is ready to provide suggestions.
Methods
Scans all markdown files in the vault and builds the TF-IDF model.Parameters:
app: App- Obsidian app instanceonProgress?: (pct: number) => void- Optional callback for progress updates (0.0 to 1.0)
ModelStatsProcess:- Clears existing model data
- Processes files in batches of 100
- Extracts tags and tokenizes content
- Builds word frequency maps and co-occurrence matrix
- Finalizes TF-IDF vectors
- Sets
isReadyto true
Generates tag suggestions for the given content.Parameters:
content: string- The document content to analyzeexistingTags: Set<string>- Tags already present in the document (will be excluded from suggestions)maxResults: number = 5- Maximum number of suggestions to returnminScore: number = 0.01- Minimum confidence score threshold
TagSuggestion sorted by score (descending)Algorithm:- Tokenizes content and computes TF-IDF vector
- Calculates cosine similarity with each tag’s vector
- Applies co-occurrence boost based on existing tags
- Filters by minimum score and document count (≥2)
- Sorts and returns top results
Extracts all tags from document content.Parameters:
content: string- The document content
- Inline tags:
#tag-name,#nested/tag - Frontmatter array:
tags: [a, b, c] - Frontmatter list:
Tokenizes document content into words for analysis.Parameters:
content: string- The document content
- Removes frontmatter, code blocks, inline code
- Removes images and links (keeps link text)
- Removes wiki links (keeps link text)
- Removes tags and heading markers
- Splits on non-alphanumeric boundaries
- Filters stop words and short words
Returns current model statistics.
Returns a sorted array of all tags known to the model.
Commands
The plugin registers two commands accessible from the command palette:suggest-tags
Name: “Suggest tags for current note” Function: Manually triggers tag suggestions for the active note, showing all suggestions in a modal dialog. Editor callback: Available when a markdown editor is activerescan-vault
Name: “Rescan vault for tag patterns” Function: Re-scans all notes in the vault to update the tag model. Shows progress notice during scanning. Callback: Available anytimeEvents
The plugin listens to the following Obsidian workspace events:editor-change
Trigger: Fired when the editor content changes Handler: Schedules a debounced tag check if auto-suggest is enabledactive-leaf-change
Trigger: Fired when switching between notes Handler:- Clears pending suggestions
- Hides active notice
- Runs tag check on newly opened note after 500ms delay
Usage Examples
Accessing the Plugin Instance
Manual Tag Suggestions
Extracting Tags
Triggering a Rescan
TF-IDF Algorithm Details
For developers interested in the underlying algorithm:Term Frequency (TF)
Inverse Document Frequency (IDF)
TF-IDF Weight
Cosine Similarity
Co-occurrence Boost
For each existing tag in the document:Performance Considerations
- Files are processed in batches of 100
- Yields to UI thread between batches
- Uses
cachedRead()for better performance
- Debounced by default (2000ms)
- Only processes when editor content changes
- Tag vectors are precomputed during scan
- Full vocabulary is kept in memory
- Tag profiles include word frequency maps
- Co-occurrence matrix is sparse but grows with O(tags²)
Type Definitions
For TypeScript developers, here are the internal type definitions:TagProfile is internal to TagModel and not exposed in the public API.