Production RAG System: Streaming, Semantic Caching and Evals by Mohsin SheikhaniProduction RAG System: Streaming, Semantic Caching and Evals by Mohsin Sheikhani

Production RAG System: Streaming, Semantic Caching and Evals

Portfolio project
Mohsin Sheikhani
A RAG backend built for a client and used to measure the decisions that matter in production. This public version shares the methods and code, with a smaller synthetic dataset in place of the client's documents.

What I built and measured

Streaming over SSE: time to first token P50 of 1.7s, against 4.5s total for the blocking endpoint, over 50 paired requests
Exact-match cache in Redis: P50 on repeated questions dropped from 3.9s to 7ms
Semantic cache in Redis Stack: P50 on rephrased questions dropped from 3.9s to 610ms, with the similarity threshold set at 0.85 after studying real misses in Langfuse
Embedding choice: moved to text-embedding-3-small after a small local model couldn't match "make money" with "earn income". Query expansion didn't fix it
Cost model: about $400 to $600 a month at 1M queries, with LLM input tokens the largest cost and cache hit rate the next biggest lever

What I found in evals

With a deliberately broken retriever, faithfulness and answer relevancy both stayed at 1.00 while contextual recall dropped to 0.00. Recall was the only one of four standard RAG metrics (DeepEval) that caught it.

Stack

Python, FastAPI, Haystack, Qdrant, Redis Stack, OpenAI, DeepEval, Langfuse, Docker

0 likes · 0 views · Dec 1, 2026

A Haystack and Qdrant RAG backend with SSE streaming and two cache layers, where each engineering choice is measured for latency, quality and cost.

Tags