EmbeddingGemma-MLX

Implements the embeddinggemma-300m-4bit model in Swift with parity scripts, samples, and Hugging Face integration.


Project maintained by gradinnovate Hosted on GitHub Pages — Theme by mattgraham

EmbeddingGemma Banner

EmbeddingGemma-MLX

This repository ports Google’s EmbeddingGemma text encoder to the Swift MLX stack by extending the mlx-swift-examples project. It provides a Swift implementation of the embeddinggemma-300m-4bit model, a sample executable that exercises the embedder, and parity scripts that verify the implementation against the original Python reference.

Repository Layout

Prerequisites

Getting Started

  1. Clone and resolve dependencies
    git clone https://github.com/gradinnovate/EmbeddingGemma-MLX.git
    
  2. Download model weights (required once)
    huggingface-cli download mlx-community/embeddinggemma-300m-4bit \
      --local-dir models/embeddinggemma-300m-4bit
    

Running the Swift Sample

The SwiftTests package links against the modified mlx-swift-examples library to exercise EmbeddingGemmaModel.

cd SwiftTests
swift run EmbeddingGemmaSwiftTest

The executable tokenizes a trio of test sentences, generates normalized embeddings, and prints the cosine similarity matrix. You can adapt SwiftTests/Sources/EmbeddingGemmaSwiftTest/main.swift to integrate the embedder into your own MLX applications.

Development Notes

🙏 Support

If you find this fork helpful for your EmbeddingGemma development, consider supporting the work:

Buy Me A Coffee

📄 License

This project maintains the same license as the original MLX Swift Examples repository.