learn-rag-with-phoebe / Builder session 10 of 10
Learn RAG with Phoebe · Builder track · Session 10 of 10

Production RAG: keeping Recall alive - and the handoff

This is the last session. Recall works, it is cited, and it is scored - but a demo that works on your laptop is not a system that survives contact with real users and changing documents. Production RAG is about the parts nobody demos: re-indexing when documents change, caching so you do not re-embed the same text forever, a latency budget you can defend, monitoring that catches quality drift, and a cost ceiling. We close by drawing Recall's full pipeline as one diagram, checking it off for graduation, and pointing at the natural next step - orchestrating retrieval as a tool inside an agent with LangChain.

🔴 Builder track · advanced Practitioners · some Python Final session Session 10 of 10
0-3 · Welcome 3-24 · Keeping it alive 24-42 · Graduation + handoff 42-45 · Q&A
Part 0

The gap between "it works" and "it keeps working"

Everything so far assumed a fixed pile of documents and one query at a time. Production breaks both assumptions. Documents change daily, so your index goes stale. Thousands of queries arrive, so cost and latency stop being free. And no one is watching the demo anymore, so quality drifts unnoticed. Production RAG is the discipline of keeping a retrieval system fresh, fast, cheap, and honest while it runs unattended. None of it is glamorous. All of it is why some RAG systems last years and others die in a month.

Live - presented in session Self-study - full depth after class ★ Recall graduates Sources covered at the end
★ What you build today A production readiness checklist for Recall - a freshness plan, a defended latency budget, a monitoring plan, and a cost cap - plus the full-pipeline picture and a clear next step: orchestrating Recall inside an agent with LangChain.
Part 1 · covers freshness, caching, latency, monitoring, cost

Keeping a RAG system alive 11 min live

Four forces act on a live RAG system: documents drift (freshness), the same work repeats (caching), users wait (latency), and quality slips silently (monitoring) - all under a cost ceiling. Here is the production loop and where the milliseconds and dollars go.

The production loop documents change added / edited / removed re-embed CHANGED chunks + re-index serve queries only re-embed what changed - re-embedding everything is the rookie cost sink Latency budget · where the query-time ms go embed q vector search <100ms rerank (opt) LLM generation - usually the largest retrieval is cheap; the model is where the wait lives - budget accordingly Cost meter embeddings + LLM tokens ↑ cache to keep this bar from creeping Fresh, fast, cheap, watched - a live RAG system is these four forces held in balance.
🔍 Click to zoom - the production loop, the latency budget, and the cost meter
LiveFreshness: re-index without re-doing everything3 min

Your documents will change - new pages, edits, deletions. The naive move is to re-embed the entire corpus on a schedule, which is slow and expensive. The production move is to re-embed only the chunks that changed and re-index those, leaving the rest untouched.

  • Track what changed. Hash each chunk (or watch source timestamps). If the hash is unchanged, skip it - its vector is still valid.
  • Re-embed the delta, re-index it. Only new and edited chunks hit the embedding model; deleted ones are removed from the index.
  • Cadence is a design decision, not a fixed number. There is no authoritative "re-index every N hours". A legal knowledge base that changes quarterly and a news feed that changes hourly need different cadences. Pick yours from how fast your documents actually move and how stale an answer you can tolerate.
Freshness is a product decision Do not let "how often do we re-index" be an infra afterthought. It is a promise to your users about how current Recall's answers are. Write it down as a target ("answers reflect changes within 1 hour") and let that drive the cadence, not the other way around.
LiveCaching: stop paying for the same work twice3 min

Embedding is deterministic: the same text always produces the same vector. So embedding a document you have already embedded is pure waste. Two caches pay off:

  • Cache document embeddings. Compute each chunk's vector once and store it. This is really what your vector store is - the point is to never re-embed unchanged chunks (ties straight back to freshness).
  • Optionally cache frequent answers. If the same popular question arrives constantly, cache its final answer (with a sensible expiry) and skip retrieval and generation entirely. Watch staleness - a cached answer over changed docs is a subtle bug.
