How to Use Gemma 4 & EmbeddingGemma 2
Two open models from Google with two different jobs. Gemma 4 writes: it chats, reasons and codes. EmbeddingGemma 2 finds: it powers search. This guide shows how to use each one, and how to combine them.
Settings from Google's model cards and guides · code samples are starting points ·
Which model do you need?
| You want to | Use | Why |
|---|---|---|
| Chat, write, summarise, translate | Gemma 4 | It generates text |
| Write or explain code | Gemma 4 | See Gemma 4 coding |
| Ask about a picture, a recording or a video | Gemma 4 | It reads them and answers in text |
| Search documents, photos or recordings by meaning | EmbeddingGemma 2 | It turns content into vectors you can compare |
| Sort or group content | EmbeddingGemma 2 | Similar items get similar vectors |
| Answer questions from your own files | Both | One finds the right passages, the other writes the answer |
Have not downloaded anything yet? Start with how to download or the download hub.
Using Gemma 4 in four steps
Choose where to run it
Nothing to install: Google AI Studio or the playground. On your own machine: Ollama or LM Studio. In an app: Transformers or a hosted API. Unsure? Use the runtime selector.
Start a chat
With Ollama it is one command:
ollama run gemma4:12b-it-qat. Type a message and you are talking to the model, offline. Other ways in are on the chat page.Give it a system prompt
Gemma 4 has a real system role. Use it once to set the role, tone and output format, then keep your messages short and specific.
Turn thinking on for hard problems
Thinking makes the model reason before it answers. Worth it for maths, code and multi-step tasks; unnecessary for quick chat.
Your first conversation, four ways
ollama run gemma4:12b-it-qat
# Inside the chat:
/set system You are a concise assistant.
/set parameter num_ctx 32768
/clear # start a fresh conversation
/bye # leave
The simplest route. The /set lines are optional: one sets a system prompt, the other gives the model a longer memory for the conversation.
# pip install openai · ollama pull gemma4:12b-it-qat
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
reply = client.chat.completions.create(
model="gemma4:12b-it-qat",
messages=[
{"role": "system", "content": "You are a careful maths tutor."},
{"role": "user", "content": "Why is 0.1 + 0.2 not 0.3?"},
],
)
print(reply.choices[0].message.content)
Ollama serves an OpenAI-style endpoint on your own machine, so the standard client works. For LM Studio, change the address to http://localhost:1234/v1.
# Chat with a system prompt and thinking switched on messages = [ {"role": "system", "content": "You are a careful maths tutor."}, {"role": "user", "content": "Why is 0.1 + 0.2 not 0.3?"}, ] text = processor.apply_chat_template( messages, tokenize=False, add_generation_prompt=True, enable_thinking=True, # False for fast replies ) # Recommended sampling: temperature=1.0, top_p=0.95, top_k=64
The template call is from Google's thinking guide. Loading the processor and model is shown on the 12B page.
# pip install google-genai · set GEMINI_API_KEY first
from google import genai
from google.genai import types
client = genai.Client()
response = client.models.generate_content(
model="gemma-4-26b-a4b-it",
contents="Why is 0.1 + 0.2 not 0.3?",
config=types.GenerateContentConfig(
system_instruction="You are a careful maths tutor.",
thinking_config=types.ThinkingConfig(thinking_level="high"), # or "minimal"
),
)
print(response.text)
Google hosts the 31B and 26B A4B. You need a key from Google AI Studio - see the API page and pricing.
Settings worth getting right
Sampling
Google recommends one configuration for everything: temperature 1.0, top-p 0.95, top-k 64. Start there before changing anything.
Thinking in long chats
Keep only the final answers in the conversation history. Earlier reasoning is dropped before the next turn, except while a tool call is in progress.
Context length
The models accept 128K or 256K tokens, but local apps often start far lower. Raise it if the model forgets earlier messages.
Tools
Function calling is built in: describe your tools, let the model choose a call, run it yourself, and return the result. Always check a call before running it.
Recent facts
Training data ends in January 2025. For anything newer, paste the information in or give the model a search tool.
The right size
Bigger models reason better. If answers disappoint on E2B or E4B, try the 12B before changing your prompt.
From Google's model card, thinking guide and function-calling guide. Each setting is covered in depth on the capabilities page; prompt technique is in prompting; the model list is on models.
Sending images, audio and video
| Input | Works on | How to send it | Limits |
|---|---|---|---|
| Images | Every size | Put the image before your text | Choose 70 to 1,120 tokens of detail per image; 280 is the default |
| Documents and screenshots | Every size | As images, at high detail | Use 560 or 1,120 tokens for small text |
| Audio | E2B, E4B, 12B | Put the audio after your text | 30 seconds a clip; mono, 16 kHz, MP3 or WAV |
| Video | Every size | As a series of frames | 60 seconds at one frame a second |
From Google's model card. In Ollama you can put an image's file path straight in your prompt. Code for each input type is under capabilities; phones are covered on mobile downloads and the Android page.
Using EmbeddingGemma 2 in three steps
An embedding model does not answer you in words. It gives back a list of numbers - a vector - for each thing you hand it. Things with similar meaning get similar vectors, and that is all search needs.
Embed what you want to search
Run every document, image or clip through the model once and save the vectors.
Embed the query
When someone searches, turn their query into a vector the same way.
Compare
The saved vectors closest to the query's vector are your results.
# pip install -U sentence-transformers transformers
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("google/embeddinggemma-2")
query = "What causes the northern lights?"
document = "The northern lights are caused by charged particles from the sun."
query_emb = model.encode(query, prompt_name="SearchQuery")
doc_emb = model.encode(document, prompt_name="Document")
print(model.similarity(query_emb, doc_emb)) # higher means closer in meaning
The model downloads itself the first time you load it. From Google's model card.
# pip install -U "sentence-transformers[image,audio,video]" transformers query_emb = model.encode("ocean waves at sunset", prompt_name="SearchQuery") image_emb = model.encode({"image": "sunset_beach.jpg"}) audio_emb = model.encode({"audio": "ocean_waves.wav"}) # Everything lives in one space, so text can be compared with media print(model.similarity(query_emb, image_emb)) print(model.similarity(query_emb, audio_emb))
Pass a dictionary naming the input type. Values can be local files or web addresses. From Google's developer guide.
# Download once ollama pull embeddinggemma-2 # Ask the local server for an embedding curl http://localhost:11434/api/embed -d '{ "model": "embeddinggemma-2", "input": "What causes the northern lights?" }'
Ollama serves embeddings from the same local address as chat. The text-only build, embeddinggemma-2:270m, is 378 MB.
# Shorter vectors: 256 dimensions instead of 768
query_emb = model.encode(
query,
prompt_name="SearchQuery",
truncate_dim=256,
normalize_embeddings=True,
)
Vectors can be cut from 768 numbers to 512, 256 or 128 to save space. A million full-size vectors take about 1.5 GB; at 128, about 250 MB. Test quality before going to 128.
Or 512, 256, 128.
Tokens, shared by everything in one input.
378 MB for text only.
Free for commercial use.
Google's EmbeddingGemma 2 developer guide is the full walkthrough. Specs, scores and downloads are in this site's EmbeddingGemma 2 guide.
Tell it what the text is for
For text, EmbeddingGemma 2 expects a short task label. Pass a prompt name and the library adds it. Google notes that leaving it out can lower quality.
| You are doing | Use on the query | Use on the content |
|---|---|---|
| Web-style search | SearchQuery | Document |
| Question answering | QuestionAnswering | Document |
| Fact checking | FactChecking | Document |
| Code search | CodeRetrieval | Document |
| Classification | Classification | Classification |
| Clustering | Clustering | Clustering |
| Sentence similarity | SentenceSimilarity | SentenceSimilarity |
How much fits in one input
About 8,192 tokens of text, or 29 images, or 58 video frames, or 5.5 minutes of audio. These share one budget, so split long media.
Load only what you need
The model is modular: 270M for text and code, 440M with images, 570M with audio, 740M for everything.
One setting to avoid
Google warns the model is not compatible with float16. Use bfloat16 or float32.
Prompt names and limits from Google's EmbeddingGemma 2 model card.
Answer questions from your own documents
This is the most common reason to use both. EmbeddingGemma 2 finds the passages that matter; Gemma 4 reads them and writes the answer. The pattern is called retrieval-augmented generation, or RAG.
# pip install -U sentence-transformers transformers openai # ollama pull gemma4:12b-it-qat from sentence_transformers import SentenceTransformer from openai import OpenAI embedder = SentenceTransformer("google/embeddinggemma-2") gemma = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama") # 1. Embed your passages once passages = [ "Refunds are available within 30 days of purchase.", "Support is open Monday to Friday, 9am to 5pm.", "Orders over $50 ship free within the country.", ] passage_embs = embedder.encode(passages, prompt_name="Document") # 2. Embed the question and find the closest passages question = "Can I get my money back after three weeks?" q_emb = embedder.encode(question, prompt_name="QuestionAnswering") scores = embedder.similarity(q_emb, passage_embs)[0] top = [passages[i] for i in scores.argsort(descending=True)[:2]] # 3. Let Gemma 4 answer from what was found reply = gemma.chat.completions.create( model="gemma4:12b-it-qat", messages=[ {"role": "system", "content": "Answer only from the context. " "If the answer is not there, say you do not know."}, {"role": "user", "content": "Context:\n" + "\n".join(top) + "\n\nQuestion: " + question}, ], ) print(reply.choices[0].message.content)
Why not just paste everything in?
Gemma 4's context is large, but searching first is faster, cheaper and keeps the model focused on what is relevant.
Tell it to stay in the context
The system prompt above asks the model to say when the answer is not there. That one line prevents most made-up answers.
Growing beyond a demo
For thousands of documents, store the vectors in a vector database instead of a list. Google's launch post names Qdrant among supported tools.
This sample is a starting point written for this page and has not been run against live models here; the calls it uses come from Google's guides and Ollama's OpenAI-compatible endpoint. For a shared deployment see self-hosting; for memory planning, the VRAM guide.
Common mistakes
With Gemma 4
- Leaving the context window at a small default
- Using thinking mode for simple chat
- Feeding old reasoning back into the conversation
- Sending audio to the 26B A4B or 31B
- Running a tool call without checking it
- Using weights from before the July 2026 refresh
With EmbeddingGemma 2
- Expecting it to write an answer
- Leaving out the task prompt for text
- Mixing vectors from version 1 and version 2
- Loading it in
float16 - Embedding a long recording as one input
- Comparing vectors of different lengths
Known gaps are listed under limitations; responsible-use notes under safety.
What is the easiest way to start using Gemma 4?
Install Ollama and run ollama run gemma4:12b-it-qat. To try it with nothing installed, use Google AI Studio.
Do I need to know how to code?
Not for Gemma 4: LM Studio and the phone app need no code at all. EmbeddingGemma 2 is a building block for developers, so using it does involve a little code or a tool that has it built in.
What is the difference between Gemma 4 and EmbeddingGemma 2?
Gemma 4 generates text. EmbeddingGemma 2 turns content into vectors for search and sorting, and does not generate anything.
Can EmbeddingGemma 2 search images with a text query?
Yes. Text, images, audio and video share one vector space, so a typed description can be compared directly with a photo or a recording.
Which Gemma 4 size should I pair with EmbeddingGemma 2?
The 12B is a good default on a 16 GB machine. The embedding model adds at most 1.3 GB. See the model comparison and benchmarks.
Can both run offline?
Yes. Once downloaded, neither needs a connection, and both are Apache 2.0.
Is there a hosted EmbeddingGemma 2 API?
Not from Google yet; it says a Model Garden listing is coming soon. You can serve it yourself in minutes with Ollama.
Can I use Gemma 4 inside other tools?
Yes. Any app that accepts an OpenAI-style endpoint can point at a local Gemma 4 server. See coding and Gemma 4 vs Claude Code.
Get both models and start building
One chat model and one search model, both free and both able to run on your own machine.