Choosing an Embedding Model: Dimension, Context Length, Domain and Cost, Tested on Your Own Questions
Bigger is not always better. Four questions decide an embedding model: vector size, how many tokens it reads, your domain and the cost. Then a 12-question test on real help articles: all-MiniLM-L6-v2 puts the right article first 10 times out of 12 (MRR 0.896), the larger bge-small-en-v1.5 9 times (MRR 0.861).
What you will learn
- Name the four things that decide an embedding model: dimension, context length, domain and cost
- Estimate the storage a vector size needs for a million chunks
- Compare two local models on your own questions with top-1 hits and MRR
- Pick the smallest model that is good enough, and know the cost of switching later
Before you start
- What an Embedding Actually Is
- Basic Python and pip
There are many embedding models out there, and it's tempting to grab the biggest one on a leaderboard. Four things actually decide the choice: the vector size, how much text the model reads, your domain, and the cost. And bigger is not always better.
In this article we go through those four, then test two small local models on our own help-centre questions and let the numbers pick.
Picking a delivery vehicle
A shop delivers small parcels in a busy city. Which vehicle should it buy? A lorry has more capacity, but most parcels are small, so that space is wasted. Then there's range, how far it goes before it has to stop. Then the terrain: narrow city streets, not motorways. And the running cost, fuel and parking, every single day. So the cargo bike wins.
Choosing an embedding model is the same. Capacity is the dimension, range is the context length, terrain is your domain, and running cost is the cost.
Dimension: the size of each vector
Every chunk you store becomes one vector, and bigger vectors cost memory and search time. Stored as 4-byte floats:
| Dimension | Bytes per vector | 1 million chunks |
|---|---|---|
| 384 | about 1,500 | about 1.5 GB |
| 768 | about 3,000 | about 3 GB |
| 1,536 | about 6,000 | about 6 GB |
That's just the vectors. More numbers can hold more detail, but they are not automatically better. Both models we test today use 384.
Context length: how much it reads
Each model reads up to a fixed number of tokens, and the rest is simply cut off. Your search results won't warn you. all-MiniLM-L6-v2 reads 256 tokens per input; bge-small-en-v1.5 reads 512. A longer limit helps with long chunks, but you still split your documents into chunks: one vector can't hold a whole manual. (More on cutting in Chunking Strategies for RAG.)
Domain: your words, not the web's
These models learn from general text, but your customers write in their own words, with your product's jargon. A customer writes my money still has not come back to my card. The help article says Refund timing. Refunds go back to the original card 5 to 7 working days after the parcel is scanned by the carrier. Not many shared words, so the model has to understand the meaning. The only benchmark that really counts is your own questions against your own documents.
Cost: where it runs
| Local model | Hosted embedding API | |
|---|---|---|
| Fee per call | None, runs on your CPU or GPU | Per token, check the provider's pricing page |
| Setup | One-time download (our two: about 91 MB and 133 MB) | An API key |
| Your data | Stays on your machine | Text is sent to the provider |
The catch: switching models later means re-embedding every document, because vectors from two different models can't be mixed. Choose carefully the first time.
Our test: twelve questions
The project has 12 short help articles (data/help_docs.json) and 12 questions in customers' own words, each with the right article (data/queries.json). The question: does the right article come first? compare.py embeds every article and every question with each model, scores them all at once, and records where the right article lands (an excerpt of the function; the full file also records sizes and timings):
MODELS = {
"all-MiniLM-L6-v2": {"name": "sentence-transformers/all-MiniLM-L6-v2", "query_prefix": ""},
"bge-small-en-v1.5": {"name": "BAAI/bge-small-en-v1.5",
"query_prefix": "Represent this sentence for searching relevant passages: "},
}
def evaluate(short: str) -> dict:
cfg = MODELS[short]
model = SentenceTransformer(cfg["name"], device="cpu")
texts = [d["title"] + ". " + d["text"] for d in DOCS]
model.encode(texts[:2]) # warm-up
t0 = time.perf_counter()
doc_vecs = model.encode(texts, normalize_embeddings=True)
ms = (time.perf_counter() - t0) * 1000
q_vecs = model.encode([cfg["query_prefix"] + q["query"] for q in QUERIES], normalize_embeddings=True)
sims = q_vecs @ doc_vecs.T
rows, hits, rr = [], 0, 0.0
for q, row in zip(QUERIES, sims):
order = row.argsort()[::-1]
ranked = [DOCS[i]["id"] for i in order]
rank = ranked.index(q["answer"]) + 1
hits += rank == 1
rr += 1 / rank
...
Two details matter. The bge model expects a query prefix in front of questions (its instruction), and MiniLM doesn't. And rr += 1 / rank builds the MRR, mean reciprocal rank: 1 when the right article is always first, 0.5 when it's always second, and so on.
The results
python compare.py
| Model | Dims | Max tokens | Weights | Right article first | MRR |
|---|---|---|---|---|---|
| all-MiniLM-L6-v2 | 384 | 256 | 90.9 MB | 10 / 12 | 0.896 |
| bge-small-en-v1.5 | 384 | 512 | 133.5 MB | 9 / 12 | 0.861 |
The smaller model came out slightly ahead on this data. Embedding the 12 articles also took 767 ms for MiniLM against 2,195 ms for bge on the lecture machine (your timings will differ). On your data the order may flip, and that's exactly why you test.
The misses are worth reading, because they tell you what each model confuses:
| Question | Right article | MiniLM | bge-small |
|---|---|---|---|
| the headphones crackle and stopped working after a week | faulty | warranty first (rank 2) | first |
| can I send something back that I just don't like | returns | address first (rank 4) | faulty first (rank 3) |
| how fast will my package get here | shipping | first | returns first (rank 2) |
| what does the guarantee cover | warranty | first | faulty first (rank 2) |
Neither model is better everywhere. bge gets the broken-headphones question that MiniLM misses, and misses two that MiniLM gets.
How to choose
- Collect 20 to 50 real questions, each with the right document.
- Try two or three models. Start with small local ones.
- Measure how often the right document comes first, and the MRR.
- Pick the smallest model that is good enough, then check its input limit and its cost.
Good enough on your data, and cheap to run, beats bigger.
Common mistakes
- Choosing from a public leaderboard alone. General benchmarks don't use your customers' words or your documents.
- Forgetting the query prefix for models that expect one, such as bge. Without it the model is not used the way it was trained.
- Chunks longer than the model's limit. Text past 256 or 512 tokens is silently dropped and never searched.
- Mixing vectors from two models in one index. A new model means re-embedding everything.
- Testing on three questions. With so few, one lucky hit decides the winner. Use 20 or more.
Quick recap
| Question | What to check |
|---|---|
| Dimension | Storage and search time: 384 numbers is about 1.5 GB per million chunks |
| Context length | Max tokens: 256 for MiniLM, 512 for bge-small; the rest is cut |
| Domain | Your own questions against your own documents |
| Cost | Local download vs per-token API, and where your data goes |
| The test | Top-1 hits and MRR: 10/12 and 0.896 vs 9/12 and 0.861 here |
Try it yourself
Run python compare.py and look at both models on the twelve questions. Then add five questions of your own to data/queries.json, and finally add a third sentence-transformers model to MODELS and compare again. To see what you can build once the model is chosen, read Real Embedding Models: an Open Model or a Provider API.
Related course on Udemy
Become an AI Engineer: LLMs, RAG, Agents and MCP
Build real AI systems in Python: LLM APIs, RAG, evals, agents and MCP.View on Udemy ↗: Become an AI Engineer: LLMs, RAG, Agents and MCP (paid course, opens in a new tab)Related posts
What an Embedding Actually Is: Meaning as Numbers, Search by Closeness, and Where Hand-Made Numbers Break
A customer types "I cannot log in" and keyword search finds nothing, although a password-reset article exists. Turn meaning into numbers by hand, find the nearest point with math.dist, build a three-topic toy embedder that finds the right article at 1.00, and watch it score 0.00 on "I can't get into my account".
The RAG Pipeline Explained: 7 Stages From Documents to a Cited Answer
Ingest, chunk, embed, store, retrieve, rerank and generate, in one Python file. Follow one question through a 26-chunk employee handbook to an answer that cites its source.
Similarity Search: Finding the Closest Vectors with NumPy and NearestNeighbors
Ask one question of a whole collection of vectors: which items are closest to this one? Normalise, score every row with one matrix multiply, keep the top k or everything above a threshold, and check it with NearestNeighbors.
Why RAG Exists: The Problem It Solves, Compared With Pasting Everything and Fine-Tuning
A smart model has never read your company's files, and they change every month. Three ways to give it the facts: paste everything, fine-tune, or retrieve only the right pieces. Follow a refund-policy question through all three and see why RAG wins when documents change.