AI Hints
Home›RAG Tutorial›Vector Search
RAG · Lesson 29 of 120

Gemini Embeddings

An embedding API.

⏱ 2 min read▶ Video at 28:59🎓 Free
Watch this lesson in the RAG courseWatch on YouTube ↗Full RAG course

Local models are great to start with. But API models are often more accurate, and handle many languages and long text. Google's Gemini embedding model is one, and LangChain makes it easy to use.

Gemini Embeddings
From the video: Gemini Embeddings
  • Often more accurate
  • Many languages
  • Easy with LangChain

Embedding with Gemini

Google generative AI embeddings connects to the Gemini embedding model. Embed query turns one question into a vector. Run it. Each vector has three thousand and seventy two numbers, much bigger than our local model's.

gemini_embed.pypython
from langchain_google_genai import GoogleGenerativeAIEmbeddings

embeddings = GoogleGenerativeAIEmbeddings(model="gemini-embedding-001")

vector = embeddings.embed_query("How long does charging take?")
print("numbers:", len(vector))
print("first three:", [round(x, 3) for x in vector[:3]])
Output
numbers: 3072
first three: [0.027, -0.017, 0.007]

Local or API?

Choose a local model for privacy, zero cost, and offline work. Choose an API model for the best quality, many languages, and no hardware worries. Either way, measure on your own questions before deciding.

keyvalue
Localprivate, free
APIhigher quality
Big vectorsmore storage
Decide bytesting

Summary

LangChain's Google embeddings class gives us Gemini's embedding model in two lines. Next, why queries and documents are embedded a little differently.

Key takeaways
  • GoogleGenerativeAIEmbeddings
  • embed_query
  • 3072 numbers
Next up: Queries and Documents — task types