ActiveContext: migration for update_code_model_metadata

What does this MR do and why?

This adds the migration to set the current_indexing_embedding_model and search_embedding_model values.

Note: this change has been validated to work when integrating the new model design into the ActiveContext pipelines. See validation steps in ActiveContext: integrate new model design into ... (!222417 - merged)

Step-by-step changes summary

MR Status
Introduce the new hash/object-based models
Add indexing_embedding_fields to Collection class
Add embeddings_with_model_redesign preprocessor Ready for review
Add migration to update models metadata This MR
Integrate model redesign into Code Embeddings pipeline Ready for review

References

Screenshots or screen recordings

N/A

How to set up and validate locally

Setup

  1. Ensure the self-hosted AIGW url is not set:

    Ai::Setting.instance.update(ai_gateway_url: nil)
  2. Setup your Code Embeddings Indexing pipeline

Validation - WITHOUT self-hosted AIGW url

Once you've followed the setup steps in Code Embeddings Indexing pipeline, all of the migrations (including the one in this MR) should be run already. Make sure that:

  1. The UpdateCodeModelMetadata is completed. You can do this by checking on psql, verifying that it has status=10.

    # select id, version, metadata, status from ai_active_context_migrations where version='20260213124605';
     id |    version     | metadata | status
    ----+----------------+----------+--------
     15 | 20260213124605 | {}       |     10
  2. The collection record's current_indexing_embedding_model and search_embedding_model are set to the correct values -- these should be the same values. next_indexing_embedding_model must be nil:

    Ai::ActiveContext::Collections::Code.collection_record.current_indexing_embedding_model
    => {"field"=>"embeddings_v1", "model_ref"=>"text_embedding_005_vertex"}
    
    Ai::ActiveContext::Collections::Code.collection_record.search_embedding_model
    => {"field"=>"embeddings_v1", "model_ref"=>"text_embedding_005_vertex"}
    
    Ai::ActiveContext::Collections::Code.collection_record.next_indexing_embedding_model
    => nil

Validation - with self-hosted AIGW

We need to make sure that the migration is skipped in a self-hosted AIGW setup.

  1. Set the self-hosted AIGW url:

    Ai::Setting.instance.update(ai_gateway_url: 'http://gdk.test:5052')
  2. Delete the UpdateCodeModelMetadata migration record:

    # in psql console
    delete from ai_active_context_migrations where version='20260213124605';
  3. Run the migration worker:

    Ai::ActiveContext::MigrationWorker.new.perform
  4. Verify that the status for the migration is skipped (100):

    # select id, version, metadata, status from ai_active_context_migrations where version='20260213124605';
     id |    version     | metadata | status
    ----+----------------+----------+--------
     17 | 20260213124605 | {}       |    100

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #588847

Edited by Pam Artiaga

Merge request reports

Loading