Skip to main content
How to Choose an Embedding Model for RAG and Semantic Search
Back to Blog

How to Choose an Embedding Model for RAG and Semantic Search

The embedding model sets the ceiling for your retrieval quality and is expensive to change later. How to read benchmarks like MTEB, evaluate models on your own data, and handle dimensions, formatting, cost and re-embedding.

LuminaryEra Editorial
November 21, 202614 min read14 views

The short answer: Choose an embedding model by testing a short list on your own data, not by its leaderboard rank. Shortlist models that support your languages and document lengths, fit your hosting and privacy needs, and have reasonable cost and dimensions; then measure retrieval quality (recall@k) on a few dozen real queries with known answers. Follow each model's instructions for query and document formatting, keep the model name and version next to every vector, and plan for re-embedding, because vectors from different models can't be mixed.

Every retrieval system has a decision buried in its first few lines of code: which model turns text into vectors. Teams often make it in about thirty seconds. Someone copies the model name from a tutorial, the demo works, and the choice quietly becomes permanent, because by the time anyone questions it there are millions of vectors in the index and changing models means re-embedding all of them.

That choice matters more than most. The embedding model decides what "similar" means for your whole system. If it doesn't understand your domain's vocabulary, can't handle your users' languages, or truncates your documents, no amount of prompt engineering downstream will fix the results. A better model at the start can be worth more than weeks of tuning everything else.

This guide explains what actually differs between embedding models, how to read benchmarks without being misled, how to run a quick evaluation on your own data, and the practical issues (dimensions, cost, query formatting, re-embedding) that decide whether a model works well in production. It's provider-neutral and applies whether you use a hosted API or run models yourself.

A quick refresher on embeddings

An embedding model reads a piece of text and outputs a fixed-length list of numbers, a vector, positioned so that texts with similar meaning end up close together. Retrieval works by embedding your documents once, embedding each query when it arrives, and finding the documents whose vectors are nearest to the query's.

Two consequences follow from that, and both shape how you choose:

  • The model defines similarity. Two texts are "close" only if this particular model was trained to place them close. Different models disagree, sometimes substantially, especially on specialised vocabulary.
  • Vectors are only comparable within one model. A vector from one model means nothing to another. Queries and documents must be embedded by the same model and version, and changing models means re-embedding everything.

The properties that separate models

Embedding models vary along a handful of dimensions that matter in practice.

PropertyWhy it matters
Retrieval quality on your kind of textThe whole point. Varies by domain, language and query style.
LanguagesMany models are English-first. Multilingual models can match a query in one language to a document in another.
Maximum input lengthText beyond the limit is usually truncated silently, so long chunks lose their endings.
Vector dimensionsAffects storage, memory, index limits and search speed.
Cost and latencyEvery document is embedded at least once, and every query adds a call on the user's critical path.
HostingHosted API, self-hosted open-weight model, or both. Matters for data privacy, residency and offline use.
Licence and stabilityCan you use it commercially? Will the provider keep this exact version available?

Notice that "highest benchmark score" isn't on the list on its own. It's an input to the first row, not a substitute for it.

Reading benchmarks without being misled

The most widely used benchmark for embedding models is MTEB, the Massive Text Embedding Benchmark (Muennighoff et al., 2022), along with its public leaderboard. The original paper covered 8 task types across 58 datasets and 112 languages, and one of its main findings is worth remembering: no single embedding method dominated across all tasks.

That finding is the right way to read any leaderboard. A model's average score blends many tasks, including clustering, classification and semantic similarity, that may have nothing to do with your use case. A few habits help:

  • Look at the retrieval columns, not the overall average, if you're building search or RAG.
  • Look for datasets that resemble yours: code, legal text, medical text, multilingual questions, short queries against long documents.
  • Treat small differences as noise. A one-point gap on an average rarely predicts which model will be better on your data.
  • Be wary of very recent top scores. Public benchmarks can leak into training data, which inflates scores without improving real-world performance.

Use the leaderboard to build a shortlist of three to five candidates. Then let your own evaluation decide.

Evaluating on your own data in an afternoon

A useful embedding evaluation is smaller than most people expect. You need a few dozen real queries, each paired with the document or chunk that answers it. Then you measure how often each candidate model ranks the right answer near the top.

  1. Collect 50 to 100 real queries. Search logs, support tickets, questions users asked your chatbot. Include the hard ones: exact product names, error codes, vague questions, questions in other languages if you support them.
  2. Label the answer for each query. The chunk or document ID that answers it. One correct answer per query is enough to start.
  3. Embed your corpus with each candidate. Use the same chunking for all of them, so you're comparing models, not chunkers.
  4. Measure recall@k and MRR. Recall@5 asks: for what share of queries does a correct chunk appear in the top five? MRR (mean reciprocal rank) rewards finding it at position one rather than five.
  5. Look at the failures. The queries where a model misses tell you more than the averages do.
type Labelled = { query: string; answerIds: Set<string> };

export async function evaluateModel(
  queries: Labelled[],
  search: (query: string, k: number) => Promise<string[]>, // returns chunk IDs, best first
  k = 5,
) {
  let hits = 0;
  let reciprocalRanks = 0;
  for (const { query, answerIds } of queries) {
    const results = await search(query, 20);
    const rank = results.findIndex((id) => answerIds.has(id)) + 1; // 0 if not found
    if (rank > 0 && rank <= k) hits++;
    if (rank > 0) reciprocalRanks += 1 / rank;
  }
  return { recallAtK: hits / queries.length, mrr: reciprocalRanks / queries.length };
}

This is the same measurement described in the guide on why RAG chatbots give bad answers, and once you have the labelled queries, they double as a regression test for future changes. The broader guide on testing LLM features with evals covers how to keep a dataset like this useful over time.

Diagram of an embedding model evaluation: real labelled queries and your corpus feed three candidate models; each is scored on recall at 5, MRR, cost and latency, and the best trade-off on your own data is chosen rather than the leaderboard leader

An illustrative comparison

To make the process concrete, here's how an evaluation typically plays out. Imagine a support knowledge base of a few thousand articles, with 80 real customer questions labelled with the article that answers each one, and three shortlisted models: a hosted general-purpose model, a hosted multilingual model, and a smaller open-weight model the team could run itself. These numbers are illustrative, not benchmarks of any particular product.

CandidateRecall@5MRRNotes from the failures
Hosted general model0.840.71Missed questions in Spanish and German
Hosted multilingual model0.860.72Handled other languages; slightly weaker on product codes
Small open-weight model0.790.66Most misses on long, multi-topic articles

The averages alone suggest the first two are nearly tied. The failures tell the real story: if a fifth of your customers write in other languages, the multilingual model is the clear choice, and its weakness on product codes is exactly what adding keyword search fixes. If every user writes in English and data must stay in-house, the open-weight model may be good enough once long articles are split into smaller chunks, and a re-run after rechunking would show whether that closes the gap.

That's the general lesson: read the failures, not just the scores. Two models with similar averages can fail on completely different queries, and only one of those failure patterns might matter for your users.

Code, tables and other awkward content

Most embedding models are trained mainly on natural-language prose, so content that isn't prose deserves extra testing.

  • Source code. General text models often handle code passably, but code-specific embedding models can do noticeably better at matching a natural-language question to the function that answers it. If code search matters, include code queries in your evaluation set.
  • Tables and structured data. A table flattened into a string of cells often embeds poorly. Converting each row into a short sentence, or embedding a natural-language description of the table alongside it, usually retrieves better.
  • Very short text. Titles, tags and product names carry little context. Embedding them together with a description or their parent document's title helps.
  • Mixed content. Pages that combine prose, code and tables are often best split by type, so each chunk is one kind of content.

For images, audio and other non-text content, multimodal embedding models exist that place text and images in the same vector space. They're a separate evaluation, but the same method applies: real queries, known answers, measured recall.

Query and document formatting: the detail that quietly costs accuracy

Many embedding models expect queries and documents to be formatted differently, because searching is asymmetric: a short question is matched against a long passage. Some model families ask you to prefix inputs with markers such as "query: " and "passage: ". Others take a task description or an input-type parameter in the API call, such as marking an input as a search query or a document. A few expect nothing special at all.

Ignoring these instructions doesn't produce errors. It just quietly lowers retrieval quality, sometimes noticeably. Before evaluating a model, read its documentation or model card and follow its formatting exactly, for both indexing and querying. And make sure your evaluation uses the same formatting your production code will, or the comparison is meaningless.

Dimensions, storage and the Matryoshka trick

Embedding vectors commonly have from a few hundred to a few thousand dimensions. More dimensions can capture more nuance, but they cost storage, memory and search time, and some infrastructure has hard limits. For example, PostgreSQL's pgvector extension can store vectors with up to 16,000 dimensions but can only build its approximate indexes on vectors of up to 2,000 dimensions (or 4,000 with half precision), as explained in the guide to vector search with pgvector.

Some newer models make this trade-off adjustable. They're trained with a technique called Matryoshka Representation Learning (Kusupati et al., 2022), which arranges information so that the first part of the vector carries the most important features. You can keep only the first 256 or 512 dimensions and still get a useful embedding, much like nested Russian dolls. Some embedding APIs expose this directly through a parameter that requests shorter vectors.

That gives you a practical lever: store shorter vectors to cut storage and speed up search, then measure how much recall you lose. Often it's very little, and occasionally it's more than you'd like, which is exactly why you measure. Note that truncated vectors generally need re-normalising to unit length before you use cosine similarity or inner product.

Input length and chunking

Every embedding model has a maximum input length, measured in tokens. Text beyond it is usually cut off without warning, which means the end of a long chunk simply doesn't count. If your chunks regularly exceed a model's limit, either chunk smaller or choose a model with a longer limit.

Longer limits aren't automatically better, though. A single vector has to summarise everything in its input, so a chunk covering five topics ends up matching none of them strongly. Most retrieval systems still work best with focused chunks of a few hundred tokens that carry their own context, such as the document title and section heading. A long input limit is most useful as headroom, so chunks that are a bit long don't get truncated.

Multilingual and domain-specific needs

If your users search in more than one language, or your documents are in a different language from the queries, test multilingual models specifically, with queries in each language you support. English-first models can perform poorly on other languages even when they produce vectors without complaint.

Specialised domains (code, law, medicine, finance, scientific literature) are where general-purpose rankings are least reliable. Some providers offer domain-tuned embedding models, and open-weight models can be fine-tuned on pairs of queries and relevant documents from your own data. Fine-tuning an embedding model is a bigger investment than picking one off the shelf, so do it only after your evaluation shows that general models fall short. The reasoning is similar to the decision process in the guide on fine-tuning versus RAG versus prompting.

Hosted API or self-hosted model

Both options are reasonable, and the right answer depends on your constraints.

Hosted APIs are the fastest way to start: no infrastructure, good quality, and pricing per token that's usually modest for embeddings. The trade-offs are that your text leaves your systems, you depend on the provider keeping the model version available, and every query adds a network round trip.

Self-hosted open-weight models keep data in-house, can run offline, have no per-call fees, and can be fine-tuned. The trade-offs are operational: you run the inference servers, size the hardware, and handle scaling. Many open embedding models are small enough to run efficiently on modest GPUs or even CPUs, which makes this more practical than self-hosting a large chat model.

A hybrid is common too: a hosted model in the early stages, moving to a self-hosted one once volumes or privacy requirements justify it, with an evaluation set ready to confirm the new model performs at least as well.

Plan for re-embedding from day one

Whichever model you pick, you'll probably change it eventually. Better models appear regularly, providers retire old versions, and your needs change. Because vectors from different models can't be compared, switching means re-embedding the whole corpus. Make that routine rather than a crisis:

  • Store the model name and version alongside every vector.
  • Keep the source text (or a way to regenerate it) for everything you've embedded.
  • Migrate in parallel. Fill a new vector column or index in the background, evaluate it against the old one with your labelled queries, then switch queries over in one step.
  • Re-embed queries with the same model. A common bug after a migration is embedding new documents with the new model while queries still use the old one, which quietly breaks search.
  • Budget for it. Re-embedding millions of chunks has a real cost in API fees or compute time. Batch APIs, where available, reduce it.

