Papers
Topics
Authors
Recent
Search
2000 character limit reached

Cost-Spectrum Contrastive Routing (CSCR)

Updated 3 July 2026
  • The paper introduces a unified framework for cost-sensitive routing of prompts in LLMs by mapping both prompts and models into a shared Euclidean space.
  • It employs dual descriptors, cost-banded contrastive losses, and FAISS k-NN to achieve microsecond latency and improved accuracy–cost trade-offs.
  • Empirical evaluation shows up to 25% improvement in AUDC over existing methods, ensuring robust generalization under varying expert pools.

Cost-Spectrum Contrastive Routing (CSCR) is a framework for efficient, cost-sensitive routing of prompts to LLMs within diverse and dynamic expert pools. CSCR addresses the limitations of traditional model routing—such as prompt-context ignorance, prohibitive profiling requirements, and reliance on fixed expert sets—by constructing a shared embedding space for models and prompts. This enables rapid model selection that explicitly manages the tradeoff between inference cost and predicted accuracy, using a contrastive learning approach informed by model-specific cost bands. The method leverages fast descriptors (logit footprints or perplexity fingerprints), banded cost-aware InfoNCE losses, and FAISS-index-based approximate nearest neighbor search to deliver microsecond-latency routing without retraining upon pool changes, while empirically outperforming existing schemes in accuracy–cost tradeoff and generalization (Shirkavand et al., 17 Aug 2025).

1. Embedding-Based Representations and Model Descriptors

CSCR's central innovation is mapping both prompts and expert models into a common Euclidean embedding space in which distance encodes cost-aware suitability. Model representations fall into two categories, depending on model access:

  • Logit Footprints (open-source LLMs): For hHh \in H (the expert pool), descriptors are computed by recording next-token distributions over a fixed probe prompt set Sprobes={x(i)}i=1NS_{\mathrm{probes}} = \{x^{(i)}\}_{i=1}^N and a short generation horizon TT. At each of TT steps and for each prompt, the KK most frequent tokens form the vector:

dlogit(h)=1NTi=1Nt=1T[ph(vkx(i),t)]k=1KRK,dlogit(h)2=1.d_{\mathrm{logit}}(h) = \frac{1}{N T} \sum_{i=1}^N \sum_{t=1}^T [p_h(v_k | x^{(i)}, t)]_{k=1}^K \in \mathbb{R}^K, \quad \|d_{\mathrm{logit}}(h)\|_2 = 1.

  • Perplexity Fingerprints (black-box APIs): Where logits are inaccessible, closed-source models are “fingerprinted” using a reference scorer SS. Each expert’s output is scored under SS on the probe set:

~h(x)=1y^h(x)j=1y^h(x)logpS(y^h,jy^h,<j).\tilde{\ell}_h(x) = -\frac{1}{|\hat{y}_h(x)|} \sum_{j=1}^{|\hat{y}_h(x)|} \log p_S(\hat{y}_{h,j} | \hat{y}_{h,<j}).

The descriptors are mean-centered, normalized vectors:

dPPL(h)=normalize([h(x(i))]i=1N)RN,then normalized to the unit sphere.d_{\mathrm{PPL}}(h) = \text{normalize}([\ell_h(x^{(i)})]_{i=1}^N) \in \mathbb{R}^N, \quad \text{then normalized to the unit sphere.}

This dual-descriptor system unifies open and black-box LLMs under a shared retrieval mechanism.

2. Contrastive Encoder Architecture and Loss Function

Prompts are encoded using a frozen MiniLM-L6-v2 backbone (Sprobes={x(i)}i=1NS_{\mathrm{probes}} = \{x^{(i)}\}_{i=1}^N0) followed by a two-layer trainable MLP head Sprobes={x(i)}i=1NS_{\mathrm{probes}} = \{x^{(i)}\}_{i=1}^N1, Sprobes={x(i)}i=1NS_{\mathrm{probes}} = \{x^{(i)}\}_{i=1}^N2-normalized to Sprobes={x(i)}i=1NS_{\mathrm{probes}} = \{x^{(i)}\}_{i=1}^N3. Expert keys Sprobes={x(i)}i=1NS_{\mathrm{probes}} = \{x^{(i)}\}_{i=1}^N4 inhabit the retrieval space.

