Beyond Chunking: How to Design Production-Grade RAG Systems That Actually Work
The biggest misconception in the industry: RAG is not about chunking — it is about information architecture.
Most teams I talk to treat RAG as a retrieval problem. They obsess over chunk size, overlap windows, and embedding models. They benchmark cosine similarity scores. They debate 512 tokens vs 1024 tokens.
And then they wonder why their system hallucinates on complex queries, misses obvious answers, or returns five paragraphs of irrelevant context to the LLM.
The problem isn't the chunks. The problem is the architecture.
After building RAG pipelines for production systems — spanning legal document search, internal knowledge bases, enterprise support bots, and multi-domain AI assistants — here is what I've learned: simple vector similarity is the wrong primitive for complex tasks. It is a starting point, not a solution.
This post is about what comes next.
The Naive RAG Trap
The naive RAG pipeline looks like this:
User query → Embed query → Cosine similarity search → Top-K chunks → LLM → Response
This works surprisingly well in demos. It fails quietly in production.
Why? Because it collapses everything into a single operation — a brute-force nearest-neighbour search on a flat vector space. It treats all documents equally, all queries uniformly, and all context as interchangeable.
Real-world information is none of those things.
A user asking "What are the compliance obligations for a Series B company under GDPR Article 30?" is not asking for the closest sentence to their query. They are asking for:
- A specific article from a legal framework
- Applied to a specific company stage
- With cross-references to related obligations
A cosine search on that query will return three paragraphs about GDPR from three different documents, none of which individually answers the question. The LLM then hallucinates the rest.
This is not an LLM problem. This is a retrieval architecture problem.
What Production RAG Actually Looks Like
Let me walk through the five pillars that separate toy RAG from production RAG.
1. Metadata Layers — Give Your Retriever Context Awareness
Every chunk in your vector store should carry structured metadata. Not just source filename — rich, queryable attributes.
{
"chunk_id": "gdpr-art30-sec2-para1",
"source": "GDPR_Full_Text.pdf",
"document_type": "regulation",
"jurisdiction": "EU",
"article": "Article 30",
"section": "Records of Processing Activities",
"effective_date": "2018-05-25",
"tags": ["compliance", "data-processing", "controller-obligations"],
"chunk_text": "Each controller shall maintain a record of processing..."
}
Why does this matter? Because metadata filters let you narrow the search space before semantic search runs. Instead of searching 500,000 chunks, you search 800 pre-filtered chunks. Precision improves dramatically. Latency drops.
In practice, this means:
- Pre-filtering by document type before embedding search
- Date-range filters for time-sensitive queries
- Tag-based scoping when query intent is classifiable
- Source authority weighting — a primary legal text ranks higher than a blog summary
Think of metadata as the WHERE clause in your retrieval SQL. Semantic search is the full-text search. You need both.
2. Hierarchical Retrieval — Structure Mirrors Reality
Documents are not flat. They have chapters, sections, subsections, and paragraphs. Your retrieval should reflect this.
The pattern: index at multiple granularities, retrieve at the right level.
Document
└── Section (coarse index)
└── Paragraph (fine index)
└── Sentence (ultra-fine, for precision)
How it works in practice:
- Query hits the paragraph-level index first
- The system walks up the hierarchy to fetch the parent section for broader context
- Both are passed to the LLM — precise match + surrounding context
This solves the classic RAG failure: the answer is in the chunk, but the chunk makes no sense without the paragraph before it.
Libraries like LlamaIndex call this small-to-big retrieval or parent-child chunking. The naming varies, the concept is the same: retrieve small, expand up.
3. Hybrid Search — Combine Semantic and Lexical
Pure vector search misses exact matches. If a user types a product SKU, a legal clause number, or a specific API method name — embedding similarity will dilute it across semantically similar but incorrect results.
Production systems use hybrid search: BM25 (keyword/lexical) + dense vector retrieval, fused together.
# Pseudocode — hybrid retrieval with RRF fusion
bm25_results = bm25_index.search(query, top_k=20)
vector_results = vector_store.search(embed(query), top_k=20)
# Reciprocal Rank Fusion
fused = reciprocal_rank_fusion([bm25_results, vector_results])
return fused[:10]
When BM25 wins: Exact terms, product codes, names, acronyms, technical jargon
When vector wins: Paraphrased queries, conceptual questions, cross-lingual search
Hybrid always wins: Complex enterprise queries that are both
Tools like Elasticsearch, Weaviate, and Qdrant have native hybrid search support. Use it.
4. Query Decomposition — Break Before You Retrieve
Complex queries should never hit the retrieval layer as-is. They need to be decomposed first.
The pattern:
Original query
→ LLM decomposition → [sub-query 1, sub-query 2, sub-query 3]
→ Retrieve for each sub-query independently
→ Merge results
→ LLM synthesis
Example:
User: "Compare our refund policy with what competitors typically offer and flag any legal risks."
This is three questions:
- What is our refund policy?
- What do competitors typically offer?
- What are the legal risks in refund policies?
A single retrieval pass on this compound query will return garbage. Decompose it, retrieve independently, then synthesize.
This is where frameworks like LangGraph shine — you can build stateful decomposition pipelines with explicit steps, retries, and conditional routing.
5. Re-ranking Pipelines — Retrieval Is Not the Last Word
Your top-K retrieval results are a candidate pool, not a final answer. Re-ranking is the step that separates relevant from truly useful.
Query → Retrieve top-20 → Re-ranker → Top-5 → LLM
Cross-encoder re-rankers (like Cohere Rerank, BGE-Reranker, or Jina Reranker) take query + document pairs and score them jointly. This is far more accurate than embedding similarity, but too expensive to run on the full corpus — hence the two-stage pattern.
What re-ranking catches that vector search misses:
- Documents that are topically related but not the actual answer
- Chunks that match the query surface but not the intent
- Redundant results that waste LLM context window
In production, a 20→5 re-ranking step often improves answer quality more than any chunking parameter change. It is consistently under-used.
Putting It Together — The Production RAG Stack
User Query
│
▼
Query Classifier & Decomposer
│
├── Sub-query 1 ──→ Metadata Filter → Hybrid Search → Top-20
├── Sub-query 2 ──→ Metadata Filter → Hybrid Search → Top-20
└── Sub-query 3 ──→ Metadata Filter → Hybrid Search → Top-20
│
▼
Hierarchical Expansion
(fetch parent context)
│
▼
Re-ranker (→ Top-5 per sub-query)
│
▼
Context Assembly & Deduplication
│
▼
LLM with structured prompt
│
▼
Final Response
Is this more complex than a naive pipeline? Yes.
Is it necessary for anything beyond a simple FAQ bot? Also yes.
When Simple RAG Is Fine
To be fair: not everything needs this complexity.
Simple RAG works when:
- Your document corpus is small and homogeneous (< 500 documents)
- Queries are simple and single-intent
- The cost of a wrong answer is low
- You are prototyping, not shipping
The moment you hit any of these: you need the architecture above.
- Multi-domain knowledge bases
- Regulatory or legal document search
- Complex multi-hop questions
- Enterprise-grade accuracy requirements
- Latency and cost SLAs at scale
Key Takeaways
Stop tuning chunk size as your primary lever. The returns diminish fast.
Start with metadata design. Before you index a single document, design the metadata schema. This decision has more impact than any model choice.
Implement hybrid search from day one. Pure vector search will eventually fail you on exact-match queries. BM25+vector is not complex to add and the payoff is immediate.
Add a re-ranker before going to production. It is the highest ROI improvement for a deployed RAG system.
Model your queries, not just your documents. Query decomposition is often the missing piece when systems fail on complex questions.
RAG done right is not a retrieval problem. It is an information architecture problem. Design it like one.
If you are building production RAG systems and want to discuss architecture — reach out. Always happy to go deeper on any of these layers.
Tags: RAG, LLM, AI Engineering, Information Retrieval, Vector Search, Production AI, LangChain, LlamaIndex, Enterprise AI
