2222MODEL = 'nomic-ai/nomic-embed-text-v1-GGUF'
2323FILE_NAME = 'nomic-embed-text-v1.Q8_0.gguf'
2424
25+ model = None
26+ modelLock = Lock ()
27+
2528class AStorageVecDB ():
2629 def __init__ (self ):
27- self .model = None
28- self .modelLock = Lock ()
2930 self .data = {"model" : MODEL , "file" : FILE_NAME , "collections" : {}}
3031 self .dir = None
3132 self .buffers = {}
@@ -38,8 +39,9 @@ def ModuleInfo(self):
3839 return {"NAME" : "storage" , "ACTIONS" : {}}
3940
4041 def CalcEmbeddings (self , txts : list [str ]):
41- with self .modelLock :
42- return np .array (self .model .embed (txts ))
42+ global model , modelLock
43+ with modelLock :
44+ return np .array (model .embed (txts ))
4345
4446 def Hippocampus (self ):
4547 while True :
@@ -73,30 +75,33 @@ def Load(self, dir):
7375 return
7476
7577 def PrepareModel (self ) -> str :
78+ global model , modelLock
79+
7680 ggufFile = hf_hub_download (repo_id = self .data ['model' ],filename = self .data ['file' ])
77- if self .model and ggufFile == self .model .model_path :
78- return f"Embedding model { self .model } has already been loaded."
79-
80- if "llama_cpp" == INFERENCE_ENGINE :
81- self .model = Llama (
82- model_path = ggufFile ,
83- embedding = True ,
84- n_gpu_layers = - 1 , # Uncomment to use GPU acceleration
85- # seed=1337, # Uncomment to set a specific seed
86- # n_ctx=2048, # Uncomment to increase the context window
87- )
88- return "Embedding model has been loaded."
89- elif "gpt4all" == INFERENCE_ENGINE :
90- gpus = []
91- try :
92- gpus = GPT4All .list_gpus ()
93- device = gpus [0 ] if len (gpus ) > 0 else "cpu"
94- except Exception as e :
95- device = "cpu"
96- self .model = Embed4All (ggufFile , device = device )
97- return f"GPUs found on this device: { gpus } . Embedding model has been loaded on { device } ."
98- else :
99- return "No inference engine was found. Please use one of the following commands to install: `pip install gpt4all` or `ailice_turbo`."
81+ with modelLock :
82+ if model and ggufFile == model .model_path :
83+ return f"Embedding model { self .data ['model' ]} has already been loaded."
84+
85+ if "llama_cpp" == INFERENCE_ENGINE :
86+ model = Llama (
87+ model_path = ggufFile ,
88+ embedding = True ,
89+ n_gpu_layers = - 1 , # Uncomment to use GPU acceleration
90+ # seed=1337, # Uncomment to set a specific seed
91+ # n_ctx=2048, # Uncomment to increase the context window
92+ )
93+ return "Embedding model has been loaded."
94+ elif "gpt4all" == INFERENCE_ENGINE :
95+ gpus = []
96+ try :
97+ gpus = GPT4All .list_gpus ()
98+ device = gpus [0 ] if len (gpus ) > 0 else "cpu"
99+ except Exception as e :
100+ device = "cpu"
101+ model = Embed4All (ggufFile , device = device )
102+ return f"GPUs found on this device: { gpus } . Embedding model has been loaded on { device } ."
103+ else :
104+ return "No inference engine was found. Please use one of the following commands to install: `pip install gpt4all` or `ailice_turbo`."
100105
101106 def Open (self , directory : str ) -> str :
102107 try :
0 commit comments