Embeddings are only one part of retrieval quality

It's worth keeping the choice in proportion. Even the best embedding model struggles with exact identifiers like error codes and SKUs, which is why combining vector search with keyword search (hybrid search) helps almost every system. A reranking step, which re-scores the top candidates with a more precise model, often improves results more than switching embedding models would. Good chunking and clean, deduplicated content matter at least as much as the model.

So when retrieval quality disappoints, don't reach for a new embedding model first. Check chunking, try hybrid search and a reranker, and look at what's actually being retrieved. If your evaluation then shows the embedding model is the bottleneck, change it with confidence.

Cost and latency in practice

Embedding costs have two very different shapes. Indexing is a one-time bulk cost (plus updates), paid when you embed your corpus, and it scales with the total size of your documents. Querying is a small cost per search, but it sits on the user's critical path, so latency matters more than price.

For indexing, batch requests wherever the API allows it, and use a provider's batch or asynchronous endpoint if one exists for large backfills. Skip unchanged content by storing a hash of each chunk's text and only re-embedding chunks whose hash changed. For queries, the network round trip to a hosted API is often the largest part of the latency, so a nearby region, connection reuse and caching embeddings for frequent queries all help. Caching works well for search boxes, where many users type the same popular queries.

When comparing candidates, estimate the full monthly cost: corpus size times re-embedding frequency, plus queries per month, plus storage for the vectors at the dimension you plan to keep. A model that's slightly cheaper per token but produces vectors twice as large can end up more expensive once storage and memory for the index are counted.

A selection checklist

  • ☐ Shortlist three to five models using the retrieval part of benchmarks, plus your language and domain needs
  • ☐ Check input length limits against your chunk sizes
  • ☐ Check dimensions against your storage and index limits
  • ☐ Confirm licence, hosting, privacy and data residency requirements
  • ☐ Follow each model's query and document formatting instructions exactly
  • ☐ Evaluate recall@k and MRR on 50 to 100 real labelled queries
  • ☐ Compare cost and query latency, not just quality
  • ☐ Store the model name and version with every vector
  • ☐ Keep source text so you can re-embed when you change models

Frequently asked questions

How do I choose the best embedding model for RAG?

Shortlist a few models that support your languages, document lengths, hosting needs and budget, using the retrieval sections of benchmarks such as MTEB as a starting point. Then embed your own documents with each and measure recall@k on 50 to 100 real queries with known answers. Pick the model with the best trade-off of quality, cost and latency on your data.

Is the top model on the MTEB leaderboard the best choice?

Not necessarily. Overall leaderboard scores average many tasks that may not matter for your use case, small differences are often noise, and benchmark data can leak into training. Use the leaderboard to shortlist candidates and decide with an evaluation on your own data.

Do more embedding dimensions mean better results?

Not always. More dimensions can capture more detail but cost more storage, memory and search time, and some vector indexes limit dimensions. Models trained with Matryoshka Representation Learning can be shortened with limited quality loss, so measure recall at smaller sizes before assuming you need the full vector.

Can I mix embeddings from different models?

No. Vectors from different models, or different versions of the same model, are not comparable. Queries and documents must be embedded with the same model and version, and switching models means re-embedding your whole corpus.

Should I self-host an embedding model or use an API?

Hosted APIs are the quickest way to start and need no infrastructure. Self-hosting open-weight models keeps data in-house, removes per-call fees and allows fine-tuning, at the cost of running inference servers. Many embedding models are small enough to self-host affordably once volume or privacy requirements justify it.

The takeaway

The embedding model sets the ceiling for everything your retrieval system does, and it's expensive to change once your index is full. Spend an afternoon choosing it properly: shortlist from benchmarks, evaluate on your own queries, follow each model's formatting rules, and keep what you need to re-embed later. That small investment up front saves a lot of guessing when search quality is questioned months from now.

Share this article
LuminaryEra Editorial
Editorial

Author at LuminaryEra

The LuminaryEra editorial desk publishes long-form, hands-on guides on AI-assisted development, large language models, developer tools and web engineering. Articles are researched and drafted with the help of AI tools, link to their sources, and are corrected when readers report errors.

View all articles