AI / Google Antigravity Gemini Fundamentals Interview Questions
How do you build a Retrieval-Augmented Generation (RAG) pipeline with the Gemini API?
RAG enhances Gemini responses with content from your own documents, databases, or knowledge bases. The Gemini API supports two approaches: using the built-in file_search tool (managed by Google) or building your own pipeline with Gemini embeddings and an external vector database.
from google import genai from google.genai import types import numpy as np client = genai.Client() # APPROACH 1: Built-in file_search (simplest - Google manages everything) # 1. Upload documents: uploaded = client.files.upload(file="knowledge-base.pdf") # 2. Query against them (no vector DB needed): response = client.models.generate_content( model="gemini-3.5-flash", contents="What is our refund policy?", config=types.GenerateContentConfig( tools=[types.Tool(retrieval=types.Retrieval( vertex_ai_search=types.VertexAISearch(datastore="projects/my-project/...") ))] ) ) print(response.text) # APPROACH 2: Custom RAG with Gemini embeddings def embed(texts: list[str]) -> list[list[float]]: result = client.models.embed_content( model="gemini-embedding-exp-03-07", contents=texts, config=types.EmbedContentConfig(task_type="RETRIEVAL_DOCUMENT"), ) return [e.values for e in result.embeddings] # Index your documents: docs = ["Our policy is...", "For returns, contact..."] doc_embeddings = embed(docs) # store in Pinecone/pgvector/Weaviate # At query time: query_embedding = client.models.embed_content( model="gemini-embedding-exp-03-07", contents="Can I return a product?", config=types.EmbedContentConfig(task_type="RETRIEVAL_QUERY"), ).embeddings[0].values # Find most similar docs (cosine similarity): similarities = [np.dot(query_embedding, d) / (np.linalg.norm(query_embedding) * np.linalg.norm(d)) for d in doc_embeddings] top_idx = int(np.argmax(similarities)) # Generate with context: response = client.models.generate_content( model="gemini-3.5-flash", contents=f"Context: {docs[top_idx]}\n\nQuestion: Can I return a product?", )
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...
