Skip to content

Commit

Permalink
(improvement)(common) When EmbeddingModel retrieval fails, use the de…
Browse files Browse the repository at this point in the history
…fault embedded model. (#1176)
  • Loading branch information
lexluo09 authored Jun 20, 2024
1 parent 3831f9f commit 5555dc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.tencent.supersonic.common.config.EmbeddingConfig;
import com.tencent.supersonic.common.util.ContextUtils;
import dev.langchain4j.data.embedding.Embedding;
import dev.langchain4j.model.embedding.BgeSmallZhEmbeddingModel;
import dev.langchain4j.model.embedding.EmbeddingModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;

import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -95,7 +97,13 @@ public void addQuery(String collectionName, List<EmbeddingQuery> queries) {
}

private static EmbeddingModel getEmbeddingModel() {
return ContextUtils.getBean(EmbeddingModel.class);
EmbeddingModel embeddingModel;
try {
embeddingModel = ContextUtils.getBean(EmbeddingModel.class);
} catch (NoSuchBeanDefinitionException e) {
embeddingModel = new BgeSmallZhEmbeddingModel();
}
return embeddingModel;
}

private InMemoryEmbeddingStore<EmbeddingQuery> getEmbeddingStore(String collectionName) {
Expand Down

0 comments on commit 5555dc8

Please sign in to comment.