Qwen3 Embedding¶
Overview and status¶
Registry type: qwen3_embedding. The retrieval loader maps a publisher
model_type=qwen3 checkpoint into this task-specific native implementation.
It uses final-token pooling, instruction-formatted queries, normalized vectors,
and configurable Matryoshka dimensions.
Qwen/Qwen3-Embedding-0.6B
is the implemented profile. The pinned 0.6B checkpoint has a bounded native
qualification run on Apple M4: 32 STS-B pairs, public Python/CLI/HTTP calls, and
an eight-input comparison with the publisher's Transformers implementation.
See the recorded result.
These samples do not establish full-corpus retrieval quality or long-context support.
Weights retain their published BF16 storage. The native backbone computes in FP32 to keep padded batches consistent with individual inputs. The recorded maximum batch/single difference is 2.4e-7, within the unchanged 2e-4 tolerance; the publisher comparison differs by at most 4.4e-7. FP32 execution uses more activation/cache memory than BF16; no throughput improvement is claimed.
Model Architecture¶
The diagram follows the native implementation. Layer counts, widths, head counts, and input sizes come from the checkpoint configuration; this is an architecture map, not an additional support or qualification claim.
Document text / instruction + query → tokenizer + padding mask
↓
Qwen3 dense causal decoder (GQA, Q/K norm, RoPE)
↓
Last active token's hidden representation
↓
Optional leading-dimension truncation
↓
Optional L2 normalization → [batch, dim]
└→ Cosine similarity
Papers and upstream references¶
Paper: Qwen3 Embedding: Advancing Text Embedding and Reranking Through Foundation Models. Backbone: Qwen3 Technical Report.
This is final-token pooling, not mean pooling or ColBERT-style token retrieval. Requested dimensions are validated against the checkpoint profile.
Installation and assets¶
Use Python 3.10+, install python -m pip install -e . from the repository root,
and use Apple Silicon/Metal for execution. Keep config.json, complete
safetensors weights/index, tokenizer.json, tokenizer metadata, and
1_Pooling/config.json declaring last-token pooling and embedding width.
Task metadata helps distinguish the embedding bundle from a Qwen3 language model.
The current Qwen3 retrieval loader validates ordinary weights; it does not apply
the generic text loader's MLX quantization preparation to this profile.
Query/document formatting and examples¶
input_type="query" formats text as Instruct: {instruction}\nQuery:{text}.
Documents remain unformatted. Do not pre-add this prefix when using the query API.
These examples may download weights; pin an immutable revision for
reproducible retrieval experiments.
mlx-one inspect Qwen/Qwen3-Embedding-0.6B
mlx-one embed Qwen/Qwen3-Embedding-0.6B "What is unified memory?" \
--input-type query --dimensions 512 --max-length 512
from mlx_one import embed, load_retrieval_model
bundle = load_retrieval_model("Qwen/Qwen3-Embedding-0.6B", task="embedding")
query = embed(
bundle,
"What is unified memory?",
input_type="query",
instruction="Retrieve passages that answer the question",
dimensions=512,
max_length=512,
)
documents = embed(
bundle,
["CPU and GPU share memory.", "A recipe for sourdough."],
dimensions=512,
max_length=512,
)
scores = [
sum(left * right for left, right in zip(query.embeddings[0], vector))
for vector in documents.embeddings
]
print(scores)
Reusing the loaded bundle avoids reloading weights between query and document calls. Use the same dimensions and model revision throughout an index.
Settings and troubleshooting¶
The implemented 0.6B profile accepts dimensions from 32 through 1024; the default is its full width. Its configured sequence maximum is 32768, while the service defaults to 8192. Neither value is a measured safe workload on every host. Batching uses padding-aware last-token pooling; start with short inputs/small batches.
Missing last-token pooling metadata, inconsistent vocabulary IDs, or a conflicting
task indicates the wrong/incomplete bundle. A generic Qwen3 chat model is not this
embedding checkpoint. This task produces one vector per text, not generated text;
APC and block decoding are not exposed by embed.
Implementation and validation¶
See configuration, model, weights, retrieval service, backend-free tests, and synthetic Metal tests.
pytest -q tests/test_native_qwen3_retrieval.py
MLX_ONE_RUN_MLX_TESTS=1 pytest -q tests/test_native_qwen3_retrieval_mlx.py
See qualification levels before claiming measured retrieval performance or quality.