Skip to content

Commit

Permalink
Merge no_model bug fix (#666)
Browse files Browse the repository at this point in the history
skip preloading for no_model, add error handling if no model, update version.py to 1.5.1 (#664)
  • Loading branch information
vicilliar committed Dec 15, 2023
1 parent 702b668 commit cd86cea
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Release 1.5.1
## Bug fixes and minor changes
- Adding `no_model` to `MARQO_MODELS_TO_PRELOAD` no longer causes an error on startup. Preloading process is simply skipped for this model [#657](https://github.com/marqo-ai/marqo/pull/657).


# Release 1.5.0
## New Features
- Separate model for search and add documents (https://github.com/marqo-ai/marqo/pull/633). Using the `search_model` and `search_model_properties` key in `index_defaults` allows you to specify a model specifically to be used for searching. This is useful for using a different model for search than what is used for add_documents. Learn how to use `search_model` [here](https://docs.marqo.ai/1.5.0/API-Reference/Indexes/create_index/#search-model).
Expand Down
2 changes: 2 additions & 0 deletions src/marqo/tensor_search/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

MARQO_OBJECT_TYPES = {MappingsObjectType.multimodal_combination, MappingsObjectType.custom_vector}

MODELS_TO_SKIP_PRELOADING = {"no_model"}

ILLEGAL_CUSTOMER_FIELD_NAME_CHARS = {'.', '/', '\n'}

ALLOWED_CUSTOMER_FIELD_TYPES = [str, int, float, bool, list, dict]
Expand Down
16 changes: 16 additions & 0 deletions src/marqo/tensor_search/on_start_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# we need to import backend before index_meta_cache to prevent circular import error:
from marqo.tensor_search import backend, index_meta_cache, utils
from marqo import config
from marqo.tensor_search import constants
from marqo.tensor_search.web import api_utils
from marqo import errors
from marqo.tensor_search.throttling.redis_throttle import throttle
Expand Down Expand Up @@ -152,6 +153,21 @@ def run(self):
N = 10
messages = []
for model in self.models:
# Skip preloading of models that can't be preloaded (eg. no_model)
if isinstance(model, str):
model_name = model
elif isinstance(model, dict):
try:
model_name = model["model"]
except KeyError as e:
raise errors.EnvVarError(
f"Your custom model {model} is missing `model` key."
f"""To add a custom model, it must be a dict with keys `model` and `model_properties` as defined in `https://marqo.pages.dev/0.0.20/Advanced-Usage/configuration/#configuring-preloaded-models`"""
) from e
if model_name in constants.MODELS_TO_SKIP_PRELOADING:
self.logger.info(f"Skipping preloading of `{model_name}`.")
continue

for device in self.default_devices:
self.logger.debug(f"Beginning loading for model: {model} on device: {device}")

Expand Down
2 changes: 1 addition & 1 deletion src/marqo/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.5.0"
__version__ = "1.5.1"


def get_version() -> str:
Expand Down
16 changes: 16 additions & 0 deletions tests/tensor_search/test_on_start_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@ def run():
return True
assert run()

def test_preload_no_model(self):
no_model_object = {
"model": "no_model",
"model_properties": {
"dimensions": 123
}
}
mock_preload = mock.MagicMock()
@mock.patch("marqo.tensor_search.on_start_script._preload_model", mock_preload)
@mock.patch.dict(os.environ, {enums.EnvVars.MARQO_MODELS_TO_PRELOAD: json.dumps([no_model_object])})
def run():
model_caching_script = on_start_script.ModelsForCacheing()
model_caching_script.run()
mock_preload.assert_not_called() # The preloading function should never be called for no_model
run()

# TODO: test bad/no names/URLS in end-to-end tests, as this logic is done in vectorise call

def test_set_best_available_device(self):
Expand Down

0 comments on commit cd86cea

Please sign in to comment.