Real world

Prompt caching for the RAG prompt itself. Anthropic's contextual retrieval technique contextualizes every chunk once at index time - and keeps that one-time cost low (roughly $1.02 per million document tokens) precisely by using prompt caching. The same idea helps at query time: if a large, stable block of context or instructions repeats across requests, prompt caching means you are not re-paying to process it every call.

LiveLatency budget: know where the time goes3 min

A user-facing RAG query has a time budget, and you should be able to name where every millisecond goes. Roughly, in order:

  • Embed the query. One short embedding call. Small.
  • Vector search. A good ANN index returns in well under 100ms even over millions of vectors. Cheap.
  • Rerank (optional). The cross-encoder or rerank API you added in b5 costs real time but sharply improves precision - a deliberate trade.
  • LLM generation. Almost always the largest slice, and it grows with output length. This is where you spend your latency budget, so it is where optimization (streaming, smaller models, shorter answers) pays back most.
Budget backwards from the user Start with "answers must feel instant, say under 2 seconds to first token", then allocate: retrieval gets a small fixed slice, and the rest belongs to the model. If you are over budget, the lever is almost always generation - not the retriever.
LiveMonitoring: catch drift before users do2 min

In the demo you watched every answer. In production nobody does - so you instrument instead. Log the signals that tell you Recall's quality is slipping:

  • Retrieval quality signals. Log top scores, whether the top-k cleared your b7 refusal threshold, and periodically run the b9 eval on a sample of real traffic.
  • Refusals. Track how often Recall says "I don't know". A sudden spike means retrieval broke (or docs went stale); a drop to zero can mean the refusal guard stopped working and hallucinations are leaking through.
  • Latency and cost per query. Watch the budget and the meter over time - both creep quietly.
Part 2 · covers Recall's full pipeline + the next course

The graduation, and the handoff to LangChain 10 min live

Ten sessions ago Recall was an idea. Here is everything you built, in one picture - split into what happens once at index time and what happens on every query - and where it goes next.

INDEX TIME · once per document change ingest chunk embed store (vector index) QUERY TIME · every user question retrieve rerank augment generate cite evaluate NEXT: orchestrate this inside an agent the model decides when to retrieve → LangChain / LangGraph This is Recall, whole. Index time builds the memory; query time uses it. You built all of it.
🔍 Click to zoom - Recall's full pipeline, index-time and query-time, and the road to agents
LiveThe 2026 frontier: contextual and agentic RAG3 min

RAG did not stop moving. Two directions are where the field is heading, and both build directly on what you now understand:

  • Contextual retrieval. Anthropic's technique prepends a short, chunk-specific context blurb to each chunk before embedding, so an isolated chunk carries the meaning of its whole document. It measurably cuts failed retrievals, and prompt caching keeps the one-time cost low.
  • Agentic RAG. Instead of always retrieving, the model decides when to call a retrieve tool - and can retrieve multiple times, refine its query, or combine sources - as steps in a reasoning loop. Retrieval becomes one tool an agent chooses to use, not a fixed first step.
Prompt caching for RAG cost As systems get more agentic and prompts get longer (instructions, tools, stable context), Anthropic's prompt caching becomes a core cost lever - repeated context is processed once and reused across calls rather than re-billed every request. Keep it in mind as Recall grows.
Self-studyRecall's graduation checklist2 min read

Recall is production-shaped when it can answer yes to all of these. This is your handoff document - the difference between a demo and a system.

  • Freshness plan. Only changed chunks are re-embedded and re-indexed, on a cadence tied to how fast your docs actually change.
  • Caching. Document embeddings computed once; frequent answers cached with expiry; prompt caching for stable repeated context.
  • Latency budget. A named target with time allocated across embed, search, rerank, generate - and generation is the slice you optimize.
  • Monitoring. Retrieval scores, refusal rate, latency, and cost logged; a sample of real traffic run through the b9 eval.
  • Cost cap. A ceiling per month, with alerts, so nothing runs away silently.
  • Eval gate. No change ships unless the b9 scorecard holds or improves.
