Skip to main content

Module embedding_qwen3

Module embedding_qwen3 

Source
Expand description

Qwen3-Embedding-0.6B provider (ADR-059) — the preferred ECC embedder.

Unlike the BERT OnnxEmbeddingProvider, Qwen3-Embedding is a causal decoder-with-KV-cache ONNX export. This provider therefore:

  • feeds input_ids / attention_mask / position_ids (0..seq_len) plus empty, dtype-matched past_key_values.* tensors for every layer (shape [1, n_kv_heads, 0, head_dim], derived from the graph — never hardcoded);
  • pools the last non-pad token hidden state (not mean/CLS);
  • applies MRL: slice to the first QWEN3_DIMS dims, then L2-renormalize;
  • uses the HF tokenizers crate (Qwen3 BPE from tokenizer.json);
  • exposes embed_query for the asymmetric query lane (prepends the Qwen3 instruction prefix); the EmbeddingProvider::embed trait method is document mode.

Without the onnx-embeddings feature, the model file, or the tokenizer, the provider degrades gracefully to a MockEmbeddingProvider so builds and tests never require the ~1.2 GB artifact. The BERT provider stays intact as a lower-priority fallback (see select_embedding_provider).

Structs§

Qwen3EmbeddingProvider
Qwen3-Embedding-0.6B provider — decoder-ONNX, last-token pooling, MRL-512.

Constants§

QUERY_INSTRUCTION
Qwen3 asymmetric query instruction prefix. Documents are embedded raw; queries are prefixed with this (Instruct: {task}\nQuery: {q} format). The task description is the code-search instruction pinned by the lab probe set (ADR-059 consistency contract) so the lab and prod share one vector space; embed_query appends the raw query directly after the trailing space.
QWEN3_DIMS
MRL target dimensionality — the empirical sweet spot (ADR-059, recall@10 0.983).
QWEN3_MODEL_NAME
Canonical model identifier (pins the consistency contract; ADR-059).