MaxKB/apps/common/config/embedding_config.py
shaohuzhang1 cdc7e13415
Some checks failed
sync2gitee / repo-sync (push) Has been cancelled
Typos Check / Spell Check with Typos (push) Has been cancelled
feat: 升级langchain版本到2.2.3 (#617)
2024-06-07 11:08:32 +08:00

52 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# coding=utf-8
"""
@project: maxkb
@Author
@file embedding_config.py
@date2023/10/23 16:03
@desc:
"""
from langchain_huggingface.embeddings import HuggingFaceEmbeddings
from smartdoc.const import CONFIG
class EmbeddingModel:
instance = None
@staticmethod
def get_embedding_model():
"""
获取向量化模型
:return:
"""
if EmbeddingModel.instance is None:
model_name = CONFIG.get('EMBEDDING_MODEL_NAME')
cache_folder = CONFIG.get('EMBEDDING_MODEL_PATH')
device = CONFIG.get('EMBEDDING_DEVICE')
e = HuggingFaceEmbeddings(
model_name=model_name,
cache_folder=cache_folder,
model_kwargs={'device': device})
EmbeddingModel.instance = e
return EmbeddingModel.instance
class VectorStore:
from embedding.vector.pg_vector import PGVector
from embedding.vector.base_vector import BaseVectorStore
instance_map = {
'pg_vector': PGVector,
}
instance = None
@staticmethod
def get_embedding_vector() -> BaseVectorStore:
from embedding.vector.pg_vector import PGVector
if VectorStore.instance is None:
from smartdoc.const import CONFIG
vector_store_class = VectorStore.instance_map.get(CONFIG.get("VECTOR_STORE_NAME"),
PGVector)
VectorStore.instance = vector_store_class()
return VectorStore.instance