mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-07-01 12:02:16 +00:00
FIX: Update migrations with latest vector rep changes (#199)
This commit is contained in:
parent
ee734a340a
commit
175def1267
@ -2,27 +2,24 @@
|
|||||||
|
|
||||||
class CreateAiTopicEmbeddingsTable < ActiveRecord::Migration[7.0]
|
class CreateAiTopicEmbeddingsTable < ActiveRecord::Migration[7.0]
|
||||||
def change
|
def change
|
||||||
models = [
|
truncation = DiscourseAi::Embeddings::Strategies::Truncation.new
|
||||||
DiscourseAi::Embeddings::Models::AllMpnetBaseV2,
|
vector_reps =
|
||||||
DiscourseAi::Embeddings::Models::TextEmbeddingAda002,
|
[
|
||||||
]
|
DiscourseAi::Embeddings::VectorRepresentations::AllMpnetBaseV2,
|
||||||
strategies = [DiscourseAi::Embeddings::Strategies::Truncation]
|
DiscourseAi::Embeddings::VectorRepresentations::TextEmbeddingAda002,
|
||||||
|
].map { |k| k.new(truncation) }
|
||||||
|
|
||||||
models.each do |model|
|
vector_reps.each do |vector_rep|
|
||||||
strategies.each do |strategy|
|
create_table vector_rep.table_name.to_sym, id: false do |t|
|
||||||
table_name = "ai_topic_embeddings_#{model.id}_#{strategy.id}".to_sym
|
|
||||||
|
|
||||||
create_table table_name, id: false do |t|
|
|
||||||
t.integer :topic_id, null: false
|
t.integer :topic_id, null: false
|
||||||
t.integer :model_version, null: false
|
t.integer :model_version, null: false
|
||||||
t.integer :strategy_version, null: false
|
t.integer :strategy_version, null: false
|
||||||
t.text :digest, null: false
|
t.text :digest, null: false
|
||||||
t.column :embeddings, "vector(#{model.dimensions})", null: false
|
t.column :embeddings, "vector(#{vector_rep.dimensions})", null: false
|
||||||
t.timestamps
|
t.timestamps
|
||||||
|
|
||||||
t.index :topic_id, unique: true
|
t.index :topic_id, unique: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -5,16 +5,17 @@ class MigrateEmbeddingsFromDedicatedDatabase < ActiveRecord::Migration[7.0]
|
|||||||
return unless SiteSetting.ai_embeddings_enabled
|
return unless SiteSetting.ai_embeddings_enabled
|
||||||
return unless SiteSetting.ai_embeddings_pg_connection_string.present?
|
return unless SiteSetting.ai_embeddings_pg_connection_string.present?
|
||||||
|
|
||||||
models = [
|
truncation = DiscourseAi::Embeddings::Strategies::Truncation.new
|
||||||
DiscourseAi::Embeddings::Models::AllMpnetBaseV2,
|
|
||||||
DiscourseAi::Embeddings::Models::TextEmbeddingAda002,
|
|
||||||
]
|
|
||||||
strategies = [DiscourseAi::Embeddings::Strategies::Truncation]
|
|
||||||
|
|
||||||
models.each do |model|
|
vector_reps =
|
||||||
strategies.each do |strategy|
|
[
|
||||||
new_table_name = "ai_topic_embeddings_#{model.id}_#{strategy.id}"
|
DiscourseAi::Embeddings::VectorRepresentations::AllMpnetBaseV2,
|
||||||
old_table_name = "topic_embeddings_#{model.name.underscore}"
|
DiscourseAi::Embeddings::VectorRepresentations::TextEmbeddingAda002,
|
||||||
|
].map { |k| k.new(truncation) }
|
||||||
|
|
||||||
|
vector_reps.each do |vector_rep|
|
||||||
|
new_table_name = vector_rep.table_name
|
||||||
|
old_table_name = "topic_embeddings_#{vector_rep.name.underscore}"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
row_count =
|
row_count =
|
||||||
@ -55,7 +56,6 @@ class MigrateEmbeddingsFromDedicatedDatabase < ActiveRecord::Migration[7.0]
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def down
|
def down
|
||||||
# no-op
|
# no-op
|
||||||
|
@ -2,24 +2,18 @@
|
|||||||
|
|
||||||
class CreateMultilingualTopicEmbeddingsTable < ActiveRecord::Migration[7.0]
|
class CreateMultilingualTopicEmbeddingsTable < ActiveRecord::Migration[7.0]
|
||||||
def change
|
def change
|
||||||
models = [DiscourseAi::Embeddings::Models::MultilingualE5Large]
|
truncation = DiscourseAi::Embeddings::Strategies::Truncation.new
|
||||||
strategies = [DiscourseAi::Embeddings::Strategies::Truncation]
|
vector_rep = DiscourseAi::Embeddings::VectorRepresentations::MultilingualE5Large.new(truncation)
|
||||||
|
|
||||||
models.each do |model|
|
create_table vector_rep.table_name.to_sym, id: false do |t|
|
||||||
strategies.each do |strategy|
|
|
||||||
table_name = "ai_topic_embeddings_#{model.id}_#{strategy.id}".to_sym
|
|
||||||
|
|
||||||
create_table table_name, id: false do |t|
|
|
||||||
t.integer :topic_id, null: false
|
t.integer :topic_id, null: false
|
||||||
t.integer :model_version, null: false
|
t.integer :model_version, null: false
|
||||||
t.integer :strategy_version, null: false
|
t.integer :strategy_version, null: false
|
||||||
t.text :digest, null: false
|
t.text :digest, null: false
|
||||||
t.column :embeddings, "vector(#{model.dimensions})", null: false
|
t.column :embeddings, "vector(#{vector_rep.dimensions})", null: false
|
||||||
t.timestamps
|
t.timestamps
|
||||||
|
|
||||||
t.index :topic_id, unique: true
|
t.index :topic_id, unique: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user