Add embedding_sft algorithm for contrastive embedding fine-tuning #139
All Vouch review confidence checks passed
Residual risk 0.34 = Change Risk (0.60) × (1 − Review Confidence (0.44)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.60 · 555 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 10%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.378
Shallow Review Depth
shallow_review_depth
0.344
No Reviewer Assigned
no_reviewer_assigned
0.120
Real PR Conversation Timeline
1 comments
"Review active on #139"
general
weight: 0.35
Maxusmusti
Summary
embedding_sftalgorithm for fine-tuning sentence embedding models using contrastive lossessentence-transformerslibrary viaSentenceTransformersBackendDetails
Algorithm:
embedding_sft()Fine-tunes embedding models (e.g.
all-MiniLM-L6-v2, 23M params) so that inputs with the same label cluster together in embedding space. Supports three loss functions:| Loss | Description | Best for |
|------|-------------|----------|
|
batch_all_triplet| Mines all valid triplets per batch | Default — exhaustive boundary learning ||
batch_hard_triplet| Mines hardest triplet per anchor | Focused on worst-case boundaries ||
mnrl| Multiple Negatives Ranking Loss | General semantic similarity |Key features:
GROUP_BY_LABELbatch sampling ensures every batch has all classes (required for triplet mining)loss_fncallable support for extensibilityUsage
Files
src/training_hub/algorithms/embedding_sft.py— Algorithm, Backend, convenience functionsrc/training_hub/__init__.py— exportspyproject.toml—[embedding]extra:sentence-transformers>=5.0examples/embedding_sft_semantic_routing.py— full POC reproducer (data gen → train → eval)examples/notebooks/routing_demo.ipynb— interactive walkthrough notebook (data gen → fine-tune → router runtime → eval), with rendered outputstests/test_embedding_sft.py— unit tests for validation and data helpersdocs/algorithms/embedding_sft.md,docs/api/{functions,classes,backends}/embedding_sft.md— algorithm docsdocs/README.md,docs/_sidebar.md,docs/api/README.md,docs/examples/README.md— support matrix, nav, and examples entriesTest plan
batch_all_tripletloss — PASSbatch_hard_tripletloss — PASSmnrlloss (with auto pair conversion) — PASStests/test_embedding_sft.py— 17 unit tests passingrouting_demo.ipynbend-to-end against the reviewed source (baseline 64.17% → fine-tuned 100%, live demo 10/10)🤖 Generated with Claude Code
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
New Features
Added embedding model fine-tuning with triplet and multiple-negative-ranking losses.
Supports common training data formats, configurable sampling, evaluation data, checkpoints, and custom loss functions.
Added public APIs for configuring and running embedding fine-tuning.
Added a semantic-routing example with generated datasets and baseline versus fine-tuned accuracy, F1, and misrouting metrics.
Added configurable model, output, training, and reproducibility options for the example.
Documentation
* Added installation guidance, usage examples, and API reference documentation for embedding fine-tuning.
<!-- end of auto-generated comment: release notes by CodeRabbit -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
- Added embedding fine-tuning for sentence-transformer models with contrastive, triplet, and custom losses.
- Added configurable data loading, evaluation, sampling, checkpointing, and structured training results.
- Added semantic-routing example with baseline and fine-tuned accuracy metrics.
- Added optional embedding support and public API access.
- Added comprehensive guides, API references, installation instructions, and quick-start examples.
- Added coverage for dataset loading, validation, pair conversion, custom losses, and deterministic sampling.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->