All case studies

HIPAA Embedding Model: A Domain-Tuned Retriever

An internal showcase build: bge-base-en-v1.5 fine-tuned for retrieval over HIPAA regulation, then tested on rules it never saw in training.

Industries
Healthcare
Published
Last updated

Internal showcase build: Solvren AI built and measured this on public or synthetic data. There is no client.

Problem

A RAG system over regulation is only as good as its retriever. General-purpose embedding models were not trained on regulatory phrasing, and many HIPAA sections read alike, so the right section and its neighbours compete for the top slot.

We wanted to measure whether a small model fine-tuned on one part of HIPAA retrieves better on parts it never saw, and whether the whole pipeline runs on a laptop with no cloud services.

This is an internal showcase build, not a client engagement. The source text is public regulation.

What we built

  • BAAI/bge-base-en-v1.5 fine-tuned with sentence-transformers for retrieval over 45 CFR Parts 160 and 164 (eCFR snapshot of 2026-10-06).
  • Training data: 813 synthetic query-passage pairs over 271 chunks of Part 160 and the Privacy Rule (Part 164 Subpart E). Questions were generated locally by Qwen3-4B (4-bit).
  • Held-out test: 99 queries over 33 chunks of the Security Rule and Breach Notification Rule (Subparts C and D), regulations the model never saw in training.
  • Data generation and training ran on a MacBook Pro (Apple M5, 16 GB) in about 35 minutes, with no cloud services.
  • Published as SolvrenAI/bge-base-en-v1.5-hipaa, with the dataset SolvrenAI/hipaa-retrieval-pairs and code at github.com/solvren-ai/domain-embedding-finetune.

How it works

Training and evaluation pipeline
  1. 1Pull regulation

    eCFR API, title 45, snapshot 2026-10-06, split by CFR section.

  2. 2Chunk

    Whole paragraphs packed to about 220 words, prefixed with the section heading.

  3. 3Generate queries

    Up to 3 questions per chunk from Qwen3-4B, locally with mlx-lm.

  4. 4Fine-tune

    bge-base-en-v1.5, in-batch negatives, 4 epochs on Apple MPS.

  5. 5Evaluate

    99 held-out queries over the full 304-chunk corpus, plus BEIR SciFact.

Split by regulation, not at random

Train and validation come from different regulations. A random split would put near-duplicate paragraphs from the same section on both sides. Splitting by rule measures out-of-document retrieval.

A strict full-corpus test

Each held-out query retrieves over all 304 chunks, so the 271 Privacy Rule and Part 160 chunks act as same-domain distractors. Only the source chunk counts as relevant, for every model.

Training

MultipleNegativesRankingLoss with in-batch negatives and a no-duplicates batch sampler: 4 epochs, batch size 8, learning rate 2e-5, max sequence length 256, on Apple MPS. 408 steps in 7.6 minutes. No hard-negative mining or model merging.

What we compared

The base model, bge-large-en-v1.5 (about 3x its size), and snowflake-arctic-embed-m-v1.5, none of them fine-tuned. All use the same query instruction, cosine similarity, and max sequence length. A BEIR SciFact run checks for general-domain regression.

Controls

  • Train and validation come from different regulations, so the held-out score is not inflated by near-duplicate text.
  • Every model, tuned or not, is scored with the same query instruction, similarity, and sequence length.
  • Local pipeline. The text here was public, but the same path keeps internal policies or contracts on the machine for generation and training.
  • No PHI or personal data: the source is regulation text, and the questions were generated from it.
  • Raw metric files and a one-command reproduce path are published with the code.

Results

Note: Small n. The held-out set is 99 queries, so one query moves Hit@1 by about 1 point; read the gains as directional. Queries are LLM-generated from the chunk they target and share its vocabulary, so real user queries will score lower. The tuned model trained on the 271 chunks that act as distractors in the full-corpus test; the reference models did not.

Results for HIPAA Embedding Model: A Domain-Tuned Retriever
Measure Result
NDCG@10, 99 held-out queries over 304 chunks (base model) 0.9071 (0.8337)
Hit@1, same test (base model) 0.7879 (0.6970)
Hit@10, same test (base model) 1.0000 (0.9495)
NDCG@10, same test, bge-large-en-v1.5 0.8638
BEIR SciFact NDCG@10, general-domain check (base model) 0.7427 (0.7404)
Training time on Apple MPS 7.6 min

We publish only numbers we measured.

Why it fits regulated teams

Compliance teams need a retriever that finds the right section, and often cannot send internal text to an outside service to build one. This build ran end to end on one laptop and was measured on rules it never saw. Coverage is HIPAA only, so it needs evaluating on any other corpus before use.

Related industries: Healthcare

FAQ

Was this built for a client?

No. It is an internal showcase build on public HIPAA regulation text. The model, training data, and code are public.

Does a fine-tuned base model beat a larger general model?

On this test, yes: 0.9071 NDCG@10 against 0.8638 for bge-large-en-v1.5, which was not fine-tuned. With 99 queries, treat the margin as directional.

Did fine-tuning hurt general retrieval?

Not on the one check we ran: BEIR SciFact NDCG@10 went from 0.7404 to 0.7427, within noise. That is one small task, not a full MTEB run.

Does it work for other healthcare regulation?

Unknown. It has only been tested on HIPAA, not on 42 CFR Part 2 or state privacy law. Its output is retrieval, not legal advice.

More case studies

Start with one workflow

Book a free 30-minute AI audit. We look at one workflow with you and tell you whether it can reach production in 6 to 8 weeks. No commitment, just 30 minutes with an engineer.

Book a free AI audit
Book a free AI audit