Gemmbeddings (Core ML)
google/embeddinggemma-2 converted to Core ML for iOS 18 / macOS 15 or later: text, images and audio, all embedded into the same space. The three parts install separately, so an app that only needs text downloads only the root folder.
This is a modified version of Google's model: the graphs were rewritten for Apple hardware and some weights are compressed (details below). Against Google's full-precision model, every embedding we test lands at cosine 0.998 or better.
Files
| Path | What | Size |
|---|---|---|
GemmbeddingsText.mlpackage | text encoder, Neural Engine, 6-bit weights; one function per size (64, 80, 144, 288, 512, 576, 768, 1152 tokens), weights shared on disk | 114 MB |
embeddings.q8 | token table: int8 rows [262144, 512], then one fp16 scale per row | 135 MB |
tokenizer.bin | Gemma vocab and merges, raw deflate | 3.9 MB |
vision/GemmbeddingsVision.mlpackage | image encoder, GPU, fp16; one model for 70 / 140 / 280 / 560 / 1120 image tokens | 305 MB |
vision/positions.bf16 | 2D position table | 9.8 MB |
audio/GemmbeddingsAudio.mlpackage | audio encoder, Neural Engine, 4-bit feed-forward and 6-bit other weights, clips up to 30 s | 172 MB |
audio/mel.f32 | mel filter bank for the log-mel features | 0.1 MB |
manifest.json (each folder) | functions, input layout, and every file's size and SHA-256 |
| Install | Download | On disk after install |
|---|---|---|
| Text only | 253 MB | ~253 MB |
| + images | +315 MB | +~315 MB |
| + audio | +173 MB | +~173 MB |
| Everything | 740 MB | ~740 MB |
The Swift library compiles each package on device and then deletes it, so the disk cost is about the download size.
Accuracy
Cosine similarity of the final embedding against sentence-transformers running Google's model in fp32, measured
through the Swift library on an M5 Mac:
| Input | Cases | Worst cosine |
|---|---|---|
| Text (queries, documents, code search, German, Japanese with emoji, a 966-token document) | 11 | 0.9981 |
| Images (photo, scanned invoice, tall, wide, tiny; every detail level) | 16 | 0.9982 |
| Text with an image in it | 1 | 0.9983 |
| Audio (speech clips of 4, 6 and 12 s) | 3 | 0.9985 |
| Text with an audio clip in it | 1 | 0.9983 |
Retrieval benchmarks, one text per call at 512 tokens on the Neural Engine:
| SciFact NDCG@10 | STS-B Spearman | |
|---|---|---|
| Google's model, fp16 Core ML conversion (FluidInference) | 0.8543 | 0.8750 |
| This release | 0.8490 | 0.8741 |
| This release with the 16-bit token table instead of 8-bit | 0.8516 | 0.8741 |
The SciFact gap between the 8- and 16-bit tables comes from 3 of 300 queries in which two neighbouring results swap places; a lossier 6-bit table scored 0.8514, higher than 8-bit, so differences this small are within tie-breaking noise.
Why the quality holds
Every compression step was checked against the fp32 original, and anything that measurably hurt retrieval was left out.
-
Text encoder, 6-bit lookup tables per 16 output channels (k-means). Worst text embedding 0.998 against fp32. 4-bit was tried and rejected: embeddings fell to 0.92–0.97 and SciFact to 0.826.
-
fp16 everywhere without overflow. The activation range of every normalization input was measured on real text, images and audio, and scaled so squares stay far below fp16's limit (for images the largest is 12,248 of 65,504) and the smallest values stay above fp16's normal range.
-
Token table, int8 with a scale per row. Each of the 262,144 rows gets its own scale, so rare and common tokens keep the same relative precision (about 1% error per value). Every embedding stays at cosine ≥ 0.99984 to the 16-bit table; STS-B is unchanged. 4-bit rows were rejected (0.997).
-
Tokenizer. The binary file holds exactly the vocab and merge order of Google's
tokenizer.json; token ids are identical on every test text. -
Image encoder kept at fp16. On the GPU, compressed weights save download size but not memory (an int8 build doubled memory) and 6-bit tables broke individual image tokens (cosine 0.47), so it ships uncompressed. Images are resized with exact antialiased bicubic matching Google's preprocessing, and the token budget is picked from the image's pixel count so detail is not thrown away.
-
Audio encoder, 4 bits only where it is safe. The feed-forward layers tolerate 4 bits; attention, convolutions and projections stay at 6 bits. Against fp32, with the same text encoder:
Audio weights Size Speech Silence Tone Noise 6-bit everywhere 213 MB 0.99990–0.99998 0.99870 0.99964 0.99904 4-bit feed-forward, 6-bit rest (this release) 173 MB 0.99983–0.99997 0.99868 0.99946 0.99878 4-bit everywhere (rejected) 149 MB 0.99912–0.99971 0.97082 0.99195 0.99655 The log-mel features computed in Swift match Google's feature extractor within 0.0008.
Speed (M5 Mac, through the Swift library)
| Time | |
|---|---|
| Search query (64 tokens) | 2.5 ms |
| 512-token document | 25 ms |
| Image at 70 / 280 / 1120 tokens | 25 / 107 / 720 ms |
| 30 s audio clip | 113 ms (about 110 ms per clip in batches) |
Changes from the previous version
The previous revision (05268f234afb1fa843177168786b924bcfab4774) held a text-only model with 2 sizes, a bf16 token
table and the JSON tokenizer. This version adds images and audio, six more text sizes (including a bidirectional
512-token sliding window for texts over 513 tokens), the int8 token table and the binary tokenizer. Code written for
the previous revision cannot read this one.
License
Apache 2.0, the same as the original model (see LICENSE). EmbeddingGemma 2 is by Google DeepMind.