Class: DSPy::Registry::RegistryManager

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dspy/registry/registry_manager.rb

Overview

High-level registry manager that integrates with the DSPy ecosystem Provides automatic version management and integration with optimization results

Defined Under Namespace

Classes: RegistryIntegrationConfig

Constant Summary collapse

@@instance =

Global registry instance

T.let(nil, T.nilable(RegistryManager))

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry_config: nil, integration_config: nil) ⇒ RegistryManager



70
71
72
73
# File 'lib/dspy/registry/registry_manager.rb', line 70

def initialize(registry_config: nil, integration_config: nil)
  @registry = SignatureRegistry.new(config: registry_config)
  @integration_config = integration_config || RegistryIntegrationConfig.new
end

Instance Attribute Details

#integration_configObject (readonly)

Returns the value of attribute integration_config.



62
63
64
# File 'lib/dspy/registry/registry_manager.rb', line 62

def integration_config
  @integration_config
end

#registryObject (readonly)

Returns the value of attribute registry.



59
60
61
# File 'lib/dspy/registry/registry_manager.rb', line 59

def registry
  @registry
end

Class Method Details

.configure(registry_config: nil, integration_config: nil) ⇒ Object



276
277
278
# File 'lib/dspy/registry/registry_manager.rb', line 276

def self.configure(registry_config: nil, integration_config: nil)
  @@instance = new(registry_config: registry_config, integration_config: integration_config)
end

.instanceObject



271
272
273
# File 'lib/dspy/registry/registry_manager.rb', line 271

def self.instance
  @@instance ||= new
end

Instance Method Details

#bulk_deployment_status(signature_names) ⇒ Object



229
230
231
232
233
234
235
236
237
# File 'lib/dspy/registry/registry_manager.rb', line 229

def bulk_deployment_status(signature_names)
  results = {}
  
  signature_names.each do |name|
    results[name] = get_deployment_status(name)
  end

  results
end

#cleanup_old_versionsObject



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/dspy/registry/registry_manager.rb', line 241

def cleanup_old_versions
  cleaned_signatures = 0
  cleaned_versions = 0

  @registry.list_signatures.each do |signature_name|
    versions = @registry.list_versions(signature_name)
    
    # Keep deployed version and recent versions
    deployed_version = versions.find(&:is_deployed)
    recent_versions = versions.sort_by(&:created_at).last(5)
    
    keep_versions = [deployed_version, *recent_versions].compact.uniq
    
    if keep_versions.size < versions.size
      @registry.send(:save_signature_versions, signature_name, keep_versions)
      cleaned_signatures += 1
      cleaned_versions += (versions.size - keep_versions.size)
    end
  end

  {
    cleaned_signatures: cleaned_signatures,
    cleaned_versions: cleaned_versions
  }
end

#create_deployment_plan(signature_name, target_version) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/dspy/registry/registry_manager.rb', line 182

def create_deployment_plan(signature_name, target_version)
  current_deployed = @registry.get_deployed_version(signature_name)
  target = @registry.list_versions(signature_name).find { |v| v.version == target_version }

  return { error: "Target version not found" } unless target

  plan = {
    signature_name: signature_name,
    current_version: current_deployed&.version,
    target_version: target_version,
    deployment_safe: true,
    checks: [],
    recommendations: []
  }

  # Performance check
  if current_deployed&.performance_score && target.performance_score
    performance_change = target.performance_score - current_deployed.performance_score
    plan[:performance_change] = performance_change
    
    if performance_change < 0
      plan[:checks] << "Performance regression detected"
      plan[:deployment_safe] = false
    else
      plan[:checks] << "Performance improvement expected"
    end
  else
    plan[:checks] << "No performance data available"
    plan[:recommendations] << "Run evaluation before deployment"
  end

  # Version age check
  if target.created_at < (Time.now - 7 * 24 * 60 * 60) # 7 days old
    plan[:recommendations] << "Target version is more than 7 days old"
  end

  # Configuration complexity check
  config_complexity = estimate_configuration_complexity(target.configuration)
  if config_complexity > 0.8
    plan[:recommendations] << "Complex configuration detected - consider gradual rollout"
  end

  plan
end

#deploy_with_strategy(signature_name, strategy: nil) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/dspy/registry/registry_manager.rb', line 126

def deploy_with_strategy(signature_name, strategy: nil)
  strategy ||= @integration_config.deployment_strategy

  case strategy
  when "conservative"
    deploy_conservative(signature_name)
  when "aggressive"
    deploy_aggressive(signature_name)
  when "best_score"
    deploy_best_score(signature_name)
  else
    nil
  end
end

#get_deployment_status(signature_name) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/dspy/registry/registry_manager.rb', line 164

def get_deployment_status(signature_name)
  deployed_version = @registry.get_deployed_version(signature_name)
  all_versions = @registry.list_versions(signature_name)
  performance_history = @registry.get_performance_history(signature_name)

  recommendations = generate_deployment_recommendations(signature_name, all_versions, deployed_version)

  {
    deployed_version: deployed_version&.to_h,
    total_versions: all_versions.size,
    performance_history: performance_history,
    recommendations: recommendations,
    last_updated: all_versions.max_by(&:created_at)&.created_at&.iso8601
  }
end

#monitor_and_rollback(signature_name, current_score) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/dspy/registry/registry_manager.rb', line 143

def monitor_and_rollback(signature_name, current_score)
  return false unless @integration_config.rollback_on_performance_drop

  deployed_version = @registry.get_deployed_version(signature_name)
  return false unless deployed_version&.performance_score

  # Check if performance dropped significantly
  performance_drop = deployed_version.performance_score - current_score
  threshold_drop = deployed_version.performance_score * @integration_config.rollback_threshold

  if performance_drop > threshold_drop
    rollback_result = @registry.rollback(signature_name)
    emit_automatic_rollback_event(signature_name, current_score, deployed_version.performance_score)
    !rollback_result.nil?
  else
    false
  end
end

#register_optimization_result(optimization_result, signature_name: nil, metadata: {}) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/dspy/registry/registry_manager.rb', line 83

def register_optimization_result(optimization_result, signature_name: nil, metadata: {})
  return nil unless @integration_config.auto_register_optimizations

  # Extract signature name if not provided
  signature_name ||= extract_signature_name(optimization_result)
  return nil unless signature_name

  # Extract configuration from optimization result
  configuration = extract_configuration(optimization_result)
  
  # Get performance score
  performance_score = extract_performance_score(optimization_result)

  # Enhanced metadata
   = .merge({
    optimizer: extract_optimizer_name(optimization_result),
    optimization_timestamp: extract_optimization_timestamp(optimization_result),
    trials_count: extract_trials_count(optimization_result),
    auto_registered: true
  })

  # Register the version
  version = @registry.register_version(
    signature_name,
    configuration,
    metadata: ,
    program_id: extract_program_id(optimization_result)
  )

  # Update performance score
  if performance_score
    @registry.update_performance_score(signature_name, version.version, performance_score)
    version = version.with_performance_score(performance_score)
  end

  # Check for auto-deployment
  check_auto_deployment(signature_name, version)

  version
end