Skip to content

Adds gemma3 embedding support#209

Open
wesc wants to merge 5 commits into
StarlightSearch:mainfrom
filament-dm:gemma3-port
Open

Adds gemma3 embedding support#209
wesc wants to merge 5 commits into
StarlightSearch:mainfrom
filament-dm:gemma3-port

Conversation

@wesc
Copy link
Copy Markdown
Contributor

@wesc wesc commented May 27, 2026

Adds gemma3 embedding support.

from embed_anything import EmbeddingModel, Dtype

model = EmbeddingModel.from_pretrained_hf(
    model_id="google/embeddinggemma-300m",
    dtype=Dtype.F32,
    token="hf_...",
)

data = model.embed_query(["Hello, world!"])
print(data[0].embedding)

Completed work started from #173. I cherry-picked commits from the referenced branch into this branch, and authored w/ Claude the completed implementation. I pulled embeddinggemma from HF and generated golden vectors from sentence-transformers. You will find tests checking the first 6 dims of those vectors as per what appears to be custom in the rest of the repo.

sonam-pankaj95 and others added 5 commits May 26, 2026 18:36
(cherry picked from commit 3095231)
(cherry picked from commit 056c4a6)
- Cleaned up gemma3.py by removing commented-out code related to HuggingFace token.
- Updated the token placeholder in bert.rs to reflect the correct usage of "hf_key".
- Minor adjustments in gemma3.rs to remove unnecessary code for clarity.

(cherry picked from commit 2b3c8da)
The dev merge reworked EmbeddingModel.from_pretrained_hf to drop the
WhichModel argument and auto-detect the architecture from config.json
(Gemma3TextModel). Update the example call to the new signature.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Add 768→3072→768 dense projection head between mean-pool and L2-norm
- Switch the transformer to bidirectional attention with a padding mask
- Apply per-layer RoPE: local base freq for sliding layers, global for full-attention layers
- Add golden test against sentence-transformers output verified to ~1e-6
@wesc wesc mentioned this pull request May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants