[Connection record] One-click connect to Advanced Search cluster

What

Currently in order to connect the same cluster used for Advanced Search (Elasticsearch/OpenSearch), the admin must open a rails console and create a record:

Ai::ActiveContext::Connection.create!(
  name: "elastic",
  adapter_class: "ActiveContext::Databases::Elasticsearch::Adapter",
  options: ::Gitlab::CurrentSettings.elasticsearch_config
)

We want to make it as easy as possible to use the AI feature by making it a one-click connection between the vector store and Advanced Search cluster.

How

Backend

I believe that it could be as simple as a special options hash:

Ai::ActiveContext::Connection.create!(
  name: "elastic",
  adapter_class: "ActiveContext::Databases::Elasticsearch::Adapter",
  options: { use_advanced_search_config: true }
)

When we detect this key, we can automatically use ::Gitlab::CurrentSettings.elasticsearch_config

UX

This could be done on the Advanced Search settings page but it's not really for Advanced Search so it might have to be on an AI-specific page.

backend

Use the settings to create the connection. We also need to keep the vector store connection in sync if the settings are updated.

Edited by 🤖 GitLab Bot 🤖