Ollama
The ollama embedder turns code chunks and search queries into vectors by calling an Ollama server on your machine. It is the default: a profile without an embeddings block uses ollama with the model bge-m3. Nothing leaves the machine. This page covers the entry, how requests are batched and retried, what happens to inputs the model refuses, and why changing the model means indexing again.
Profile entry
type: ollama
model: bge-m3That block is also what you get when embeddings is left out. The model has to be present in Ollama:
ollama pull bge-m3
safran doctor
safran syncsafran doctor makes one embedding call and reports the embedder; safran sync embeds what changed. safran status shows which embedder the index was built with:
$ safran status --profile /work/acme/safran.yaml
profile acme /work/acme/safran.yaml
trackers none
code hosts disk (local)
doc sources none
knowledge 0 groups, 0 teams, 0 glossary terms
environment no variables referenced
index 2 repos, 2 chunks, embedder ollama:bge-m3, oldest index just now
links not applicable: no code host in the profile lists pull requests
data /work/acme/dataThe same from the SDK:
import { createSafran } from "@safran/core";
await using safran = await createSafran({ profile: "safran.yaml" });
const status = await safran.code.status();
console.log(status.embedder); // ollama:bge-m3
for (const repo of status.repos) console.log(repo.name, repo.chunks, repo.embedder, repo.stale === true ? "needs sync" : "");Another server, another model
type: ollama
model: bge-m3
url: http://ollama.acme.test:11434
batch_size: 16
timeout_ms: 300000
keep_alive: 30mIf url points at another machine, chunk text is sent to that machine.
Configuration reference
| Field | Type | Default | Required | Meaning |
|---|---|---|---|---|
type | "ollama" | yes | Selects this plugin. | |
model | string | bge-m3 | no | Model name as Ollama knows it. Part of the embedder id. |
url | URL | http://localhost:11434 | no | Root of the Ollama server. No credentials, query string or fragment. |
batch_size | integer, 1 to 256 | 32 | no | Inputs per request. |
timeout_ms | integer, at least 1000 | 120000 | no | Timeout of one attempt, in milliseconds. A cold model load can take tens of seconds on CPU. |
keep_alive | string | no | How long Ollama keeps the model in memory after a call (5m, or -1 for forever). Unset leaves Ollama's own default. |
The entry has no id: a profile has exactly one embedder. There is no token field; the connector sends no credentials.
How it calls Ollama
- Endpoint.
POST <url>/api/embedwith the model, the list of inputs andtruncate: true;keep_aliveis added when set. - Batching. Inputs are sent
batch_sizeat a time, one request after the other. Requests are not sent in parallel: the model works through its queue at a fixed rate, so parallel requests would not be faster. - Timeout and retries. Each attempt may take
timeout_ms. A failed attempt (a network failure, or a retryable status such as 429 or 503) is retried up toDEFAULT_OLLAMA_MAX_RETRIEStimes, one fewer than the default of the shared HTTP client: a local server that is down stays down, and each attempt may wait the full timeout. - Vectors. Every answer is checked: one vector per input, all of the same size, every value a finite number. Vectors are scaled to unit length. A response that fails the check is
UPSTREAM.
Two failures get their own message, because they are the common ones:
$ safran search "refund amount" --profile /work/acme/safran.yaml
✘ Cannot reach Ollama at http://localhost:11999
→ Start it with `ollama serve`, or set `embeddings.url` in the profile.A model that is not pulled is reported as UPSTREAM with the message Ollama does not have the model "<model>" and the hint to run ollama pull.
Reading tickets, safran grep, safran read and lexical search (safran search --mode lexical) do not need the embedder at all. It is built on first use, so an Ollama that is not running only fails the calls that embed.
Inputs the model refuses as too long
truncate: true asks Ollama to cut inputs that exceed the model's context. It is not a guarantee: the server can still refuse a whole request because one input is too long (HTTP 413, or a 400, 422 or 500 whose error text says so). One such chunk must not fail the batch, and with it the index run of a repository, so the embedder handles it:
- The batch is sent as usual.
- If the server refuses it for length, its inputs are embedded one by one.
- An input that is refused on its own is shortened to
DEFAULT_SHORTEN_FACTOR(75 %) of its text, cut at a line break or a space when one is near, and tried again, up toDEFAULT_MAX_SHORTEN_ATTEMPTS(6) times. A warning is logged when a shortened version was embedded. - An input that still does not fit fails with
INVALID_INPUT, withdetails.reasonset toinput_too_longanddetails.inputto its position.
The code index reads that last error and skips only the one chunk: it is stored without a vector, so lexical search and grep still find it while the dense channel does not, and it is counted in the sync result under filesSkipped.chunk_too_long_for_embedder. A shortened chunk is embedded from its beginning; the stored text is still the whole chunk.
The embedder id, and changing the model
The embedder's id is ollama:<model>, for example ollama:bge-m3. The index records, per repository, the id its vectors were made with, and vectors from different ids never mix: two models place text in different spaces, so comparing a query vector from one with chunk vectors from the other would produce numbers that mean nothing.
What that means in practice when you change model (or switch to another embedder type):
-
Search that uses vectors (
auto,hybrid,dense) fails withINDEX_NOT_READYuntil the repositories are indexed again:$ safran search "refund amount" --profile /work/acme/safran.yaml ✘ The code index holds vectors from "ollama:bge-m3" but the configured embedder is "ollama:acme-embed-v2" (repositories: ledger, payments-api) → Run `safran sync` to re-index these repositories with the configured embedder, or configure the embedder they were built with. Until then only lexical search (mode "lexical"), grep and reading files work. -
Lexical search, grep and reading files keep working in the meantime.
-
safran statusandsafran doctorreport the repositories built with another embedder, andIndexStatus.repos[].staleistruefor them. -
safran syncre-embeds every chunk of such a repository, not only the changed files. -
Cached vectors are keyed by embedder id and chunk text, and vectors no chunk uses any more are kept for 30 days. Going back to the previous model within that time re-indexes from the cache without calling the model.
If a model is replaced under the same name by one with another vector size, the id does not change and Safran cannot see it in advance. Search then fails with INDEX_NOT_READY ("The index holds N-dimensional vectors but the embedder returned M"); delete the index directory and run safran sync.
Limits
| Constant | Value | Meaning |
|---|---|---|
DEFAULT_OLLAMA_BATCH_SIZE / MAX_OLLAMA_BATCH_SIZE | 32 / 256 | Default and largest batch_size. |
DEFAULT_OLLAMA_TIMEOUT_MS | 120000 | Default timeout_ms. |
MIN_EMBEDDER_TIMEOUT_MS | 1000 | Smallest timeout_ms a profile may set. |
DEFAULT_OLLAMA_MAX_RETRIES | 2 | Retries after the first attempt. |
DEFAULT_SHORTEN_FACTOR | 0.75 | Share of an input kept by each shortening step. |
DEFAULT_MAX_SHORTEN_ATTEMPTS | 6 | Shortening steps before an input is given up (about 18 % of the text is left). |
Known caveats
Nothing in this connector is marked UNVERIFIED. The source records two things observed on a real Ollama (version 0.40.13 with bge-m3) that explain the design above:
truncate: truedoes not prevent length errors. A 5,906-character chunk was refused with413 the input length exceeds the context lengthalthough truncation was requested.- The effective limit cannot be looked up. Ollama cut inputs to 2,048 tokens for that model whatever context size was requested, while its model information reported 8,192. The connector therefore does not try to clip inputs in advance; it shortens only what the server refuses.
Both are observations of one version, not guarantees about others. The kind hint of the embedder contract (query or document) is not used by this connector: queries and chunks are embedded the same way.
See also
- OpenAI-compatible, the other built-in embedder.
- Code search in the SDK and requirements.
- Evaluation, for measuring whether another model searches your code better before you switch.