-
Notifications
You must be signed in to change notification settings - Fork 0
USE 113 - Rework model registration and loading #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,12 +7,25 @@ | |
| class BaseEmbeddingModel(ABC): | ||
| """Abstract base class for embedding models. | ||
|
|
||
| Args: | ||
| model_uri: HuggingFace model identifier (e.g., 'org/model-name'). | ||
| All child classes must set class level attribute MODEL_URI. | ||
| """ | ||
|
|
||
| def __init__(self, model_uri: str) -> None: | ||
| self.model_uri = model_uri | ||
| MODEL_URI: str # Type hint to document the requirement | ||
|
|
||
| def __init_subclass__(cls, **kwargs: dict) -> None: # noqa: D105 | ||
| super().__init_subclass__(**kwargs) | ||
|
|
||
| # require class level MODEL_URI to be set | ||
| if not hasattr(cls, "MODEL_URI"): | ||
| msg = f"{cls.__name__} must define 'MODEL_URI' class attribute" | ||
| raise TypeError(msg) | ||
| if not isinstance(cls.MODEL_URI, str): | ||
| msg = f"{cls.__name__} must override 'MODEL_URI' with a valid string" | ||
| raise TypeError(msg) | ||
|
Comment on lines
+13
to
+24
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This establishes |
||
|
|
||
| @property | ||
| def model_uri(self) -> str: | ||
| return self.MODEL_URI | ||
|
|
||
| @abstractmethod | ||
| def download(self, output_path: Path) -> Path: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,8 @@ class OSNeuralSparseDocV3GTE(BaseEmbeddingModel): | |
| HuggingFace URI: opensearch-project/opensearch-neural-sparse-encoding-doc-v3-gte | ||
| """ | ||
|
|
||
| MODEL_URI = "opensearch-project/opensearch-neural-sparse-encoding-doc-v3-gte" | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now, each model (and we may only have a couple ever), will define their HuggingFace URI in the class itself. |
||
|
|
||
| def download(self, output_path: Path) -> Path: | ||
| """Download and prepare model, saving to output_path. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DRY's up the
--model-uriCLI arg, and gives it an env var default.