add nomic-embed-vision-v1.5#651
Conversation
📝 WalkthroughWalkthroughAdds Nomic vision embedding model descriptors and ONNX-specific embedding classes. The new implementation reshapes model outputs, selects the CLS token, and normalizes the resulting vectors. Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
fastembed/image/image_embedding.py (1)
7-15: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAnnotate mutable class attribute with
ClassVar.As hinted by Ruff (RUF012),
EMBEDDINGS_REGISTRYis a class-level mutable list. Annotating it withtyping.ClassVaris a best practice that signals it should not be overridden on instances.♻️ Proposed refactor
Ensure
ClassVaris imported at the top of the file:from typing import ClassVarThen update the attribute annotation:
class ImageEmbedding(ImageEmbeddingBase): - EMBEDDINGS_REGISTRY: list[Type[ImageEmbeddingBase]] = [ + EMBEDDINGS_REGISTRY: ClassVar[list[Type[ImageEmbeddingBase]]] = [ OnnxImageEmbedding, NomicVisionEmbedding, ]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@fastembed/image/image_embedding.py` around lines 7 - 15, Import ClassVar from typing in the image embedding module and annotate ImageEmbedding.EMBEDDINGS_REGISTRY as ClassVar containing the existing image embedding class type, preserving the current registry contents.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@fastembed/image/image_embedding.py`:
- Around line 7-15: Import ClassVar from typing in the image embedding module
and annotate ImageEmbedding.EMBEDDINGS_REGISTRY as ClassVar containing the
existing image embedding class type, preserving the current registry contents.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 98523fe7-f0b8-4935-803c-b4c92da69c52
📒 Files selected for processing (3)
fastembed/image/image_embedding.pyfastembed/image/onnx_embedding.pytests/test_image_onnx_embeddings.py
Do I fully know what I'm doing? Not really
Was AI involved? Absolutely
Did I do my best testing and verifying the contents? Yes sir
new: add nomic-embed-vision-v1.5
Adds
nomic-ai/nomic-embed-vision-v1.5and its quantized-Qvariant toImageEmbedding.Both models use the same 768-dimensional embedding space as the existing
nomic-embed-text-v1.5, enabling text-to-image and image-to-text search without extra alignment.How
nomic-embed-vision-v1.5returnslast_hidden_statewith shape[batch, 197, 768]instead of a pooled embedding. This PR adds aNomicVisionEmbeddingsubclass that takes the CLS token at index0and L2-normalizes it, matching the model's reference recipe.This mirrors the existing text-side pooling override in
PooledEmbedding. The base class and other image models are unchanged.Canonical values
For fp32, canonical values were computed from the original HF Transformers model and match the ONNX path bit-for-bit (
max abs diff 0.0):For
-Q, there is no torch reference for the quantized graph, so the canonical value is the quantized ONNX output onlinux/amd64with cosine0.995to fp32. The test is skipped on macOS because ARM int8 kernels diverge, matching the existing handling fornomic-embed-text-v1.5-Q.Models added:
nomic-embed-vision-v1.5: 768 dims, 0.37 GB, Apache-2.0nomic-embed-vision-v1.5-Q: 768 dims, 0.1 GB, Apache-2.0Checklist:
New Feature Submissions:
pre-commitwithpip3 install pre-commitand set up hooks withpre-commit install?New models submission: