From a0b9fb97212e20528e3fe0f3c15cfff14e2d2348 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 29 Nov 2023 16:36:56 +1100 Subject: [PATCH] FIX: explicitly load embedding strategies (#325) If not, sometimes during tests these constants may not be loaded leading to flaky tests --- lib/embeddings/vector_representations/base.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/embeddings/vector_representations/base.rb b/lib/embeddings/vector_representations/base.rb index caf20244..3a3ec9d0 100644 --- a/lib/embeddings/vector_representations/base.rb +++ b/lib/embeddings/vector_representations/base.rb @@ -5,7 +5,14 @@ module DiscourseAi module VectorRepresentations class Base 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 def initialize(strategy)