refusal rate
Subscribe

The best embedding model for code you can run locally, compared on MTEB Code scores, size, context, licence and Ollama tags. Picks for laptops, GPUs and teams.

[ fig. 01 — comparison ]48×5
[ fig. 01 — comparison ]16×5

Short answer

The best open-weight embedding model for code search is Qwen3-Embedding: the 8B scores 80.69 on the MTEB Code leaderboard and the 4B scores 80.07 at half the memory, both Apache 2.0 and in Ollama. On a laptop, Google's EmbeddingGemma 2 reports 78.68 from a 270M text backbone. C2LLM-7B tops the leaderboard at 80.75 but needs a Transformers stack.

Top open score
80.75 (C2LLM-7B)
Best value
Qwen3-Embedding-4B, 80.07
Laptop pick
EmbeddingGemma 2, 78.68
Benchmark
MTEB (Code, v1), NDCG@10

Key takeaways

  1. Qwen3-Embedding-4B scores 80.07 on MTEB Code, within 0.7 points of the 8B and the 7B leader, at 2.5 GB in Ollama's Q4_K_M tag.
  2. EmbeddingGemma 2 reports 78.68 on MTEB Code from a 270M text backbone, up from 68.76 for the first EmbeddingGemma.
  3. jina-code-embeddings scores well (78.7 to 78.9) but ships under CC BY-NC 4.0, which rules out commercial use without a separate licence.
  4. Benchmarks flatter long natural-language queries: a 2026 benchmark found short keyword queries push nearly every model to near-zero NDCG@10.
  5. Developers who benchmarked their own task found leaderboard rank did not carry over, so test two or three models on your own repo.

Which embedding model should you use for code?

The best embedding model for code depends on your hardware more than on the leaderboard, because the top open models sit within about one point of each other. Every score below is the MTEB (Code, v1) average, NDCG@10, taken from the leaderboard snapshot in the C2LLM technical report (December 25, 2025) or from the model maker’s own card where the model is newer than that snapshot. Fetched on October 28, 2026.

  • GPU with 8 GB or more: qwen3-embedding:4b. It scores 80.07, Apache 2.0, 2.5 GB at Q4_K_M in Ollama, 32K context per the model card.
  • Biggest GPU, best quality in Ollama: qwen3-embedding:8b. It scores 80.69, 4.7 GB at Q4_K_M. That is 0.6 points over the 4B for roughly twice the memory and compute.
  • Laptop or CPU-only: embeddinggemma-2. It reports 78.68 from a 270M text backbone, with 768 dimensions and an 8,192-token window. It is very new, so community reports are thin.
  • Highest score, Python stack: C2LLM-7B, at 80.75. It is Apache 2.0 but not in Ollama, and it was trained at a 1,024-token maximum sequence length.
  • Avoid for commercial products: jina-code-embeddings. The scores are strong, but the licence is CC BY-NC 4.0.

If you are choosing a model for a full retrieval pipeline, the chunking, the hybrid keyword search and the reranker matter as much as this choice. That build is covered in local RAG for your codebase.

How are code embedding models benchmarked?

Code embedding models are mostly compared on MTEB (Code, v1), a 12-task slice of the Massive Text Embedding Benchmark scored with NDCG@10. The tasks mix natural-language-to-code search (CodeSearchNet, CosQA, StackOverflowQA, Synthetic-Text2SQL), code-to-code retrieval (CodeTransOcean, CodeSearchNet-CC) and code-with-feedback tasks (CodeFeedback, CodeEdit). The CoIR suite contributes one of those tasks. You can see the full per-task breakdown in the C2LLM report’s leaderboard table.

Three caveats should change how you read the numbers:

  1. Self-reported versus leaderboard numbers drift. Qwen’s paper lists Qwen3-Embedding-0.6B at 75.41. Jina’s paper evaluates the same model at 74.69. A gap under one point between two models is therefore not a real ranking.
  2. Real queries are shorter than benchmark queries. The 2026 CoREB benchmark rewrote LiveCodeBench problems to limit training-data contamination and tested eleven embedding models. Short keyword queries, the format closest to how developers actually search, drove nearly every model to near-zero NDCG@10. No single model won all three of its tasks.
  3. Code-to-code is where specialization pays. The same paper found code-specialized models scored roughly twice as well as general encoders on code-to-code retrieval, such as finding the Go port of a Python function. For questions in English, general models closed most of the gap.

How do the main open models compare?

The open-weight field splits into three groups: large LLM-based embedders (7B to 8B), mid-size models around 1B to 4B, and small encoders under 1B that run on a CPU.

