Self-hosted models: test embedding model on the embeddings route
What does this MR do and why?
Self-hosted models support embedding as a model family. Embedding requests payloads are different from other AI models, so the Test connection functionality on Add Self-hosted model form always fails.
This MR fixes that failure with:
- Adding a service specifically for testing Self-hosted embedding models:
TestSelfHostedEmbeddingModelService. This inherits from theTestEmbeddingModelService, with 2 main differences:- the new service does not require the self-hosted model records to be persisted
- The new service does not validate the dimensions (since the embedding
dimensionsis not yet specified in the "Add Self-hosted model form")
- In
CloudConnector::StatusChecks::Probes::SelfHosted::ModelConfigurationProbe, call the newTestSelfHostedEmbeddingModelServiceservice for an embedding model
References
- This bug was reported by a user. See issue: Semantic Code Search self-hosted embedding: sup... (#627970 - closed)
Screenshots or screen recordings
Self-hosted embedding model tested through the Add Self-hosted model form.
Regression test: testing the embedding model on the Semantic search Code embeddings page, dimensions is tested.
How to set up and validate locally
Setup a litellm proxy for an embedding model
-
Install litellm proxy
-
Configure an embedding model in your proxy. The example below sets up a proxy to Vertex AI's
text-embedding-005# in a config.yml file model_list: - model_name: text-embedding-005 litellm_params: model: vertex_ai/text-embedding-005 # what the proxy calls -
Run your litellm proxy with
litellm --config config.yml. This should output the hostname for the proxy. By default, that ishttp://0.0.0.0:4000.
Test
- Go to the Add Self-hosted model form and add an embedding model
- On the Model family field, select
EMBEDDING - On the Endpoint field, set your proxy's host with the API version, e.g.:
http://0.0.0.0:4000/v1 - On the Model identifier field, set the model name from your proxy configuration, e.g.:
- Use
text-embedding-005, if you have checked out gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!7173 (merged) - Use
openai/text-embedding-005if your AIGW does not have the changes from gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!7173 (merged)
- Use
- (Optional) If you did not set API key authentication for your proxy
- set any dummy key
- or check out gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!7173 (merged) and leave the field blank
Regression Test
Since we've updated the Embeddings::ModelFactory and Embeddings::ModelDefinition, we need to ensure that the existing embeddings indexing pipeline and semantic search functionality are still working:
sf_model = Ai::SelfHostedModel.find_by(identifier: "text-embedding-005") # ensure this self-hosted model is added first
collection_record = ::Ai::ActiveContext::Collections::Code.collection_record
collection_record.reload.update_metadata!(
current_indexing_embedding_model: {
field: 'embeddings_v1',
model_type: 'self_hosted',
model_ref: sf_model.id.to_s,
dimensions: 768
},
search_embedding_model: {
field: 'embeddings_v1',
model_type: 'self_hosted',
model_ref: sf_model.id.to_s,
dimensions: 768
},
)
::Ai::ActiveContext::Collections::Code.current_indexing_embedding_model.generate_embeddings(["test content"])
::Ai::ActiveContext::Collections::Code.search_embedding_model.generate_embeddings(["test content"])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 #627970 (closed)