Gemma 4 & EmbeddingGemma 2 on Ollama
Ollama is the most popular way to run Google's open models on your own machine. One command downloads a model, keeps it ready in the background, and gives every app on your computer a local API. This guide covers both the chat model and the new search model.
Windows, macOS and Linux · free · sizes from Ollama's library ·
Up and running in three steps
Install Ollama
Download it from ollama.com/download. On Linux:
curl -fsSL https://ollama.com/install.sh | shRun a Gemma 4 model
In a terminal:
ollama run gemma4:12b-it-qat. The first run downloads 7.2 GB, then opens a chat. On an 8 GB machine usegemma4:e4b-it-qat.Add the search model if you want it
ollama pull embeddinggemma-2adds EmbeddingGemma 2 in 1.3 GB.
Step-by-step help for each system is in the install guide; Mac details in Mac setup. Prefer an app with buttons? See LM Studio.
Commands you will use
In the terminal
ollama pull gemma4:12b-it-qat # download a model ollama run gemma4:12b-it-qat # chat in the terminal ollama run gemma4 "roses are red" # one-off prompt ollama list # models you have ollama ps # models loaded now, and on what ollama show gemma4:12b-it-qat # details of a model ollama stop gemma4:12b-it-qat # unload from memory ollama rm gemma4:12b-it-qat # delete to free disk
Inside a chat
/set system You are a concise assistant. /set parameter num_ctx 32768 # longer memory for this chat /set think # reason before answering /set nothink # answer straight away /clear # forget the conversation so far /bye # leave
Ask about a picture
ollama run gemma4:12b-it-qat "What is in this image? ./photo.png"
Put the image's file path in the prompt. Every Gemma 4 size reads images.
Thinking controls from Ollama's thinking documentation. More on using the model in how to use Gemma 4, chat and prompting.
Three settings worth changing
Context length
Gemma 4 holds 128K or 256K tokens, but Ollama starts a model with a much smaller window. Raise it if long chats lose their beginning. More context uses more memory.
Thinking
On for maths, code and planning; off for quick chat. Use /set think and /set nothink, or the think field in the API.
Graphics card use
Run ollama ps while a chat is open. If it does not say the model is on the GPU, choose a smaller size or a shorter context.
# Put these two lines in a file called Modelfile: FROM gemma4:12b-it-qat PARAMETER num_ctx 32768 # Then build and run your saved version: ollama create gemma4-32k -f Modelfile ollama run gemma4-32k
Three ways to set the context
For one chat: /set parameter num_ctx 32768. For everything: set OLLAMA_CONTEXT_LENGTH before Ollama starts. For a saved model: a Modelfile, as shown.
Sampling
Google recommends temperature 1.0, top-p 0.95 and top-k 64 for every Gemma 4 size.
Sampling values from Google's model card; around 32K is this site's suggested starting context. What each setting does is covered under capabilities.
Call Gemma 4 from your own code
Once a model is pulled, Ollama serves it at localhost:11434. No key, no internet.
# pip install ollama
import ollama
reply = ollama.chat(
model="gemma4:12b-it-qat",
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Why is the sky blue?"},
],
)
print(reply["message"]["content"])
Ollama's own Python library. There is a JavaScript one too.
curl http://localhost:11434/api/chat -d '{
"model": "gemma4:12b-it-qat",
"messages": [
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Why is the sky blue?"}
],
"think": false,
"stream": false
}'
# pip install openai
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": "user", "content": "Why is the sky blue?"}],
)
print(reply.choices[0].message.content)
Ollama also speaks the OpenAI format at /v1, so existing tools and editor extensions can use it by changing one address.
More on endpoints and hosted alternatives on the API page; connecting an editor is in Gemma 4 coding.
EmbeddingGemma 2 on Ollama
EmbeddingGemma 2 is Google's new open model for search. You do not chat with it: you send it content and it returns a vector, a list of 768 numbers that captures the meaning. It was in Ollama's library the day after release.
| Tag | Parameters | Download | Inputs Ollama lists | Choose it for |
|---|---|---|---|---|
embeddinggemma-2:270m | 270M | 378 MB | Text | Text and code search; the lightest option |
embeddinggemma-2:440m | 440M | 714 MB | Text, image | Text and image search |
embeddinggemma-2:570m | 570M | 990 MB | Text | The build that includes the audio part |
embeddinggemma-2 · :740m | 740M | 1.3 GB | Text, image | The full model |
ollama pull embeddinggemma-2 # full model, 1.3 GB ollama pull embeddinggemma-2:270m # text and code only, 378 MB
curl http://localhost:11434/api/embed -d '{
"model": "embeddinggemma-2",
"input": "What causes the northern lights?"
}'
# Several texts at once: pass a list
curl http://localhost:11434/api/embed -d '{
"model": "embeddinggemma-2",
"input": ["first passage", "second passage", "third passage"]
}'
# pip install ollama
import ollama
out = ollama.embed(
model="embeddinggemma-2",
input=["first passage", "second passage"],
)
print(len(out["embeddings"]), len(out["embeddings"][0])) # 2 768
Ready-to-compare vectors
Ollama's documentation says the embed endpoint returns unit-length vectors, and recommends cosine similarity for search.
Same model both sides
Embed your documents and your queries with the same model and size. Vectors from different models cannot be compared.
Task labels
Google recommends a short task label on text, such as task: search result | query: before a query. Through a raw endpoint you add it yourself.
Shorter vectors
You can keep only the first 512 or 256 numbers to save space, then re-normalise. Google reports a sharp drop at 128 for images.
Tags, sizes and inputs from Ollama's embeddinggemma-2 page; endpoint behaviour from Ollama's embeddings documentation; task labels and quality figures from Google's model card and developer guide.
Each size also has -bf16, -mxfp8 and -nvfp4 variants. Known limits are on the limitations page.
Answer questions from your own documents
With both models pulled, about thirty lines of Python give you private question-answering: EmbeddingGemma 2 finds the right passage, Gemma 4 writes the answer.
# pip install ollama # ollama pull embeddinggemma-2 · ollama pull gemma4:12b-it-qat import ollama 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.", ] question = "Can I get my money back after three weeks?" # 1. Turn the passages and the question into vectors p_vecs = ollama.embed(model="embeddinggemma-2", input=passages)["embeddings"] q_vec = ollama.embed(model="embeddinggemma-2", input=question)["embeddings"][0] # 2. Find the closest passage (the vectors are unit length, so a dot product is enough) scores = [sum(a * b for a, b in zip(q_vec, p)) for p in p_vecs] best = passages[scores.index(max(scores))] # 3. Let Gemma 4 answer from it reply = ollama.chat( 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": f"Context: {best}\n\nQuestion: {question}"}, ], ) print(reply["message"]["content"])
Everything stays local
Both models run through the same Ollama server on your machine. Nothing is sent to a cloud service.
For more documents
Keep the vectors in a vector database instead of a list, and retrieve the top few passages, not just one.
Memory needed
The 12B needs about 6.7 GB for its weights and EmbeddingGemma 2 at most 1.3 GB, so both fit on a 16 GB machine.
This sample was written for this page from Ollama's documented calls and has not been run against live models here. The same idea with Google's Python library is in how to use both.
More things Ollama can do
# Run Google's official GGUF straight from Hugging Face ollama run hf.co/google/gemma-4-12B-it-qat-q4_0-gguf:Q4_0 # No suitable hardware? Ollama's hosted version (your prompts leave your machine) ollama run gemma4:cloud # Use a local model behind Claude Code (unofficial; see the linked page) ollama launch claude # In Docker docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama docker exec -it ollama ollama run gemma4:12b-it-qat
The Claude Code setup and its trade-offs are explained in Gemma 4 vs Claude Code; serving a team is under self-hosting; hosted prices are on the pricing page. Phones use a different app - see mobile downloads and the Android page.
Troubleshooting
| Problem | Likely cause | Fix |
|---|---|---|
| Nothing answers at localhost:11434 | Ollama is not running | Open the app, or run ollama serve |
| Replies are very slow | The model is on the processor, not the graphics card | Check ollama ps; use a smaller size or shorter context |
| It forgets earlier messages | The context window is at its small default | Raise num_ctx |
| Odd symbols or broken tool calls | A model pulled before the July 2026 refresh | ollama pull the same tag again |
| "Model not found" | The tag is mistyped | Ollama tags are lowercase: gemma4:12b, not gemma-4-12B |
| The model changed by itself | You used a general tag that was repointed | Name the size and build explicitly |
| Embedding search gives odd results | Different models or sizes used for documents and queries | Re-embed everything with one tag |
| The disk is filling up | Several large models kept | ollama list, then ollama rm what you do not use |
Causes and fixes are this site's guidance, not an official list. More in the install guide and the FAQ.
Ollama questions
Which Gemma 4 tag should I use on Ollama?
gemma4:12b-it-qat on a 16 GB machine, gemma4:e4b-it-qat on 8 GB, and gemma4:26b-a4b-it-qat or gemma4:31b-it-qat with a 24 GB graphics card.
Is Ollama free?
Running models on your own machine with Ollama is free, and both models are Apache 2.0. Ollama's hosted :cloud option is a separate service with its own terms.
Does it work offline?
Yes. After a model is pulled, it runs with no connection and your prompts stay on your machine.
How do I use EmbeddingGemma 2 with Ollama?
Run ollama pull embeddinggemma-2, then send text to http://localhost:11434/api/embed. You get a vector back for each text.
Can I chat with EmbeddingGemma 2?
No. It only produces vectors. Use a Gemma 4 model for chat, and combine the two to answer questions from your own files.
How do I turn thinking on or off?
In a chat, type /set think or /set nothink. In the API, set the think field to true or false.
How do I update a model?
Run ollama pull with the same tag. Refreshed weights arrive as updates to existing tags.
Ollama or LM Studio?
Ollama if you are comfortable in a terminal or want to script things; LM Studio if you prefer an app with a chat window. Other options are in the runtime selector and the download hub; results to expect are on benchmarks, features and safety.
One command to start
ollama run gemma4:12b-it-qat