Fitness RAG: what building a small retrieval system taught me

A RAG system over 873 gym exercises: ask for "a good bodyweight leg exercise" and get an answer that only uses exercises that exist. I kept it small on purpose, to learn how the parts of an ML system fit together.

Sentence-Transformers CLIP BM25 Milvus Lite MLflow Ollama
873exercises, with images and metadata
69labelled eval queries
+15%Recall@10 from hybrid search
0.36 → 0.81Recall@10 after fine-tuning

From my project journal

  • Don't overthink it. Start simpler.
  • Be product-oriented, not tool-oriented.
  • Classic ML and GenAI need different toolchains. Learn one at a time.
  • Build it end to end first, then measure it.
The data

One exercise, as the model sees it

Each of the 873 exercises has two photos and a small record. The feature pipeline flattens the record into one string, and that string is what gets embedded.

Show a sample exercise Superman · photos, record and embedder text
Superman exercise, start position: lying face down on a mat with arms extended forward
0.jpg · start
Superman exercise, held position: arms, chest and legs raised off the floor
1.jpg · hold

Superman

level
beginner
equipment
body only
mechanic
compound
force
static
primary
lower back
secondary
glutes, hamstrings
category
stretching

→ text for the embedder

Superman . static . beginner . compound . body only . lower back . glutes, hamstrings . stretching . To begin, lie straight and face down on the floor or exercise mat. Your arms should be fully extended in front of you…

From the public-domain exercises.json dataset.

The metadata (muscles, equipment, level) is what made a labelled eval set possible without hand-labelling anything.

01 · The system

Feature, Training, Inference

Three pipelines that only talk through what they store (the FTI pattern). Hover or tap the numbers for tips.

