Guide · AI and GenAI
Advanced RAG Explained: Naive vs Advanced vs Modular RAG
26 min readUpdated By Saket Bhatnagar
Researched and drafted with AI, reviewed and edited by Saket Bhatnagar.
In short
- RAG, retrieval-augmented generation, means a system searches your documents first and a model answers from what it finds. Advanced RAG is that simple pipeline plus targeted fixes before and after its search step.
- Naive RAG is the simplest version. It searches once with the user's exact words, pastes the top few chunks (small pieces of documents) into the prompt, and lets the model answer.
- Query rewriting turns the user's words into the documents' words. Hybrid search adds exact keyword matching for codes and names. Reranking puts the best chunks first, and compression trims the rest.
- Modular RAG splits the pipeline into swappable parts. A router, a step that picks a path for each question, can send it to a database instead, and a capped loop can search once more.
- Beginners can stop after the section on which one to build. Engineers then get runnable rank-fusion, failure-sorting and capped-retry router code with expected output, and where the two source papers really place each fix.
What goes wrong when a simple RAG chatbot answers from the wrong text?
A simple RAG chatbot gives a wrong answer when its search brings back the wrong text, or misses the right text. The model can only answer from what the search hands it. Advanced RAG is the name for the fixes that target exactly these search failures.
Picture a common setup. An IT services firm in Hyderabad with about 5,000 employees builds an HR policy assistant. The setup is made up, but the problem is real.
The HR team keeps 220 policy documents on leave, travel, insurance and tax forms. Staff send hundreds of policy questions a week, and most answers already sit in those documents. An engineer builds the first version of the assistant in a week.
Before launch, the HR team collects 60 real questions from its inbox and checks every answer by hand. The assistant gets 38 right. The failures are not random. Three of them show the pattern:
- How many EL (earned leave) can I roll over to next year? The assistant says it cannot find the answer. The policy says earned leave can be carried forward, so the words never match.
- Where do I submit Form 12BB? The assistant explains general tax rules. The one page that names Form 12BB never comes back from the search.
- What is the carry-forward limit for earned leave? The assistant says 45 days, from an old 2023 policy. The current 2025 policy says 30 days, but it came back sixth, just outside the five chunks the model reads.
Each of these failures has a known fix. A 2023 survey of RAG research by Gao and colleagues sorts such fixes into three stages: naive RAG, advanced RAG and modular RAG. The term RAG itself comes from a 2020 paper by Lewis and colleagues. This guide follows the HR assistant through all three.
Which words do you need before comparing RAG types?
You need six words. Each one is a plain idea with a technical name, and the rest of the guide uses them without stopping.
- Chunk: a small piece of a document, usually a few paragraphs. The leave policy is split into 40 chunks, and one of them covers the carry-forward rule.
- Embedding: a list of numbers that captures the meaning of a piece of text. Texts with similar meaning get numbers that sit close together.
- Vector search: finding the chunks whose embeddings sit closest to the question's embedding. It searches by meaning, not by exact words.
- Retrieval: the search step that picks chunks for a question. The part of the program that does it is called the retriever.
- Top-k: how many chunks the retriever returns, where k is a number you choose. The first assistant uses k = 5.
- Context: all the text the model reads for one answer, sent as one prompt. It holds your instructions, the question and the retrieved chunks.
What is naive RAG and where does it fail?
Naive RAG is the simplest version: search once with the user's exact question, take the top few chunks, and ask the model to answer from them. The survey calls it a Retrieve-Read process, one search and then one read.
Before any question arrives, naive RAG also indexes the documents. It cuts them into chunks, turns each chunk into an embedding and stores them. So the survey's full naive pipeline has three steps: indexing, retrieval and generation.
Picture a fresher who asks a hostel senior for notes on the heat chapter. The senior grabs the first five notebooks with heat on the cover and hands them over unread. Two are from an old syllabus, and the best notes, labelled thermodynamics, stay on the shelf.
Map it part by part. The shelf of notebooks is your chunk store. The word on the cover is the search match. The five notebooks are top-k = 5, and the fresher is the model, who studies whatever he is handed.
Here is the first version of the assistant. Follow the boxes from the question to the answer. The notes on the middle boxes show where the failed questions broke.
Naive RAG and where it breaks
Drag to exploreOne search, one prompt, one answer, wrong 22 times in 60 (made up). Notice that every failure starts before the model writes a word.
Diagram connections:
- Employee asks a question to Question becomes numbers
- Question becomes numbers to Vector search, top 5
- Vector search, top 5 to Chunks pasted into prompt (5 closest chunks)
- Chunks pasted into prompt to Model writes the answer
- Model writes the answer to Answer shown
- Employee asks a question: How many EL can I roll over?
- Question becomes numbers: Same embedding method as the chunks
- Vector search, top 5: Breaks: roll over never matches carry forward
- Chunks pasted into prompt: Breaks: 2025 policy came sixth, left out
- Model writes the answer: Answers from whatever text it was given
- Answer shown: Wrong 22 times out of 60
The 2023 survey lists the same three kinds of weak spots in naive RAG:
- Retrieval: low precision and recall. The search returns chunks that only look related, and misses chunks that matter.
- Generation: the model may add facts that are not in the retrieved text, often called hallucination.
- Augmentation, the step that joins chunks into one prompt: repeated or clashing chunks can make the answer disjointed or repetitive.
What is advanced RAG?
Advanced RAG keeps the same one-way pipeline from question to answer, but adds fixes before and after the search. The survey calls these two groups pre-retrieval and post-retrieval.
Pre-retrieval covers two kinds of change. Some improve the index, such as better chunk sizes or extra fields like a policy's year. Others improve the query, the text you search with, such as rewriting it in the documents' own words.
Post-retrieval covers changes to the search results before the model reads them. The survey names two: reranking, which reorders the chunks, and compression, which cuts them down.
This guide also adds hybrid search, keyword search running beside vector search, at the search step itself. The survey lists mixed retrieval as an index fix, and files hybrid retrieval under modular RAG's patterns. It fits here because it changes how the one search runs, not the shape of the flow.
Back at the hostel, a careful senior asks which professor and which exam first. She rephrases heat as thermodynamics, checks both covers and contents, and hands over only the two chapters that matter. That is rewriting, hybrid search, reranking and compression.
Here is the advanced pipeline. Pause and predict which failed question each new box fixes. The notes give the answer.
The advanced RAG pipeline
Drag to exploreStill one fixed path from question to answer. Notice that the model now runs twice: once to rewrite the question and once to answer it.
Diagram connections:
- Employee question to Rewrite the question
- Rewrite the question to Keyword search
- Rewrite the question to Vector search
- Keyword search to Merge both lists (Top 20 by words)
- Vector search to Merge both lists (Top 20 by meaning)
- Merge both lists to Rerank the candidates
- Rerank the candidates to Compress the context
- Compress the context to Model writes the answer
- Model writes the answer to Answer with its source
- Employee question: How many EL can I roll over?
- Rewrite the question: Pre-retrieval: fixes the EL wording gap
- Keyword search: Finds exact codes: fixes the 12BB miss
- Vector search: Finds similar meaning
- Merge both lists: About 30 unique candidate chunks
- Rerank the candidates: Post-retrieval: lifts the 2025 policy to the top
- Compress the context: Post-retrieval: keep only useful lines
- Model writes the answer: Reads 4 short, current extracts
- Answer with its source: Cites the 2025 leave policy
How does query rewriting fix missed searches?
Query rewriting fixes searches that fail because the user's words differ from the document's words. A model rewrites the question into clearer search text before the search runs.
Employees type EL, roll over and next year. The policy says earned leave, carried forward and calendar year. So the rewrite step asks the model to restate each question in the style of an HR policy.
The rewritten query reads something like: earned leave carry-forward limit per calendar year. That now matches the right chunk, and the employee never had to learn HR language.
There are four common styles of rewriting, and each fits a different problem:
- Rewrite: turn a short or chatty question into one clear search query. Good for short forms like EL and WFH (work from home).
- Multi-query: write three or four versions of the question, search with each, and merge the results. Good when any single phrasing might miss.
- Sub-queries: split a two-part question into two searches. Good for comparing the Hyderabad and Pune travel rules.
- HyDE, short for hypothetical document embeddings: a model writes a made-up answer, and you search with that answer's embedding. A fake answer often sits closer to the real document than a short question does.
The HyDE paper accepts that the made-up answer may contain false details. Only its embedding is used, to find real documents that sit nearby. The employee's answer still comes from real chunks.
Why combine keyword search with vector search?
You combine them because each one misses what the other finds. Vector search finds text with similar meaning, and keyword search finds exact words, codes and names. Running both and merging the results is called hybrid search.
Vector search handles roll over versus carry forward well. A code like 12BB is different. An embedding model may never have learned what 12BB means, so meaning search can rank general tax pages above the one page that names the form.
Keyword search scores chunks by the exact words they share with the query. A standard scoring method is BM25. It gives more weight to rare words, so the one chunk that contains 12BB scores high.
We checked this with the rank-bm25 0.2.2 Python package on 7 toy HR chunks. 12bb appeared in 1 chunk and tax in 4. So 12bb weighed 1.466 against 0.303 for tax. For the query 12bb tax, the 12BB chunk scored 1.656 and the general tax page, which says tax four times, only 0.544.
The 0.303 is a floor, not the raw formula. A word in more than half the chunks gets a negative raw weight, and rank-bm25 0.2.2 raises it to a small positive value.
The 2024 modular RAG paper makes the same point: keyword retrievers help meaning-based ones with queries about rare entities. Rare codes such as policy numbers behave the same way.
To merge the two lists, a common method is reciprocal rank fusion. Each chunk earns points from its position in each list, so a chunk near the top of both lists wins. The engineer section shows it in ten lines of code.
What do reranking and context compression fix in RAG?
Reranking fixes good chunks that come back in a bad order, and compression fixes context that is too long or too noisy. Both run after the search and before the model answers.
Reranking puts the best chunks first
A reranker reorders the candidate chunks. Some use simple rules, such as favouring variety, but the one here is a second, slower model that scores each chunk against the question. Vector search compared embeddings made separately for the question and for each chunk. It never looked at the two side by side.
One kind of reranker is a cross-encoder: a model that reads the question and the chunk together as one input and returns one relevance score. A 2019 paper by Nogueira and Cho used this setup to re-rank passages first found by BM25.
Reading every pair costs time, so you only rerank a short list. The assistant reranks its 30 merged chunks and keeps the best 4. The 2025 leave policy, which says 30 days, now comes first.
Context compression sends less, but better, text
Compression means cutting the retrieved text down to the parts that matter before the model reads it. You can drop chunks the reranker scored low, or keep only the sentences that relate to the question.
More text is not always better. A 2023 study called Lost in the Middle tested two tasks: answering from many documents, and finding a value by its key in a long list. Models often did best when the needed fact sat at the start or end of the input.
When the fact sat in the middle, results dropped sharply, even for models built for long inputs. So four short, relevant extracts can beat fifteen long chunks. Shorter context also costs less when your model provider bills by the token.
A token is a small piece of text, often a word or part of a word. Fewer tokens in means a smaller bill for every question.
What is modular RAG?
Modular RAG treats each step of the pipeline as a separate part, or module, that you can add, swap or rearrange. Instead of one fixed line, the flow can branch into different paths and loop back to search again.
A module is one part with one job and a clear input and output, like the reranker or the keyword search. A 2024 paper by four of the survey's authors develops this idea, and its title compares the parts to toy building bricks.
Its abstract names four flow patterns, and the body adds a fifth, tuning, which trains the retriever or the answering model further:
- Linear: modules run in a fixed line. Naive RAG is the simplest linear flow, and the advanced pipeline above is linear too, with pre-retrieval and post-retrieval steps added.
- Conditional: a routing module picks one pipeline for each question.
- Branching: several searches or paths run side by side, and their results are merged.
- Looping: retrieval and generation repeat, and a judge step decides when to stop.
The HR assistant needed this soon after launch, because some questions had nothing to do with documents. One employee asked how many leave days she had left. That answer lives in the HR database, not in any policy. A simple thanks needs no search at all.
Sending both through the policy pipeline wasted model calls and produced odd answers. So the team added a router: a step that labels each question and sends it down the right path. Each path can change without touching the others.
Here is the modular assistant. Follow each labelled arrow from the question. On the policy path, an answer not backed by the policy text gets one more rewrite and search.
The modular RAG assistant
Drag to exploreThe router picks a path, and the policy path can loop once before it gives up. Notice that the employee ID comes from the login, not from the model.
Diagram connections:
- Employee question to Router
- Router to Policy pipeline (Policy question)
- Router to HR records lookup (My own data)
- Router to Small talk reply (Small talk)
- Policy pipeline to Answer backed by the text?
- Answer backed by the text? to Send the reply (Yes)
- Answer backed by the text? to Rewrite and search again (No)
- Rewrite and search again to Policy pipeline (Search again)
- HR records lookup to Send the reply
- Small talk reply to Send the reply
- Employee question: Arrives with the employee's login
- Router: A small model call gives one label
- Policy pipeline: The advanced RAG steps from earlier
- HR records lookup: Leave balance for this employee only
- Small talk reply: No search needed
- Answer backed by the text?: Code check: its numbers must be in the extracts
- Rewrite and search again: At most 1 extra round, then refer to HR
- Send the reply: Policy answers name their source
Naive vs advanced vs modular RAG: which one should you build?
Start with naive RAG, measure it on real questions, and upgrade only where you can name the failure. A few advanced fixes are often enough. Add routing and loops only when your questions need different sources or a second try.
Here is the full map of upgrades, each tied to the problem it fixed in the HR assistant.
| Upgrade | Where it acts | Problem it fixes | HR assistant example |
|---|---|---|---|
| Query rewriting | Before the search | The question uses different words from the documents | EL and roll over never matched carried forward |
| Multi-query or HyDE | Before the search | One phrasing is not enough to find the chunk | A vague question about relocation support |
| Hybrid search | The search itself | Exact codes and names get lost in meaning search | Form 12BB and policy HR-POL-114 |
| Reranking | After the search | The right chunk is found but ranked too low | The 2025 leave policy came back sixth |
| Context compression | After the search | Too much text: key lines buried, cost too high | 30 merged chunks cut to 4 short extracts |
| Routing | Between paths | Questions need a different source, or none | Leave balance comes from the HR database |
| Loop with a check | Between paths | The first search was not enough | Rewrite and search once more, then refer to HR |
Here is how the three versions compared on the 60-question test set.
| Version | Model calls per question | Wait per answer | Correct answers | Cost per answer |
|---|---|---|---|---|
| Naive RAG | 1 | About 2 seconds | 38 of 60 | About Rs 0.30 |
| Advanced RAG | 2, plus a rerank | About 4 seconds | 52 of 60 | About Rs 0.70 |
| Modular RAG | 3, plus a rerank, and more on a retry | About 5 seconds | 56 of 60 | About Rs 0.85 |
Read the table as a trade. Each step bought correct answers with time and money. The retry loop caught most of the modular gain, and leave balance questions now get real answers from the HR database.
When an answer is wrong, the chart below helps you pick the fix. Start with one failed question and ask where the right chunk ended up.
Which RAG upgrade does this failure need?
Drag to exploreFind the stage where the answer broke, then add only the fix for that stage.
Diagram connections:
- Take one failed question to Is it in the documents?
- Is it in the documents? to Add a router (No)
- Is it in the documents? to Right chunk in top 20? (Yes)
- Right chunk in top 20? to Fix the search (No)
- Right chunk in top 20? to In the chunks it reads? (Yes)
- In the chunks it reads? to Add reranking (No)
- In the chunks it reads? to Compress and fix the prompt (Yes)
- Take one failed question: From your test set of real questions
- Is it in the documents?: Or does it need a database or no search?
- Add a router: Modular RAG: send it to the right source
- Right chunk in top 20?: Look at the raw search results
- Fix the search: Query rewriting or hybrid search
- In the chunks it reads?: The top 5 the model actually sees
- Add reranking: Move the best chunks to the top
- Compress and fix the prompt: Trim noise, tell the model to stick to the text
Run the failed questions through it. The EL and Form 12BB questions failed the top-20 check, so they needed rewriting and hybrid search. The carry-forward question was found but ranked sixth, so it needed reranking. The leave balance question needed a router.
The team followed this order to upgrade the assistant:
Build the naive baseline
Get the simplest version working end to end, with one search and k = 5.
Build a test set
Collect real questions with checked answers, like the 60 here, before changing anything.
Sort the failures
For each wrong answer, note whether the right chunk was missing, ranked too low, or not in the documents at all.
Fix the biggest group first
Add the one upgrade that matches the most failures, then rerun the whole test set.
Keep only what pays
Keep an upgrade only if the score rises enough to justify the extra cost and wait.
How does reciprocal rank fusion merge keyword and vector results?
Reciprocal rank fusion (RRF) gives each chunk 1 divided by (60 plus its rank) in each list, then adds the points up. It uses only positions, never the raw scores, which is why it suits hybrid search.
Raw scores do not mix. In our BM25 test the top score was 4.116. A cosine similarity, a common vector score, always sits between minus 1 and 1. Adding the two would let the keyword score drown the vector score. The 2009 RRF paper by Cormack, Clarke and Buettcher combines ranks for this reason, with the constant 60 fixed in a pilot study.
Here is RRF in plain Python 3, with no packages. It merges the two result lists for the Form 12BB question. Save it as rrf.py and run python3 rrf.py.
def rrf(*ranked_lists, k=60):
"""Reciprocal rank fusion: merge ranked lists using ranks only."""
scores = {}
for ranking in ranked_lists:
for rank, chunk_id in enumerate(ranking, start=1):
scores[chunk_id] = scores.get(chunk_id, 0) + 1 / (k + rank)
return sorted(scores.items(), key=lambda item: item[1], reverse=True)
by_words = ["tax-12bb", "tax-80c", "tax-hra"] # keyword search, best first
by_meaning = ["tax-general", "tax-hra", "tax-12bb"] # vector search, best first
for chunk_id, score in rrf(by_words, by_meaning):
print(chunk_id, round(score, 4))You should see exactly these four lines:
tax-12bb 0.0323
tax-hra 0.032
tax-general 0.0164
tax-80c 0.0161The constant matters. A smaller one rewards the very top ranks more. In our run, rank 1 earned twice the points of rank 3 at k = 1, but only 1.03 times at k = 60.
In the paper's pilot runs, 60 was near-optimal but the choice was not critical: values from 10 to 100 scored almost the same. Keep 60 unless your test set shows better, and log both input lists.
How do you find which stage broke for each failed question?
Compare where the right chunk landed with what the model actually read. If the chunk is missing, fix the search. If it is found but too low, add reranking. If the model read it and still erred, fix the context or prompt.
This needs one extra field in your test set: the ID of the chunk that holds each answer. Here is the decision chart as code, run on the four failures from this guide. It also runs on plain Python 3.
def stage_that_broke(right_id, top_20, read_k=5):
"""Say which stage failed for one wrong answer."""
if right_id is None:
return "source: no document has it, so route it elsewhere"
if right_id not in top_20:
return "search: rewrite the query or add keyword search"
if top_20.index(right_id) >= read_k:
return "ranking: add a reranker"
return "reading: compress the context or fix the prompt"
failures = [ # question, chunk that holds the answer, what the search returned
("How many EL can I roll over?", "leave-2025",
["holiday-list", "leave-sick", "wfh-rules", "leave-2023"]),
("Where do I submit Form 12BB?", "tax-12bb",
["tax-general", "tax-80c", "tax-hra"]),
("What is the carry-forward limit?", "leave-2025",
["leave-2023", "leave-faq", "holiday-list", "leave-sick", "wfh-rules", "leave-2025"]),
("How many leave days do I have left?", None,
["leave-2025", "leave-faq"]),
]
for question, right_id, top_20 in failures:
print(question, "->", stage_that_broke(right_id, top_20))Expected output:
How many EL can I roll over? -> search: rewrite the query or add keyword search
Where do I submit Form 12BB? -> search: rewrite the query or add keyword search
What is the carry-forward limit? -> ranking: add a reranker
How many leave days do I have left? -> source: no document has it, so route it elsewhereCount the labels across your whole test set before building anything. If most failures say ranking, a reranker is your next step. If most say search, a reranker cannot help, because it only reorders what the search found.
How do you route questions and cap the retry loop in code?
Map each label to a function in a plain dictionary, fall back to a safe default for unknown labels, and cap retries with a fixed loop count. Here is a runnable version with stand-ins for the model calls.
MAX_SEARCHES = 2 # the first search plus one retry, never more
POLICY_INDEX = {"earned leave carry forward limit": "Up to 30 days (Leave Policy 2025)"}
REWRITES = {"How many EL can I roll over?": "earned leave carry forward limit"}
def search_policies(query): # stand-in for the advanced pipeline
return POLICY_INDEX.get(query)
def rewrite(query): # stand-in for a model call
return REWRITES.get(query, query)
def policy_path(question, employee_id):
query = question
for _ in range(MAX_SEARCHES):
answer = search_policies(query)
if answer: # stand-in for the "backed by the text?" check
return answer
query = rewrite(query)
return "No policy covers this. Please ask HR."
def records_path(question, employee_id):
return f"Employee {employee_id}: 12 days of earned leave left"
def chat_path(question, employee_id):
return "Happy to help."
MODULES = {"policy": policy_path, "my_data": records_path, "chat": chat_path}
def handle(question, employee_id, label):
"""label comes from a small model call; employee_id comes from the login."""
module = MODULES.get(label.strip().lower(), policy_path)
return module(question, employee_id)
print(handle("How many EL can I roll over?", "E1042", "policy"))
print(handle("How many leave days do I have left?", "E1042", "my_data"))
print(handle("Thanks!", "E1042", " Chat"))
print(handle("Is Diwali a holiday?", "E1042", "not sure"))Run it with python3 and you should see:
Up to 30 days (Leave Policy 2025)
Employee E1042: 12 days of earned leave left
Happy to help.
No policy covers this. Please ask HR.Three design choices carry the safety. The model only picks a label, and an unknown label lands on the policy path. The employee ID comes from the login, so the model's label cannot point the lookup at someone else's records. And range(MAX_SEARCHES) makes an endless loop impossible.
Adding a payslip module later means one new dictionary entry. Swapping the reranker inside the policy path does not touch the router at all. That is what modular means in practice.
Where do the two papers put each advanced RAG technique?
Not always where blog posts do. The 2023 survey and the 2024 modular RAG paper place some fixes in different stages, so treat the three labels as a map, not a law.
| Technique | 2023 survey | 2024 modular RAG paper |
|---|---|---|
| Query rewriting | Advanced RAG, pre-retrieval; also the Rewrite-Retrieve-Read pattern under modular RAG | Pre-retrieval module, query transformation |
| HyDE and sub-queries | Modular RAG new patterns; also query optimisation in the retrieval section | Pre-retrieval module: sub-queries under query expansion, HyDE under query transformation |
| Hybrid search | Modular RAG new patterns; mixed retrieval also listed as an advanced indexing fix | Retrieval module, retriever selection |
| Reranking | Advanced RAG, post-retrieval | Post-retrieval module |
| Context compression | Advanced RAG, post-retrieval | Post-retrieval module |
| Routing | Modular RAG new module; also query routing under query optimisation in the retrieval section | Conditional flow pattern |
| Search loops | Augmentation process: iterative, recursive and adaptive retrieval | Looping flow pattern |
Two things follow. First, an interviewer who files hybrid search under modular RAG is quoting the survey, not making a mistake. Second, the modular paper calls a pipeline with pre-retrieval and post-retrieval steps linear, so advanced RAG is one linear flow inside modular RAG.
How do you explain advanced RAG in a system design interview?
Explain it as a series of fixes, each tied to a failure you can measure. Interviewers want to hear why you add each part, not a list of technique names.
Draw the naive baseline
Question, search, top chunks, model, answer. Say it is the starting point, not the final design.
Say how you would measure it
Describe a test set of real questions, each with its checked answer and the chunk that holds it, run after every change.
Map failures to stages
Wording gaps go to query rewriting, missed codes to hybrid search, and bad order or noise to reranking and compression.
Add modules where sources differ
Add a router for questions that need a database or no search, and a loop with a hard limit.
Talk about cost and wait time
Each upgrade adds model calls or a reranker. Give rough numbers, and say they are estimates to check on the test set.
Questions people ask
- Is advanced RAG always better than naive RAG?
- No. Each upgrade adds cost, wait time and one more part that can break. If naive RAG already answers your test questions well, an upgrade only makes it slower and pricier. Keep a fix only if your test score rises enough to pay for it.
- What is the difference between advanced RAG and modular RAG?
- Advanced RAG improves the parts of one fixed pipeline, such as rewriting the question before search and reranking after it. Modular RAG lets you rearrange the parts themselves. A router can send questions down different paths, and a loop can search again. The 2024 modular RAG paper treats an advanced pipeline as one linear flow inside the modular design.
- What are pre-retrieval and post-retrieval in RAG?
- Pre-retrieval covers changes made before the search: to the index, such as chunk size and extra fields like a policy's year, and to the query, such as rewriting it. Post-retrieval covers changes to the search results before the model reads them, mainly reranking and compression. Both terms come from the 2023 survey that sorts RAG into naive, advanced and modular stages.
- Does reranking make RAG slower?
- Yes. A cross-encoder reranker runs the model once for every question and chunk pair, which is far more work than one vector search. That is why you rerank only a short list, such as the 30 merged chunks in this guide, and pass the best few to the model. Measure the added wait on your own hardware.
- Can a bigger context window replace advanced RAG?
- Not fully. A context window is the most text a model can read at once. Even when everything fits, the 2023 Lost in the Middle study found models used facts in the middle of a long input less well on its two tasks. Long inputs also cost more tokens, so fewer, better chunks usually win.
- Is modular RAG the same as agentic RAG?
- They overlap, but they are not the same. Modular RAG builds RAG from swappable parts, with routes and loops you design in code. Agentic RAG usually means the model itself decides when to search, what to search for and when to stop. The 2023 survey calls that kind of choice adaptive retrieval.
- Do I need a framework to build advanced RAG?
- No. As the Python examples here show, each upgrade is a plain function, and routing is one dictionary. A framework can save time on wiring and logging. But building the plain steps first makes it much easier to see which part fails when answers go wrong.
Sources and further reading
- Retrieval-Augmented Generation for Large Language Models: A Survey (Gao et al., arXiv 2312.10997, v5 March 2024)
- Modular RAG: Transforming RAG Systems into LEGO-like Reconfigurable Frameworks (Gao et al., arXiv 2407.21059, 2024)
- Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (Lewis et al., 2020)
- Precise Zero-Shot Dense Retrieval without Relevance Labels, the HyDE paper (Luyu Gao, Ma, Lin and Callan, arXiv 2212.10496, 2022)
- Lost in the Middle: How Language Models Use Long Contexts (Liu et al., 2023)
- Reciprocal Rank Fusion outperforms Condorcet and individual Rank Learning Methods (Cormack, Clarke and Buettcher, SIGIR 2009)
- Passage re-ranking that reads the query and passage together (Nogueira and Cho, arXiv 1901.04085, 2019)