Skip to content

Commit 80be7fe

Browse files
committed
Download and configure model on Docker image build
Why these changes are being introduced: We have opted to include the model weights and assets inside the Docker image. When the model is small-ish like ours, this avoids the need to save the model to S3 and download each time the CLI is invoked. How this addresses that need: The CLI command `download-model` is used within the Dockerfile itself to download the model. As noted via inline comments, the env vars `TE_MODEL_URI` and `TE_MODEL_DOWNLOAD_PATH` are also set in the Dockerfile. This has a dual purpose. First, these env vars inform the `download-model` CLI invocation within the Dockerfile. Second, they persist to the container and establish the model as default for all calls. Side effects of this change: * On Docker image build, the model will be downloaded from HuggingFace, configured, and included in the final Docker image. Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/USE-113
1 parent a50f256 commit 80be7fe

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Dockerfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,13 @@ COPY embeddings ./embeddings
1818
# Install package into system python, includes "marimo-launcher" script
1919
RUN uv pip install --system .
2020

21-
ENTRYPOINT ["embeddings"]
21+
# Download the model and include in the Docker image
22+
# NOTE: The env vars "TE_MODEL_URI" and "TE_MODEL_DOWNLOAD_PATH" are set here to support
23+
# the downloading of the model into this image build, but persist in the container and
24+
# effectively also set this as the default model.
25+
ENV HF_HUB_DISABLE_PROGRESS_BARS=true
26+
ENV TE_MODEL_URI=opensearch-project/opensearch-neural-sparse-encoding-doc-v3-gte
27+
ENV TE_MODEL_DOWNLOAD_PATH=/model
28+
RUN python -m embeddings.cli --verbose download-model
29+
30+
ENTRYPOINT ["python", "-m", "embeddings.cli"]

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ TE_MODEL_DOWNLOAD_PATH=# Download location for model
2828
HF_HUB_DISABLE_PROGRESS_BARS=#boolean to use progress bars for HuggingFace model downloads; defaults to 'true' in deployed contexts
2929
```
3030

31+
## Configuring an Embedding Model
32+
33+
This CLI application is designed to create embeddings for input texts. To do this, a pre-trained model must be identified and configured for use.
34+
35+
To this end, there is a base embedding class `BaseEmbeddingModel` that is designed to be extended and customized for a particular embedding model.
36+
37+
Once an embedding class has been created, the preferred approach is to set env vars `TE_MODEL_URI` and `TE_MODEL_DOWNLOAD_PATH` directly in the `Dockerfile` to a) download a local snapshot of the model during image build, and b) set this model as the default for the CLI.
38+
39+
This allows invoking the CLI without specifying a model URI or local location, allowing this model to serve as the default, e.g.:
40+
41+
```shell
42+
uv run --env-file .env embeddings test-model-load
43+
```
44+
3145
## CLI Commands
3246

3347
For local development, all CLI commands should be invoked with the following format to pickup environment variables from `.env`:

0 commit comments

Comments
 (0)