Add Multimodal Semantic Search quickstart using gemini-embedding-2#1286
Add Multimodal Semantic Search quickstart using gemini-embedding-2#1286NaveenKumarG-dev wants to merge 4 commits into
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
Note Gemini is unable to generate a summary for this pull request due to the file types involved not being currently supported. |
|
View / edit / reply to this conversation on ReviewNB markmcd commented on 2026-07-21T07:09:00Z Thanks for the PR, this is a great guide!
Since this is in examples/, feel free to add a byline with a link to a social profile or similar. You can see an example on the Sketch2Paint notebook, but it can be simple too if you prefer. |
|
View / edit / reply to this conversation on ReviewNB markmcd commented on 2026-07-21T07:09:01Z Can you rename the notebook such that it omits the model name from the filename?
This way we can update the notebook in future when new models are released.
The title is OK to leave, just rename the file. |
|
View / edit / reply to this conversation on ReviewNB markmcd commented on 2026-07-21T07:09:02Z Note: gemini-embedding-2 is a preview model
I don't think this is true. If you saw it somewhere, please lmk so we can update the docs.
https://ai.google.dev/gemini-api/docs/models/gemini
This link can change to https://ai.google.dev/gemini-api/docs/embeddings |
|
View / edit / reply to this conversation on ReviewNB markmcd commented on 2026-07-21T07:09:03Z public domain (CC0 / public domain).
Can you provide a source for this claim? It looks to me that they are licensed under the GNU FDL or CC-BY-SA (I only checked the first image)
I think CC is fine though, we just need to correctly document the license and provide links back to each image's
And they need to be checked individually as licenses differ per-file.
Oh and can you confirm that the text content is original? I can't see it online so I assume it's yours but please confirm. |
|
View / edit / reply to this conversation on ReviewNB markmcd commented on 2026-07-21T07:09:03Z User-Agent
Thanks for being a good citizen |
|
View / edit / reply to this conversation on ReviewNB markmcd commented on 2026-07-21T07:09:04Z def generate_embedding( content: str | bytes, mime_type: str | None = None, is_query: bool = False, title: str | None = None, ) -> list[float]:
Re: list[float], when dealing with a small sample size, using Python data types to manage embedding vectors is OK, but almost any real scenario will want to use
I don't think you have to change it for this, but if you choose not to, please make a note along the lines of "For real applications, consider using a library like |
|
View / edit / reply to this conversation on ReviewNB markmcd commented on 2026-07-21T07:09:05Z def cosine_similarity(vec1: list[float], vec2: list[float]) -> float: """Returns the cosine similarity between two embedding vectors.""" a = np.array(vec1) b = np.array(vec2) norm_a = np.linalg.norm(a) norm_b = np.linalg.norm(b) if norm_a == 0 or norm_b == 0: return 0.0 return float(np.dot(a, b) / (norm_a * norm_b))
Couple things here:
1) the output from the GE2 embedding model is always a unit vector, so this function can be replaced with
2) if you want to work with np types throughout, this can be done in batch (with CPU / GPU acceleration, etc). so that
You should be able to find some similar examples in the cookbook that use this approach, or see this older notebook I wrote. And btw you don't have to do this second part - I think your example is illustrative enough with Python primitives. |
|
View / edit / reply to this conversation on ReviewNB markmcd commented on 2026-07-21T07:09:06Z Notice that the results are ranked by semantic content, not by filename.
It's both really. You can see the 3rd result for "a dog running in a field" is the cat picture with a document title "dog_picture.jpg". It's worth noting that the titles are still factored in, and they are given some weight, though it is not exclusive. |
|
View / edit / reply to this conversation on ReviewNB markmcd commented on 2026-07-21T07:09:06Z When you set the background colour, you need to set the foreground (text colour) too. In dark mode, the result is light text on the light grey background.
(this is a nice summary display btw) |
|
View / edit / reply to this conversation on ReviewNB markmcd commented on 2026-07-21T07:09:07Z Some future work that could be good to add to or supplement this one day (not part of this PR, just if you want to riff on it further).
|
|
View / edit / reply to this conversation on ReviewNB markmcd commented on 2026-07-21T07:09:08Z I think drop the two points on "Continue your discovery..." as they are a bit simple to "continue" from here. |
|
Hi @markmcd, Thanks again for the detailed review and the helpful suggestions! I've addressed all of the review comments and pushed the requested changes, including:
Thanks as well for the future work ideas—they're great suggestions and I'll definitely keep them in mind for follow-up examples. I've re-requested your review. When you have a chance, I'd appreciate another look. Thanks! |
|
Hi @NaveenKumarG-dev Thanks for the patience ,I found the CI failure cause. Please run: After pushing, the Notebooks / Notebook format job should pass. |
|
@NaveenKumarG-dev , Also Please fix examples/Multimodal_Semantic_Search.ipynb: Lint failure: gemini_cookbook::button_colab Then commit and rerun the workflow for PR #1286. |
Description
This PR contributes a new notebook example demonstrating built-in multimodal semantic search and cross-modal retrieval using the
gemini-embedding-2model and the officialgoogle-genaiPython SDK.The notebook serves as a task-oriented recipe to help developers understand the direct SDK usage of multimodal embeddings.
Overview of Content
google-genaiclient and configuring it forgemini-embedding-2.task: search result | query:for queries; andtitle: | text:for documents) before callingclient.models.embed_content.Licensing & Compliance