Fitness RAG system architecture Three lanes: feature pipeline, training pipeline and inference pipeline. Underneath them sit three stores: a feature store of JSONL and embeddings, an MLflow model registry, and a Milvus Lite vector database. A shared config bar spans the bottom. 01 · FEATURE Raw data → features src/feature_pipeline/ 02 · TRAINING Features → model weights src/training_pipeline/ 03 · INFERENCE Query → grounded answer src/inference_pipeline/ Load & clean exercises exercises.json → dataset.jsonl Embed text + images Sentence-Transformers · CLIP Save embeddings one .npy file per model Bootstrap eval set 69 queries + training pairs Contrastive fine-tune MultipleNegativesRankingLoss Log every run params + retrieval metrics Embed the user query same model as the corpus Hybrid search BM25 + dense, fused with RRF Grounded answer Ollama · qwen2.5:7b · Gradio UI Feature store JSONL + embeddings Model registry MLflow · local SQLite Vector DB Milvus Lite · one local file create_db.py loads the vectors into the index metadata weights configs/*.yaml one file per pipeline run, validated by Pydantic schemas in src/config/ · deps via uv 1 2 3 4 5 6 7 8
  1. Configs live outside src/One YAML per run, checked by Pydantic, so every run can be repeated.
  2. JSONL for the datasetOne exercise per line: easy to stream, split and process in parallel.
  3. Text + image in one vectorCLIP embeds the description and the images, then averages them 50/50.
  4. Eval set before tuning69 queries from metadata, kept separate from the training pairs.
  5. Track runs, don't print themParams and metrics go to MLflow, in a local SQLite file.
  6. Same model on both sidesQuery and corpus must use the same model version. New model = re-index.
  7. One backend interfaceNumPy, Milvus Lite and BM25 all implement search(vector, top_k).
  8. Fail loudlyNo Ollama, no answer: a clear error instead of a silent search-only fallback.

Splitting the code this way made each part swappable: a new embedder, backend or LLM is one config change.

02 · Training vs. inference

Same model, two different jobs

TrainingInference
RunsOffline, when the model changesOn every query
Cares aboutThroughput, reproducibilityLatency, consistent answers
Fails byOverfitting to the eval setUsing a different model than the index

The only thing they share is a model version, and that's exactly what has to match.

03 · Embeddings

Text vs. images

The dataset has images, so I started with CLIP. But CLIP is trained to match an image with its caption, not text with text.

Text embedding space vs. CLIP embedding space Left: a text embedder places exercise descriptions with similar meaning close together. Right: CLIP is trained to place an image close to its own caption, not captions close to each other. TEXT EMBEDDER · all-MiniLM-L6-v2 text ↔ text push-up press-up incline push-up query: "chest, no equipment" hamstring curl Romanian deadlift Similar meaning → close together. Good for text queries. CLIP · clip-vit-base-patch32 text ↔ image "a person doing a push-up" "a person doing a deadlift" text query: no image to anchor it Image close to its own caption. Text-to-text is a side effect.
Sentence embedder
0.356
CLIP (text side)
0.033

Recall@10 on text queries: about 10× apart.

Pick the embedder for the query, not the data. My users type text, so a text model wins.

Normalize the vectors and cosine, dot product and Euclidean distance give the same ranking.

04 · Retrieval

Keyword search still matters

Dense search barely beat BM25: short queries like "hamstrings" or "kettlebell" are keyword search's home turf. Combining both with Reciprocal Rank Fusion beat either one.

BM25

  1. Bodyweight squat #1
  2. Walking lunge #2
  3. Step-up #3

Dense

  1. Walking lunge #1
  2. Glute bridge #2
  3. Bodyweight squat #3

Fused (RRF, k = 60)

  1. Walking lunge 0.0325
  2. Bodyweight squat 0.0323
  3. Glute bridge 0.0161
  4. Step-up 0.0159

score(doc) = Σ 1 / (60 + rank) · illustrative example

SystemRecall@10nDCG@10MRRMAP@10
BM250.3480.6140.5280.274
Dense (Sentence-Transformers)0.3560.6650.6200.317
Dense (CLIP text)0.0330.0800.0510.016
Hybrid RRF (BM25 + Sentence)0.4080.7070.6700.354
Hybrid RRF (BM25 + CLIP)0.2410.5470.5080.153

Fuse ranks, not scores (BM25 and cosine use different scales), and fuse from a top-20 pool before cutting to 10.

Fine-tuning

Off-the-shelf
0.356
Fine-tuned
0.813

A big jump on a templated eval set mostly means the model learned this dataset's phrasing. Real queries need real users.

05 · Experiment tracking

Tracking experiments with MLflow

  • Setup goes in log_param, results in log_metric, so runs line up in one sortable table.
  • Log retrieval metrics, not just loss. Loss going down says nothing about search quality.
  • Each run is one with mlflow.start_run(): block, and a local SQLite file is enough to start.

A tracking server only matters once other people need to see the runs.

06 · The vector database

Milvus Lite, and an index sweep that found nothing

Milvus Lite is the full Milvus engine in one local file, with the same API as a cluster. I also prototyped Lance, a versioned file format with no server at all.

Index sweep: p95 latency per index configuration Seven index configurations all had p95 latency between 0.33 and 0.44 milliseconds, and all returned the same top 10 as exact search. 0.30 ms 0.35 ms 0.40 ms 0.45 ms HNSW starved HNSW M=32 IVF nlist=16 IVF starved FLAT (exact) IVF nlist=64 HNSW M=16 P95 LATENCY · RECALL VS. FLAT = 1.000 FOR ALL SEVEN

With 873 vectors, exact search is already instant. Measure before reaching for HNSW.

07 · At scale

What would break with a million exercises

Nothing here is hard at 873 rows, so I sketched the scaled version using the System Design Primer.

From one laptop to a scaled deployment Today everything runs on one laptop: Gradio, the inference pipeline, a Milvus Lite file and Ollama. At scale, clients go through a load balancer to several API replicas, which use a cache, a sharded and replicated vector database, GPU LLM serving, and an offline re-embedding job. TODAY · ONE LAPTOP Gradio app InferencePipeline Milvus Lite file Ollama, 7B on CPU/GPU AT SCALE Clients Load balancer API replica API replica API replica Cache · query → results Vector DB shard 1 · shard 2 · replicas LLM serving on GPUs Offline re-embed job 1 2 3 4 5 6
  1. Exact search stops being freeMillions of vectors need an ANN index, and recall becomes a real trade-off.
  2. Shards fan outEvery query hits every shard; the slowest one sets the latency.
  3. New model, re-embed everythingA batch job over the whole corpus, then a switch-over without downtime.
  4. Cache repeat queriesKey on hash(query + model + top_k); clear it when the index changes.
  5. One file, one point of failureAt scale: replicas, backups, and metadata in a replicated database.
  6. The LLM is the slow partMany users means GPU serving and batching; search is the cheap step.
08 · Next

Where it goes from here

  • A cross-encoder reranker over the hybrid top-k.
  • Search as a tool the LLM calls, the first step to agentic retrieval.
  • Real benchmarks: BEIR and HotpotQA.

Resources

Code, eval harness and notes on GitHub