Answers for LLM inference engineers

Embeddings or rerank scores from llama.cpp or Ollama don't match sentence-transformers? Find the cause

A correct GGUF served by llama-server gives the same vectors as sentence-transformers. We measured a cosine of 1.000000 on F32 GGUFs. When the numbers differ, the engine is usually computing something else. It may pool differently, skip the query: prefix that sentence-transformers adds on its own, or read more tokens than the model's max_seq_length. For rerankers, the GGUF may have lost part of the model. BERT cross-encoders converted before llama.cpp b12818 have no pooler (#33109). Qwen3-Reranker GGUFs converted as a plain LLM have no head at all and return meaningless scores. embedcheck.py sends the same inputs to your server and to the original model, and names the cause.

Published 2026-11-28 · llama-server measured at b12826 (2026-11-27) on CPU, with GGUFs converted by b12826 and by b12816 (the last build before the pooler fix). The models were small random-weight checkpoints with the real BERT (bge) and Qwen2 vocabularies. References came from sentence-transformers 6.3.0 and transformers 5.24.1. Ollama v0.40.19, TEI v1.10.0 and vLLM v0.34.0 were read from source, not run · Corrected 2026-12-05 · Tool version 1.0 (Python 3.9+, needs sentence-transformers and requests)

Corrected on 2026-12-05: this page said that Ollama's legacy /api/embeddings returns unnormalized vectors. It depends on the model. The legacy endpoint passes on what Ollama's llama-server runner returns, and Ollama asks the runner for raw vectors (embd_normalize: -1) only when legacyEmbeddingsWereRaw in llm/llama_server.go says so: when the GGUF has a pooling_type, for a bert GGUF whose tokenizer.ggml.model is not bert or whose normalize_embeddings is false, and for a nomic-bert GGUF unless normalize_embeddings is true. Otherwise the vector is L2-normalized, as llama-server does by default. Read from the Ollama v0.40.21 source (the function is the same in v0.40.19). With Ollama v0.40.21 and two small BERT test models with the BERT tokenizer (CLS and mean pooling), /api/embeddings, /api/embed and /v1/embeddings all returned vectors of length 1.0; nomic-bert models were not run.

The six causes, and what each engine does

Each row is a setting where an engine can quietly compute something different from SentenceTransformer.encode() or CrossEncoder.predict(). None of them raises an error. The only exceptions are the long-input refusals and llama-server's Pooling type 'none' 400.

Settingsentence-transformersllama-server (b12826)Ollama (v0.40.19)TEI (v1.10.0)vLLM (v0.34.0)
Pooling1_Pooling/config.jsonGGUF pooling_type, set by the converter from 1_Pooling. --pooling overrides it. No pooling_type: /v1/embeddings answers 400 Pooling type 'none' is not OAI compatible (measured)GGUF pooling_type1_Pooling. If it is missing on a BERT: CLS with a warning. --pooling overrides it1_Pooling via modules.json. --pooler-config overrides it
Prompt prefix (query: , search_query: )adds default_prompt_name from config_sentence_transformers.json on every encode()neverneveronly with --default-prompt-name or prompt_name in the requestonly on the Cohere-style /v2/embed with input_type. Never on /v1/embeddings
Long inputcut at max_seq_lengthno cut. Over -ub (default 512): HTTP 500 input (N tokens) is too large to process. increase the physical batch size (measured)cut at the GGUF context_length (= max_position_embeddings) or num_ctx, not max_seq_length. "truncate": false gives a 400 insteadcut at max_seq_length (--auto-truncate, default true)refused over max_model_len (= max_seq_length) unless truncate_prompt_tokens is set
Normalizationonly if the model has a Normalize module/v1/embeddings: L2 by default (--embd-normalize 2). -1 returns raw vectors (measured)/api/embed and /v1/embeddings: always L2. Legacy /api/embeddings: depends on the model (raw for some bert and nomic-bert GGUFs, otherwise L2; see the note above)normalize defaults to truefollows the Normalize module
Cross-encoder segment idsquery 0, document 10 for every token (type_row0 in src/models/bert.cpp). Scores shift slightly (measured)no rerank endpointpasses thempasses them
Rerank score scalepredict(): sigmoid for 1 label (use activation_fn=Identity() for logits)raw logit for BERT. P(yes) for Qwen3-Reranker–sigmoid unless "raw_scores": truesigmoid for 1 label unless use_activation: false

A different scale (raw logit vs sigmoid) does not change the ranking, so it is not a bug. Normalization does not change cosine, but it does change dot-product and L2 scores. Everything else in the table changes the vectors themselves.

