feat: Use embeddings in help center search (#9227)

This commit is contained in:
Sojan Jose
2024-04-15 16:35:23 -07:00
committed by GitHub
parent ade658ad86
commit 42a457ff5d
12 changed files with 190 additions and 12 deletions

View File

@@ -0,0 +1,7 @@
class Features::BaseService
MIGRATION_VERSION = ActiveRecord::Migration[7.0]
def vector_extension_enabled?
ActiveRecord::Base.connection.extension_enabled?('vector')
end
end

View File

@@ -0,0 +1,42 @@
# ensure vector extension is enabled via response bot service
class Features::HelpcenterEmbeddingSearchService < Features::BaseService
def enable_in_installation
create_tables
end
def disable_in_installation
drop_tables
end
def feature_enabled?
vector_extension_enabled? && MIGRATION_VERSION.table_exists?(:article_embeddings)
end
def create_tables
return unless vector_extension_enabled?
%i[article_embeddings].each do |table|
send("create_#{table}_table")
end
end
def drop_tables
%i[article_embeddings].each do |table|
MIGRATION_VERSION.drop_table table if MIGRATION_VERSION.table_exists?(table)
end
end
private
def create_article_embeddings_table
return if MIGRATION_VERSION.table_exists?(:article_embeddings)
MIGRATION_VERSION.create_table :article_embeddings do |t|
t.bigint :article_id, null: false
t.text :term, null: false
t.vector :embedding, limit: 1536
t.timestamps
end
MIGRATION_VERSION.add_index :article_embeddingsk, :embedding, using: :ivfflat, opclass: :vector_l2_ops
end
end

View File

@@ -1,6 +1,4 @@
class Features::ResponseBotService
MIGRATION_VERSION = ActiveRecord::Migration[7.0]
class Features::ResponseBotService < Features::BaseService
def enable_in_installation
enable_vector_extension
create_tables
@@ -21,10 +19,6 @@ class Features::ResponseBotService
MIGRATION_VERSION.disable_extension 'vector'
end
def vector_extension_enabled?
ActiveRecord::Base.connection.extension_enabled?('vector')
end
def create_tables
return unless vector_extension_enabled?