Class: SwarmMemory::Optimization::Analyzer
- Inherits:
-
Object
- Object
- SwarmMemory::Optimization::Analyzer
- Defined in:
- lib/swarm_memory/optimization/analyzer.rb
Overview
Analyzes memory health and generates statistics
Provides insights about memory state, quality, and organization.
Instance Method Summary collapse
-
#analyze ⇒ Hash
Analyze overall memory health.
-
#health_report ⇒ String
Generate formatted health report.
-
#initialize(adapter:) ⇒ Analyzer
constructor
Initialize analyzer.
Constructor Details
#initialize(adapter:) ⇒ Analyzer
Initialize analyzer
12 13 14 |
# File 'lib/swarm_memory/optimization/analyzer.rb', line 12 def initialize(adapter:) @adapter = adapter end |
Instance Method Details
#analyze ⇒ Hash
Analyze overall memory health
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/swarm_memory/optimization/analyzer.rb', line 24 def analyze # List entries (handle errors gracefully) entries = @adapter.list return empty_analysis if entries.empty? stats = { total_entries: entries.size, total_size: @adapter.total_size, by_type: Hash.new(0), by_confidence: Hash.new(0), with_frontmatter: 0, with_embeddings: 0, with_tags: 0, with_links: 0, quality_scores: [], } # Analyze each entry entries.each do |entry_info| analyze_entry(entry_info[:path], stats) end # Calculate averages stats[:average_quality] = if stats[:quality_scores].empty? 0 else stats[:quality_scores].sum / stats[:quality_scores].size end # Calculate health score stats[:health_score] = calculate_health_score(stats) stats.except(:quality_scores) # Remove internal array end |
#health_report ⇒ String
Generate formatted health report
62 63 64 65 |
# File 'lib/swarm_memory/optimization/analyzer.rb', line 62 def health_report stats = analyze format_health_report(stats) end |