You built a real RAG system, from scratch From "an embedding is meaning as numbers" in b1 to a monitored, evaluated, production-shaped assistant here in b10 - you understand every stage, why it exists, and how to measure it. That is rarer than it should be. Thank you for building Recall with me across all ten sessions. Now go make it do something that matters.
Build-along · graduate Recall

Write Recall's production readiness checklist ★ 12 min

Your final build-along is a document, not code - and it is the most valuable thing you will write in this track. Turn the graduation checklist into a concrete, filled-in plan for Recall, with real numbers you would actually defend.

Freshness plan. How do your documents change, how fast, and what re-index cadence follows? State the staleness promise ("answers reflect changes within X").

Latency budget. Write your target (e.g. under 2s to first token) and allocate ms across embed / search / rerank / generate. Name the slice you would cut first if over budget.

Monitoring plan. List the exact signals you will log - top retrieval scores, refusal rate, latency, cost per query - and what threshold triggers an alert.

Cost cap + eval gate. Set a monthly ceiling and the rule that no change ships unless the b9 scorecard holds. Now Recall has a constitution, not just code.

★ Recall graduates Recall is fresh, fast, cheap, watched, and scored - a production-shaped RAG system you understand end to end. There is nothing left to add to the pipeline itself. The next move is to give Recall agency: let a model decide when to retrieve, chain steps, and use retrieval as one tool among many. That is orchestration - and it is a whole course of its own.
Homework

After the track ◐ light · your choice

That is the whole track. You started not knowing what an embedding was, and you finish with a production-shaped, evaluated retrieval assistant you built yourself. Be proud of that - and keep building. See you in LangChain. - Phoebe

Source material

Official sources covered

Taught from Anthropic's production RAG writing plus Pinecone and LlamaIndex operational guidance. This page covers the working ideas; hosted-infra specifics stay with the source.

Anthropic · Contextual Retrieval + prompt cachingPart 1-2 · one-time contextualization (~$1.02/M doc tokens via prompt caching) · prompt caching as a cost lever · the 2026 frontier
Pinecone · rerankers & latencyPart 1 · vector search under 100ms · rerank as a latency/precision trade-off
LlamaIndex · storing & freshnessPart 1 · persist/re-index changed chunks · note: no single authoritative re-index cadence - it is a design decision
Check yourself

Three questions before you go 🎯 ◐ 90 seconds

1 · Your knowledge base updates daily. What is the production-right way to keep the index fresh?

Embeddings are deterministic, so unchanged chunks keep valid vectors. Re-embed only the delta (new/edited chunks) and re-index them - re-embedding everything is the classic cost sink.

2 · In a typical query-time latency budget, which stage is usually the largest?

Vector search is well under 100ms and query embedding is tiny. Generation is almost always the largest slice and grows with output length - so it is where latency optimization pays off most.

3 · What best describes agentic RAG, the direction the field is heading?

In agentic RAG retrieval becomes a tool the model chooses to use - it can retrieve zero, one, or several times and refine its query - orchestrated in a reasoning loop (the LangChain/LangGraph handoff).

Builder session 10 cheat sheet · pin this

FreshnessRe-embed only CHANGED chunks and re-index them. Cadence is a design decision tied to how fast docs move.
CachingCompute document embeddings once; cache frequent answers with expiry; prompt-cache stable repeated context.
Latency budgetembed q + vector search (<100ms) + rerank (opt) + generation. Generation is usually the largest.
MonitoringLog retrieval scores, refusal rate, latency, cost. Run b9 eval on sampled real traffic.
Cost + eval gateSet a monthly cap with alerts. No change ships unless the b9 scorecard holds or improves.
Prompt cachingContextual retrieval's one-time cost (~$1.02/M doc tokens) rides on prompt caching. A core cost lever.
2026 frontierContextual retrieval (per-chunk context blurb) + agentic RAG (model decides when to retrieve).
The handoffNext: orchestrate retrieval as a tool inside an agent - LangChain / LangGraph. Recall graduates.