Advanced RAG patterns and pipelines

Retrieval-Augmented Generation (RAG) has become one of the most powerful techniques in the world of large language models (LLMs). At its core, RAG is simple: instead of relying only on the LLM’s memory, we fetch relevant knowledge from an external source (like a vector database), feed it to the model, and get better, fact-based answers.
But as many teams quickly realize, the basic RAG pipeline doesn’t always scale well. It can miss the right context, return slow responses, or produce answers that sound correct but are actually misleading. That’s where advanced RAG techniques come in.
Let’s walk through this journey step by step like building a smarter assistant one layer at a time.
Scaling RAG Systems: Accuracy vs Speed
When you first build a RAG system, it works fine on small datasets. But what happens when your knowledge base grows into millions of documents? Suddenly, retrieving the right chunk becomes harder, and you face the speed vs accuracy trade-off.
If you focus on speed, you might grab the wrong documents.
If you focus on accuracy, the system might slow down.
To balance this, engineers use indexing strategies like hybrid search (mixing keyword + vector search) and caching frequent queries. This way, the system keeps up both accuracy and efficiency.
Smarter Queries: Translation and Sub-Query Rewriting
Often, users don’t ask questions in the most “retrieval-friendly” way. A student might ask, “Who built the first iPhone?” while your database only has text like “Apple Inc. launched the first iPhone in 2007.”
Here, query translation helps the system rewrites the question into a better form for the retriever. Even more advanced is sub-query rewriting, where one big query is split into smaller, manageable parts. For example, asking “What’s the history and impact of the iPhone?” can become two separate searches: one for history and one for impact.
This ensures your retriever finds richer context, and your LLM answers with more depth.
Ranking Strategies: Picking the Best Context
Imagine your retriever pulls back 50 possible chunks. Not all of them are equally useful. Some might be highly relevant, while others are just noise.
That’s where ranking strategies come in. Instead of sending all chunks to the LLM (which is expensive and confusing), the system re-ranks them and selects the top few.
Some pipelines even use an LLM as the evaluator here — scoring how well each chunk answers the query before passing them along. This helps filter out irrelevant text and boosts precision.
HyDE and Corrective RAG: Getting Creative with Context
Sometimes, the retriever doesn’t find the perfect answer at all. That’s where Hypothetical Document Embeddings (HyDE) come in. Instead of searching only real documents, the LLM first generates a fake but likely-looking answer, embeds it, and uses that as the search query. Strangely enough, this works really well when data is sparse.
HyDE (Hypothetical Document Embeddings) is a technique that improves retrieval by asking the LLM to first generate a plausible answer (a hypothetical document) for a given query.
Instead of embedding the raw query directly, we embed this generated document.
This embedding usually represents the semantics of the “ideal” answer better than the original short query.
Example:
Query → “Impact of AI on medical imaging”
LLM generates a hypothetical doc:
"AI in medical imaging has improved diagnosis accuracy, automated anomaly detection, and reduced workload for radiologists…”
This doc is then embedded → better match in the vector DB.
⚙️ How it Works (Pipeline)
User Query → “What are the risks of blockchain in banking?”
LLM Expansion → Generate a “hypothetical document” that might answer this.
- Prompt: “Write a short passage that could plausibly answer the question.”
Embed the Hypothetical Doc → Convert to vector embedding.
Retrieve Documents → Use the new embedding to query vector DB (Qdrant, Pinecone, etc.).
Rerank/Combine → Retrieved docs are reranked and passed to the LLM for final answer.
Advanced Technical Variations
Multi-HyDE: Generate multiple hypothetical docs → embed all → merge results → improves recall.
Weighted HyDE: Combine query embedding + hypothetical embedding with a weight factor (α).
- Final Embedding = α QueryEmbedding + (1-α) HyDEEmbedding
Self-Consistency HyDE: Sample multiple hypothetical docs with temperature > 0, then average embeddings.
Rerank Hybrid HyDE: Retrieve with both raw query & HyDE doc, then rerank.
On the other hand, Corrective RAG is like a safety net. After the model generates an answer, another step checks if it’s factually correct. If not, the system tries to retrieve again and refine the response. Think of it like a “second chance” for RAG.
Contextual Embeddings and Hybrid Search
The quality of retrieval depends heavily on embeddings. Basic embeddings only capture semantic similarity, but advanced pipelines use contextual embeddings that adapt to the domain for example, medicine, law, or finance.
Pair this with hybrid search (keyword + vector), and you get the best of both worlds: exact keyword matches for precision and semantic matches for flexibility.
Contextual embeddings:
Advanced pipelines fine-tune embeddings on domain-specific corpora so that the vector space aligns better with the field’s language.In medicine → "angioplasty" is closer to "stent" than to "painting".
In law → "habeas corpus" sits near other legal doctrines, not random Latin phrases.
In finance → "liquidity" relates to "cash flow" more than "water".
This ensures high recall + domain relevance.
Hybrid search (keyword + vector):
Instead of relying only on semantic similarity, hybrid search combines:Lexical / keyword search (BM25, Elasticsearch) → great for exact matches like "Section 420 IPC".
Vector search (FAISS, Pinecone, Weaviate) → great for semantic similarity like "law against fraud".
Together → precision (keywords) + flexibility (semantics).
Example: In legal queries, a lawyer asking "rules about fraud in contracts" might miss the exact keyword "Section 17 of Indian Contract Act". Hybrid search ensures both are retrieved.
GraphRAG: Beyond Flat Retrieval
Traditional RAG treats documents like independent islands. But knowledge is often connected. That’s where GraphRAG comes in instead of storing chunks in a flat index, you connect them as nodes in a graph.
So if someone asks, “How did Einstein influence quantum theory?”, the system can walk through relationships between people, events, and papers — finding more meaningful connections than plain vector similarity.
Production-Ready Pipelines: Caching and Optimization
In the real world, you don’t just want a “working” RAG system. You want one that’s reliable, cost-efficient, and fast. That’s where caching plays a huge role: if a user asks the same or similar query multiple times, you don’t need to re-run the whole pipeline you just reuse past results.
Production-ready systems also use monitoring (to track errors), fallback strategies (like keyword search if vector search fails), and optimizations like prefetching likely queries.
The Bigger Picture
All these techniques from sub-query rewriting to GraphRAG are not separate hacks. They are pieces of a larger story: making RAG systems more human-like in understanding, faster in response, and more reliable in output.
Think of it as teaching your assistant not just to look things up, but to understand context, connect dots, and learn from past mistakes.
As RAG evolves, it’s moving closer to being not just a retrieval system, but a reasoning system. And that’s the future of human-AI collaboration.
Subscribe to my newsletter
Read articles from Chaitrali Kakde directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
