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:
Debanjum Singh Solanky
2022-01-14 16:31:55 -05:00
parent 2e53fbc844
commit b63026d97c
5 changed files with 43 additions and 10 deletions

View File

@@ -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