CSCR generalizes classical InfoNCE contrastive loss by incorporating costs Sprobes={x(i)}i=1NS_{\mathrm{probes}} = \{x^{(i)}\}_{i=1}^N5:

  • Cost Bands: Experts are partitioned into Sprobes={x(i)}i=1NS_{\mathrm{probes}} = \{x^{(i)}\}_{i=1}^N6 percentile bands Sprobes={x(i)}i=1NS_{\mathrm{probes}} = \{x^{(i)}\}_{i=1}^N7 by cost, with positives Sprobes={x(i)}i=1NS_{\mathrm{probes}} = \{x^{(i)}\}_{i=1}^N8 per query in each band, and adaptive band-specific temperature Sprobes={x(i)}i=1NS_{\mathrm{probes}} = \{x^{(i)}\}_{i=1}^N9, where TT0 is the mean cost in band TT1.
  • Cost-Spectrum InfoNCE Loss:

TT2

where TT3 is the “negative-cost penalty,” controlling the penalization of incorrect, costly experts.

This structure ensures the learned metric ranks cheap correct experts above expensive or wrong ones, accommodates band-specific gradient allocation (critical for high-cost bands), and extends InfoNCE with cost-sensitive weighting.

3. Routing Inference via k-NN and FAISS

At inference, CSCR computes the query embedding for a given prompt, and identifies the top-TT4 nearest experts via cosine similarity using a FAISS IndexFlatIP (inner-product) search over TT5-normalized expert descriptors.

Routing proceeds as follows:

  1. TT6
  2. Retrieve TT7 top-TT8 experts using FAISS: TT9
  3. For each TT0 compute TT1
  4. Return the expert maximizing TT2: TT3

In practice, TT4 suffices, and lookup takes TT5s for thousands of experts. New experts are incorporated by updating the descriptor set, eliminating the need for retraining.

dlogit(h)=1NTi=1Nt=1T[ph(vkx(i),t)]k=1KRK,dlogit(h)2=1.d_{\mathrm{logit}}(h) = \frac{1}{N T} \sum_{i=1}^N \sum_{t=1}^T [p_h(v_k | x^{(i)}, t)]_{k=1}^K \in \mathbb{R}^K, \quad \|d_{\mathrm{logit}}(h)\|_2 = 1.9

4. Theoretical Properties

CSCR provides theoretical guarantees in terms of excess risk and embedding consistency:

  • Excess-Risk Bound: Under a Lipschitz-in-query embedding assumption, the TT6-NN routing rule on TT7 i.i.d. prompts achieves:

TT8

where TT9 is embedding dimension, KK0 is Bayes-optimal, KK1 is a constant. This recovers the standard KK2-NN rate.

  • Cost-Spectrum InfoNCE Consistency: At any stationary point of KK3, for each query KK4 and correct expert KK5 in a cheaper band than any incorrect KK6, KK7, ensuring the induced metric aligns with the desired cost-adjusted ranking.

5. Empirical Evaluation

CSCR is benchmarked on three routing datasets:

Benchmark Model Access Descriptor Metric(s)
EmbedLLM Open-source Logit-footprint AUDC, QNC, Peak accuracy
MixInstruct Open-source Logit-footprint Exponentiated BARTScore, Quality/Cost
RouterBench Black-box APIs PPL fingerprint USD cost, binary accuracy

Deferral curves plot response quality vs. cumulative cost as KK8 varies. Key reported metrics:

  • AUDC: Area under deferral curve (higher = better)
  • QNC: Query-normalized cost to match best expert (lower = better)
  • Peak Accuracy: Maximum observed for routing

Across all datasets, CSCR improves the accuracy–cost trade-off by up to 25% in AUDC over baselines such as UMR, Thompson, Soft-MoE, and others. Generalization experiments—holding out two-thirds of experts or switching from STEM to non-STEM prompts—show that CSCR retains top AUDC performance for novel experts and out-of-distribution prompts. Ablation studies confirm that logit/perplexity descriptors and cost-aware losses are both critical for these results. Optimal performance is achieved with KK9 cost bands, dlogit(h)=1NTi=1Nt=1T[ph(vkx(i),t)]k=1KRK,dlogit(h)2=1.d_{\mathrm{logit}}(h) = \frac{1}{N T} \sum_{i=1}^N \sum_{t=1}^T [p_h(v_k | x^{(i)}, t)]_{k=1}^K \in \mathbb{R}^K, \quad \|d_{\mathrm{logit}}(h)\|_2 = 1.0 for dlogit(h)=1NTi=1Nt=1T[ph(vkx(i),t)]k=1KRK,dlogit(h)2=1.d_{\mathrm{logit}}(h) = \frac{1}{N T} \sum_{i=1}^N \sum_{t=1}^T [p_h(v_k | x^{(i)}, t)]_{k=1}^K \in \mathbb{R}^K, \quad \|d_{\mathrm{logit}}(h)\|_2 = 1.1-NN, dlogit(h)=1NTi=1Nt=1T[ph(vkx(i),t)]k=1KRK,dlogit(h)2=1.d_{\mathrm{logit}}(h) = \frac{1}{N T} \sum_{i=1}^N \sum_{t=1}^T [p_h(v_k | x^{(i)}, t)]_{k=1}^K \in \mathbb{R}^K, \quad \|d_{\mathrm{logit}}(h)\|_2 = 1.2–dlogit(h)=1NTi=1Nt=1T[ph(vkx(i),t)]k=1KRK,dlogit(h)2=1.d_{\mathrm{logit}}(h) = \frac{1}{N T} \sum_{i=1}^N \sum_{t=1}^T [p_h(v_k | x^{(i)}, t)]_{k=1}^K \in \mathbb{R}^K, \quad \|d_{\mathrm{logit}}(h)\|_2 = 1.3 for cost penalty, and moderate smoothing of band temperatures (dlogit(h)=1NTi=1Nt=1T[ph(vkx(i),t)]k=1KRK,dlogit(h)2=1.d_{\mathrm{logit}}(h) = \frac{1}{N T} \sum_{i=1}^N \sum_{t=1}^T [p_h(v_k | x^{(i)}, t)]_{k=1}^K \in \mathbb{R}^K, \quad \|d_{\mathrm{logit}}(h)\|_2 = 1.4–dlogit(h)=1NTi=1Nt=1T[ph(vkx(i),t)]k=1KRK,dlogit(h)2=1.d_{\mathrm{logit}}(h) = \frac{1}{N T} \sum_{i=1}^N \sum_{t=1}^T [p_h(v_k | x^{(i)}, t)]_{k=1}^K \in \mathbb{R}^K, \quad \|d_{\mathrm{logit}}(h)\|_2 = 1.5, dlogit(h)=1NTi=1Nt=1T[ph(vkx(i),t)]k=1KRK,dlogit(h)2=1.d_{\mathrm{logit}}(h) = \frac{1}{N T} \sum_{i=1}^N \sum_{t=1}^T [p_h(v_k | x^{(i)}, t)]_{k=1}^K \in \mathbb{R}^K, \quad \|d_{\mathrm{logit}}(h)\|_2 = 1.6–dlogit(h)=1NTi=1Nt=1T[ph(vkx(i),t)]k=1KRK,dlogit(h)2=1.d_{\mathrm{logit}}(h) = \frac{1}{N T} \sum_{i=1}^N \sum_{t=1}^T [p_h(v_k | x^{(i)}, t)]_{k=1}^K \in \mathbb{R}^K, \quad \|d_{\mathrm{logit}}(h)\|_2 = 1.7).

6. Extensions, Limitations, and Future Directions

CSCR has been validated on pools of approximately 5–15 experts. Further evaluation on larger, heterogeneous expert pools (dlogit(h)=1NTi=1Nt=1T[ph(vkx(i),t)]k=1KRK,dlogit(h)2=1.d_{\mathrm{logit}}(h) = \frac{1}{N T} \sum_{i=1}^N \sum_{t=1}^T [p_h(v_k | x^{(i)}, t)]_{k=1}^K \in \mathbb{R}^K, \quad \|d_{\mathrm{logit}}(h)\|_2 = 1.8) is necessary for operational-scale deployments. Fixed probe prompt sets underpin descriptor construction; adopting adaptive or learnable probes could result in further footprint compression. Integration of dense user feedback, such as pairwise preference data, could refine label sets and margins within cost bands. Broadening cost-awareness to dynamic, per-prompt cost budgets or multi-objective contexts, such as latency or API quota optimization, represents another unexplored direction. Finally, exploration of reinforcement learning for routing within LLMs, potentially achieving token-level granularity, is proposed for future research.

CSCR establishes a plug-and-play, lightweight paradigm for cost-aware routing among LLMs by embedding prompts and models in a unified space, deploying a cost-banded contrastive loss, and performing microsecond-scale FAISS k-NN inference. It achieves superior accuracy–cost profiles and robust generalization relative to existing methods, while remaining compatible with a wide range of LLM deployment scenarios (Shirkavand et al., 17 Aug 2025).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Cost-Spectrum Contrastive Routing (CSCR).