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 |
More Related questions...