ActiveContext embedding update: add validations and put inside transaction

What does this MR do and why?

For the ActiveContext Model Selection UI, we need to validate that the model_type and dimension values are supported. Instead of having this validation in a controller, it's simpler to have it on the json schema.

We also need to make sure that the next_indexing_embedding_model is not set if Task chain creation fails, so we don't end up in an incomplete scenario where there is a next_indexing_embedding_model but there are no tasks. See !232069 (comment 3265121637).

In this MR:

  • we move the embedding metadata to its own json schema and reference it in the Collection#metadata schema
  • update the embedding metadata schema to have an enum of valid values for model_type and dimensions
  • update the spec for Ai::ActiveContext::Collection and Ai::ActiveContext::EmbeddingModelActivationService to test invalid values
  • In Ai::ActiveContext::EmbeddingModelActivationService#execute, put the metadata update and tasks creation within a transaction so that the metadata change rolls back if there is an error in the tasks creation.

References

Screenshots or screen recordings

N/A

How to set up and validate locally

The changes in this MR (json schema + wrapping DB updates in a transaction) make use of well-known and established ruby frameworks, so the unit tests should cover the required validations.

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