AI / Google Antigravity Gemini Fundamentals Interview Questions
What are Gemini API embeddings and what models support them?
Embeddings convert text into dense numerical vectors capturing semantic meaning. The Gemini API provides text embedding models for building semantic search, RAG pipelines, clustering, and classification systems.
from google import genai from google.genai import types import numpy as np client = genai.Client() # Generate embeddings with Gemini Embedding: result = client.models.embed_content( model="gemini-embedding-exp-03-07", # current experimental embedding model contents=[ "Python is a versatile programming language.", "Gemini is Google's AI model family.", "The stock market fell today.", ] ) vectors = [e.values for e in result.embeddings] print(f"Embedding dimensions: {len(vectors[0])}") # typically 768 or 3072 # Compute cosine similarity: def cosine_sim(a, b): a, b = np.array(a), np.array(b) return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b)) print(f"Python vs Gemini: {cosine_sim(vectors[0], vectors[1]):.3f}") # medium print(f"Python vs stocks: {cosine_sim(vectors[0], vectors[2]):.3f}") # low # Task type specification (improves accuracy): result = client.models.embed_content( model="gemini-embedding-exp-03-07", contents="How does async/await work in Python?", config=types.EmbedContentConfig( task_type="RETRIEVAL_QUERY" # vs RETRIEVAL_DOCUMENT, SEMANTIC_SIMILARITY ) )
| task_type | Use when |
|---|---|
| RETRIEVAL_QUERY | Embedding a user's search query |
| RETRIEVAL_DOCUMENT | Embedding documents to be indexed |
| SEMANTIC_SIMILARITY | Comparing two texts for similarity |
| CLASSIFICATION | Embedding text for classification |
| CLUSTERING | Embedding for grouping similar texts |
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
