Class: Ragnar::CLI::Umap

Inherits:
Thor
  • Object
show all
Defined in:
lib/ragnar/cli_umap.rb

Instance Method Summary collapse

Instance Method Details

#applyObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ragnar/cli_umap.rb', line 51

def apply
  config = Config.instance
  model_path = if options[:model_path]
    options[:model_path]
  else
    File.join(config.models_dir, "umap_model.bin")
  end

  unless File.exist?(model_path)
    say "Error: UMAP model not found at: #{model_path}", :red
    say "Please run 'ragnar umap train' first to create a model.", :yellow
    exit 1
  end

  say "Applying UMAP model to embeddings...", :green

  processor = UmapProcessor.new(
    db_path: options[:db_path] || config.database_path,
    model_path: model_path
  )

  begin
    stats = processor.apply(batch_size: options[:batch_size] || 100)

    say "\nUMAP application complete!", :green
    say "Embeddings processed: #{stats[:processed]}"
    say "Already processed: #{stats[:skipped]}"
    say "Errors: #{stats[:errors]}" if stats[:errors] > 0
  rescue => e
    say "Error applying UMAP: #{e.message}", :red
    exit 1
  end
end

#trainObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ragnar/cli_umap.rb', line 14

def train
  say "Training UMAP model on embeddings...", :green

  config = Config.instance
  model_path = if options[:model_path]
    options[:model_path]
  else
    File.join(config.models_dir, "umap_model.bin")
  end

  processor = UmapProcessor.new(
    db_path: options[:db_path] || config.database_path,
    model_path: model_path
  )

  begin
    stats = processor.train(
      n_components: options[:n_components] || 50,
      n_neighbors: options[:n_neighbors] || 15,
      min_dist: options[:min_dist] || 0.1
    )

    say "\nUMAP training complete!", :green
    say "Embeddings processed: #{stats[:embeddings_count]}"
    say "Original dimensions: #{stats[:original_dims]}"
    say "Reduced dimensions: #{stats[:reduced_dims]}"
    say "Model saved to: #{processor.model_path}"
  rescue => e
    say "Error during UMAP training: #{e.message}", :red
    exit 1
  end
end