Skip to content

Commit

Permalink
Fix error of changing embedding model (#4184)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

1. Change embedding model of knowledge base won't change the default
embedding model.
2. Retrieval test bug

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Signed-off-by: jinhai <haijin.chn@gmail.com>
  • Loading branch information
JinHai-CN authored Dec 23, 2024
1 parent a4bccc1 commit 4abc144
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions rag/llm/embedding_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ def __init__(self, key, model_name, **kwargs):
^_-
"""
if not settings.LIGHTEN and not DefaultEmbedding._model:
if not settings.LIGHTEN:
with DefaultEmbedding._model_lock:
from FlagEmbedding import FlagModel
import torch
if not DefaultEmbedding._model:
if not DefaultEmbedding._model or model_name != DefaultEmbedding._model_name:
try:
DefaultEmbedding._model = FlagModel(os.path.join(get_home_cache_dir(), re.sub(r"^[a-zA-Z0-9]+/", "", model_name)),
query_instruction_for_retrieval="为这个句子生成表示以用于检索相关文章:",
Expand Down Expand Up @@ -261,7 +261,7 @@ def __init__(
threads: int | None = None,
**kwargs,
):
if not settings.LIGHTEN and not FastEmbed._model:
if not settings.LIGHTEN:
with FastEmbed._model_lock:
from fastembed import TextEmbedding
if not DefaultEmbedding._model or model_name != DefaultEmbedding._model_name:
Expand Down

0 comments on commit 4abc144

Please sign in to comment.