Class: Admin::EmbeddingsController
- Inherits:
-
CrmController
- Object
- CrmController
- Admin::EmbeddingsController
- Defined in:
- app/controllers/admin/embeddings_controller.rb
Constant Summary collapse
- EMBEDDABLE_TYPES =
Base embeddable types (Item split into subtypes below)
%w[Post Article Showcase Video Image SiteMap ReviewsIo Item ProductLine CallRecord Activity Communication AssistantBrainEntry].freeze
- ITEM_SUBTYPES =
Item subtypes for distinguishing publications from regular items
{ 'publication' => 'Publication (PDF)', 'product' => 'Product (Regular Item)' }.freeze
- ARTICLE_SUBTYPES =
{ 'ArticleFaq' => 'FAQ', 'ArticleTechnical' => 'Technical', 'ArticleTraining' => 'Training', 'ArticleProcedure' => 'Procedure' }.freeze
Instance Method Summary collapse
-
#cleanup ⇒ Object
Trigger orphan cleanup (removes embeddings for unpublished/inactive records).
-
#generate ⇒ Object
Trigger embedding generation for a specific type Uses background worker to avoid timeout on large datasets.
-
#generate_one ⇒ Object
Generate embedding for a single record.
- #index ⇒ Object
-
#refresh ⇒ Object
Trigger embedding refresh (stale check).
- #search ⇒ Object
Instance Method Details
#cleanup ⇒ Object
Trigger orphan cleanup (removes embeddings for unpublished/inactive records)
67 68 69 70 71 |
# File 'app/controllers/admin/embeddings_controller.rb', line 67 def cleanup ServiceRunner.perform_async('Maintenance::EmbeddingOrphanCleanup') flash[:info] = 'Orphan embedding cleanup has been queued' redirect_to end |
#generate ⇒ Object
Trigger embedding generation for a specific type
Uses background worker to avoid timeout on large datasets
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/admin/embeddings_controller.rb', line 39 def generate type = params[:type] if ARTICLE_SUBTYPES.key?(type) EmbeddingBatchQueueWorker.perform_async('Article', article_type: type) flash[:info] = "Queued batch worker for #{ARTICLE_SUBTYPES[type]} articles. Check Sidekiq for progress." elsif EMBEDDABLE_TYPES.include?(type) EmbeddingBatchQueueWorker.perform_async(type) flash[:info] = "Queued batch worker for #{type} records. Check Sidekiq for progress." elsif type == 'ImageFingerprints' # pHash fingerprint generation (separate from full analysis) EmbeddingBatchQueueWorker.perform_async(type) flash[:info] = 'Queued batch worker for pHash fingerprints. Check Sidekiq for progress.' else flash[:error] = "Invalid type: #{type}" end redirect_to end |
#generate_one ⇒ Object
Generate embedding for a single record
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/admin/embeddings_controller.rb', line 74 def generate_one type = params[:type] id = params[:id] unless EMBEDDABLE_TYPES.include?(type) flash[:error] = "Invalid type: #{type}" redirect_to and return end EmbeddingWorker.perform_async(type, id.to_i, force: true) flash[:info] = "Queued #{type}##{id} for embedding generation" redirect_to end |
#index ⇒ Object
22 23 24 25 |
# File 'app/controllers/admin/embeddings_controller.rb', line 22 def index @stats = build_stats @recent_embeddings = ContentEmbedding.order(updated_at: :desc).limit(10).includes(:embeddable) end |
#refresh ⇒ Object
Trigger embedding refresh (stale check)
60 61 62 63 64 |
# File 'app/controllers/admin/embeddings_controller.rb', line 60 def refresh EmbeddingRefreshWorker.perform_async flash[:info] = 'Embedding refresh worker has been queued' redirect_to end |
#search ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/admin/embeddings_controller.rb', line 27 def search @query = params[:query] @types = params[:types].presence @limit = (params[:limit] || 10).to_i.clamp(1, 50) @use_hybrid = params[:hybrid] != '0' @min_similarity = (params[:min_similarity] || 0).to_f.clamp(0, 1) @results = perform_search if @query.present? end |