FIX: Generate embeddings job was broken (#211)

* FIX: Use correct methods to generate embeddings

* FIX: Generate embeddings job was broken
This commit is contained in:
Roman Rizzi 2023-09-07 11:54:43 -03:00 committed by GitHub
parent 615eb8b440
commit 0828254d61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 2 deletions

View File

@ -13,9 +13,9 @@ module Jobs
strategy = DiscourseAi::Embeddings::Strategies::Truncation.new
vector_rep =
DiscourseAi::Embeddings::VectorRepresentations::Base.find_vector_representation.new
DiscourseAi::Embeddings::VectorRepresentations::Base.current_representation(strategy)
vector_rep.generate_topic_representation_from(topic, strategy)
vector_rep.generate_topic_representation_from(topic)
end
end
end

View File

@ -0,0 +1,39 @@
# frozen_string_literal: true
require_relative "../../../../support/embeddings_generation_stubs"
RSpec.describe Jobs::GenerateEmbeddings do
subject(:job) { described_class.new }
describe "#execute" do
before do
SiteSetting.ai_embeddings_discourse_service_api_endpoint = "http://test.com"
SiteSetting.ai_embeddings_enabled = true
SiteSetting.ai_embeddings_model = "all-mpnet-base-v2"
end
fab!(:topic) { Fabricate(:topic) }
fab!(:post) { Fabricate(:post, post_number: 1, topic: topic) }
let(:truncation) { DiscourseAi::Embeddings::Strategies::Truncation.new }
let(:vector_rep) do
DiscourseAi::Embeddings::VectorRepresentations::Base.current_representation(truncation)
end
it "works" do
expected_embedding = [0.0038493] * vector_rep.dimensions
text =
truncation.prepare_text_from(
topic,
vector_rep.tokenizer,
vector_rep.max_sequence_length - 2,
)
EmbeddingsGenerationStubs.discourse_service(vector_rep.name, text, expected_embedding)
job.execute(topic_id: topic.id)
expect(vector_rep.topic_id_from_representation(expected_embedding)).to eq(topic.id)
end
end
end