ModelParamsDimsContextMTEB CodeLicenceIn Ollama
C2LLM-7B7Bnot statedtrained at 1,02480.75 (LB)Apache 2.0No
Qwen3-Embedding-8B8B4,096 (MRL 32–4,096)32K80.69 (LB)Apache 2.0qwen3-embedding:8b
Qwen3-Embedding-4B4B2,56032K80.07 (LB)Apache 2.0qwen3-embedding:4b
jina-code-embeddings-1.5b1.5B1,536 (MRL to 128)32,76878.94 (self)CC BY-NC 4.0No official tag
jina-code-embeddings-0.5b0.5B896 (MRL to 64)32,76878.72 (self)CC BY-NC 4.0No official tag
EmbeddingGemma 2270M text (740M all modalities)768 (MRL to 128)8,19278.68 (self)Apache 2.0embeddinggemma-2
C2LLM-0.5B0.5Bnot statedtrained at 1,02475.46 (LB)see cardNo
Qwen3-Embedding-0.6B0.6B1,02432K75.42 (LB)Apache 2.0qwen3-embedding:0.6b
Nomic Embed Code7B3,58432,768not on MTEB CodeApache 2.0No
CodeRankEmbed137Mnot stated8,192CoIR 60.1MITNo

LB means the score comes from the MTEB leaderboard snapshot dated December 25, 2025, in the C2LLM report. Self means the model maker’s paper or card reported it. Sizes, dimensions and context come from each model card on Hugging Face, and Ollama tags come from the Ollama embedding library, all fetched October 28, 2026. Nomic Embed Code reports CodeSearchNet results instead, from 72.3 on PHP to 93.8 on Go, so it can’t be placed on the same axis.

[ fig. 01 — MTEB (Code, v1) averages. Sources: C2LLM report leaderboard snapshot 2025-12-25; Jina arXiv 2508.21290; EmbeddingGemma 2 model card ]
Dot chart: on MTEB Code, C2LLM-7B scores 80.75 and Qwen3-Embedding-8B 80.69, Qwen3-Embedding-4B 80.07, the two jina-code models and EmbeddingGemma 2 about 78.7, C2LLM-0.5B and Qwen3-Embedding-0.6B about 75.4, and the first EmbeddingGemma 68.76.

The chart makes the practical point: going from 4B to 8B buys 0.6 points, while going from the first EmbeddingGemma to the second bought 10. Model generation matters more than model size right now.

Which run in Ollama, LM Studio or llama.cpp?

Only Qwen3-Embedding and EmbeddingGemma 2 among the top scorers have official Ollama tags. The older defaults, nomic-embed-text (93.9M pulls), mxbai-embed-large and bge-m3, are still the most downloaded embedding models in the library. None of them has a published MTEB Code average in the sources above.

bash
ollama pull qwen3-embedding:4b
curl http://localhost:11434/api/embed -d '{"model":"qwen3-embedding:4b","input":["def parse_config(path):"]}'

Ollama also serves embeddings on its OpenAI-compatible /v1/embeddings route, which is what most editor plugins and agent tools expect. The setup is in Ollama’s OpenAI-compatible API. The editor side, pointing Continue or a similar extension at that endpoint, is in local LLM VS Code setup.

Three details catch people out:

  • Context in Ollama is not context on the card. Ollama lists nomic-embed-text with a 2K window, and EmbeddingGemma 2 at 256K in its tags while the model card says 8,192. Chunk to the model card’s figure, not the tag page’s.
  • Prefixes are mandatory for most code models. EmbeddingGemma 2 expects task: code retrieval | query: ... for queries and title: <filename> | text: <code> for documents. CodeRankEmbed and Nomic Embed Code need Represent this query for searching relevant code: . jina-code uses separate query and passage prompts. Skipping them can silently drop retrieval quality.
  • Matryoshka truncation is cheap. Qwen3-Embedding-8B accepts output sizes from 32 to 4,096, and EmbeddingGemma 2 loses about 1.4 points going from 768 to 512 dimensions (78.68 to 77.24). Smaller vectors make the index cheaper to store and search.

C2LLM, jina-code-embeddings and Nomic Embed Code run through sentence-transformers or Transformers in Python. Some have community GGUF conversions on Hugging Face, but none of them has an official Ollama tag.

Do you need a code-specific model or is a general one enough?

For natural-language questions about a codebase, a strong general model is enough. Qwen3-Embedding is a general multilingual model, and it scores within 0.1 points of the code-specialized C2LLM-7B. That also makes it the safer pick for a multilingual repo, with comments and docs in several human languages. Code-specific models earn their place on code-to-code retrieval, such as finding duplicates, ports or similar implementations, where CoREB measured roughly a 2x advantage.

