Class: OnlineMigrations::DataMigrations::ReembedInfraredHeatingPanels

Inherits:
OnlineMigrations::DataMigration
  • Object
show all
Defined in:
lib/online_migrations/data_migrations/reembed_infrared_heating_panels.rb

Overview

Re-embeds the line items whose names/descriptions changed in the radiant-panel
-> infrared-heating-panels rename, so semantic search stops returning the old
vectors. Enqueues one +EmbeddingWorker+ per item (the embedding itself runs on
the +ai_embeddings+ Sidekiq queue, off the deploy path); batching + the
enqueuing migration's +iteration_pause+ keep that queue from being flooded.

Idempotent: re-running simply re-enqueues, and EmbeddingWorker overwrites the
item's vector with one built from current (clean) content.

See Also:

  • The migration that enqueues this and inline-enqueues the (few) product-line + article embeddings.

Constant Summary collapse

BATCH_SIZE =

Enqueue is light (one Sidekiq push per item), so a large batch is fine; the
enqueuing migration throttles batches via iteration_pause.

200
SCOPE_SQL =

Line items under the renamed product line.

Returns:

  • (String)
"primary_pl_path_slugs::text LIKE 'infrared_heating_panels%'"

Instance Method Summary collapse

Instance Method Details

#collectionActiveRecord::Batches::BatchEnumerator

Yields batches of line items to re-embed.

Returns:

  • (ActiveRecord::Batches::BatchEnumerator)

Raises:

  • (ActiveRecord::ActiveRecordError)

    on database error.



30
31
32
# File 'lib/online_migrations/data_migrations/reembed_infrared_heating_panels.rb', line 30

def collection
  Item.where(SCOPE_SQL).in_batches(of: BATCH_SIZE)
end

#countInteger

Number of items queued for re-embedding. Used for progress reporting.

Returns:

  • (Integer)

Raises:

  • (ActiveRecord::ActiveRecordError)

    on database error.



49
# File 'lib/online_migrations/data_migrations/reembed_infrared_heating_panels.rb', line 49

def count = Item.where(SCOPE_SQL).count

#process(items) ⇒ void

This method returns an undefined value.

Enqueues an embedding refresh for each item in the batch.

Parameters:



38
39
40
41
42
43
# File 'lib/online_migrations/data_migrations/reembed_infrared_heating_panels.rb', line 38

def process(items)
  items.find_each do |item|
    chunked = item.respond_to?(:needs_chunking?) && item.needs_chunking?
    EmbeddingWorker.perform_async('Item', item.id, { 'chunked' => chunked })
  end
end