Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Modal 11 min read Research mediumAdept

Beating proprietary models with a quick fine-tune

Fine-tuning an open-source embedding model on a few hundred labeled pairs can beat OpenAI's text-embedding-3-small on duplicate-question detection, at lower cost. A grid search on the Quora duplicates dataset covered three base models (bge-base-en-v1.5, all-mpnet-base-v2, jina-embeddings-v2-small-en), dataset sizes from 100 to ~100k examples, and 256 vs 512 output dimensions, with each run on its own GPU in parallel via Modal's map. bge-base passed the baseline by 200 examples and kept improving, reaching about 13% error versus 17%. mpnet plateaued early, jina never beat the baseline, and the larger dimension gave no accuracy gain, so 256 dimensions is the cheaper choice.

Assumes: text embeddingsfine-tuning basicshyperparameters

Related posts

  • Build a Domain-Specific Embedding Model in Under a Day

    Hugging Face mediumAdept

    A single-GPU pipeline fine-tunes Llama-Nemotron-Embed-1B-v2 for a specific domain in under a day without manual labels. An LLM generates synthetic single- and multi-hop QA pairs from raw documents, which are quality-filtered. The base model then mines hard negatives, using a 95% margin ceiling to avoid false negatives. Training is a contrastive biencoder run at temperature 0.02, followed by BEIR evaluation, ONNX/TensorRT export and serving through NIM. On NVIDIA docs this gave about 10% gains in NDCG@10 and Recall@10, and Atlassian raised Jira Recall@60 from 0.751 to 0.951. The guide also covers practical defaults: 1–2 epochs for real data, LR 1e-5, and 1 positive plus 4 hard negatives per query.

  • Embedding English Wikipedia in under 15 minutes

    Modal mediumAdept

    Embedding all of English Wikipedia with the open-source BAAI/bge-small-en-v1.5 model takes about 15 minutes and just over $15 when Hugging Face's Text Embeddings Inference server runs across many parallel GPUs on Modal. The walkthrough covers Modal Functions, Volumes, and class lifecycle hooks (@enter/@exit). It also shows code for downloading the dataset to a persistent volume, launching the TEI server inside an A10G container, and chunking text into fixed-size pieces. Batched async requests are fanned out with .map. Fast regeneration of embeddings is pitched as the enabler for frequent fine-tuning of open-source embedding models instead of relying on rate-limited closed APIs.

  • Welcome EmbeddingGemma, Google's new efficient embedding model

    Hugging Face mediumAdept

    EmbeddingGemma is Google's 308M-parameter multilingual text embedding model. It is built on a Gemma3 backbone modified to use bidirectional attention, with mean pooling and two dense layers producing 768-dimensional vectors. It supports a 2K-token context and over 100 languages, runs in under 200 MB of RAM when quantized, and ranks highest among text-only multilingual models under 500M parameters on MMTEB. Because it was trained with Matryoshka Representation Learning, embeddings can be truncated to 512, 256 or 128 dimensions, and inputs need task-specific prompts such as "task: search result | query: " to get correct results. Code examples cover Sentence Transformers, LangChain, LlamaIndex, Haystack, txtai, Transformers.js, TEI and ONNX, plus a finetuning walkthrough on the MIRIAD medical dataset whose resulting model outperforms models twice its size on that task.

  • Mistral 7B and BAAI on Workers AI vs. OpenAI Models for RAG

    Neon mediumAdept

    Swapping gpt-3.5-turbo for mistral-7b-instruct-v0.1 and text-embedding-ada-002 for BAAI's bge-base-en-v1.5 (both on Cloudflare Workers AI) in Neon's docs chatbot shows embeddings are close to interchangeable but text generation is not. Across eight Postgres questions, the two embedding models returned the same retrieved chunks 46% of the time at k=3 (42% at k=10), with Jaccard and TF-IDF cosine scores indicating substantial context overlap. Expert raters scored GPT-3.5 answers 3.8/5 versus 2.5/5 for Mistral 7B. Migrating embeddings to BGE looks viable and can cut vector storage, while replacing the generation model would noticeably hurt answer quality.

  • Matryoshka embeddings: faster OpenAI vector search using Adaptive Retrieval

    Supabase mediumAdept

    OpenAI's text-embedding-3 models are trained with Matryoshka Representation Learning, so an embedding can be shortened by truncating trailing dimensions and renormalizing, which reproduces the API's `dimensions` output. Adaptive Retrieval exploits this with a two-pass search: a fast HNSW-indexed ANN pass on a low-dimensional prefix fetches an oversized shortlist, then exact KNN on the full 3072d vectors re-ranks it. Benchmarks on 1M dbpedia embeddings found a 512d first pass (ef_construction=400, m=32, ef_search=200, limit = top_k × 8) reached 99% accuracy against 3072d KNN at about 580 QPS. By comparison, a single pass on 1536d vectors topped out near 89%. The post finishes with a Postgres/pgvector implementation using a sub_vector SQL function.

The quest for software engineering knowledge.

Look:
Layout: