Dev.to
7/18/2026

RAG - Semantic Caching
Short summary
Semantic caching in RAG pipelines stores previous query results so semantically similar queries can reuse answers without re-querying the vector database or LLM. Redis or Valkey can serve as in-memory stores for cached queries, embeddings, and answers, with cosine similarity used to match semantically equivalent requests. Cache invalidation is critical — time-sensitive answers like stock prices must expire quickly, and only valuable queries should be cached given limited RAM.
- •Semantic caching reuses RAG results for semantically similar queries, cutting retrieval time and LLM calls
- •Redis/Valkey store query embeddings and answers; cosine similarity determines cache hits
- •Cache invalidation strategy depends on data type — time-sensitive content needs short TTLs
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



