BXUP Track progress & test yourself — free
Forward Deployed AI Engineer · Hands-on lab · ~1 min read
FORWARD DEPLOYED AI ENGINEER · HANDS-ON LAB

Lab 05 · Semantic Cache & Intelligent Model Router with Redis

Deploy an intelligent routing gateway backed by a Redis semantic vector cache that intercepts repetitive queries, serves cached responses in sub-15ms at $0 cost, and routes non-cached queries between small language models and frontier models.

Time & Tier

~90 minutes hands-on · FDE Track, Core Production difficulty.

The Scenario

A corporate client’s OpenAI API bill reached $25,000 in two weeks. An audit reveals that 65% of employee queries are repetitive FAQ inquiries. You will build a proxy gateway using Redis vector search that intercepts queries with $\ge 0.95$ cosine similarity and dispatches residual queries by task complexity.

Deliverables

  1. cache_gateway.py: Redis semantic cache with vector index creation.
  2. router.py: Intent and complexity classifier dispatching to SLM vs LLM.
  3. telemetry.py: Token savings and latency metric counter.

Step-by-Step Instructions

  1. Install Dependencies:

    pip install redis==5.0.7 numpy==1.26.4
    
  2. Implement Vector Distance Caching: Embed incoming queries and run a vector similarity search against cached questions in Redis. If similarity exceeds 0.95, return the cached answer immediately.

  3. Deploy Tiered Routing: For cache misses, inspect query length and intent classification. Route simple single-clause queries to lightweight models (gpt-4o-mini or local Llama-3-8B), reserving frontier models for multi-document reasoning.

  4. Verify It Works: Simulate 1,000 queries with 60% repetition. Confirm that the semantic cache achieves a $\ge 55%$ hit rate, cutting simulated API spend by over 70%.

This is the free reading view. Open BXUP to track your progress, run the hands-on labs, and prove it with original, exam-pattern assessments.
© Anvi Innovate · BXUP — Be Exponentially Upskilled · BXUP is an independent learning platform, not affiliated with or endorsed by AWS, Microsoft, Google, NVIDIA, IBM, Salesforce, Databricks, Oracle or Anthropic. All trademarks belong to their respective owners. · bxup.in