Save AI messages to PostgreSQL alongside Redis

Proposal

This issue is to achieve the following tasks for Switch to PostgreSQL from Redis in ChatStorage (&15713 - closed).

  • Add the storage abstraction Gitlab::Llm::ChatStorage::Postgresql, Gitlab::Llm::ChatStorage::Redis and Gitlab::Llm::ChatStorage::Base.
  • Starts saving AI message (i.e. Gitlab::Llm::ChatMessage.save!) to PostgreSQL alongside saving to Redis. We still read messages from Redis.
    • We should also update the last_message_updated_at column of threads table. e.g. current_thread.touch(:last_message_updated_at).
  • Add duo_chat_storage_postgresql feature flag.
  • When the duo_chat_storage_postgresql is enabled, the messages are read from PostgreSQL instead of Redis.

PoC

See PoC MR PoC: Duo Chat Storage with PostgreSQL (Not For ... (!170230 - closed).

Edited by Shinya Maeda