Overview
Refactron’s Pattern Learning System learns from your refactoring decisions, building a knowledge base that improves the quality and relevance of future recommendations. The more you use Refactron, the smarter it gets!How It Works
Pattern Fingerprinting
When Refactron suggests a refactoring, it creates a unique “fingerprint” of the code pattern
Pattern Learning
Refactron tracks:
- Acceptance rates for each pattern
- Pattern frequency and recency
- Code metrics improvements
- Project-specific preferences
Key Features
Automatic Learning
Learns from every refactoring decision you make
Smart Ranking
Ranks suggestions by historical acceptance patterns
Project-Specific
Adapts to your project’s unique coding style
Persistent Storage
Patterns persist across sessions
Configuration
Enable Pattern Learning
Pattern learning is enabled by default. Configure in.refactron.yaml:
.refactron.yaml
Python API
Providing Feedback
Interactive Feedback
Automatic Feedback
Feedback is automatically recorded when you apply refactorings:Manual Feedback
Provide explicit feedback for specific operations:Python API Feedback
Pattern Analysis
View Pattern Statistics
- Most accepted patterns
- Patterns with low acceptance
- Recommendations for tuning
Get Tuning Recommendations
Apply Tuning
Ranking in Action
When pattern learning is enabled, suggestions show ranking scores:Storage Location
Pattern data is stored in JSON files: Default Locations:- Project root:
.refactron/patterns/ - User home:
~/.refactron/patterns/(fallback)
patterns.json- Learned patternsfeedback.json- Feedback recordsproject_profiles.json- Project configspattern_metrics.json- Pattern metrics
.refactron.yaml
Configuration Options
Master switch for all pattern learning features
Enable learning from feedback (requires
enable_pattern_learning)Enable ranking based on learned patterns (requires
enable_pattern_learning)Custom storage directory (null = auto-detect project root or home directory)
Best Practices
Provide Consistent Feedback
Provide Consistent Feedback
The more feedback you provide, the better the system learns:
- Accept good refactorings
- Reject inappropriate suggestions
- Ignore if unsure
Use Project-Specific Tuning
Use Project-Specific Tuning
For large projects, use automated tuning:
Review Pattern Statistics
Review Pattern Statistics
Periodically check pattern performance:
Custom Storage for CI/CD
Custom Storage for CI/CD
In CI/CD environments, use consistent storage:
Advanced Usage
Custom Pattern Weights
Batch Learning
Pattern Cleanup
Integration with AI
Pattern learning integrates with AI Features:- AI suggestions use learned patterns for better context
- Feedback on AI refactorings improves future AI suggestions
- RAG system considers pattern preferences
Troubleshooting
Patterns Not Learning
Patterns Not Learning
Solutions:
- Check
pattern_learning_enabledistrue - Verify storage directory is writable
- Check logs:
refactron refactor --log-level DEBUG
Ranking Not Working
Ranking Not Working
Solutions:
- Check
pattern_ranking_enabledistrue - Ensure patterns have been learned (provide feedback first)
- Verify sufficient pattern history exists
Storage Issues
Storage Issues
Solutions:
- Check directory permissions
- Use custom
pattern_storage_dirif needed - Verify disk space available
Performance
- Memory: In-memory caching with invalidation on updates
- Storage: ~100-200 KB for typical project (100-1000 patterns)
- Learning Speed: <100ms per feedback record
- Ranking Speed: ~10ms per operation
