To keep serving pipelines predictable under bursty prompts, fast TTFT, zero ACL leaks, and predictable token spend.
TL;DR30-second simplified summary▾
The design partitions state, bounds tail latency, and isolates failure domains.
Fast TTFT, zero ACL leaks, and predictable token spend.
ACL-filtered Hybrid Retrieval & Reranking.
Combine dense HNSW vector search with sparse BM25 lexical search using Reciprocal Rank Fusion (RRF), filtering strictly by the user's document ACLs before ranking. Read more on how Input & Output Tokens shape prompt budgets.
| Choice | What it buys | What it costs |
|---|---|---|
| Semantic Cache in Redis | Sub-20ms cache hits for recurring queries | Must key cache by `(tenant_id, acl_group)` to prevent cross-tenant data leaks |
Insight 1
Enforce tenant/role ACL filters inside the vector index metadata filter—never filter only after retrieving Top-K.
Insight 2
Use a lightweight cross-encoder reranker to narrow Top-50 hybrid hits down to the 5 sharpest chunks.
Token Budgeting, Prefix Caching & Rate Limiting.
Track token-per-minute (TPM) quotas in Redis alongside request-per-minute limits, and place static system prompts at index 0 so the LLM engine reuses KV prefix caches.
Insight 1
Reserve max_tokens for output before fitting retrieved chunks into the context window.
Insight 2
Stream responses over SSE so users perceive low latency even when Decode takes several seconds.
Cross-Tenant Semantic Cache Leak
User B hits a cached answer generated from User A's confidential document.
Put the Enterprise RAG Gateway together
Unite [Redis](/domains/redis) semantic/token rate limiting, ACL-enforced hybrid retrieval, and KV-cache-friendly prompt assembly for [LLM](/domains/llm) serving.
Reference Topology & Execution Flow
- Check tenant-scoped semantic cache and TPM token bucket in Redis.
- Run ACL-filtered Hybrid Search (Dense + BM25) and rerank to Top-5 chunks.
- Assemble prompt with static prefix first and stream tokens via SSE.
Interview Readiness Check
Fast TTFT, zero ACL leaks, and predictable token spend.
Walk through bottlenecks, back-of-the-envelope math, and failure recovery.
Practice: Make the trade-off yourself.
Practice Check
Test your understanding
Why does placing request_timestamp at the very beginning of a 3,000-token system prompt hurt latency and cost?