Embeddings
Revised
Embeddings turn text into numeric vectors you can store in a vector database, search with cosine similarity, or use in retrieval-augmented generation (RAG)1 pipelines. The vector length depends on the model (typically 384–1024 dimensions).
Generate embeddings
CLI
Generate embeddings directly from the command line:
ollama run embeddinggemma "Hello world"
You can also pipe text to generate embeddings:X42
echo "Hello world" | ollama run embeddinggemma
Output is a JSON array.
cURL
curl -X POST http://localhost:11434/api/embed \
-H "Content-Type: application/json" \
-d '{
"model": "embeddinggemma",
"input": "The quick brown fox jumps over the lazy dog."
}'
Python
import ollama
single = ollama.embed(
model='embeddinggemma',
input='The quick brown fox jumps over the lazy dog.'
)
print(len(single['embeddings'][0])) # vector length
JavaScript
import ollama from 'ollama'
const single = await ollama.embed({
model: 'embeddinggemma',
input: 'The quick brown fox jumps over the lazy dog.',
})
console.log(single.embeddings[0].length) // vector length
Note: The
/api/embedendpoint responds with2 L2‑normalized (unit‑length) vectors.
Generate a batch of embeddings
Pass an array of strings to input.
cURL
curl -X POST http://localhost:11434/api/embed \
-H "Content-Type: application/json" \
-d '{
"model": "embeddinggemma",
"input": [
"First sentence",
"Second sentence",
"Third sentence"
]
}'
Python
import ollama
batch = ollama.embed(
model='embeddinggemma',
input=[
'The quick brown fox jumps over the lazy dog.',
'The five boxing wizards jump quickly.',
'Jackdaws love my big sphinx of quartz.',
]
)
print(len(batch['embeddings'])) # number of vectors
JavaScript
import ollama from 'ollama'
const batch = await ollama.embed({
model: 'embeddinggemma',
input: [
'The quick brown fox jumps over the lazy dog.',
'The five boxing wizards jump quickly.',
'Jackdaws love my big sphinx of quartz.',
],
})
console.log(batch.embeddings.length) // number of vectors
Tips
- Use cosine similarity for most semantic search use cases.
- Use the same embedding model for both indexing and querying.
Notes on this page
1 Wording Audit: improved Spells out the acronym at its first use.
Was:
RAGSpellOutFirstAuditor: Spelling out retrieval-augmented generation before introducing RAG helps readers who do not know the acronym.
2 Wording Audit: improved An endpoint responds with a result; a function returns one.
Was:
returnsReturnsRespondscode-returns-respondsAuditor: “Responds with” reads naturally for an API endpoint and preserves the claim that the endpoint provides normalized vectors.
Questions for the owner
X42 Embedding CLI example uses different models. The CLI reference and Embeddings page both show piping text to an embedding model, with different models. Should both pages use the same embedding model?
Pages: CLI reference, Embeddings
Original
Embeddings turn text into numeric vectors you can store in a vector database, search with cosine similarity, or use in RAG pipelines. The vector length depends on the model (typically 384–1024 dimensions).
Generate embeddings
CLI
Generate embeddings directly from the command line:
ollama run embeddinggemma "Hello world"
You can also pipe text to generate embeddings:
echo "Hello world" | ollama run embeddinggemma
Output is a JSON array.
cURL
curl -X POST http://localhost:11434/api/embed \
-H "Content-Type: application/json" \
-d '{
"model": "embeddinggemma",
"input": "The quick brown fox jumps over the lazy dog."
}'
Python
import ollama
single = ollama.embed(
model='embeddinggemma',
input='The quick brown fox jumps over the lazy dog.'
)
print(len(single['embeddings'][0])) # vector length
JavaScript
import ollama from 'ollama'
const single = await ollama.embed({
model: 'embeddinggemma',
input: 'The quick brown fox jumps over the lazy dog.',
})
console.log(single.embeddings[0].length) // vector length
Note: The
/api/embedendpoint returns L2‑normalized (unit‑length) vectors.
Generate a batch of embeddings
Pass an array of strings to input.
cURL
curl -X POST http://localhost:11434/api/embed \
-H "Content-Type: application/json" \
-d '{
"model": "embeddinggemma",
"input": [
"First sentence",
"Second sentence",
"Third sentence"
]
}'
Python
import ollama
batch = ollama.embed(
model='embeddinggemma',
input=[
'The quick brown fox jumps over the lazy dog.',
'The five boxing wizards jump quickly.',
'Jackdaws love my big sphinx of quartz.',
]
)
print(len(batch['embeddings'])) # number of vectors
JavaScript
import ollama from 'ollama'
const batch = await ollama.embed({
model: 'embeddinggemma',
input: [
'The quick brown fox jumps over the lazy dog.',
'The five boxing wizards jump quickly.',
'Jackdaws love my big sphinx of quartz.',
],
})
console.log(batch.embeddings.length) // number of vectors
Tips
- Use cosine similarity for most semantic search use cases.
- Use the same embedding model for both indexing and querying.
What Changed
Fixed the two wording findings: RAG is now spelled out where it first appears, and the endpoint "responds with" vectors instead of "returns" them. Nothing else changed. The CLI example uses a different embedding model from the CLI reference page, so that line carries the inventory question.
Content type: task. The page shows how to generate embeddings, one text or a batch, from the CLI, the REST API, and the SDKs.
Automated check, original: 0 errors, 1 warnings, 1 suggestions. Revised: 0 errors, 0 warnings, 0 suggestions.
Independent audit (GPT-6): mixed. The revision improves the acronym wording and makes the endpoint sentence clearer. It also leaves an unexplained inventory marker in the page, which makes the revision less ready to publish.
Regressions:
- The unexplained ⟦X42⟧ marker appears after the CLI instruction, and the notes list it as an inventory question without stating the question for the documentation owner.
What the revision missed:
- The standard says that when a reader has something to do, the page should end with the action; this page ends with general tips rather than telling readers what to do next.