Ollama embeddings vs ONNX Runtime: in the app or a server
An embedding model turns text into a list of numbers, so a search can find passages that mean the same thing. If you want to run an embedding model locally, you have two choices. Your app can load the model file and run it itself. Or a separate program holds the model, like Ollama embeddings over HTTP, and your app sends it text and gets numbers back. This note explains both, where each breaks, and what I saw.
In short
Think of a kitchen. In the first way, the cook keeps the oven in the same room. Nothing to call, nothing to wait for. But the oven has to fit in that room, and its parts must be installed in every kitchen you use.
In the second way, the oven is in a shop next door. The cook sends an order and waits for the food. The shop can serve many cooks, and you can swap its oven without touching the kitchen. But the shop can be closed.
Pick inside the app when one app on one kind of machine needs the model. Pick a server when several apps share it, when you want to cap its memory, or when the runtime does not install on your machine.
Three things matter more than which way you pick. First, check what the program does with text that is too long. Some cut it, and some refuse it. Second, the same model file can give slightly different numbers on different chips or in different number formats. Third, if the model is not there, your search must say so loudly. Mine failed quietly for a whole day.
The technical details
Way one: inside the app
your app
+-- tokenizer
+-- model file (.onnx)
+-- runtime (onnxruntime) -> numbers
The app loads the model with a runtime library such as onnx runtime and calls it like any function. There is no network and no second program to keep alive. Load the model when the app starts. Then a missing runtime stops the app at once, which is easy to notice. If you load it on the first search, as my code did, the error shows up later and can be swallowed.
The costs: the model’s memory lives inside your app, and the runtime must ship for every machine and Python version you use. Check that first. onnxruntime 1.31.1 had a wheel, a ready to install package, for my arm64 Mac but not for my Intel Mac on Python 3.14.
Way two: an embedding server
your app --POST text--> embedding server (model loaded)
<--numbers----
A separate program holds the model and answers over HTTP. Ollama embeddings work this way, through /api/embed. llama-server and ready made Docker images do the same, each with its own endpoint. The server can sit in its own container with its own memory cap. You can swap the model without touching the app.
The costs: one more program to start and watch, a network call per text, and a new way to fail. If the server is down, every call fails while the app keeps running.
How they compare
| Question | Inside the app | Embedding server |
|---|---|---|
| What has to be running | Only the app | The app and the server |
| When a missing model shows up | At start, if you load it then | On each search |
| Memory | Inside the app | In its own process, can be capped |
| Swap the model | Change the app | Change the server |
| Share with other apps | No | Yes |
Traps that change your results
Long text. Each program handles it its own way. My code cuts text at 512 tokens. llama-server refused anything over its batch size of 512 tokens with HTTP 500 instead of cutting it. That batch size is a setting you can raise. In my Ollama runs the real input limit was num_batch, 2,048 tokens by default, not num_ctx. A 2,427 token chunk got HTTP 400 even with num_ctx at 4,096. Setting both to 4,096 fixed it.
Pooling. A server picks pooling for you. Ollama reads it from the model file, and for bge-m3 that is bert.pooling_type: 2, which is CLS. Check it. See mean vs CLS pooling.
Number format and batching. int8 and f16 are smaller, rounder ways to store the model’s numbers. An int8 file and an f16 file of the same model give different vectors. With int8, even batching can change the numbers. My code embeds one text per call because “dynamic int8 quantization scales activations over the whole input, so batching (and padding) would change the numbers.”
for text in texts:
enc = tok.encode(text)
feeds = {"input_ids": np.array([enc.ids], dtype=np.int64),
"attention_mask": np.array([enc.attention_mask], dtype=np.int64),
"token_type_ids": np.array([enc.type_ids], dtype=np.int64)}
hidden = session.run(None, {n: feeds[n] for n in names})[0][0] # (tokens, dims)
mask = np.array(enc.attention_mask, dtype=np.float32)[:, None]
rows.append((hidden * mask).sum(axis=0) / max(float(mask.sum()), 1e-9))
Silent failure. A server that is down looks like “no results” unless your code says otherwise.
What happened in Nooor
Nooor, my Quran search, uses mxbai-embed-large-v1 as an int8 ONNX file, 1024 numbers per text. One setting picks the way: NOOOR_EMBED=onnx, the default, or NOOOR_EMBED=http. My Intel laptop had no onnxruntime wheel, so it used a local container holding the same file. The ARM machine loads the file in the app. More is on the Nooor project page.
The test sets are 30 main questions and 20 held out, searched across all of Nooor’s sources. Hit@10 means a right verse is in the top 10. MRR rewards it near the top.
| Setup | Main 30: hit@10, MRR | Held out 20: hit@10, MRR |
|---|---|---|
| Intel laptop, server, int8 | 0.80, 0.58 | 0.75, 0.41 |
| Intel laptop, int8 in the app | top 20 overlap with the server: 0.998 | |
| Intel documents, ARM questions | 0.80, 0.57 | 0.75, 0.41 |
| Everything on ARM, in the app | 0.80, 0.58 | 0.70, 0.36 |
| Intel, llama-server, f16 file | 0.80, 0.53 | 0.60, 0.40 |
How you run an embedding model locally made almost no difference here. On the same Intel laptop, in the app and the server agreed on 0.998 of the top 20. The ARM run lost 1 held out question of 20, and the cause is not confirmed. Neighbours in a top 10 list sit only 0.01 to 0.03 apart, so tiny changes swap ranks. The f16 row changes both the server and the number format, so it cannot separate the two. That file matched the original model at a cosine of 0.999995, where 1.0 means the same direction. It still scored 3 fewer held out questions. Its vectors differ from int8 (mean cosine 0.976 over 200 chunks), and my questions and terms were tuned on int8.
What went wrong
On 12 November the laptop’s search failed all day and nothing told me. onnxruntime was missing and the container was off. My code loads onnxruntime on the first search, not at start, and the chat code catches any search error and carries on:
try:
retrieved = retrieve.search(client, rw.standalone_question, terms)
except Exception:
retrieved = [] # carry on with pinned passages only
Turns got 3.2 passages instead of 8, and hadith showed up in only 35 of 92 turns. The other machine, with search working, gave 8 a turn and hadith in every turn. That is two machines on the same day, so a rough contrast, not a controlled test.
The chip gap has a likely cause, the int8 maths on each chip, but it is not confirmed.
What I will try next
Make a failed search show up: log it, count it, and fail the eval run. Then find the cause of the chip gap.