Home›Guides›Ollama embeddings: /api/embed, 4 embedding models and a tiny RAG, tested (v0.40.17)

Setup · Guide

Ollama embeddings: /api/embed, 4 embedding models and a tiny RAG, tested (v0.40.17)

To get Ollama embeddings, send POST /api/embed with a model and an input, either one string or a list of strings. Ollama answers with embeddings: a list of vectors, one per text, already normalized to length 1. You need an embedding model such as embeddinggemma or nomic-embed-text; a chat model won’t do it.

Measured and written by Local AI ScopePublished Figures measured by Local AI Scope

To get Ollama embeddings, send POST /api/embed with a model and an input, either one string or a list of strings. Ollama answers with embeddings: a list of vectors, one per text, already normalized to length 1. You need an embedding model such as embeddinggemma or nomic-embed-text; a chat model won’t do it.

We tested all of it on 24 November 2026 with Ollama 0.40.17, the latest stable release that day: the official Linux binary, an AMD Ryzen 7 7730U CPU with no GPU and four embedding models side by side. Every error message below is copied from the server’s real output, and there were quite a few of them, because breaking things on purpose is half the fun.

OllamaOllamaRuntime sheet

Your first embedding with /api/embed

The request is short. With the model already pulled (ollama pull embeddinggemma), this is all it takes:

curl -s http://localhost:11434/api/embed -d '{
  "model": "embeddinggemma",
  "input": "How do I run a language model on my own computer?"
}'

The answer is a JSON object with embeddings, a list of lists. With a single string you still get a list with one vector inside, so your code can always read embeddings[0]. With a list of three sentences you get three vectors, in the same order, in one request. It also returns prompt_eval_count (how many tokens it read) and the timings.

Terminal with Ollama 0.40.17: /api/embed returns one 768-dimension vector for embeddinggemma, and three vectors for a list of three sentences
One string, one vector of 768 numbers; three sentences, three vectors Output of our test, Ollama 0.40.17, 24 Nov 2026

From Python you don’t need any special library. This is the same request with requests:

import requests

r = requests.post("http://localhost:11434/api/embed",
                  json={"model": "embeddinggemma", "input": ["first text", "second text"]})
vectors = r.json()["embeddings"]   # one list of floats per text
print(len(vectors), len(vectors[0]))   # 2 768

And if you only want to peek, the command line works too: ollama run all-minilm "Hello world" printed the vector as a JSON array straight into our terminal, 384 numbers in a row.

Which embedding models Ollama runs: 4 embedding models compared

There are many in the Ollama library; we picked four that cover the range, from a tiny one to a 0.6B, and ran them on the same machine. The size, dimensions and context come from ollama show (the model’s own metadata); the memory and the cold load we measured.

Model Parameters Quantization · download Dimensions Context (model) Memory loaded (measured) Cold load (measured)
all-minilm 23M F16 · 45 MB 384 512 (Ollama sets num_ctx 256) 49 MB 0.27 s
nomic-embed-text 137M F16 · 274 MB 768 2,048 389 MB 0.51 s
embeddinggemma 307.58M BF16 · 621 MB 768 2,048 693 MB 1.30 s
qwen3-embedding:0.6b 595.78M Q8_0 · 639 MB 1,024 32,768 (Ollama used 4,096) 1.24 GB (1.72 GB at num_ctx 8192) 1.35 s

Measured on Ollama 0.40.17, AMD Ryzen 7 7730U, CPU only, 24 November 2026. Memory from /api/ps; cold load is the load_duration of the first request.

None of them needs a graphics card: even the biggest one fits in under 2 GB of RAM. Which one to choose depends on your texts. all-minilm is tiny and the fastest by far, but it only reads 256 tokens per text in Ollama, so long documents get cut. embeddinggemma was the one that best separated similar sentences from unrelated ones in our test (more on that below). qwen3-embedding:0.6b accepts much longer texts and has the largest vectors, at the price of being the slowest of the four.

/api/embed vs /api/embeddings vs /v1/embeddings

Ollama has three routes that return embeddings, and they don’t behave the same. With v0.40.17:

  • /api/embed is the current one: field input, answer embeddings (plural), normalized vectors, string or list.
  • /api/embeddings is the old one, which the documentation marks as superseded by /api/embed: field prompt, answer embedding (singular), one text only, and the vector comes without normalizing. With nomic-embed-text its length was 21.63 instead of 1, although it points in exactly the same direction (cosine 1.0 against the one from /api/embed).
  • /v1/embeddings is the OpenAI-compatible route: vectors in data[].embedding, tokens in usage.prompt_tokens, normalized, and it accepted a list, dimensions and encoding_format: "base64". The 0.40.17 documentation lists arrays of tokens and the user field as unsupported.
Terminal with Ollama 0.40.17: /api/embed vectors have norm 1, /api/embeddings returns norm 21.63, and input on the old endpoint returns an empty embedding with HTTP 200
Norm 1 on the new route, 21.63 on the old one, and the empty vector you get by sending input to the old route Output of our test, Ollama 0.40.17, 24 Nov 2026

The last line of that screenshot is the nastiest trap. If you send input (the new field name) to the old /api/embeddings route, Ollama doesn’t complain: it returns HTTP 200 with "embedding": []. No error, just an empty vector that your vector database will happily store. And if you send a list in prompt, the old route answers with a 400: json: cannot unmarshal array into Go struct field EmbeddingRequest.prompt of type string. If you have old code, move it to /api/embed; if you mix vectors from both routes, keep in mind that one is normalized and the other isn’t.

Shorter vectors with the dimensions field

Since /api/embed accepts dimensions, you can ask for shorter vectors to save space in the database. With "dimensions": 256, all four models returned 256 values, normalized to length 1 again. If you ask for more than the model has, it fails with a 400 and a clear message:

Terminal with Ollama 0.40.17: dimensions 256 returns a 256-value vector with norm 1, dimensions 2048 exceeds embedding length 768
256 dimensions with norm 1, and the error when you ask for more than the model’s 768 Output of our test, Ollama 0.40.17, 24 Nov 2026

The message changes with the model: exceeds embedding length 384 in all-minilm, 768 in nomic-embed-text and embeddinggemma, 1024 in qwen3-embedding. One honest note: Ollama accepted dimensions in all four, including all-minilm, and we didn’t measure how much a shortened vector loses. Test it with your own texts before shrinking, and never compare a 256-dimension vector with a 768 one.

“the input length exceeds the context length”: truncate and num_ctx

Each embedding model reads a maximum number of tokens. We sent all four the same text of 39,999 characters (6,801 tokens for qwen3-embedding). By default /api/embed has truncate set to true, and what it does is cut the end of the text without telling you: it returned a vector and a prompt_eval_count of 256 in all-minilm, 2,048 in nomic-embed-text and embeddinggemma, and 4,095 in qwen3-embedding. Everything after that point simply doesn’t exist for the vector.

With "truncate": false the four models refuse the text with HTTP 400 and this message, word for word:

{"error":"the input length exceeds the context length"}
Terminal with Ollama 0.40.17: the input length exceeds the context length error with truncate false, and qwen3-embedding cutting at 4095 tokens unless num_ctx is 8192
The 400 with truncate: false; qwen3-embedding reads 4,095 tokens by default and 6,801 with num_ctx 8192 Output of our test, Ollama 0.40.17, 24 Nov 2026

The surprise was qwen3-embedding. Its model supports 32,768 tokens, but it stopped at 4,095, because what limits it in Ollama is num_ctx, the context window that Ollama opens for the model, and on our machine that was 4,096. Passing "options": {"num_ctx": 8192} it read the 6,801 tokens of the text, in 57 seconds on our CPU, with 1.72 GB of memory. With nomic-embed-text the same trick doesn’t help: it stays in 400, because the model’s own limit is 2,048. If you want to understand how num_ctx works, it’s explained in our Ollama context length guide.

“This server does not support embeddings”: a chat model on /api/embed

What happens if you ask a chat model for an embedding? We tried it with gemma3:270m, and Ollama 0.40.17 answered with HTTP 501 and a message that is confusing, because it seems to talk about your server:

{"error":"This server does not support embeddings. Start it with `--embeddings`"}

There’s no flag to add: ollama serve --help lists only --help. In our server log, Ollama started its inference engine with --embedding for the four embedding models and without it for gemma3:270m. The solution is to use an embedding model. Through /v1/embeddings it’s the same message in OpenAI format, with "type":"api_error".

Terminal with Ollama 0.40.17: gemma3:270m on /api/embed returns HTTP 501 This server does not support embeddings, and nomic-embed-text on /api/chat does not support chat
A chat model on /api/embed gives a 501; an embedding model on /api/chat, a 400 Output of our test, Ollama 0.40.17, 24 Nov 2026

The other way round also fails, with a clearer message: an embedding model on /api/chat returns 400 "nomic-embed-text" does not support chat, and on /api/generate, does not support generate. It happened with qwen3-embedding:0.6b too, even though ollama show lists tools and thinking among its capabilities next to embedding. To know what a model is for, look at that Capabilities block: if it says embedding, it’s for /api/embed.

“model not found”: the 404 on /api/embeddings and /api/embed

This 404 is the least mysterious one: a name that doesn’t match any model you’ve downloaded. We wrote nomic-embed instead of nomic-embed-text, and each route told us in its own way:

Terminal with Ollama 0.40.17: model not found errors with HTTP 404 on /api/embeddings and /api/embed
The same typo, two wordings: the old route suggests pulling the model Output of our test, Ollama 0.40.17, 24 Nov 2026

The fix is to copy the exact name from ollama list, or download it with ollama pull nomic-embed-text. Two more routes that fail: the route written in the singular, /api/embedding, returns a plain 404 page not found, and /api/embeddings/ with a final slash returns a 307 redirect instead of a vector. And one that doesn’t fail but should worry you: an empty input ("", [] or no field at all) returns HTTP 200 with "embeddings": []. If a text arrives empty in your pipeline, Ollama won’t stop you.

