Production RAG: ingestion, freshness, access control, caching, latency and cost per answer
A RAG demo answers questions; a production RAG system answers them correctly, for the right users, from current documents, within a latency and cost budget. This guide covers ingestion, freshness, access control, caching, latency and cost per answer, with runnable Python and worked numbers.
- Reading time
- 13 min
- Sections
- 7
- Code examples
- 4
- Tables
- 2
- Sources
- 7
- Published
- 24 Nov 2026
- What changed
- LlamaIndex relocks integrations for security fixes
- Why it matters
- Production RAG is mostly data engineering and operations.
- What to do
- Set freshness targets per source
Building a retrieval-augmented generation (RAG) prototype takes an afternoon. Running one for thousands of employees or customers is a different job. The questions change from "does it answer?" to "does it answer from this morning's version of the policy, without showing salary data to the wrong person, in under two seconds, for less than a cent?" Most production failures are not model failures. They are stale indexes, leaked permissions, slow pipelines and bills nobody estimated.
This article covers the six concerns that separate a production RAG system from a demo: ingestion, freshness, access control, caching, latency and cost per answer. It starts from this autumn's releases in the RAG supply chain, which are a reminder that the pipeline is software that needs patching, then works through each concern with runnable Python and worked numbers.
An analogy: a prototype RAG system is a talented new hire with a box of photocopies. A production system is that same person with a filing process, a shredder for outdated copies, a security badge that limits which cabinets they can open, a notepad of common answers, and a manager watching response times and expenses.
What happened
LlamaIndex relocks integrations for security fixes (13 November 2026)
The LlamaIndex changelog entry for 13 November 2026 relocks the uv.lock files of all integration packages for security fixes and marks a breaking change that raises the required Python version across integrations; LlamaIndex core moved to 0.14.26 the same day. Earlier this year Microsoft's GraphRAG bumped its NLTK dependency in 3.0.8 to resolve CVE-2025-14009. RAG stacks pull in parsers, tokenizers, database clients and model SDKs, and each is part of the attack surface.
Docling 2.152.0 improves ingestion as a service (23 November 2026)
Docling v2.152.0, released on 23 November 2026, lets the server choose the default pipeline in its service mode and cancels queued PDF parsing when conversions stop. Both matter when parsing runs as a shared service under load: cancelled jobs no longer consume workers, and clients need not hard-code pipeline choices.
pgvector 0.8.7 patches an index build overflow (1 October 2026)
pgvector 0.8.7 fixed a buffer overflow during IVFFlat index builds, after earlier 2026 patch releases fixed possible HNSW index corruption during vacuuming. For teams that keep vectors in Postgres, index maintenance and extension upgrades belong in the same change process as database upgrades.
Ingestion and freshness
Parse once, keep the structure
Ingestion starts before chunking. Each source type needs a parser that keeps structure: heading paths, page numbers, table boundaries, list items and links. Run parsing as a queue-backed service with retries and timeouts, because a few malformed PDFs can otherwise stall a nightly job, and Docling's new cancellation of queued work addresses exactly that failure. Store the parsed, structured output as an intermediate artefact. When you later change chunk size or embedding model, you re-chunk and re-embed from that artefact instead of re-parsing millions of files, which is usually the slowest and least deterministic step.
Attach metadata at this stage, not later: source system and URL, document owner, language, last-modified time, version, and the permission groups that may read it. Every later stage, from filtering to citations to cache invalidation, depends on it.
Ingest incrementally, keyed by content
A production index changes every day. Re-embedding everything nightly is wasteful and slow; the standard pattern is incremental ingestion: detect what changed, re-parse and re-embed only that, and delete what disappeared. Content hashes make change detection cheap and exact.
import hashlib
def chunk_hashes(doc_id, chunks):
return {f"{doc_id}#{i}": hashlib.sha256(c.encode()).hexdigest()[:12]
for i, c in enumerate(chunks)}
old = chunk_hashes("policy-7", ["Refunds within 14 days.", "Shipping 3-5 days.", "Support 9-17 CET."])
new = chunk_hashes("policy-7", ["Refunds within 30 days.", "Shipping 3-5 days.",
"Support 9-17 CET.", "Returns are free."])
to_embed = [k for k in new if old.get(k) != new[k]]
to_delete = [k for k in old if k not in new]
print("re-embed:", to_embed, "delete:", to_delete)
The output is re-embed: ['policy-7#0', 'policy-7#3'] delete: []: the changed refund rule and the new returns sentence are re-embedded, and the two unchanged chunks are skipped. There is a trap in this simple version. The chunk IDs are positions, so inserting a sentence at the top would shift every ID and force a full re-embed. Production systems use stable anchors, such as a heading path plus a content hash, so an insertion touches only its neighbours.
Freshness is a pipeline property
Freshness is the time from a document changing at its source to the new version being retrievable. It has three parts: detection (polling, webhooks or change data capture from the source system), processing (parse, chunk, embed) and index visibility (some indexes need a refresh or merge before new vectors are searchable). Set a freshness target per source, for example 15 minutes for the policy wiki and 24 hours for the archive, and measure it.
Store metadata that lets the model and the user see freshness: source URL, last-modified time and version on every chunk. When two chunks disagree, the newer one should win, and the prompt should say so. Deletions need as much care as additions: a withdrawn policy that stays in the index is worse than a missing one, because it is confidently wrong.
Access control
RAG systems often index documents with different audiences: public pages, team wikis, HR records. The rule is simple and often broken: filter by permission before ranking, never after generation. If restricted text reaches the prompt, the model can paraphrase it into the answer, and no output filter reliably catches a paraphrase.
chunks = [{"id": "hr-1", "acl": {"hr"}, "text": "Salary bands for 2027"},
{"id": "pub-1", "acl": {"all"}, "text": "Holiday calendar 2027"},
{"id": "eng-4", "acl": {"eng"}, "text": "Incident runbook"}]
def visible(user_groups):
return [c["id"] for c in chunks if c["acl"] & (user_groups | {"all"})]
print(visible({"eng"}), visible({"hr"})) # ['pub-1', 'eng-4'] ['hr-1', 'pub-1']
In a real system the access control list travels with each chunk as metadata, copied from the source system at ingestion, and the vector query includes a filter on the user's groups. Three details matter. First, permission changes at the source must reach the index as fast as content changes, or revoked access lingers. Second, approximate indexes apply filters with care: as the site's pgvector page explains, post-filtering an HNSW result can return too few rows, so use filter-aware search or iterative scans. Third, caches must respect permissions too: a cached answer built from HR documents must never be served to an engineer. For multi-tenant products, the strongest isolation is structural rather than a filter: a separate index, collection or namespace per customer, so a bug in a filter expression cannot cross tenants. Shared indexes with tenant filters are cheaper and simpler to run, but they need tests that try to read another tenant's data on every release. Either way, keep an audit log of which chunks were shown to which user, because "who could have seen this document?" is a question security teams will ask.
The guardrails page and the prompt injection defence page cover the other side of RAG security: retrieved text is untrusted input.
Caching, latency and cost per answer
Where caching helps
Three caches are common. Embedding caches store query embeddings for repeated questions. Semantic answer caches return a stored answer when a new question is close enough to a previous one, often kept in a store such as Redis; they are powerful for FAQ-like traffic and dangerous when answers depend on the user, the date or permissions, so key them by permission scope and expire them when sources change. Prompt or KV caches make the stable prefix of every prompt, such as instructions and tool definitions, cheaper and faster.
Latency is a sum of sequential stages
With example median timings:
| Stage | Example p50 |
|---|---|
| Query embedding | 15 ms |
| Hybrid retrieval | 40 ms |
| Rerank top 30 | 60 ms |
| LLM time to first token | 450 ms |
| Generate 250 tokens at 80 tokens/s | 3,125 ms |
Time to first token is 15 + 40 + 60 + 450 = 565 ms; the full answer takes 3,690 ms. Generation dominates, so streaming the answer matters more for perceived speed than shaving retrieval. Every added sequential step, such as a query rewrite or a second retrieval round, adds its full latency to time to first token. Track p95 and p99 as well as medians: rerankers and LLM endpoints have long tails under load.
Cost per answer
The same pipeline, priced with example rates of 3 dollars per million input tokens, 15 per million output tokens, 2,400 input and 250 output tokens per answer, 0.0004 dollars for reranking and 0.0002 for retrieval infrastructure per query:
def cost_per_answer(in_tok=2_400, out_tok=250, p_in=3e-6, p_out=15e-6,
rerank=0.0004, retrieval=0.0002, hit_rate=0.0):
full = in_tok * p_in + out_tok * p_out + rerank + retrieval
return (1 - hit_rate) * full + hit_rate * retrieval # a hit still pays one lookup
| Semantic cache hit rate | Dollars per answer | Dollars per month at 300,000 answers |
|---|---|---|
| 0 percent | 0.01155 | 3,465 |
| 20 percent | 0.00928 | 2,784 |
| 40 percent | 0.00701 | 2,103 |
Input tokens are the largest item (0.0072 of the 0.01155), so the number and size of retrieved chunks is the main cost lever, followed by output length. A 20 percent cache hit rate saves about 680 dollars a month here, but only if cached answers stay correct. The site's page on cost and latency budgets and the article on LLM serving stacks, caching and routing go further.
Continue learning
How this article connects
10 pages link to or from it. Drag to turn, click a dot to open it.
What it means in practice
Production RAG is mostly data engineering and operations. The model call is one line; ingestion, metadata, permissions, caching and monitoring are most of the code and most of the incidents. Teams that treat the index as a living dataset, with change detection, versioning, deletion and audits, avoid the classic failures: stale answers, phantom documents and permission leaks.
Treat index changes like deployments. A new embedding model, chunking rule or parser version produces a new index; build it alongside the live one, run the evaluation suite against both, send a small share of traffic to the new index, and switch only when quality, latency and cost hold. Keep the old index until the new one has served real traffic without regressions, so rollback is a configuration change rather than a rebuild. Ongoing model monitoring then watches the live system for drift in retrieval scores, refusal rates and user feedback.
Observability ties it together. For every answer, log the question, the user's permission scope, the retrieved chunk IDs with their versions and scores, the prompt size, the model, latency per stage and cost. That trace turns "the bot said something wrong" into a specific failure: missing chunk, stale chunk, wrong rank or unfaithful generation. Tracing with OpenTelemetry-compatible tools is now standard, as the site's article on agent observability with Langfuse and OpenTelemetry shows.
The releases this autumn underline a less glamorous point: dependencies move fast. Parsers, vector extensions and framework integrations all shipped security and stability fixes. Pin versions, track advisories, and run your evaluation suite on every upgrade.
What to do now
- Set freshness targets per source. Define how quickly changes must be searchable, and measure detection, processing and index visibility separately.
- Ingest incrementally with stable chunk IDs. Use heading paths plus content hashes so edits re-embed only what changed.
- Handle deletions explicitly. Remove chunks when documents are withdrawn, and verify by searching for them.
- Copy permissions into chunk metadata. Filter retrieval by the user's groups before ranking, and sync permission changes as fast as content changes.
- Scope every cache. Key semantic and answer caches by permission scope and source versions, and expire them when sources change.
- Budget latency by stage. Measure p50 and p95 per stage, stream answers, and avoid adding sequential steps without measuring their cost.
- Track cost per answer. Log tokens, reranking and retrieval cost per request and alert on drift.
- Trace every answer. Record chunk IDs, versions, scores and prompt size so wrong answers can be diagnosed.
- Patch the pipeline. Pin dependencies, follow advisories for parsers, vector stores and frameworks, and rerun evaluations after upgrades.
Risks and open questions
Permission leaks are the worst failure. A single misconfigured filter or shared cache can expose confidential text to every user. Test access control with adversarial queries before launch and after every change.
Stale content is silent. Users cannot tell an outdated answer from a current one unless the system shows dates and sources. Monitor index lag and show last-updated times.
Semantic caches can serve wrong answers. Two questions that look alike may need different answers, for example for different countries or dates. Set strict similarity thresholds and scope keys.
Costs drift with behaviour. Longer questions, more retrieved chunks and longer answers raise cost quietly. Per-answer cost tracking catches it early.
The supply chain keeps moving. Breaking changes and security fixes in frameworks and extensions can alter behaviour. Upgrades need the same evaluation gate as feature changes.
Watch next: whether vector databases and frameworks make permission-aware retrieval and cache scoping default rather than optional, and how parsing services evolve as vision-language parsers move into ingestion pipelines.
Frequently asked questions
What is the difference between a RAG prototype and production RAG?
A prototype answers questions from a static index for trusted users. Production RAG adds incremental ingestion, freshness targets, deletions, access control, caching, latency and cost budgets, monitoring and security patching, so it stays correct, safe and affordable as documents and users change.
How do I keep a RAG index up to date?
Detect source changes with webhooks, polling or change data capture, re-parse and re-embed only changed chunks using content hashes and stable IDs, delete withdrawn chunks, and measure the time from source change to searchable update.
How should access control work in RAG?
Copy each document's permissions into its chunks' metadata and filter retrieval by the user's groups before ranking. Never rely on filtering the generated answer, because the model can paraphrase restricted text that reached the prompt.
What does a RAG answer cost?
It depends mainly on input tokens. In the worked example, 2,400 input and 250 output tokens plus reranking and retrieval cost about 0.0116 dollars per answer, or about 3,465 dollars for 300,000 answers a month; a 40 percent cache hit rate cut that to about 2,103 dollars.
Is semantic caching safe for RAG?
Only with care. Scope cache keys by permission and source versions, use strict similarity thresholds, and expire entries when sources change. Without that, a cache can serve outdated or unauthorised answers.
Summary
Production RAG is the discipline of keeping a retrieval system correct, safe, fast and affordable. Ingest incrementally with content hashes and stable chunk IDs so edits re-embed only what changed; the worked example re-embedded two of four chunks. Set freshness targets and handle deletions. Enforce access control before ranking, carry permissions in chunk metadata, and scope caches by permission. Budget latency by stage, where generation dominates a 3.7-second answer, and track cost per answer, where input tokens are the biggest share of about 0.0116 dollars. This autumn's security and stability releases in LlamaIndex, Docling and pgvector are the reminder that the pipeline is software: pin, patch, trace and re-evaluate.
Sources
Cite this article
Kelahmet, Ö. C. (2026, November 24). Production RAG: ingestion, freshness, access control, caching, latency and cost per answer. Özer Cem KELAHMET. https://www.ozercemkelahmet.com/articles/production-rag-ingestion-freshness-access-cost
BibTeX
@online{kelahmet2026production,
author = {Kelahmet, {\"O}zer Cem},
title = {{Production RAG: ingestion, freshness, access control, caching, latency and cost per answer}},
year = {2026},
month = {nov},
url = {https://www.ozercemkelahmet.com/articles/production-rag-ingestion-freshness-access-cost}
}Version historyfirst version
- Published
Factual corrections are listed here with what changed. Wording and formatting edits are not listed.