|
|
|
|
|
|
|
|
^_- |
|
|
^_- |
|
|
|
|
|
|
|
|
""" |
|
|
""" |
|
|
if not settings.LIGHTEN and not DefaultEmbedding._model: |
|
|
|
|
|
|
|
|
if not settings.LIGHTEN: |
|
|
with DefaultEmbedding._model_lock: |
|
|
with DefaultEmbedding._model_lock: |
|
|
from FlagEmbedding import FlagModel |
|
|
from FlagEmbedding import FlagModel |
|
|
import torch |
|
|
import torch |
|
|
if not DefaultEmbedding._model: |
|
|
|
|
|
|
|
|
if not DefaultEmbedding._model or model_name != DefaultEmbedding._model_name: |
|
|
try: |
|
|
try: |
|
|
DefaultEmbedding._model = FlagModel(os.path.join(get_home_cache_dir(), re.sub(r"^[a-zA-Z0-9]+/", "", model_name)), |
|
|
DefaultEmbedding._model = FlagModel(os.path.join(get_home_cache_dir(), re.sub(r"^[a-zA-Z0-9]+/", "", model_name)), |
|
|
query_instruction_for_retrieval="为这个句子生成表示以用于检索相关文章:", |
|
|
query_instruction_for_retrieval="为这个句子生成表示以用于检索相关文章:", |
|
|
|
|
|
|
|
|
threads: int | None = None, |
|
|
threads: int | None = None, |
|
|
**kwargs, |
|
|
**kwargs, |
|
|
): |
|
|
): |
|
|
if not settings.LIGHTEN and not FastEmbed._model: |
|
|
|
|
|
|
|
|
if not settings.LIGHTEN: |
|
|
with FastEmbed._model_lock: |
|
|
with FastEmbed._model_lock: |
|
|
from fastembed import TextEmbedding |
|
|
from fastembed import TextEmbedding |
|
|
if not DefaultEmbedding._model or model_name != DefaultEmbedding._model_name: |
|
|
if not DefaultEmbedding._model or model_name != DefaultEmbedding._model_name: |