Search Tutorials
--Ads--Choosing an Embedding Model
Proprietary vs open-source models and how to read the MTEB leaderboard.
The embedding model decides what "similar" means in your RAG system. A model that does not understand your domain or language will retrieve the wrong chunks however well everything else is tuned. This lesson explains how to choose one: what to look for, the main options, and how to test candidates on your own data.
Selection criteria
| Criterion | Question to ask |
|---|---|
| Retrieval quality | How well does it rank relevant passages for queries like mine? |
| Languages | Does it support every language in my documents and queries? |
| Maximum input length | Does it accept my chunk size (512, 8,192 or 32,000 tokens)? |
| Dimensions | How large are the vectors? This drives storage cost and search speed. |
| Speed and cost | How long and how much to embed my whole collection, and each query? |
| Hosting and privacy | Can documents be sent to an API, or must everything run on my servers? |
| Licence | Is commercial use allowed? |
Reading the MTEB leaderboard
The Massive Text Embedding Benchmark (MTEB), hosted on Hugging Face, scores embedding models on many tasks and languages. Use it as a shortlist, not as a final answer:
- Look at the Retrieval column, not the overall average. Overall scores include clustering, classification and other tasks that do not matter for RAG.
- Filter by language and model size. A 7-billion-parameter model may top the chart but be too slow or expensive for you.
- Be sceptical of small differences. A one-point gap rarely shows up on real data, and some models are trained on data similar to the benchmark.
- Check the max tokens and dimensions columns against your design.
The main options
Open-source models (run locally)
Popular families include BAAI's BGE (bge-small, bge-base, bge-large, bge-m3), Microsoft's E5, Alibaba's GTE and Qwen3-Embedding, Nomic Embed, Jina Embeddings and Snowflake's Arctic Embed. They are free, keep data on your machines and can be fine-tuned. Small models (around 30 to 130 million parameters) run fast on a CPU; large ones need a GPU.
Hosted embedding APIs
Providers such as Voyage AI, OpenAI, Cohere and Google offer embedding APIs with strong quality, long inputs and no infrastructure to run. You pay per token and your text leaves your network. Anthropic does not offer its own embedding model and recommends Voyage AI, whose model family includes domain-specific variants for code, finance and law.
Using different models in code
With sentence-transformers, switching between open-source models is one line. Pay attention to each model's prompt or prefix conventions; using the wrong one quietly lowers quality.
from sentence_transformers import SentenceTransformer
# BGE v1.5: instruction prefix on queries only
bge = SentenceTransformer("BAAI/bge-base-en-v1.5")
q = bge.encode("Represent this sentence for searching relevant passages: what is RAG?",
normalize_embeddings=True)
# E5: "query: " and "passage: " prefixes on both sides
e5 = SentenceTransformer("intfloat/e5-base-v2")
q = e5.encode("query: what is RAG?", normalize_embeddings=True)
d = e5.encode("passage: Retrieval-augmented generation combines search with an LLM.",
normalize_embeddings=True)
# Nomic: task prefixes; needs trust_remote_code
nomic = SentenceTransformer("nomic-ai/nomic-embed-text-v1.5", trust_remote_code=True)
q = nomic.encode("search_query: what is RAG?", normalize_embeddings=True)
d = nomic.encode("search_document: Retrieval-augmented generation ...", normalize_embeddings=True)
print(bge.get_sentence_embedding_dimension(), bge.max_seq_length)
Hosted APIs follow the same pattern: an "input type" tells the model whether it is embedding a query or a document. With Voyage AI:
# pip install voyageai ; set VOYAGE_API_KEY
import voyageai
vo = voyageai.Client()
docs = vo.embed(["Employees get 18 days of paid leave."],
model="voyage-3.5", input_type="document").embeddings
query = vo.embed(["How many vacation days do I get?"],
model="voyage-3.5", input_type="query").embeddings[0]
Model names change as providers release new versions; check the provider's documentation for the current list.
Test candidates on your own data
The only benchmark that really matters is your documents and your users' questions. Reuse the retrieval harness from Evaluating Chunking Strategies, with the chunking fixed and the model varied:
import numpy as np
from sentence_transformers import SentenceTransformer
CANDIDATES = {
"bge-small": ("BAAI/bge-small-en-v1.5", "Represent this sentence for searching relevant passages: ", ""),
"bge-base": ("BAAI/bge-base-en-v1.5", "Represent this sentence for searching relevant passages: ", ""),
"e5-base": ("intfloat/e5-base-v2", "query: ", "passage: "),
}
def compare_models(chunks: list[str], test_set: list[dict], k: int = 5) -> None:
for name, (model_id, q_prefix, d_prefix) in CANDIDATES.items():
model = SentenceTransformer(model_id)
doc_vecs = model.encode([d_prefix + c for c in chunks], normalize_embeddings=True, batch_size=64)
q_vecs = model.encode([q_prefix + t["question"] for t in test_set], normalize_embeddings=True)
hits = 0
for t, q in zip(test_set, q_vecs):
top = np.argsort(-(doc_vecs @ q))[:k]
hits += any(t["evidence"].lower() in chunks[i].lower() for i in top)
print(f"{name:10} hit@{k} = {hits / len(test_set):.2f}")
Start with a small, fast open-source model such as bge-small-en-v1.5 while you build the pipeline. Once you have an evaluation set, test two or three stronger models (open-source and hosted) and switch only if the gain is worth the cost. Remember that switching models means re-embedding everything.
Key takeaways
- Judge models on retrieval quality for your languages and domain, plus length limits, size, cost, privacy and licence.
- Use the MTEB Retrieval column to build a shortlist, not to make the final decision.
- Follow each model's query and document prefix conventions.
- Pick the final model with a retrieval test on your own data.