Licence is the other filter. The two jina-code models are CC BY-NC 4.0, and C2LLM’s 7B card is Apache 2.0. If the index feeds a paid product, read the terms before you pick a model. See LLM licences and acceptable use, explained.

Your query mostly looks likePick
“Where do we validate JWTs?” (English to code)General or code model; Qwen3-Embedding-4B
A pasted function, “find similar” (code to code)Code-specialized model; test jina-code (non-commercial) or C2LLM
Exact identifiers, error stringsNot embeddings alone; pair with keyword or trigram search

What do developers report in practice?

Practitioner reports agree on one thing: the benchmark winner is often not the winner on your task, and indexing at all matters more than which model you index with.

  • Leaderboard rank didn’t transfer to duplication detection. One developer built an open benchmark of 19 duplicated and non-duplicated code pairs and published the results (HN, Aug 2026; write-up). Voyage’s code-specialized models ranked near the bottom, while jina-code-embeddings-0.5b ranked first, slightly ahead of the 1.5b. Cutting vectors to 256 dimensions made no measurable difference. It is a small hand-built test, but it shows the method: build twenty cases from your own code and run them.
  • A local code embedding index cut agent cost. The ory/lumen project indexes a repo through Ollama with a Jina code embedding model by default, and it publishes a with-versus-without comparison on real GitHub bug-fix tasks: 26% lower cost, 28% less time and 37% fewer output tokens on average (GitHub). Its author noted on HN that indexing is CPU-heavy and that results are noisy (HN, Sep 2026). These are the project’s own numbers, not an independent test.
  • CPU is enough for a small model. A developer running Roo Code’s codebase indexing against a local Qdrant and Ollama reported that nomic-embed-text was fast enough on CPU. After the first full embed, updates were close to real time, and the agent found code without flooding its context (HN).
  • Hybrid beats pure vectors for exact matches. A search tool described in an October 2026 HN thread pairs Qwen3-Embedding-0.6B vectors with an SQLite trigram full-text index specifically to catch exact identifiers (HN). Simon Willison’s quick trial of CodeRankEmbed over his own codebase’s functions returned relevant commands for a plain-English query, from a 521.60 MB model (blog, Mar 2025).

FAQ

What is the best Ollama embedding model for code?

Among official Ollama tags, qwen3-embedding:4b (80.07 on MTEB Code) is the best balance, and qwen3-embedding:8b (80.69) is the highest scorer. embeddinggemma-2 (78.68, self-reported) is the pick for CPU-only machines.

Is nomic-embed-text good for code?

It is fast, small (274 MB) and runs on a CPU, and developers report it works for agent codebase indexing. It has no published MTEB Code average in the sources we checked, and newer models such as EmbeddingGemma 2 publish much stronger code scores at a similar size.

What is the best open source embedding model for code?

On the MTEB Code leaderboard, C2LLM-7B (80.75) and Qwen3-Embedding-8B (80.69) are effectively tied at the top, and both are Apache 2.0. Qwen3-Embedding is easier to run locally because it has official Ollama tags.

How many dimensions do code embeddings need?

Fewer than the default, usually. EmbeddingGemma 2 loses 1.4 points going from 768 to 512 dimensions. One developer’s duplication benchmark found no measurable loss at 256. Start at 512 to 1,024 and measure on your own queries.

Should I use a reranker for code search?

Only after testing it. The CoREB benchmark found off-the-shelf rerankers swung by 12 points on code-to-code retrieval, and none of the five it tested improved all three tasks.

Sources (9)
  1. Qwen3 Embedding: Advancing Text Embedding and Reranking Through Foundation Models, arXiv 2506.05176 (Jun 2025)
  2. C2LLM Technical Report, MTEB-Code leaderboard snapshot of 2025-12-25, arXiv 2512.21332
  3. EmbeddingGemma 2 model card, Google DeepMind, Hugging Face (fetched 2026-10-28)
  4. Efficient Code Embeddings from Code Generation Models (jina-code-embeddings), arXiv 2508.21290 (Aug 2025)
  5. Beyond Retrieval: A Multitask Benchmark and Model for Code Search (CoREB), arXiv 2605.04615 (May 2026)
  6. Nomic Embed Code model card, Hugging Face
  7. Ollama embedding model library (fetched 2026-10-28)
  8. Embedding benchmark for code duplication, R. Kochanowski (Aug 20, 2026)
  9. ory/lumen: local semantic code search for coding agents, GitHub

Keep reading