AI Development

RAG in Production: Architecture Patterns That Actually Scale

A RAG demo with 50 documents and a RAG system with 500,000 documents are different engineering problems. Here's the architecture that held up once we stopped treating retrieval as an afterthought to the prompt.

KAKabir AnandLead Developer
11 min read
Smooth abstract gradient waves in blue and purple

Most RAG tutorials get you a working demo in an afternoon: chunk some documents, embed them, stuff the top results into a prompt. That pipeline works beautifully at 50 documents and quietly falls apart somewhere between 5,000 and 50,000 — not because the model got worse, but because retrieval quality did.

Chunking is a product decision, not a default

The default "split every 500 tokens" chunking strategy treats every document like undifferentiated text. A support article, a legal contract and a changelog all fail differently when chunked naively — the fix is chunking that respects each content type's actual structure, not one universal setting.

  • Structured docs (contracts, policies) chunk by section heading, never mid-clause — a clause split across two chunks retrieves neither correctly.
  • Conversational content (support tickets, chat logs) chunks by exchange, preserving the question-answer pair as one retrievable unit.
  • Code and changelogs chunk by logical unit (a function, a version entry) — token-count chunking routinely splits a single relevant example in half.

The retrieval pipeline that held up at scale

Production retrieval, not the demo version

QueryUser's raw question
RewriteExpand + clarify ambiguous terms
Hybrid searchVector + keyword, not vector alone
RerankCross-encoder scores top-k
GenerateOnly the reranked top 3–5 reach the prompt

The single highest-leverage change we've made across client RAG systems is adding a reranking step. Vector similarity alone reliably returns results that are topically related but not actually the best answer — a cross-encoder reranker scoring the initial candidates catches that gap, and it's cheap relative to the generation call that follows it.

rag/retrieve.ts
1const candidates = await vectorStore.similaritySearch(query, { k: 20 });
2const reranked = await reranker.rank(query, candidates);
3const context = reranked.slice(0, 5);
4// only the top 5, reranked — not the raw top 20 vector hits
The failure mode nobody demos

"The answer isn't in the retrieved chunks" is nearly always a retrieval bug, not a generation bug — teams that debug it by tweaking the prompt are fixing the wrong layer. Log what got retrieved before touching the prompt.

Evaluation is the part that never makes the demo

We run a fixed set of representative queries with known-correct answers against every retrieval change, before it ships. Without that harness, a chunking or reranking tweak that helps one query can silently regress ten others — and you won't find out until a user does.

34%

improvement in answer accuracy after adding a reranking step

3 types

of chunking strategy we run in parallel across different content types

100%

of retrieval changes gated behind a regression eval before shipping

When a RAG answer is wrong, the prompt is rarely the bug. It's almost always what got retrieved before the model ever saw the question.

Kabir Anand, Lead Developer

Key Takeaways

  • Chunking strategy should match content structure — one universal token-count setting degrades differently across document types.
  • Hybrid search plus a reranking step consistently outperforms vector similarity alone, and it's the single highest-leverage addition we've made.
  • Debug "the answer isn't in the context" as a retrieval problem first — tuning the prompt fixes the wrong layer almost every time.
  • Build a fixed regression eval set before you need one — without it, retrieval tweaks trade one query's accuracy for another's silently.

Bringing it together

RAG that works in a demo and RAG that works at scale differ almost entirely in the retrieval layer, not the generation call. Invest there first — the model was probably never the bottleneck.

Keep Reading

More from the blog

The Engineering Partner You Can Build On

Reliable software takes an experienced team that owns delivery end to end. Here’s the track record behind ours.

11+

Years Building Custom Software

320+

Projects Delivered Across Web, Mobile & AI

85%

Repeat Client Rate

12+

Countries Served Worldwide

Trusted by startups and enterprises worldwide

Work With Us

Let’s create
with purpose

Share your goals, timeline, and challenges — we’ll respond with clarity and next steps.

Ambitious ideas deserve thoughtful execution. Start the conversation and let’s define what success looks like.

Team

Acetrum

Est. 2015

4.9/5

Trusted by
top brands

Services interested in:

By submitting, I confirm I’ve read and agree with Privacy and Cookie Policies.

Newsletter

Signals worth
paying attention

No recycled headlines — just the patterns we’re seeing across real client work, distilled into one read a month.

A curated digest of practical thinking and real-world brand perspectives monthly.

No spam. Unsubscribe anytime.