Skip to content

Add embedding_huggingface() engine for step_sentence_embeddings() - #361

Merged
EmilHvitfeldt merged 5 commits into
mainfrom
add-huggingface-embedding-engine
Oct 20, 2026
Merged

EmilHvitfeldt merged 5 commits into
mainfrom
add-huggingface-embedding-engine

Conversation

@EmilHvitfeldt

Copy link
Copy Markdown
Member

Adds an engine that runs a sentence-transformers model from the Hugging Face Hub through reticulate, so step_sentence_embeddings() can use local models without a server. The model is pinned with a required revision and only the id and revision are stored in the recipe, never the loaded model. tidy() for the step gained a revision column to show it.

On macOS, starting Python after recipes is loaded aborts R with an OpenMP error, because data.table and torch each load a libomp. The engine sets KMP_DUPLICATE_LIB_OK and OMP_NUM_THREADS before Python starts when they are unset, and says so, which is the same workaround the text package uses. The cost is a single-threaded model.

Test plan

Most tests mock the Python boundary. The one live test is skipped unless sentence_transformers can be imported. To run it, point reticulate at an environment that has it, for example RETICULATE_PYTHON=/path/to/venv/bin/python3, and run devtools::test(filter = "sentence_embeddings-huggingface"). It downloads all-MiniLM-L6-v2 and checks the embeddings against values from sentence-transformers.

Part of #303.

Engines that can pin a version of their model report it through a new engine_revision() generic. It is NA for the custom and ollama engines.
Runs a sentence-transformers model through reticulate, pinned to a model revision. The loaded model is cached for the session and never stored in the recipe. On macOS the engine sets the OpenMP environment variables that stop R from aborting when torch is loaded.
Earlier test files start Python through the spaCy skip helper, which made the helper warn instead of message. The check is now mockable, and both branches are tested.
@EmilHvitfeldt
EmilHvitfeldt merged commit 2889f38 into main Oct 20, 2026
14 checks passed
@EmilHvitfeldt
EmilHvitfeldt deleted the add-huggingface-embedding-engine branch October 20, 2026 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant