PoC: Duo Chat Storage with PostgreSQL (Not For Merge)
This is PoC MR. Not For Merge.
What does this MR do and why?
This MR demonstrates the change size for transitioning to PostgreSQL from Redis as Duo Chat storage. This is a preliminary work for Iteration 1: Multi-threaded conversations in th... (&15622 - closed).
The ides here is that:
- Add
ai_conversation_threadsandai_conversation_messagestables to Postgresql. - Make
ai_conversation_messages(Ai::Conversation::MessageAR model) compatible withGitlab::Llm::AiMessage, so that we don't need to refactor the related components yet. Also, we can avoid blocking the work from stable counterparts (e.g. !170311 (closed)). - We switch to PosgreSQL storage without changing the business logic. Users won't notice the difference.
- We don't migrate the data from Redis to PosgreSQL as the data will be expired in 3 days anyway.
- We should remove the Redis dependency
Gitlab::Llm::ChatStorage::Redis. This is follow-up. - We should consolidate
Ai::Conversation::MessageandGitlab::Llm::AiMessage. This is follow-up. - After these follow-ups are done, we can work on iteration 1.
If we agree upon the structure, I'll create issues in the epic.
Related to Create PoC for multi-threaded conversations (#500031 - closed)
Verification
[17] pry(main)> User.first.ai_conversation_threads.last.messages.map { |message| [message.role, message.content] }
User Load (0.6ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 /*application:console,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:shinya-XPS-15-9530,console_username:shinya,line:(pry):27:in `__pry__'*/
Ai::Conversation::Thread Load (0.3ms) SELECT "ai_conversation_threads".* FROM "ai_conversation_threads" WHERE "ai_conversation_threads"."user_id" = 1 ORDER BY "ai_conversation_threads"."id" DESC LIMIT 1 /*application:console,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:shinya-XPS-15-9530,console_username:shinya,line:(pry):27:in `__pry__'*/
Ai::Conversation::Message Load (0.3ms) SELECT "ai_conversation_messages".* FROM "ai_conversation_messages" WHERE "ai_conversation_messages"."thread_id" = 2 /*application:console,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:shinya-XPS-15-9530,console_username:shinya,line:(pry):27:in `map'*/
=> [["user", "How do I clone a repository?"],
["assistant",
"To clone a repository, you can follow these steps:\n\n1. On the project's overview page, in the upper-right corner, select \"Code\".\n2. Copy the URL for either SSH (recommended) or HTTPS cloning.\n3. Open a terminal and navigate to the directory where you want to clone the files.\n4. Run the command: `git clone <copied URL>`\n5. To view the files, navigate to the new directory: `cd <new directory>`\n\nIf you're using SSH, make sure you've authenticated with GitLab by following the SSH documentation. For HTTPS, you'll need to authenticate each time you perform an operation between your computer and GitLab.\n\nAlternatively, you can clone directly into code editors like Visual Studio Code, Apple Xcode, or IntelliJ IDEA using the GitLab UI."]]
Edited by Shinya Maeda
