Testing embedding models on the Mac's Neural Engine
Dackel is my Markdown notes app for the Mac. I want it to search notes by meaning: you type what you remember, not the exact words. For that it needs a text embedding model, and the model runs on the Mac, so that no note leaves the machine.
Which model should that be, and how should it run? Every option trades one thing for another. A larger model is better at capturing meaning, but it needs more time and memory. A smaller model downloads and runs faster, but it may capture less of what a note means. So I shortlisted four models and set out to quantify the trade-offs.
The answer: Dackel’s search model will be EmbeddingGemma 2, on the Neural Engine, with 8-bit weights, reading notes in chunks of 128 tokens.
Contents
What a good model means for Dackel
A text embedding model turns a text into a vector: a fixed list of numbers. EmbeddingGemma 2 returns 768 of them. Texts that mean similar things get vectors that point in similar directions, and search looks for the notes whose vectors point the same way as the query’s.
Dackel downloads the model on first use, then it searches while you type, on a laptop that is doing other things. So the model has to stay within a few resource budgets. I set them by my best judgement:
| Budget | |
|---|---|
| Embedding one search query | at most 15 ms |
| Memory the model adds | at most 250 MB |
| Download | at most 400 MB |
| System | macOS 14, Apple silicon |
| Languages | English, German and Spanish |
| Licence | allows shipping a converted copy |
Inside those budgets, the model that finds the right note most often wins. The main metric is how often the right note comes first.
The notes and queries I measured with
- A vault of notes. 430 synthetic notes with 360 search queries, written by a language model for an invented person, in English, German and Spanish. This is the set closest to what Dackel reads.
- XQuAD-R. 240 Wikipedia paragraphs with 3,570 human-written questions in the same three languages. Two thirds of the questions are asked in another language than the paragraph.
- A stress corpus. 2,894 texts in 34 scripts, built by code: long runs of one character, near-empty texts, unusual Unicode. I use it only to check the arithmetic, never to score search.
I split the queries once into two halves. Every choice was made on the first half, 1,953 queries. The second half, 1,977 queries, was kept back to confirm the result. All comparisons are paired, query by query.
The candidates
I took the shortlist from the multilingual retrieval leaderboard MTEB: the four best models of at most about 350 million parameters that meet the language and licence budgets.
| Model | From | Parameters | Leaderboard, retrieval |
|---|---|---|---|
| harrier-oss-v1-270m | Microsoft | 268M | 66.4 |
| granite-311m | IBM | 312M | 65.2 |
| EmbeddingGemma 2 | 271M | 60.6 | |
| granite-97m | IBM | 97M | 60.3 |
Two models score well above the other two. granite-97m matches EmbeddingGemma 2 at a third of the size. Plain keyword search runs along as a baseline.
More details on the selection
These models were left out:
- jina-embeddings-v5-text-nano: its licence forbids commercial use.
- mSlideOn: it returns sparse vectors, and Dackel’s index stores dense ones.
- geevec-embeddings-1.0-lite: over the size limit, and it states no languages.
embeddinggemma-300m sits behind Google’s Gemma terms of use, so I left it out as well.
Harrier’s card says MIT, but the model is adapted from Gemma 3, which has its own terms. I would have had to settle that before shipping it.
Which chip?
A Mac has three chips that can run the model. The CPU and the GPU calculate at full precision, float32. The Neural Engine calculates only at half precision, float16.
All four models, at 256 tokens:
| Time for one call, ms | CPU | GPU | Neural Engine |
|---|---|---|---|
| EmbeddingGemma 2 | 72.6 | 31.0 | 10.8 |
| granite-311m | 57.5 | 23.4 | 10.0 |
| harrier-270m | 50.7 | 21.2 | 6.8 |
| granite-97m | 16.3 | 6.4 | 4.0 |
Against the 15 ms budget, the three larger models fit only on the Neural Engine. Only granite-97m is small enough to fit on the GPU as well.
Targeting the Neural Engine has two other advantages. Float16 weights are half the size of float32 weights, on disk and in memory. And the CPU and GPU stay free for other apps running on the Mac.
What does float16 cost?
Calculating in float16 instead of float32 can damage a vector in two ways.
- Loudly. The largest number float16 can hold is 65,504. Anything larger becomes infinity, and the vector fills with NaN, “not a number”. It is easy to detect.
- Quietly. Float16 keeps about three significant digits. Rounding errors add up through the layers, and the vector comes out finite, of normal length, and pointing somewhere else. Search still returns notes, only the wrong ones.
To detect the quiet kind of damage, the float16 vector has to be compared against a reference. So I computed every vector twice: on the Neural Engine in float16, and in PyTorch in float32 on the CPU. The cosine between the two is what I call fidelity. At 1.0 they point the same way. My rule of thumb was at least 0.99 on every single text, over 9,480 texts. So the number that counts is the fidelity of the worst text.
| Largest value inside, share of float16’s maximum | Fidelity, worst text | Texts below 0.99 | |
|---|---|---|---|
| granite-311m | 13% | 0.9988 | 0 |
| granite-97m | 17% | 0.9986 | 0 |
| EmbeddingGemma 2 | 81% | 0.9947 | 0 |
| harrier-270m | 201% | 0.9711 | 4,811 |
For three models, float16 cost nothing I could measure. That includes EmbeddingGemma 2, whose model card says: “Do not use float16.” Nevertheless, its margin is the thinnest of the three: its largest value is just 19% below the limit.
Harrier is the exception. The Neural Engine returned no infinity and no NaN, because it cuts a value that is too large off at the limit and carries on. Every vector had a length between 0.9987 and 1.0011, where 1 is correct. Half the vectors were wrong.
I checked this with a few tiny models. On the Neural Engine, the step after an overflow reads the value as 65,536, however far over the limit it was, and no NaN ever appears. Apple does not document this. The measurements are in the appendix.
However, Harrier could be fixed. Its large values sit in the running total that each layer reads from and adds to. Every read goes through a normalisation, which divides out the overall size. So I divided the total by 16. At full precision the output did not change. On the Neural Engine the worst fidelity rose from 0.9711 to 0.9995, with no text below 0.99.
So float16 had no real cost, beyond the work of checking every model for quiet damage and fixing it where it shows up.
What exactly gets divided
Harrier is built from Gemma 3 layers. The running total starts as the token embeddings, is read only through a normalisation, and is written only by adding a normalisation’s output. That gives three edits to the weights, and no new operation:
- The token embeddings are multiplied by 1/16.
- The gain of the two normalisations that write to the total in each layer is multiplied by 1/16.
- The epsilon of the normalisations that read from it is multiplied by 1/256, since it is added to a squared value.
The largest value inside drops from 131,781 to 8,236. At full precision the output matches the published model at a cosine of 0.9999999.
Which model?
All four models now run correctly on the Neural Engine, inside the speed budget. What is left is how well they search. I compared them on the first half of the queries, at full precision:
| Right note first | All 1,953 queries | Vault of notes, 180 | Asked in another language than the text, 1,239 |
|---|---|---|---|
| granite-311m | 83.4% | 63.9% | 82.7% |
| EmbeddingGemma 2 | 82.2% | 69.4% | 77.9% |
| granite-97m | 79.1% | 45.0% | 78.0% |
| harrier-270m | 75.8% | 60.6% | 66.2% |
| Keyword search | 40.8% | 48.3% | 13.9% |
Harrier has the highest leaderboard score of the four, and here it came last: 6.4 points behind EmbeddingGemma 2.
granite-97m runs the most efficiently, as expected: one call takes 4.0 ms instead of 10.8, and it needs about a quarter of the Neural Engine’s memory. Overall it gives up 3 points. On the vault of notes it gives up far more, and falls behind keyword search.
The top two can’t be told apart overall: the difference of 1.2 points is within the noise. Split by where the queries come from, they go opposite ways. On questions asked in another language than the text, granite-311m is ahead by 4.8 points. On the vault of notes, EmbeddingGemma 2 is ahead by 5.5 points.
That comparison ran at full precision. To validate it, I ran the models again on the second half of the queries (the held-out split). This time they ran as Dackel would ship them: on the Neural Engine, with the 8-bit weights of the next section. Overall, granite-311m had 85.1% and EmbeddingGemma 2 had 83.8%, again within the noise. On the vault of notes, EmbeddingGemma 2 had 75.6% and granite-311m had 65.6%.
Dackel is a notes app, so I chose EmbeddingGemma 2.
How small can the weights be?
Weights stored in 8 bits take half the space of 16-bit ones. For EmbeddingGemma 2 the model file shrinks from 276 MB to 139 MB, and the whole download comes to 283 MB.
Smaller weights are a second way to fail quietly, so they need the same comparison against full precision. Search did not suffer: at 128 tokens, the 8-bit model found the right note first as often as the full-precision one, within 0.1 points. Fidelity is a different matter. The table shows the worst text at each length: the one whose 8-bit vector is furthest from its full-precision vector. It gets worse as the input gets longer:
| Input length, tokens | 64 | 128 | 256 | 512 |
|---|---|---|---|---|
| Fidelity, worst text | 0.9949 | 0.9866 | 0.9483 | 0.9221 |
By my own rule of thumb of 0.99, that fails from 128 tokens up. At 128 it fails on exactly two texts, and both are stress texts made of nothing but zero-width spaces: invisible characters with no meaning to embed. Dackel never sends such a text to the model, since it skips notes of fewer than five words. It also removes invisible characters before embedding.
Therefore, I think it is fair to conclude that 64 and 128 tokens are OK.
How long should a chunk be?
The model reads a fixed number of tokens, so notes are cut into chunks that fit. Shorter chunks make a query faster. Do they make search worse?
With the model alone, on the first half of the queries, they made it better:
| Chunk length, tokens | 64 | 128 | 256 | 512 |
|---|---|---|---|---|
| Right note first | 84.0% | 84.1% | 82.2% | 81.5% |
512 was out in any case: one call of the model takes 28 ms there, over the budget of 15. 64 and 128 were level, and 64 is faster, so I decided on 64.
Then I ran it through Dackel’s own search code. The app does not search with the model alone: keyword search runs first, and a second step adds notes found by meaning. On the vault of notes:
| 360 queries | 64 tokens | 128 tokens | 256 tokens |
|---|---|---|---|
| Right note first | 66.7% | 72.2% | 73.9% |
| Right note in the list | 85.0% | 90.6% | 92.5% |
| Embedding a query | 3.0 ms | 4.6 ms | 9.9 ms |
| Indexing the vault | 54 s | 23 s | 24 s |
At 64 tokens the app found the right note first 7 points less often than at 256. Also, indexing took more than twice as long, because 64 tokens gives four times as many chunks as 128. I reversed the decision and went with 128.
Trying to understand the disagreement between the two tables, I saw that nine in ten queries of the first are over Wikipedia paragraphs, not notes. And the first scores the model, where the second scores the app. The second is the one that counts.
So I chose 128. It buys a query embedded in half the time of 256. What it costs is less certain. Against 256, 16 queries got better and 22 got worse, a difference of 1.7 points that is within the noise.
A safety net
In the app, Dackel checks every vector the Neural Engine returns: it must be finite and of length 1, within 0.05. A vector that fails is computed again by the same model on the GPU.
This catches the loud failures. I tested it with 100 failures injected on purpose, and all were recovered. But it will not catch the quiet kind of failure that I observed with Harrier.
It costs about 95 MB while the GPU copy is loaded, and nothing otherwise.
The result in the app
EmbeddingGemma 2 at 128 tokens with 8-bit weights, measured in a release build of Dackel:
| Budget | Measured | |
|---|---|---|
| Memory the model adds, at its peak while indexing | 250 MB | 219 to 223 MB |
| Download | 400 MB | 283 MB |
From the last keystroke to results by meaning, a search takes 210 ms at the median:
| Step | Time |
|---|---|
| Dackel waits for you to stop typing | 151 ms |
| Keyword search, and showing its results | 34 ms |
| Embedding the query (budget: 15 ms) | 9 ms |
| Ranking by meaning, and showing the merged results | 15 ms |
| Total | 210 ms |
More timings
- The first load after install takes 6.2 s, while the Neural Engine prepares the model. Later loads take 0.06 s.
- Once per install, during that preparation, the app’s memory peaks at 418 MB.
Limits
- One Mac: an M5 with 24 GB, on macOS 27. Older chips, Macs with less RAM and older versions of macOS are still unmeasured.
- No real vault was tested. The notes were written by a language model, and XQuAD-R may be in the models’ training data.
- 360 queries can’t resolve differences under about 5 points in the app’s search.
- Energy use is unmeasured.
Appendix: what the Neural Engine does with a value that is too large
Float16 cannot hold a number above 65,504. Harrier produces larger numbers, and still the Neural Engine returned no infinity and no NaN. The same model in float16 in PyTorch, on the Mac’s GPU, returned NaN for all 9,480 texts. I wanted to know what the Neural Engine does differently.
So I built a few tiny models. Each one does a single calculation that goes over the limit. I ran each in float16 twice, on the CPU and on the Neural Engine, and compared both with the correct result.
An overflow is read as 65,536
The first models multiply two numbers so that the result is too large, and then scale it back down.
| Calculation | Correct | CPU | Neural Engine |
|---|---|---|---|
| 300 × 300, then × 0.25 | 22,500 | infinity | 16,384 |
| 2,000 × 2,000, then × 0.25 | 1,000,000 | infinity | 16,384 |
| 40,000 + 40,000, then × 0.5 | 40,000 | infinity | 32,768 |
| 300 × 300, then × 0, then + 7 | 7 | NaN | 7 |
| 300 × 300 as the model’s output | 90,000 | infinity | infinity |
The CPU does what float16 normally does: the value becomes infinity, and a later step turns it into NaN.
The Neural Engine does something else. Look at the first two rows: 16,384 is 65,536 × 0.25. The next step read the overflowed value as 65,536, whether the true value was 90,000 or 4 million. The result is a normal number, and it is wrong. No NaN ever appears. Only when the overflowed value is the model’s final output does it come out as infinity.
A linear layer overflows earlier
A linear layer is the most common step in these models. On the Neural Engine its output overflows at 32,768, half of float16’s maximum.
| Calculation | Correct | CPU | Neural Engine |
|---|---|---|---|
| A linear layer whose output is 30,000, then × 0.5 | 15,000 | 15,000 | 15,000 |
| A linear layer whose output is 40,000, then × 0.5 | 20,000 | 20,000 | 32,768 |
None of the three models that passed comes near that value in a linear layer.
A normalisation is safe, as long as Core ML recognises it
A normalisation squares every value, takes the mean of the squares, and divides by its square root. The squares can be far above the limit even when the values are not: 400 squared is 160,000.
| Calculation | CPU | Neural Engine |
|---|---|---|
| A normalisation whose squares average 160,000 | all zeros | correct |
| The same, with one extra multiplication inside it | all zeros | all zeros |
On the CPU the squares overflow and the output is all zeros. On the Neural Engine the output is correct, because Core ML recognises the normalisation and computes it as one step. The squares never exist as float16 values. With one extra multiplication inside, Core ML no longer recognises it, and the Neural Engine returns zeros as well.
What this says about the two models
Harrier. A few values in each of its vectors go over the limit. The Neural Engine reads them as 65,536, and the next normalisation hides the change in size. The vector comes out with a normal length and points the wrong way. I checked this with one more model: 6 of 512 values at 100,000, followed by a normalisation. The Neural Engine’s output matched the correct one at a cosine of 0.9987. It matched exactly what I get when I cut the values off at 65,536 by hand.
EmbeddingGemma 2. Inside its normalisations, the sums of squares reach 11 million, 168 times the limit. On paper that cannot work in float16. On the Neural Engine it does, because those sums never exist as float16 values.
Why it matters
In ordinary float16, an overflow announces itself: infinity turns into NaN a step or two later. On the Neural Engine an overflow leaves no trace in the output. And the same model file gives different results on the CPU, so a test on another chip says little about the Neural Engine, in either direction.
Apple does not document this. The closest description I found is Spencer Bryngelson’s independent study Apple Neural Engine: Architecture, Programming, and Performance, which reaches the chip below Core ML and measures the M1 and the M5. My results agree with its chapter on numerics where they overlap:
- The engine “never produces a NaN anywhere”, and infinity times zero gives zero.
- An overflow as the output is infinity.
- A linear layer’s output overflows at 32,768. The study measured this on the M1, and I see it on the M5.
- Normalisations are operations of their own on the chip.
Two things I measured are not in it: that a later step reads an overflowed value as 65,536, and that a normalisation stays correct when its squares exceed the limit, and stops being correct when Core ML no longer recognises it.
What I measured is one M5 Mac on macOS 27, through Core ML, with each calculation on its own and not inside the full models.