All guides

Generate and check batch text embeddings with Ollama's /api/embed endpoint

Pass an array of strings as input to /api/embed to get several vectors in one call, check the count and dimensions, then verify each sentence's vector with its own request.

AINavWritten / Updated Sources checked
On this page

At a glance

Before comparing texts you need vectors that are reliable and correctly labeled. This guide sends three synthetic support questions to the /api/embed endpoint of a local Ollama in one call, gets three vectors back, and confirms before any comparison that the response structure is sound and that each vector belongs to A, B or C. The official page says input can be a single string or an array of strings, so a batch needs only one request. You need Ollama running on port 11434 and an embedding model you already have.

Workflow

  1. Check the request

    model and input are required; input may be a string or an array of strings.

  2. Check the response

    embeddings is a nested array. Also read model, the durations and prompt_eval_count.

  3. Compare last

    Compute similarity in your own client code only after the count, the dimensions and the per-sentence correspondence are confirmed.

Each stage cites official sources.

Before you start

  • Ollama is running locally. The official example uses http://localhost:11434, so substitute your own host or port if you changed it.
  • You have a model that can produce embeddings. The official example uses embeddinggemma, but this guide did not check whether it exists on your machine, so use an embedding model you have downloaded.
  • A terminal or script environment that can send JSON requests; the official example uses curl.
  • Synthetic text only: do not include real customers, accounts or internal material.

1. Decide what to compare

Write three synthetic sentences outside the terminal: A "How do I reset the demo account password", B "What if I forgot the demo account password", C "Inspection interval for server room air conditioning". Note the order A, B, C, which you will need for checking.

2. Build the batch request body

The body is JSON with required model and input. Write input as an array of the three strings and model as an embedding model you have. The page also lists optional truncate (default true, truncating inputs beyond the context window; false returns an error), dimensions, keep_alive and options. For a first attempt, leave them all out and confirm the basic call works.

3. POST to /api/embed

Run a curl like the official example against http://localhost:11434/api/embed, passing your JSON with -d. The official example sends one string; the array form follows the page's description of the input type. It is a single call with no loop. If it hangs, press Ctrl+C in the terminal to stop it.

4. Check the count

After a 200 response, inspect embeddings. It should be an array of arrays whose outer length equals the number of texts you sent, 3. If it holds one vector or none, stop and recheck the request body before comparing anything.

5. Check dimensions and model

Count the length of each vector. All three should match, and the returned model field should be the model you requested. The dimensions parameter sets the number of dimensions to generate, so if you set it, the actual length should agree. The page does not say which models support it, so test it yourself.

6. Read timing and input size

total_duration and load_duration use nanoseconds; prompt_eval_count is the number of input tokens processed. Record the returned values. The documentation gives no performance threshold, and this guide does not infer first-call behavior or anomaly causes from them.

7. Verify each sentence's correspondence, then compare

The page does not explicitly say that returned vectors follow input order, so request each of A, B and C alone (one call each, with input as a single string) and compare each result with the batch vector at the same position: A with entry 1, B with entry 2, C with entry 3. Assign the labels A, B and C to the batch vectors only if all three match. If any pair differs or the comparison is inconclusive (for example, tiny numeric differences you cannot judge), assign no labels, do not compare, and leave the correspondence unconfirmed. Once confirmed, compute similarity in your own code; that is client-side work, not an endpoint feature. Then stop and do not store the vectors elsewhere.

Original example

Request body (original illustration): {"model": "your downloaded embedding model", "input": ["How do I reset the demo account password", "What if I forgot the demo account password", "Inspection interval for server room air conditioning"]}. Send it with -d to http://localhost:11434/api/embed. Accept the structure first: embeddings has 3 outer entries, every entry has the same length, model matches the request, and the duration and count fields are present. Then request A, B and C each alone and compare them with batch entries 1, 2 and 3. Only if all three match do you hand the labeled vectors A, B and C to your own similarity script; if any is different or unclear, keep the labels unconfirmed and do not compare. No numeric values are shown because nothing was actually run.

Completion checks

  • Does the outer length of embeddings equal the length of the input array?
  • Are all vectors the same length, and does it equal dimensions if you set one?
  • Does the returned model match the model name you requested?
  • Do the single requests for A, B and C match batch entries 1, 2 and 3 respectively? Confirm correspondence only if all three do.
  • Is there an error? With truncate set to false, over-long text should return an error rather than be cut.

Limits

  • A successful response does not prove semantic quality; the page documents the interface format, not how well any model compares texts.
  • Do not put real private text in requests; every sentence here is synthetic.
  • Do not assume dimensions or options work for every model without testing.
  • The endpoint returns embeddings and response metadata. Similarity computation, thresholds, ranking and storage belong to the client workflow and need separate design.
  • Checking only part of the correspondence, such as A alone, does not establish order; the remaining labels stay unconfirmed.

Verification scope

Only the official /api/embed documentation was read. No login, no installation of Ollama, no execution of the product API, no file upload, and no generated output were tested. The request body is an original illustration and no response values are given.

Article sources

Original editorial content; official descriptions and checking suggestions are distinguished.

  1. Ollama · Official sources
    View details