FIX: explicitly load embedding strategies (#325)

If not, sometimes during tests these constants may not be loaded
leading to flaky tests
This commit is contained in:
Sam 2023-11-29 16:36:56 +11:00 committed by GitHub
parent 6ddc17fd61
commit a0b9fb9721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -5,7 +5,14 @@ module DiscourseAi
module VectorRepresentations module VectorRepresentations
class Base class Base
def self.current_representation(strategy) def self.current_representation(strategy)
subclasses.map { _1.new(strategy) }.find { _1.name == SiteSetting.ai_embeddings_model } # we are explicit here cause the loader may have not
# loaded the subclasses yet
[
DiscourseAi::Embeddings::VectorRepresentations::AllMpnetBaseV2,
DiscourseAi::Embeddings::VectorRepresentations::BgeLargeEn,
DiscourseAi::Embeddings::VectorRepresentations::MultilingualE5Large,
DiscourseAi::Embeddings::VectorRepresentations::TextEmbeddingAda002,
].map { _1.new(strategy) }.find { _1.name == SiteSetting.ai_embeddings_model }
end end
def initialize(strategy) def initialize(strategy)