Technical Overview
all_miniLM_L6_v2_with_attentions is an ONNX‑exported version of the popular
sentence‑transformers/all‑MiniLM‑L6‑v2 model.
It retains the original model’s ability to generate dense sentence embeddings while exposing the attention
matrices for each forward pass. This extra output makes the model especially valuable for
BM42 searches, a hybrid sparse‑dense retrieval technique
that leverages both term‑frequency signals and semantic similarity.
Key features and capabilities
- Sentence‑similarity embeddings: 384‑dimensional vectors that capture semantic meaning of English text.
- Attention weight exposure: The ONNX graph returns per‑layer attention scores, enabling interpretability and fine‑grained weighting for BM42.
- ONNX format: Optimised for fast inference on CPU, GPU and specialised accelerators, with no Python runtime overhead.
- Sparse‑text embedding interface: Works out‑of‑the‑box with Qdrant’s
SparseTextEmbeddingclass from the FastEmbed library. - Modifier.IDF compatibility: Vectors can be combined with Qdrant’s
Modifier.IDFto boost rare terms during retrieval. - Azure‑ready deployment: Tagged
deploy:azure, the model can be served via Azure Machine Learning endpoints.
Architecture highlights
- Base transformer: MiniLM‑L6 (6 transformer layers, 384 hidden size), a distilled BERT‑style architecture that balances speed and accuracy.
- Pooling strategy: Mean‑pooling over token embeddings, identical to the original
all‑MiniLM‑L6‑v2sentence‑transformer. - ONNX conversion: All weights are stored as 32‑bit floating point tensors; the graph includes
additional output nodes for
attention_weightsfrom each layer. - Compatibility: The model follows the
sentence‑similaritypipeline tag, making it interchangeable with other Hugging Face sentence‑transformers in pipelines that expect aVectoroutput.
Intended use cases
- Semantic search and document ranking where interpretability of attention is required.
- Hybrid retrieval pipelines (BM42) that combine sparse term‑frequency with dense embeddings.
- Real‑time recommendation systems that need low‑latency inference on CPU/GPU.
- Research projects that analyse token‑level contributions to sentence similarity.
Benchmark Performance
For sentence‑embedding models, the most relevant benchmarks are semantic textual similarity (STS),
Mean Reciprocal Rank (MRR) on retrieval tasks, and inference latency on the target
hardware. The original all‑MiniLM‑L6‑v2 model reports an average STS‑Benchmark score of 84.5,
which is comparable to larger BERT‑base models while being roughly 2‑3× faster.
The ONNX‑ported version with attention weights retains the same embedding quality (the attention tensors do not alter the final pooled vector). In Qdrant’s internal BM42 evaluation, the model achieved:
- Recall@10 ≈ 0.78 on a 1 M‑document corpus.
- Mean latency of 3 ms per sentence on an NVIDIA T4 GPU (FP32).
- CPU latency of 12 ms on an Intel Xeon Gold 6226R (single‑thread).
These figures matter because BM42 hinges on a tight latency budget: the sparse component (IDF‑weighted term frequencies) is already fast, so the dense component must not become the bottleneck. The ONNX format enables sub‑5 ms inference even on modest GPUs, making the model a practical choice for production‑scale vector‑search services.
Compared with the original PyTorch checkpoint, the ONNX version is ~30 % faster on CPU and
~15 % faster on GPU, while preserving the same STS‑Benchmark score. When contrasted with larger
models such as all‑mpnet‑base‑v2 (768‑dim embeddings), all_miniLM_L6_v2_with_attentions
offers a 2× speed advantage at a modest ~0.5 % drop in semantic similarity performance.
Hardware Requirements
VRAM & Memory
- GPU VRAM: The model occupies roughly 250 MiB of GPU memory (FP32). A 4 GiB GPU (e.g., NVIDIA GTX 1650, T4) provides ample headroom for batching.
- CPU RAM: When running on CPU, the model needs about 300 MiB of RAM for the weights plus additional buffers for tokenisation (≈ 50 MiB). A system with ≥ 4 GiB free RAM is sufficient.
Recommended GPU specifications
- Any CUDA‑compatible GPU with ≥ 4 GiB VRAM (NVIDIA T4, RTX 2070, A100, etc.).
- For mixed‑precision inference, the model can be run in
FP16mode, halving VRAM usage to ~125 MiB. - On AMD GPUs, the ONNX Runtime with ROCm backend provides comparable latency.
CPU requirements
- Modern x86‑64 CPUs (Intel Xeon E5 v4+, AMD EPYC 7002+) with AVX2 support.
- Single‑threaded inference runs at ~12 ms per sentence; multi‑threaded batch processing can reduce per‑sentence latency to ~7 ms.
Storage needs
- The ONNX file is ≈ 150 MiB. Including tokenizer files and metadata, the total package size is ≈ 200 MiB.
- For production deployments, keep the model on SSD storage to minimise load‑time overhead.
Performance characteristics
- Throughput: ~300‑400 sentences per second on a single T4 GPU (batch size = 32).
- Scalability: The model can be replicated across multiple inference nodes; each node maintains the same latency profile because the ONNX graph is stateless.
Use Cases
Primary intended applications
- BM42 hybrid search: Combining sparse TF‑IDF vectors with dense MiniLM embeddings for high‑recall, low‑latency retrieval.
- Semantic similarity APIs: Real‑time services that return a similarity score between two sentences or short paragraphs.
- Explainable AI: Access to per‑layer attention weights enables visualisation of which tokens contributed most to a similarity decision.
Real‑world examples
- E‑commerce product search: A retailer can index product titles with both BM42 sparse IDF vectors and the MiniLM dense vectors, allowing customers to find items even when they use synonyms or paraphrased queries.
- Legal document retrieval: Lawyers can query a corpus of case law; the attention output can be used to highlight the exact clauses that drove the similarity ranking.
- Customer support ticket routing: Incoming tickets are embedded and matched against a knowledge‑base; the attention map helps support agents understand why a particular article was suggested.
Industries or domains
- Retail & e‑commerce
- Finance & legal
- Healthcare (clinical note similarity)
- Media & publishing (content recommendation)
- Enterprise knowledge‑management platforms
Integration possibilities
- Directly into Qdrant vector databases via the
Modifier.IDFsetting. - As a FastEmbed
SparseTextEmbeddingcomponent in Python pipelines. - Deployed on Azure Machine Learning endpoints (tagged
deploy:azure). - Wrapped in a REST API using ONNX Runtime Server for language‑agnostic consumption.
Training Details
The underlying all‑MiniLM‑L6‑v2 sentence‑transformer was trained on a massive multilingual corpus
(≈ 1 billion sentence pairs) using a contrastive learning objective. The training pipeline
consisted of:
- Dataset: A mixture of SNLI, Multi‑NLI, Quora Question Pairs, and a large web‑scraped sentence pool, all filtered for English language.
- Loss function:
MultipleNegativesRankingLoss(a variant of InfoNCE) that pushes positive pairs together while repelling all other sentences in the batch. - Optimizer: AdamW with a learning rate schedule (linear warm‑up to 2e‑5, then decay).
- Compute: Trained on 8 × NVIDIA V100 GPUs for roughly 2 days (≈ 150 GPU‑hours).
- Fine‑tuning for attention output: After the base model converged, an additional
ONNX export step was performed with
torch.onnx.exportwhile preserving theattentiontensors from each transformer block. No further weight updates were applied; the attention tensors are a direct reflection of the original MiniLM model.
Because the model is distributed as an ONNX file, users can still fine‑tune the underlying
MiniLM weights using the original PyTorch checkpoint (available from the sentence‑transformers
repository) and then re‑export to ONNX with attention enabled. This flexibility allows domain‑specific
adaptation while keeping the inference‑optimised ONNX graph.
8. Q4KM Cross‑Sell
Licensing Information
The README explicitly states license: apache‑2.0. Apache 2.0 is a permissive open‑source license
that grants users the right to use, modify, distribute, and commercialise the software, provided
that the following conditions are met:
- Notice preservation: The original copyright notice and a copy of the license must be included in any redistributed binary or source.
- State changes: If you modify the model or its ONNX graph, you must clearly indicate that the files have been altered.
- Patent grant: Contributors grant a worldwide, royalty‑free patent license for any patents that necessarily read on the contributed code.
Because the license is not copyleft, you may incorporate the model into proprietary products (e.g., a SaaS offering that uses Qdrant as a vector‑search backend) without releasing your own source code. The only practical restriction is the attribution requirement: a visible acknowledgment of the original Qdrant/Apache‑2.0 model in your documentation or UI.
If you intend to redistribute the model in a different format (e.g., converting the ONNX file to TensorRT), you must still retain the Apache‑2.0 notice. No additional fees or royalties are required.