Skip to content
safran

Type to search. Enter opens the first result.

    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-m3

    That 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 sync

    safran 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/data

    The same from the SDK:

    index-status.ts
    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: 30m

    If url points at another machine, chunk text is sent to that machine.

    Configuration reference

    FieldTypeDefaultRequiredMeaning
    type"ollama"yesSelects this plugin.
    modelstringbge-m3noModel name as Ollama knows it. Part of the embedder id.
    urlURLhttp://localhost:11434noRoot of the Ollama server. No credentials, query string or fragment.
    batch_sizeinteger, 1 to 25632noInputs per request.
    timeout_msinteger, at least 1000120000noTimeout of one attempt, in milliseconds. A cold model load can take tens of seconds on CPU.
    keep_alivestringnoHow 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/embed with the model, the list of inputs and truncate: true; keep_alive is added when set.
    • Batching. Inputs are sent batch_size at 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 to DEFAULT_OLLAMA_MAX_RETRIES times, 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:

    1. The batch is sent as usual.
    2. If the server refuses it for length, its inputs are embedded one by one.
    3. 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 to DEFAULT_MAX_SHORTEN_ATTEMPTS (6) times. A warning is logged when a shortened version was embedded.
    4. An input that still does not fit fails with INVALID_INPUT, with details.reason set to input_too_long and details.input to 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 with INDEX_NOT_READY until 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 status and safran doctor report the repositories built with another embedder, and IndexStatus.repos[].stale is true for them.

    • safran sync re-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

    ConstantValueMeaning
    DEFAULT_OLLAMA_BATCH_SIZE / MAX_OLLAMA_BATCH_SIZE32 / 256Default and largest batch_size.
    DEFAULT_OLLAMA_TIMEOUT_MS120000Default timeout_ms.
    MIN_EMBEDDER_TIMEOUT_MS1000Smallest timeout_ms a profile may set.
    DEFAULT_OLLAMA_MAX_RETRIES2Retries after the first attempt.
    DEFAULT_SHORTEN_FACTOR0.75Share of an input kept by each shortening step.
    DEFAULT_MAX_SHORTEN_ATTEMPTS6Shortening 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: true does not prevent length errors. A 5,906-character chunk was refused with 413 the input length exceeds the context length although 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