← Back to System Design Mind Map
🏗️ System DesignID: semantic-cache-gateway

Semantic Cache & Request Deduplication

语义缓存与请求去重
🎯Core Definition
The Semantic Cache & Request Deduplication Gateway (GPTCache, Redis Semantic Caching) is an intelligent acceleration layer positioned in front of LLM inference and RAG retrieval pipelines; unlike traditional exact-string hash caches, semantic caches embed incoming queries into dense vectors and execute sub-3ms cosine similarity lookups in memory: if similarity with a cached query exceeds a calibrated threshold τ\tau (e.g. cos⁡(q1,q2)≥0.95\cos(q_1, q_2) \ge 0.95), the cached retrieval context and LLM response are returned instantly; paired with Singleflight distributed mutex locks, it prevents cache stampedes on viral prompts.
💡Use Cases
High-concurrency AI customer service desks, trending enterprise queries, and LLM API cost/latency optimization.
⚡Key Problems Solved
LLMs are expensive and slow (seconds per response); semantic caching intercepts 30%-50% of recurring semantic intents, compressing response times from 2000ms to 5ms while slashing Token expenditure by over 40%.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of Semantic Cache & Request Deduplication.
Use Cases
In production engineering, what are the primary use cases for Semantic Cache & Request Deduplication and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Compare Exact String Match vs Semantic Vector Match across cache hit rates, lookup latencies, and semantic hallucination risks?
2
How to rigorously calibrate the similarity threshold τ\tau to prevent false cache collisions on semantically opposite prompts ('open account' vs 'close account')?
3
Design a Singleflight concurrency barrier preventing Cache Stampedes when thousands of users ask identical breaking queries simultaneously?
4
How to design cascading cache invalidation via metadata reverse indexes when underlying knowledge base documents are updated?
5
Explain cryptographic and metadata-scoped partitioning ensuring Tenant A's private responses never leak to Tenant B's semantic cache hits?
Updated 2026-08-14
🎯
Verify Mastery: Practice Exam Questions for "Semantic Cache & Request Deduplication"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
← Previous CardOnline Parallel Retrieval GatewayNext Card →Multi-Tenant Partitioning & RBAC

🔗 More System Design Knowledge Cards

引用出处: TalentMe 450+ 工业级 AI 架构考点知识库 (Tech Vault) · 遵循 CC-BY-4.0 知识共享协议
URL: https://talentme.airsota.com/resources/tech/roadmap/mindmap/System_Design/card/semantic-cache-gateway
中文速览与面试要点

语义缓存与请求去重 (Semantic Cache & Request Deduplication)

定义: 语义缓存与请求去重网关 (Semantic Cache & Request Deduplication Gateway,如 GPTCache, Redis Semantic Caching) 是部署在大模型推理与 RAG 检索入口前的智能高速缓存层;与传统必须字面完全一致的精确哈希缓存 (Exact KV Cache) 不同,语义缓存利用 Embedding 模型将用户 Query 编码为稠密向量,在毫秒级内(<3 ms)在内存向量索引中进行余弦相似度检索:若与历史缓存 Query 的相似度超过设定阈值 (如 (q_1, q_2) 0.95),则判定为“语义完全等价”,直接将缓存中的检索结果与 LLM 生成文本秒级返回给用户;同时网关结合基于 Redis Distributed Lock 的单飞机制 (Singleflight / Mutex),防止相同热门 Query 瞬间高并发打垮后端检索与大模型集群。 使用场景: 智能客服高频常见问题秒级问答、企业知识库热点搜索、以及大模型 API 成本与首字延迟优化。 解决的问题: 大模型调用成本高昂(按 Token 计费)且推理延迟长(动辄数秒);语义缓存拦截了 30%~50% 的高频相似问题,将这部分请求的响应延迟从 2000ms 压缩至 5ms,并直接节省 40%+ 的 Token 调用账单。

核心要点

  • 详细对比精确匹配缓存 (Exact String Match) 与语义向量缓存 (Semantic Vector Match) 在命中率、延迟与假阳性 (False Positive) 风险上的权衡?
  • 语义相似度阈值 (如 =0.92 vs =0.98)的严谨标定方法:如何避免不同含义但句式相似的问题被错误命中(如“如何开户”与“如何销户”)?
  • 在高并发突发流量下,如何基于 Singleflight (单飞模式) 或 Redis 互斥锁防止缓存击穿 (Cache Stampede / Thundering Herd)?
  • 语义缓存的主动失效与更新策略 (Cache Eviction / Invalidation):当底层知识库文档更新时,如何通过反向元数据索引级联清除失效缓存项?
  • 多租户语义缓存的安全隔离:如何保证租户 A 的私有问答结果绝对不会被租户 B 的相似 Query 命中并泄露?