EasyDeepLearn

What can you cache in a RAG pipeline?

medium

Answer

  • (1) Embeddings: cache query embeddings by exact query hash (short-lived, small hit rate but cheap).
  • (2) Retrieval results: cache retrieved chunk IDs per query hash (good hit rate for repeated queries).
  • (3) LLM answers: cache (query, retrieved chunks) → answer for identical inputs (moderate hit rate).
  • (4) Prompt cache: cache KV state of the system prompt + few-shot examples across all requests (100% hit rate for stable prefixes; huge cost cut).
  • Combine layers for 40-80% cost reduction.
Check yourself — multiple choice
  • Cache nothing
  • Embeddings, retrieval results, answers, KV prompt cache — layer them for 40-80% cost cut
  • Only LLM outputs
  • Impossible to cache

RAG caching: embed / retrieval / answer / KV prompt caches → big cost + latency wins.

#rag#production#cost

Practise LLMs & GenAI

214 interview questions in this topic.

Related questions