Skip to content

Embed MiniLM through the Delosis embedding service, beside E5 - #37

Merged
woodthom2 merged 1 commit into
harmonydata:mainfrom
delosis:delosis/embedder-models
Dec 3, 2026
Merged

woodthom2 merged 1 commit into
harmonydata:mainfrom
delosis:delosis/embedder-models

Conversation

@ronnyTodgers

Copy link
Copy Markdown
Contributor

Description

With this change, a deployment can have the Delosis embedding service embed Harmony's default model, paraphrase-multilingual-MiniLM-L12-v2, as well as E5 (#34). The API process then no longer loads its own copy of MiniLM at start-up. With none of the new settings, nothing changes.

  • One client for both models. delosis_e5_embeddings.py becomes delosis_embeddings.py, which works with any model the service serves for Harmony (REMOTE_MODELS: e5 and minilm).
  • Model check. Each request names the model. The reply must name the same model and have that model's dimension. An older service ignores the name and answers with E5, and an E5 reply must never be taken for MiniLM.
  • Start-up and fallback. hugging_face_embeddings.py loads at start-up only the models the service doesn't serve. If the service fails, MiniLM is loaded in-process on first use and used for 60 seconds before the service is tried again. E5 still has no in-process fallback.
  • Vector scale. The service returns unit-length vectors. When the service serves MiniLM, the fallback normalises its vectors too, so every MiniLM vector in one process has the same scale.
    • Matching is cosine, so it isn't affected.
    • The optional k-means and HDBSCAN clustering work on the raw vectors, so their results can differ slightly from in-process MiniLM's.

The service's MiniLM vectors match the in-process model's to cosine 0.9999999 on 498 Mental Health Catalogue items.

No dependencies added. No file in common with #36.

Type of change

  • New feature (non-breaking change which adds functionality)

Testing

  • pytest tests/unit_tests/test_delosis_embeddings.py: 15 tests with a fake service and stand-in models, so no weights load and nothing is sent anywhere. They cover:
    • no settings: all three models load at start-up and give unnormalised vectors, as before;
    • the E5-only settings from Add multilingual-e5-base as an optional model, served over HTTP #34;
    • MiniLM requested by name, and batches split at 256;
    • a reply from the wrong model, and the wrong dimension;
    • the fallback and its 60-second pause;
    • an unknown model name in the settings.
  • The service's MiniLM vectors compared with the in-process model's, on 498 catalogue items.
  • This client against a running service over HTTP. We will run that on our deployment before switching it on.

Test Configuration

  • Library version: Harmony submodule as pinned on main
  • OS: macOS on Apple silicon, Python 3.12
  • Toolchain: pytest

Checklist

  • My PR is for one issue, rather than for multiple unrelated fixes.
  • My code follows the style guidelines of this project. (I did not run PyCharm's formatter. hugging_face_embeddings.py keeps its CRLF line endings.)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (the settings are documented in the module docstring of delosis_embeddings.py; the README is unchanged)
  • My changes generate no new warnings (not checked)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (the new ones pass; I did not run the existing local tests)
  • Any dependent changes have been merged and published in downstream modules (there are none)

🤖 Generated with Claude Code

The Delosis embedding service (delosis-embedding-api 1.2.0) now serves
several models from one container, Harmony's default MiniLM among them.
A deployment can have it embed MiniLM as well as E5, so the API process
no longer loads its own copy at start-up.

- delosis_e5_embeddings.py becomes delosis_embeddings.py, a client for
  any model the service serves for Harmony (REMOTE_MODELS: e5, minilm).
  HARMONY_EMBEDDER_URL / _TOKEN / _MODELS configure it. The old
  HARMONY_E5_EMBEDDER_URL / _TOKEN still work and mean E5 only, asked
  for without a model name, as before.
- Requests name the model, and a reply must name the same model and have
  its dimension: a service that predates model names answers with E5,
  which must never be taken for MiniLM.
- hugging_face_embeddings.py loads at start-up only the models the
  service does not serve. If the service fails, MiniLM is loaded
  in-process on first use and used for 60 s before the service is tried
  again. That fallback normalises, so every MiniLM vector in a process
  has the service's unit scale (k-means and HDBSCAN use raw vectors;
  everything else is cosine). E5 has no in-process fallback.
- With none of the settings, nothing changes.

The service's MiniLM vectors match the in-process ones to cosine
0.9999999 on 498 MHC catalogue items (2 Dec 2026).

Unit tests with a fake service and stand-in models: tests/unit_tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@woodthom2
woodthom2 merged commit 0e39963 into harmonydata:main Dec 3, 2026
1 check passed
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.

2 participants