Cosine similarity and a tiny Ollama RAG

This is where the fun starts. We took two questions that mean the same thing (“How do I run a language model on my own computer?” and “What is the way to use an LLM locally on my PC?”) and one about paella, and calculated the cosine between them with each model:

Model Similar questions Question vs paella Gap
all-minilm 0.40 0.08 0.32
nomic-embed-text 0.61 0.38 0.23
embeddinggemma 0.79 0.18 0.61
qwen3-embedding:0.6b 0.82 0.32 0.50

Measured on Ollama 0.40.17, 24 November 2026, with the vectors from /api/embed.

The lesson is that the absolute number means nothing from one model to another: 0.61 is “very similar” in nomic-embed-text and would be mediocre in qwen3-embedding. What counts is the distance between similar and unrelated, and embeddinggemma gave the largest one. So never reuse a similarity threshold when you change models.

With that, a minimal RAG (retrieval-augmented generation: find the right piece of text before asking the model) fits in a few lines. Six sentences, three questions, and for each question the sentence with the highest score:

import sys, requests

MODEL = sys.argv[1] if len(sys.argv) > 1 else "embeddinggemma"
URL = "http://localhost:11434/api/embed"
docs = ["Ollama listens on port 11434 by default.",
        "OLLAMA_HOST changes the address and port Ollama binds to.",
        "A 7B model in Q4_K_M needs about 5 GB of memory.",
        "Paella is a rice dish from Valencia.",
        "nomic-embed-text returns vectors with 768 dimensions.",
        "The keep_alive parameter controls how long a model stays in memory."]
questions = ["Which port does Ollama use?", "How much RAM for a 7B model?",
             "How long does a model stay loaded?"]

def embed(texts):
    r = requests.post(URL, json={"model": MODEL, "input": texts})
    r.raise_for_status()
    return r.json()["embeddings"]

doc_vecs = embed(docs)                      # index once
for q, qv in zip(questions, embed(questions)):
    scores = [sum(a * b for a, b in zip(qv, dv)) for dv in doc_vecs]
    best = max(range(len(docs)), key=scores.__getitem__)
    print(f"{q} -> {docs[best]} ({scores[best]:.2f})")
Terminal with Ollama 0.40.17: a minimal RAG script finds the right sentence for three questions with embeddinggemma and qwen3-embedding
Three questions, three right answers, with embeddinggemma and with qwen3-embedding Output of our test, Ollama 0.40.17, 24 Nov 2026

All four models got the 3 questions right. The difference was in the margin: for “Which port does Ollama use?”, the right sentence beat the second one (the one about OLLAMA_HOST, which also mentions ports) by 0.13 in qwen3-embedding, 0.05 in nomic-embed-text, 0.04 in all-minilm and only 0.01 in embeddinggemma. With six sentences that’s enough; with thousands of chunks, a narrow margin is where the wrong passage sneaks in. We also tried nomic-embed-text with its search_query: and search_document: prefixes: 3 out of 3 as well, with a wider margin on the port question (0.07) and narrower ones on the other two. To go from six sentences to real documents (chunking, a chat model that answers with citations and the num_ctx limit), see our Ollama RAG guide.

Opens on YouTube (no cookies) only when you press play.

Ten minutes on what an embedding is, similarity search, Ollama’s three embedding routes and which one to use, and a comparison of several embedding models. It was published in September 2024, so the model list is older than the one in our table. If you’d rather have a graphical interface on top of Ollama, we explain how to set one up in our Open WebUI with Ollama guide.

Speed on a CPU without a GPU: one by one or in a batch

We embedded 32 short sentences (about 22 tokens each) in two ways: 32 requests with one text each, and a single request with the list of 32. One run per model, on Ollama 0.40.17 and the same Ryzen 7 7730U without a GPU:

Model 32 requests × 1 text 1 request × 32 texts
all-minilm 167 texts/s 216 texts/s
nomic-embed-text 37 texts/s 44 texts/s
embeddinggemma 29 texts/s 37 texts/s
qwen3-embedding:0.6b 10 texts/s 13 texts/s

Measured on Ollama 0.40.17, 24 November 2026, one run, CPU only. Your figures will change with your processor.

Sending the list in one request was faster with all four, between 18 % and 30 % in this run, and it also saves you the code of a loop. The real gap is between models: all-minilm went through the 32 sentences in a fraction of a second, while qwen3-embedding took 2.5 seconds. With long texts the difference grows: qwen3-embedding needed 27 seconds for its 4,095 tokens, and nomic-embed-text 2.9 seconds for its 2,048. Doing the sums with this run (an estimate), 10,000 sentences as short as ours (about 22 tokens) would take all-minilm under a minute and qwen3-embedding about 13 minutes; with longer chunks, much more. If you want to call Ollama from more languages or see the other routes, everything is in our Ollama API guide, and if your next step is letting the model call your own functions, see Ollama tool calling.