AI coding assistants burn their most expensive resource before doing any real work.
A developer types a query. The tool has to decide—instantly—where to route it. Which model handles this. What context to pull. Whether a cached response exists. Syntax question or architectural refactoring, it does not matter. The routing decision comes first.
Most tools use LLM inference for that decision. Feed the query to a large language model, wait for intent classification. Three to five seconds. Tokens spent on deciding, not answering. That token cost compounds across thousands of developers and millions of daily interactions. The meter runs before a single useful token gets generated.
Semantic routing replaces inference with vector math. Decision latency drops from ~5,000ms to ~100ms. For retrieval augmented generation pipelines and coding assistants, this is not an optimization. It is a different architecture. The token efficiency difference is structural.
The Routing Problem
Before generating a single token of output, an AI coding tool has to answer: which model handles this? Which files and functions are relevant? Which tools should be available? Has this been answered before? Any safety concerns?
Five decisions. Traditional approaches handle them sequentially, using the LLM itself for classification. Intent classification, then tool selection, then context retrieval. Each step stacks latency and burns tokens. The developer types a question and waits while the tool figures out how to help. Not a great experience.
The 2026 vLLM Semantic Router showed what happens when those decisions move to vector space: six signal types extracted through a plugin chain, routing resolved in milliseconds instead of seconds. Not an incremental improvement. A category shift.
How Semantic Routing Works
None of this is complicated:
1. Convert queries to vectors: Each input gets transformed into a dense embedding (typically 768 or 1,536 dimensions) using an encoder model. 2. Compare against route definitions: Pre-defined routes also exist as embeddings. The system computes cosine similarity between the query embedding and each route. 3. Select the best match: The route with the highest similarity score above a configurable threshold gets selected. 4. Execute deterministically: Unlike LLM-based classification, the output is consistent and non-hallucinatory.
The Aurelio Labs semantic router library (3.3k GitHub stars) demonstrates this pattern with support for multiple encoders (Cohere, OpenAI, HuggingFace, FastEmbed), vector databases (Pinecone, Qdrant), and fully local execution options.
What makes this approach viable for coding tools specifically is that code queries cluster predictably. Questions about syntax, architecture, debugging, and refactoring each occupy distinct regions in embedding space. A well-designed router can distinguish "how do I use async/await" from "refactor this module to use async/await" without burning inference tokens on classification. Paired with a smart chunking strategy—semantic chunking that respects code boundaries rather than arbitrary token limits—the retrieval layer feeds the router exactly what it needs.
Where Routing Decisions Matter Most
Model Selection
Not every query needs GPT-4 or Claude Opus. Syntax questions, boilerplate, well-documented patterns—a smaller model handles those fine. Architectural reasoning, multi-file refactoring, novel problems? Those earn the big model.
Semantic routing makes this automatic. Query embedding lands near "syntax help," it routes to the fast model. Lands near "architectural decision," it gets the heavy hitter. Smaller models are cheaper and faster, so the token budget savings compound on both axes.
Tool Filtering
Modern coding agents carry extensive tool catalogs: file search, code search, terminal execution, browser access, documentation retrieval. Including the full catalog in every request wastes tokens describing tools the model will never touch.
Semantic tool filtering fixes this. Before inference, irrelevant tools get stripped from context. Code style question? No terminal access needed. Debugging request? Browser capabilities are dead weight. The vLLM Semantic Router implements this pattern. Fewer tools in the prompt means faster inference, lower costs, and less noise for the model to parse.
Semantic Caching
This might be the highest-impact application of the bunch. Redis research on semantic caching shows 50-80% reduction in LLM API costs. Response times drop from 1-5 seconds to 5-20 milliseconds. That gap is enormous.
The mechanics are simple: query arrives, its embedding gets compared against cached query embeddings. Similarity exceeds the threshold (typically 0.85-0.95), cached response serves immediately. No LLM call.
Developers ask variations of the same questions constantly. "How do I sort an array in JavaScript" and "JavaScript array sorting" are semantically identical. A well-tuned cache catches the second one instantly. The meter stops running.
Measured Impact on Coding Agents
Research on efficient coding agents quantified token reduction from semantic approaches:
| Task Type | Token Reduction |
|---|---|
| State management queries | 54% (47k → 22.8k tokens) |
| Template parsing | 30% (22k → 15.5k tokens) |
| Animation functions | 33% (33k → 22k tokens) |
The insight from this research: "Agents can spend a lot of time using many tokens trying to infer semantic information. When agents perform text-based searching, they dump all the text generated by that process into the context window."
Semantic search retrieves relevant code by meaning, not keywords. The token overhead from iterative text search—reading files, searching again, reading more files—gets replaced by a single embedding query that returns the relevant code directly. The lost in the middle problem compounds this: when context windows fill with marginally relevant content, models struggle to locate the information that actually matters. Routing and retrieval precision solve the problem before it starts.
Augment Code's February 2026 MCP release demonstrated the practical impact: 80% performance improvement when integrating their semantic Context Engine with Claude Code + Opus 4.5, and 71% improvement with Cursor.
Implementation Considerations
Threshold Tuning
The similarity threshold controls the trade-off between precision and recall. Too high (0.98), and semantically similar queries miss the cache or misroute. Too low (0.80), and unrelated queries get incorrectly matched.
Starting recommendations: - Semantic caching: 0.90-0.95 (false positives are worse than cache misses) - Route classification: 0.85-0.90 (depends on route overlap) - Safety detection: Lower thresholds (0.75-0.85) to catch edge cases
Threshold tuning requires empirical testing. What works for one codebase or user population may not work for another.
Embedding Model Selection
General-purpose embedding models (OpenAI's ada-002, Cohere's embed-v3) work reasonably well for code. They capture semantic similarity for common patterns and natural language queries about code.
The problem: generic embeddings miss domain-specific nuance. A codebase full of custom terminology, internal naming conventions, and specialized patterns won't embed the way those concepts exist in training data. The embedding for "fetch the user's pickle status" won't cluster anywhere near the internal PickleService.getStatus() method. Not without help.
Domain-adapted embeddings close that gap. Fine-tuning on codebase-specific data—or training custom embedding models from scratch—brings retrieval precision in line with what semantic routing actually needs.
Hybrid Approaches
Pure semantic routing has blind spots. Some decisions need deterministic logic—file paths, explicit commands, exact matches. Embeddings don't help there. Some decisions need structural code analysis that vector similarity simply cannot capture.
Production implementations typically combine: - Semantic signals: Embedding-based similarity for intent and topic classification - Keyword signals: Regex and exact match for explicit commands and patterns - Structural signals: AST parsing and dependency analysis for code-aware decisions
The vLLM Semantic Router's plugin chain architecture explicitly supports this: multiple signal types feed into routing decisions, with configurable weighting.
Trade-offs and Limitations
Embedding Overhead
Computing embeddings has latency and cost. For a single query, embedding computation is fast (typically <50ms with local models, <200ms with API calls). For indexing large codebases or processing high-volume traffic, embedding compute becomes a meaningful cost center.
Caching embeddings helps. Batch processing during quiet periods helps more. The overhead is real, though, and it scales with the codebase.
Cold Start Problem
Semantic routing relies on pre-defined routes, cached queries, and indexed content. A brand-new deployment has none of these. The system needs time to build up the cached embeddings and learned routes that make semantic routing effective.
Bootstrapping with common query patterns and synthetic data accelerates cold start, but some learning period is inevitable. Techniques like prompt compression can help bridge the gap—reducing token usage while the routing layer builds its knowledge base.
Embedding Staleness
Codebases change. Functions get renamed, moved, deleted. The embeddings indexed last week no longer reflect current reality. Semantic search returns code that doesn't exist anymore, or misses code that does.
Reindexing strategies matter: incremental updates on file changes, periodic full reindexes, change detection triggers. Active codebases need aggressive refresh. Stale embeddings are worse than no embeddings—they create false confidence.
Threshold Sensitivity
One number controls a lot. Different query types, different vocabulary patterns, different user populations—they all want different thresholds. What passes testing may fail in production with real developer queries.
Monitoring false positive and false negative rates matters more than getting the initial threshold "right." Thresholds that can adjust dynamically beat thresholds that were carefully chosen once and left alone.
The Broader Trajectory
Context engineering has become the differentiator for AI coding tools. Model quality matters less than it did in 2024; the frontier models are converging in capability. With context window sizes hitting 200k tokens and beyond, the bottleneck shifted from "can the model handle it" to "should the model receive it." What separates tools now is how intelligently they manage context, route requests, and integrate with developer workflows.
Semantic routing is one piece of that context engineering layer. It enables decisions that would otherwise require expensive LLM inference to happen in milliseconds at near-zero marginal cost. Combined with semantic caching, hybrid search, reranking, and context compression, the efficiency gains compound. RAG pipelines that once burned tokens on irrelevant context now deliver precise, token-efficient retrieval.
Eighty-five percent of developers now use AI coding tools regularly. They expect instant responses, predictable costs, context-aware behavior. Semantic routing is infrastructure for that expectation—not a feature anyone sees, but a layer that makes everything else faster and cheaper.
The question isn't whether to implement it. The vector math is standard. The embedding models exist. Open-source implementations are production-ready. What remains is tuning for a specific codebase, user population, and cost tolerance.
That's where the real work happens. Most teams never get there.