What we measured on llama-server

Each row is one run of embedcheck.py against llama-server b12826 on CPU, using F32 GGUFs. We used six short texts (English, Japanese, code, emoji) and one long text of 1.5× max_seq_length. For rerankers we used 2 queries × 5 documents. The weights are random, so absolute cosines here are not those of a trained model. A trained model's vectors are more spread out, so the same mistake usually costs more. Whether a setting matches does not depend on the weights.

CaseServer flagsResultCause found by the checker
CLS + Normalize (bge-style)--embeddingcos 1.000000 × 6match. The long text (785 tokens): HTTP 500, too large for -ub 512
same GGUF--embedding --pooling meancos 0.504–0.612server pools with mean (model: cls)
mean + Normalize, max_seq_length 128--embeddingshort 1.000000. Long 0.998473server reads 218 tokens, sentence-transformers cuts at 128
mean, default prompt query: (E5-style)--embeddingcos 0.978–0.992server sees no prefix (reference: 'query: ')
converted from a folder without modules.json--embeddingHTTP 400 on every inputGGUF has no pooling_type. Pooling type 'none' is not OAI compatible
CLS + Normalize--embedding --embd-normalize -1cos 1.000000, |v| = 8.0match, with a note that the vectors are not unit length
BERT cross-encoder, converted by b12816--rerankingSpearman −0.70, −0.60scores equal the head applied to raw [CLS] with segment ids 0: the pooler was dropped (#33109)
same checkpoint, converted by b12826--rerankingSpearman 0.90, 1.00scores equal the model run with token_type_ids = 0 (pooler fixed, segment ids still 0)
Qwen3-Reranker-style, converted with a README saying # Qwen3-Reranker--rerankingequal to P(yes), Spearman 1.00, 1.00match
same weights, converted from a folder named toy-model with no README--reranking --pooling rankSpearman 0.60, −0.40no cls.output.weight. Score = softmax(last hidden)[0]. Document 2 scored 0.00486 alone and 0.01073 next to document 1

How to reproduce: repro/make_toys.py builds the checkpoints, repro/run_matrix.sh starts llama-server for each case (a few seconds each), and repro/run_mock.sh runs the checker against a replay server that answers in Ollama, TEI and vLLM format. The full outputs are in repro/out/.

Check your own server

pip install sentence-transformers requests gguf
# llama-server
llama-server -m bge-small-en-v1.5-f16.gguf --embedding --port 8080
python embedcheck.py embed --model BAAI/bge-small-en-v1.5 --url http://127.0.0.1:8080 --gguf bge-small-en-v1.5-f16.gguf
# Ollama (name the model as Ollama knows it)
python embedcheck.py embed --model nomic-ai/nomic-embed-text-v1.5 --url http://127.0.0.1:11434 --api ollama --served-model nomic-embed-text --trust-remote-code
# TEI / vLLM rerankers
python embedcheck.py rerank --model BAAI/bge-reranker-base --url http://127.0.0.1:8080 --api tei
python embedcheck.py rerank --model Qwen/Qwen3-Reranker-0.6B --kind qwen3 --url http://127.0.0.1:8080 --gguf qwen3-reranker-0.6b-q8_0.gguf

Example: llama-server started with the wrong pooling.

reference: sentence-transformers, pooling=cls, normalize=True, max_seq_length=512, ...
 text    cosine  |server|  diagnosis
    1  0.504198    1.0000  server pools with mean (model: cls)
    ...
verdict: MISMATCH
 - Pooling differs. llama.cpp: the GGUF's <arch>.pooling_type wins unless you pass --pooling ...

Exit status 0 means it matches (notes such as “not normalized” or “refused the long input” are printed but do not fail). Exit 1 means a mismatch, and 2 means the server could not be reached. --gguf also reads the GGUF header. It flags a missing pooling_type, a reranker with no cls.* tensors, a Qwen3 GGUF without rank pooling, and a BERT classifier without cls.weight (the dropped pooler). How close is close enough: F32/F16 GGUFs land above 0.999. Q8_0 usually lands above 0.99. Below that, with no pooling, prefix or truncation explanation, suspect the conversion.

Fixes

Pooling
Start llama-server with --pooling cls|mean|last matching the model's 1_Pooling/config.json. Or reconvert from the full model folder: convert_hf_to_gguf.py reads modules.json and 1_Pooling to set pooling_type, and a bare folder (only config.json and weights) gives a GGUF without one.
Prefix
Add the prefix to the text yourself: search_query: / search_document: for nomic-embed, query: / passage: for E5, the instruction for Qwen3-Embedding. Or tell sentence-transformers not to add it (prompt="") when you compare.
Truncation
Cut inputs to max_seq_length tokens before sending (all-MiniLM-L6-v2: 256, although its GGUF says 512). For llama-server, raise -ub and -b together to accept longer inputs up to the model's context.
Cross-encoder pooler
Reconvert BertForSequenceClassification checkpoints with llama.cpp b12818 or later (PR #33122, merged 2026-11-27). --gguf shows cls.weight and classifier.activation=tanh on a good one.
Qwen3-Reranker head
Convert from a folder whose README.md starts with # Qwen3-Reranker, or whose name contains qwen3-reranker (support since b6578, PR #15824). Check that the GGUF lists cls.output.weight and pooling_type rank. On vLLM, the original checkpoint needs --hf_overrides '{"architectures": ["Qwen3ForSequenceClassification"], "classifier_from_token": ["no", "yes"], "is_original_qwen3_reranker": true}' and the reranker chat template.
Quantized KV cache
Don't use -ctk q4_0 -ctv q4_0 for rerankers. In #16407 ggerganov advised against it for reranking, and against q8_0 too.

Known reports

ReportModelCauseStatus (2026-11-28)
llama.cpp #33109cross-encoder/ms-marco-MiniLM-L-12-v2: transformers +8.50, llama.cpp −0.026 on the same pairpooler dropped by the converter. Segment ids 0closed by #33122 (b12818). Segment ids unchanged
llama.cpp #16407Qwen3-Reranker, bge, mxbai: near-random orderquantized KV cache, a bad community GGUF, raw vs normalized scoresno single fix recorded. The ggml-org Q8_0 GGUF gave sensible scores
llama.cpp #5783GritLM embeddings differ from the referencethe pooling default was part of itno merged fix seen
Voodisss/Qwen3-Reranker-0.6B-GGUFcommunity Qwen3-Reranker GGUFs score ~4.5e-23no cls.output.weightexplained on that model card

FAQ

Why are llama.cpp embeddings different from sentence-transformers?

On an F32 GGUF of the same model, llama-server reproduced sentence-transformers to a cosine of 1.000000 in our runs. When they differ, the cause is almost always one of four settings: a different pooling (the GGUF's pooling_type or a --pooling flag), a prompt prefix that sentence-transformers adds automatically from default_prompt_name, a different truncation length (sentence-transformers cuts at max_seq_length, llama.cpp does not), or quantization. embedcheck.py tells you which.

Why do Ollama embeddings not match Hugging Face cosine similarity?

Ollama's /api/embed and /v1/embeddings L2-normalize and truncate to the GGUF context_length (or num_ctx), not to the model's max_seq_length, and never add the model's query or document prefix. Texts longer than max_seq_length and models with a default prompt (E5-style "query: ") differ from sentence-transformers. The legacy /api/embeddings returns what the runner returns, which depends on the model: raw vectors only for BERT GGUFs whose tokenizer is not BERT's or that set normalize_embeddings to false, and for nomic-bert GGUFs unless they set normalize_embeddings to true; otherwise L2-normalized (Ollama v0.40.21 source).

Why does llama-server /v1/rerank return wrong or tiny scores (like 4.5e-23)?

The GGUF has no classifier head. A Qwen3-Reranker converted as a plain Qwen3 model has no cls.output.weight and no rank pooling; llama-server then returns softmax over the last hidden state, which is tiny on a real model and changes with the other documents in the request. The converter treats Qwen3 as a reranker only if README.md contains '# Qwen3-Reranker', the folder or _name_or_path contains 'qwen3-reranker', or the architecture is *ForSequenceClassification.

Why does a cross-encoder GGUF rank documents differently from CrossEncoder.predict?

Until 2026-11-27 llama.cpp's converter dropped the BERT pooler (dense + tanh), so BertForSequenceClassification models such as cross-encoder/ms-marco-MiniLM-L-12-v2 scored the raw [CLS] vector (llama.cpp #33109). PR #33122 fixed the converter; the first build with it is b12818. Reconvert. Separately, llama.cpp still feeds token_type_ids = 0 for the document, so scores of segment-trained cross-encoders are still slightly off in b12826.

Is llama-server's rerank score a probability?

For Qwen3-Reranker GGUFs, yes: llama.cpp applies a softmax to the yes/no head, which equals P(yes) from the model card recipe (measured equal). For BERT cross-encoders it returns the raw logit; TEI and vLLM apply a sigmoid by default, so the numbers differ but the order is the same.

Sources