Gemini Embeddings
An embedding API.
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.

- 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.
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]])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.
| key | value |
|---|---|
| Local | private, free |
| API | higher quality |
| Big vectors | more storage |
| Decide by | testing |
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