Knowledge distillation transfers the generalization capabilities of a cumbersome teacher model to a compact student model by training the student to mimic the teacher's soft output probabilities, not just the hard ground-truth labels. The student learns the relative probabilities of incorrect classes, capturing dark knowledge about the data's structure.
Glossary
Knowledge Distillation

What is Knowledge Distillation?
Knowledge distillation is a compression technique where a smaller 'student' model is trained to replicate the behavior and output distributions of a larger, more complex 'teacher' model.
In retrieval systems, cross-encoder distillation is critical: a computationally expensive cross-encoder teacher scores query-document pairs with full attention, and its relevance scores supervise a fast bi-encoder student. This yields a dense retriever that approximates the accuracy of the expensive model while maintaining the low latency required for searching billion-scale vector indexes.
Key Characteristics of Knowledge Distillation
Knowledge distillation transfers the generalization capabilities of a large, complex teacher model to a smaller, efficient student model by training the student to match the teacher's output distributions.
Teacher-Student Architecture
The core framework involves a teacher model (typically a large cross-encoder or ensemble) and a student model (a lightweight bi-encoder). The student is trained not on hard labels, but on the soft labels produced by the teacher. These soft labels—probability distributions over classes—contain rich information about inter-class similarities that one-hot labels lack.
- Teacher: High-capacity model frozen during distillation
- Student: Compact model trained to mimic teacher outputs
- Soft Targets: Probability vectors capturing dark knowledge
Cross-Encoder to Bi-Encoder Distillation
A critical application in modern search systems. A cross-encoder processes the query and document concatenated together with full self-attention, yielding high accuracy but prohibitive latency. The distilled bi-encoder encodes query and document independently, enabling pre-computed passage embeddings and fast Maximum Inner Product Search (MIPS).
- Teacher: Cross-encoder with full query-document attention
- Student: Bi-encoder for independent encoding
- Result: Cross-encoder precision at bi-encoder speed
Temperature Scaling
A temperature parameter (T) controls the softness of the teacher's output probabilities. Higher temperatures produce softer distributions, revealing more of the dark knowledge—the relative similarities between incorrect classes. The student is trained with the same high temperature, but evaluated at T=1.
- T > 1: Softens probability distribution, exposes class relationships
- T = 1: Standard softmax for inference
- Loss Function: Typically Kullback-Leibler divergence between softened distributions
Training Data Strategies
Distillation can use the original labeled dataset, a large unlabeled corpus, or synthetically generated queries. Using unlabeled data allows the student to learn from the teacher's predictions on a much larger scale than the original training set, improving generalization.
- Labeled Data: Original supervised training set
- Unlabeled Corpus: Teacher generates pseudo-labels for massive datasets
- Synthetic Queries: Augment training with generated query-passage pairs
Hard Negative Mining
To improve the student's discriminative power, training often incorporates hard negatives—passages that are top-ranked by a basic retriever but are actually irrelevant. The teacher model scores these negatives, and the student learns to push them away from the query in the embedding space, sharpening the decision boundary.
- Hard Negatives: Superficially similar but irrelevant passages
- Source: Retrieved from BM25 or a preliminary dense retriever
- Impact: Significantly improves Recall@K metrics
Distillation Loss Functions
The student is optimized using a combination of losses. The distillation loss (KL divergence) aligns the student's softened outputs with the teacher's. An optional student loss (cross-entropy with hard labels) can be added to ground the model in true labels. A weighted sum balances imitation and ground truth.
- L_KD: KL divergence between teacher and student soft labels
- L_CE: Cross-entropy loss against ground truth labels
- L_total = α * L_KD + (1-α) * L_CE
Frequently Asked Questions
Explore the core concepts behind knowledge distillation, the critical compression technique that transfers expertise from large, computationally expensive teacher models to smaller, efficient student models for production deployment.
Knowledge distillation is a model compression technique where a compact student model is trained to replicate the behavior of a larger, more complex teacher model. Instead of learning directly from hard labels in a dataset, the student learns from the teacher's output probability distribution, known as soft targets. These soft targets contain rich information about inter-class similarities that hard labels lack, providing a more informative training signal. The process minimizes the divergence between the student's predictions and the teacher's predictions, effectively transferring the teacher's generalization capabilities to a model with a fraction of the parameters and latency.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Core architectural components and training techniques that enable knowledge distillation for neural retrieval systems.
Hard Negatives Mining
A critical data curation strategy for dense retrieval distillation where training examples that are superficially similar to the query but irrelevant are deliberately selected. These hard negatives force the student model to learn fine-grained distinctions. In a distillation pipeline, the teacher cross-encoder identifies passages with high BM25 lexical overlap but low semantic relevance.
- Source: Retrieved from sparse methods like BM25 or top-K ANN results
- Teacher filtering: Cross-encoder scores identify false positives
- Impact: Dramatically improves student model discriminative power
- Mining strategies: Static pre-mining vs. dynamic in-batch hard negative selection
Score Distillation vs. Rank Distillation
Two distinct distillation objectives for training student retrievers. Score distillation uses the teacher's absolute relevance scores as regression targets, training the student to predict exact scores via MSE loss. Rank distillation focuses on preserving the relative ordering of passages, using listwise losses like ListNet or LambdaRank to optimize ranking metrics directly.
- Score distillation: Pointwise approach, MSE or KL divergence loss
- Rank distillation: Listwise approach, optimizes NDCG or MRR
- Trade-off: Score distillation is simpler; rank distillation better aligns with retrieval metrics
- Hybrid: Combining both losses for optimal performance
In-Batch Negatives with Distillation
A training efficiency technique where other positive passages within a mini-batch serve as negative examples for each query, eliminating the need for explicit negative sampling. Combined with knowledge distillation, the teacher cross-encoder scores all in-batch pairs, providing dense supervision signals. This scales training to large batch sizes on multiple GPUs.
- Mechanism: For query Q_i, passages P_j (j ≠ i) become negatives
- Teacher role: Scores all query-passage pairs in the batch
- Gradient caching: Stores teacher scores to avoid recomputation
- Memory optimization: Requires large batch sizes (1024-4096) for effective training
Margin-Based Distillation Loss
A specialized loss function for retrieval distillation that enforces a minimum margin between the scores of relevant and irrelevant passages. The student is penalized when the score gap falls below a threshold τ. This produces well-separated embeddings optimized for Maximum Inner Product Search (MIPS).
- Margin parameter (τ): Minimum required score separation
- Loss: max(0, τ - score_pos + score_neg)
- Advantage: Prevents embedding collapse and improves index quality
- Variants: Adaptive margins based on passage difficulty or teacher confidence

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us