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::EmbeddingModelobjects
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::ActiveContextclass, where it is more appropriate
- move the "who can select the model" checks to the
- rename "ModelSelector" to "ModelFactory"
- rename
Ai::ActiveContext::Embeddings::ModelSelectortoModelFactory - in the ActiveContext gem, rename
embedding_model_selectortoembedding_model_factory - naming it as
*Factorymakes it self-explanatory that this class is used for creatingEmbeddingModelobjects
- rename
- 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:
-
the now renamed
ModelFactorystill works and integrated into the Collection class:::Ai::ActiveContext::Collections::Code.current_indexing_embedding_model.generate_embeddings(["test"]) -
the "Semantic search Code embeddings" admin page still works
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.
