chore: Refactor Response Bot Data Schema (#8011)
This PR refactors the schema we introduced in #7518 based on the feedback from production tests. Here is the change log - Decouple Inbox association to a new table inbox_response_sources -> this lets us share the same response source between multiple inboxes - Add a status field to responses. This ensures that, by default, responses are created in pending status. You can do quality assurance before making them active. In future, this status can be leveraged by the bot to auto-generate response questions from conversations which require a handoff - Add response_source association to responses and remove hard dependency from response_documents. This lets users write free-form question answers based on conversations, which doesn't necessarily need a response source.
This commit is contained in:
@@ -23,19 +23,31 @@ class Features::ResponseBotService
|
||||
def create_tables
|
||||
return unless vector_extension_enabled?
|
||||
|
||||
%i[response_sources response_documents responses].each do |table|
|
||||
%i[response_sources response_documents responses inbox_response_sources].each do |table|
|
||||
send("create_#{table}_table")
|
||||
end
|
||||
end
|
||||
|
||||
def drop_tables
|
||||
%i[responses response_documents response_sources].each do |table|
|
||||
%i[responses response_documents response_sources inbox_response_sources].each do |table|
|
||||
MIGRATION_VERSION.drop_table table if MIGRATION_VERSION.table_exists?(table)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_inbox_response_sources_table
|
||||
return if MIGRATION_VERSION.table_exists?(:inbox_response_sources)
|
||||
|
||||
MIGRATION_VERSION.create_table :inbox_response_sources do |t|
|
||||
t.references :inbox, null: false
|
||||
t.references :response_source, null: false
|
||||
t.index [:inbox_id, :response_source_id], name: 'index_inbox_response_sources_on_inbox_id_and_response_source_id', unique: true
|
||||
t.index [:response_source_id, :inbox_id], name: 'index_inbox_response_sources_on_response_source_id_and_inbox_id', unique: true
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def create_response_sources_table
|
||||
return if MIGRATION_VERSION.table_exists?(:response_sources)
|
||||
|
||||
@@ -45,7 +57,6 @@ class Features::ResponseBotService
|
||||
t.string :source_link
|
||||
t.references :source_model, polymorphic: true
|
||||
t.bigint :account_id, null: false
|
||||
t.bigint :inbox_id, null: false
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
@@ -69,9 +80,11 @@ class Features::ResponseBotService
|
||||
return if MIGRATION_VERSION.table_exists?(:responses)
|
||||
|
||||
MIGRATION_VERSION.create_table :responses do |t|
|
||||
t.bigint :response_source_id, null: false
|
||||
t.bigint :response_document_id
|
||||
t.string :question, null: false
|
||||
t.text :answer, null: false
|
||||
t.integer :status, default: 0
|
||||
t.bigint :account_id, null: false
|
||||
t.vector :embedding, limit: 1536
|
||||
t.timestamps
|
||||
|
||||
Reference in New Issue
Block a user