RouterDC Selection
RouterDC uses semantic embeddings to match user queries with the most suitable model. It computes similarity between query embeddings and model representations to select the best match.
Reference: RouterDC: Query-Based Router by Dual Contrastive Learning (Guo et al., NeurIPS 2024) achieves +2.76% in-distribution and +1.90% out-of-distribution accuracy improvements.
The paper trains a query encoder using dual contrastive losses (Sample-LLM loss + Sample-Sample loss) with jointly learned LLM embeddings. Our implementation provides a simplified approach using pre-computed embeddings of model descriptions rather than jointly trained LLM-specific embeddings.
Algorithm Flow
Mathematical Foundation
Cosine Similarity
RouterDC uses cosine similarity to compare query and model embeddings:
sim(q, m) = (q · m) / (||q|| × ||m||)
= Σ(q_i × m_i) / (√Σq_i² × √Σm_i²)
Where:
q= Query embedding vector (e.g., 768 dimensions)m= Model description embedding vector- Result is in range [-1, 1], higher = more similar