OpenAI-compatible embeddings
The openai-compatible embedder calls any server that implements the OpenAI /embeddings endpoint: a local embedding server, an inference server in your own network, or a hosted API. Use it when you do not run Ollama, or when you want a model Ollama does not serve.
Profile entry
A local server without authentication:
type: openai-compatible
url: http://localhost:8080/v1
model: bge-m3An API that needs a key:
type: openai-compatible
url: https://embeddings.acme.test/v1
model: acme-embed-v2
token_env: EMBEDDINGS_API_KEY
dimensions: 1024url is the base URL up to and including the version segment; the connector appends /embeddings. Then:
safran doctor
safran sync
safran search "kısmi iade"import { createSafran, isSafranError } from "@safran/core";
await using safran = await createSafran({ profile: "safran.yaml" });
try {
const { hits } = await safran.code.search("kısmi iade", { limit: 5 });
for (const hit of hits) console.log(hit.repo, hit.path, hit.startLine, hit.channels);
} catch (error) {
// The index was built with another embedder: fall back to words until the next sync.
if (!isSafranError(error, "INDEX_NOT_READY")) throw error;
const { hits } = await safran.code.search("iade", { mode: "lexical", limit: 5 });
for (const hit of hits) console.log(hit.repo, hit.path, hit.startLine);
}Authentication
token_env is optional. When set, the key is sent as Authorization: Bearer, and the variable must hold a value: a missing one fails the first embedding call with AUTH_MISSING, not the start of the program. When the field is left out, no credentials are sent, which suits a local server.
The key is only sent to the origin of url. A redirect to another origin is not followed.
Configuration reference
| Field | Type | Default | Required | Meaning |
|---|---|---|---|---|
type | "openai-compatible" | yes | Selects this plugin. | |
url | URL | yes | Base URL up to and including the version segment, e.g. http://localhost:8080/v1. No credentials, query string or fragment. | |
model | string | yes | Model name sent with every request. Part of the embedder id. | |
token_env | variable name | no | Variable holding the API key. Omit for local servers without auth. | |
batch_size | integer, 1 to 2048 | 64 | no | Inputs per request. |
timeout_ms | integer, at least 1000 | 60000 | no | Timeout of one attempt, in milliseconds. |
dimensions | integer, at least 1 | no | Requested vector size, for models that support shortening. Part of the embedder id. |
The entry has no id: a profile has exactly one embedder.
How it calls the server
- Endpoint.
POST <url>/embeddingswithmodel,input(a list of strings) and, when set,dimensions. - Batching. Inputs are sent
batch_sizeat a time, one request after the other. - Timeout and retries. Each attempt may take
timeout_ms. Network failures and retryable statuses (408, 425, 429, 500, 502, 503, 504) are retried up toDEFAULT_HTTP_MAX_RETRIES(3) times, waiting forRetry-Afterwhen the server sends it. After that, 401 and 403 areAUTH_FAILED, 404 isNOT_FOUND, 429 isRATE_LIMITED, the restUPSTREAM. - Response. The answer must have a
dataarray with one row per input. Rows are put in order by theirindexwhen every row carries a distinct, valid one; otherwise the order of arrival is kept, because sorting by incomplete indexes would pair vectors with the wrong texts. Every vector is checked (same size, finite numbers) and scaled to unit length.
A response without data is UPSTREAM, with a hint to check that url points at the API root, usually ending in /v1.
Inputs the model refuses as too long
These servers answer 400 ("maximum context length is …") or 413 when one input does not fit the model, and refuse the whole batch with it. The handling is the same as for Ollama:
- If a batch is refused for length, its inputs are embedded one by one.
- An input refused on its own is shortened to
DEFAULT_SHORTEN_FACTOR(75 %) of its text and tried again, up toDEFAULT_MAX_SHORTEN_ATTEMPTS(6) times, with a warning in the log when a shortened version was embedded. - One that never fits fails with
INVALID_INPUTanddetails.reasonset toinput_too_long. The code index then stores that one chunk without a vector (lexical search and grep still find it) and counts it underfilesSkipped.chunk_too_long_for_embedder.
A refusal is recognised by status 413, or by a 400, 422 or 500 whose error text mentions the context or token limit. A server that words it in a way the connector does not recognise fails the batch with UPSTREAM; choose a model with a larger context then.
The embedder id, and changing the model
The id is openai-compatible:<model>, with @<dimensions> appended when dimensions is set: openai-compatible:acme-embed-v2@1024. The index records the id its vectors were made with, and vectors from different ids never mix.
- Changing
modelordimensionschanges the id. Vector search then fails withINDEX_NOT_READYuntilsafran synchas re-embedded the repositories; lexical search, grep and reading files keep working. The exact behaviour and messages are on the Ollama page and are the same here. - Switching between embedder types changes the id even for the same model:
ollama:bge-m3andopenai-compatible:bge-m3are different ids, and the index is rebuilt. - The id does not include
url. Pointing the entry at another server that offers a model under the same name keeps the id, and the stored vectors are used as they are. If that server's model is in fact a different one, search results are wrong without an error, unless the vector size differs, which is caught (INDEX_NOT_READY). When you move servers and are not certain the model is identical, delete the index directory and runsafran sync.
Limits
| Constant | Value | Meaning |
|---|---|---|
DEFAULT_OPENAI_COMPATIBLE_BATCH_SIZE / MAX_OPENAI_COMPATIBLE_BATCH_SIZE | 64 / 2048 | Default and largest batch_size. |
DEFAULT_OPENAI_COMPATIBLE_TIMEOUT_MS | 60000 | Default timeout_ms. |
MIN_EMBEDDER_TIMEOUT_MS | 1000 | Smallest timeout_ms a profile may set. |
DEFAULT_HTTP_MAX_RETRIES | 3 | Retries after the first attempt. |
DEFAULT_SHORTEN_FACTOR / DEFAULT_MAX_SHORTEN_ATTEMPTS | 0.75 / 6 | Shortening of inputs the server refuses for length. |
Your server may accept fewer inputs per request than batch_size; lower it if requests are rejected.
Known caveats
Nothing in this connector is marked UNVERIFIED, and nothing in the source says it was run against a particular server: it is tested with fixtures shaped like the OpenAI embeddings response. What to keep in mind:
- "Compatible" servers differ in details. The connector relies on three things only:
POST /embeddings, adataarray, and anembeddinglist of numbers in each row. dimensionsis passed through. A server that does not support it may ignore it or reject the request.- The
kindhint of the embedder contract (query or document) is not used: queries and chunks are sent the same way, so models that expect different prefixes for the two are not served by this connector as it is. A custom embedder plugin can add them.
See also
- Ollama, the default embedder, where nothing leaves the machine.
- Evaluation, for comparing models on your own code before switching.
- Connectors overview for the rules shared by all connectors.