mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-04 05:39:06 +00:00
Save Asymmetric Search Model to Disk
- Improve application load time - Remove dependence on internet to startup application and perform semantic search
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
# Standard Packages
|
||||
import pathlib
|
||||
from os.path import join
|
||||
|
||||
|
||||
def is_none_or_empty(item):
|
||||
@@ -32,3 +34,19 @@ def merge_dicts(priority_dict, default_dict):
|
||||
if k not in priority_dict:
|
||||
merged_dict[k] = default_dict[k]
|
||||
return merged_dict
|
||||
|
||||
|
||||
def load_model(model_name, model_dir, model_type):
|
||||
"Load model from disk or huggingface"
|
||||
# Construct model path
|
||||
model_path = join(model_dir, model_name.replace("/", "_"))
|
||||
|
||||
# Load model from model_path if it exists there
|
||||
if resolve_absolute_path(model_path).exists():
|
||||
model = model_type(get_absolute_path(model_path))
|
||||
# Else load the model from the model_name
|
||||
else:
|
||||
model = model_type(model_name)
|
||||
model.save(model_path)
|
||||
|
||||
return model
|
||||
Reference in New Issue
Block a user