ActiveContext: refactor the ModelSelector class

What does this MR do and why?

Currently, Ai::ActiveContext::Embeddings::ModelSelector is doing 2 things:

  • instance checks to determine whether the embedding model should be selected by GitLab or the user/admin
  • a factory for creating the ActiveContext::EmbeddingModel objects

This violates the single-responsibility principle, and it requires controller classes to know about the ModelSelector class. Additionally, from the Model Services perspective, "Model Selector" naturally means the services or module that provide model selection functionality. So the Embeddings::ModelSelector factory class is misleading and overloading the name usage by Model Services.

Refactors in this MR:

  • move instance checks
    • move the "who can select the model" checks to the Ai::ActiveContext class, where it is more appropriate
  • rename "ModelSelector" to "ModelFactory"
    • rename Ai::ActiveContext::Embeddings::ModelSelector to ModelFactory
    • in the ActiveContext gem, rename embedding_model_selector to embedding_model_factory
    • naming it as *Factory makes it self-explanatory that this class is used for creating EmbeddingModel objects
  • update docs referring to the ModelSelector

The design document will be updated as well, see Semantic Search: change references from ModelSe... (gitlab-com/content-sites/handbook!20258 - merged)

References

N/A

Screenshots or screen recordings

TBA

How to set up and validate locally

This refactor does not change any logic or UI, and successful tests should verify that nothing has broken.

However, we can also verify that:

  1. the now renamed ModelFactory still works and integrated into the Collection class:

    ::Ai::ActiveContext::Collections::Code.current_indexing_embedding_model.generate_embeddings(["test"])
  2. the "Semantic search Code embeddings" admin page still works

    Screenshot_2026-07-01_at_14.42.02

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.

Edited by Pam Artiaga

Merge request reports

Loading