Add embedding model in details in search page

What does this MR do and why?

For Self-managed instances with Self-hosted AIGW, we want to allow users to select the embedding model through the Admin UI.

Given the amount of changes needed to support this, the change is split into several MRs:

  • !232069 (merged) & !232569 (merged) - Add validations through the json schema and the EmbeddingModelActivationService
  • !230649 (merged) introduces the Semantic Search embeddings configuration page, accessible through the url: <gitlab-url>/admin/application_settings/semantic_search_embeddings/<collection_key>.
  • This MR adds a link to the Semantic Search embeddings configuration page in the main Admin -> Search page -> Semantic Search section

Changes summary

  • Updated: Availability of the Semantic Search section in the Admin -> Search page

    • Before: Checks for license and feature availability are called directly in the view file
    • After: Checks for availability is done in a controller and the result is assigned to a @semantic_search_available variable:
  • New: Under the Semantic Search section, we list the embedding models per collection (for now only the Code collection)

    • Scenarios:
      • if the connection is not yet configured, an information message is displayed
      • if the collection record is not yet created, an information message is displayed (this scenarios happens just after a connection is configured, but before the migration for creating collections has run)
      • if the collection record is present, the model details are shown
        • if instance does not allow model selection by user, the "change model" button is not shown
        • if instance allows model selection by user, the "change model" button is shown
        • if instance allows model selection by user but there is a next model, the "change model" button is shown but disabled

References

Screenshots or screen recordings

Scenario: Semantic Search is unavailable

unavailable_semantic_search

Scenarios: embedding model configuration is unavailable

Connection is not yet configured

connection_not_configured

Collection record not present

collection_record_not_present

Scenarios: when user can select the model

No models configured

self_hosted_no_model

Current model configured

self_hosted_current_model

Switching to next model

self_hosted_with_next_model

Scenarios: when GitLab selects the model

Current model configured

non_self_hosted_current_model

Switching to next model

non_self_hosted_with_next_model

How to set up and validate locally

Scenario: semantic search unavailable

  1. Do one of the following setups:

    • make License.ai_features_available? return false
    • make ::Gitlab::CurrentSettings.duo_features_enabled? return false
    • simulate an SM instance with a Self-hosted AIGW, and ensure FF is disabled
      • set environment variable: GITLAB_SIMULATE_SAAS=0
      • on the rails console, run: ::Ai::Setting.instance.update!(ai_gateway_url: 'http://gdk.test:3000')
      • on the rails console, run: Feature.disable(:semantic_search_user_model_selection)
  2. Verify that the Admin -> Search page does not have a Semantic Search section

Scenarios: semantic search is available

Setup:

  • ensure License.ai_features_available? returns true
  • ensure ::Gitlab::CurrentSettings.duo_features_enabled? returns true
  • further instance setups:
    • instance where GitLab selects the model, do any one of the following:
      • set environment variable: GITLAB_SIMULATE_SAAS=1
      • on the rails console, run: ::Ai::Setting.instance.update!(ai_gateway_url: nil)
    • instance where user can select the model
      • set environment variable: GITLAB_SIMULATE_SAAS=0
      • on the rails console, run: ::Ai::Setting.instance.update!(ai_gateway_url: 'http://gdk.test:3000')
      • on the rails console, run: Feature.enable(:semantic_search_user_model_selection)

Connection is not yet configured

  1. If there is an active connection, deactivate it: Ai::ActiveContext::Connection.active&.deactivate!
  2. Verify that a message is displayed: "Embedding model configuration is unavailable - Collection record not present"

Collection record has not been created yet

  1. Ensure you have an active connection
  2. Ensure that ::Ai::ActiveContext::Collections::Code.collection_record is nil.
  3. Verify that a message is displayed: "Embedding model configuration is unavailable - Connection not configured"

Collection record embedding model details are set

  • Setup: define a test GitLab-managed model for checking different model details

    diff --git a/ee/app/models/ai/active_context/embedding.rb b/ee/app/models/ai/active_context/embedding.rb
    index ceec99824a8e..e18eb9fbd46a 100644
    --- a/ee/app/models/ai/active_context/embedding.rb
    +++ b/ee/app/models/ai/active_context/embedding.rb
    @@ -29,6 +29,9 @@ module Embedding
            'text_embedding_005_vertex' => {
              model_name: 'text-embedding-005 - Vertex',
              batch_size: TEXT_EMBEDDING_VERTEX_BATCH_SIZE
    +        },
    +        'embedding_001_test' => {
    +          model_name: 'embedding-001 - TEST'
            }
          }.freeze
  • Update the current_indexing_embedding_model and verify that the current model details are displayed correctly

    ::Ai::ActiveContext::Collections::Code.collection_record.update_metadata!(
      current_indexing_embedding_model: {
        model_type: 'gitlab_managed',
        model_ref: 'text_embedding_005_vertex',
        field: "embeddings_v1",
        dimensions: 768
      }
    )
  • Update the next_indexing_embedding_model and verify that the next model details are displayed correctly

    ::Ai::ActiveContext::Collections::Code.collection_record.update_metadata!(
      next_indexing_embedding_model: {
        model_type: 'gitlab_managed',
        model_ref: 'embedding_001_test',
        field: "embeddings_v2",
        dimensions: 768
      }
    )
  • "Set model" / "Change model" button:

    • if you are in an instance where GitLab selects the model, verify that this button is not shown
    • if you are in an instance where user can select the model, verify that this button is shown

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 #582638 (closed)

Edited by Pam Artiaga

Merge request reports

Loading