Build a RAG chatbot: the pipeline from documents to answers
A RAG chatbot answers from your documents by retrieving the right passages first. See each stage of the pipeline, a small code sketch and the failures to test for.
Read articleRetrieval finds candidates and reranking puts them in the right order. See how the second pass works, when it is worth the extra step and how to measure the gain.
By the Askocto team · · 5 min read
Reranking is a second pass over search results. A first step pulls a shortlist of passages that might answer a question, and the reranker reads each one next to the question and puts them in a better order. The model then sees the strongest passages first. This article explains where reranking sits in a retrieval pipeline, when it pays off and how to test it without special tools.
In short: Retrieval is fast and rough. Reranking is slower and more careful, so it only looks at the shortlist. Add it when the right passage is usually retrieved but often buried below the top few.
A retrieval-augmented answer follows a fixed path. The customer asks a question, the system searches your content, and the best passages go to the model along with the question. If you want the background, how to build a RAG chatbot walks through the whole sequence.
With reranking, the search part splits in two:
The first step has to be quick because it searches everything. The second can be slower because it only handles a few dozen passages.
Most first-pass search relies on vector embeddings: each passage and the question become lists of numbers, and the closest passages win. That is good at finding passages about the right topic. It is weaker at telling apart passages that are close in topic but differ in the detail that matters.
Take a question like "Can I return a sale item after 30 days?" A help center might hold three nearby passages:
All three sit close to the question in meaning. A first pass may rank the general policy first because it is the broadest match. The sale item exception is the one that answers the question, and it might land third or fifth. A reranker that reads the question and each passage together is better placed to notice that "sale item" is the deciding phrase.
| Candidate retrieval | Reranking | |
|---|---|---|
| Input | The question and the whole index | The question and one passage at a time |
| Job | Find possibly relevant passages | Order them by how well they answer |
| Speed | Very fast across all content | Slower, so used on a shortlist |
| Strength | Coverage of the topic | Precision on the exact question |
| Typical failure | Right passage ranked too low | Right passage never in the shortlist |
The last row is the one to remember. A reranker cannot recover a passage the first step never returned. If the right answer is missing from the shortlist, the fix is in your content, your chunking or your search settings, not in reranking.
Reranking tends to pay off when:
It adds little when:
Reranking also adds a step, so it adds a little time to each answer and more work per question. Weigh that against the gain you measure, and read the provider's current documentation for any reranking component you plan to use.
You can measure the effect with a plain spreadsheet before you commit.
| Question | Correct passage rank without reranking | With reranking |
|---|---|---|
| Sale item return after 30 days | 4 | 1 |
| Change delivery address after ordering | 2 | 1 |
| Cancel annual plan mid-term | 1 | 1 |
The numbers above are an invented example of how to record results, not a measurement. Look at the cases where the rank got worse as well as better, because that is where a reranker misleads. Then look at the answers themselves, since a better rank only matters if the final reply improves.
Ordering is one lever among several. Clean content, sensible chunk sizes and good document parsing usually matter more, and document parsing covers how messy files hurt retrieval before any ranking happens. Once the right passage reaches the model, grounding rules and refusal behavior decide whether it uses the passage well, as stopping an AI chatbot from making things up explains.
If you use a platform instead of assembling the pipeline yourself, retrieval choices are made for you and you tune the inputs: sources, structure and procedures. In Askocto you add content under Build > Sources, then open Test > Playground to see which source each answer used. If the wrong passage keeps appearing, split the source, remove the near-duplicate or add a Q&A pair that states the exact answer. The Sources guide lists the source types, and the product overview shows how Askocto fits sources, procedures and testing together.
Reranking is a second look at search results. A fast first step finds candidates, then a more careful step sorts them by how well each one answers the question.
No. Retrieval finds possibly relevant passages across all your content. Reranking only reorders the shortlist that retrieval returns, so it cannot add passages that were missed.
Not always. Start with clean sources and test your top questions. If the right passage is often retrieved but ranked low, reranking is worth trying.
Compare the rank of the correct passage and the quality of the final answer on the same set of real questions, with and without it. Keep the set fixed so the comparison is fair.
Askocto answers the repeat questions across chat, email and voice and hands the hard ones to your team.
A RAG chatbot answers from your documents by retrieving the right passages first. See each stage of the pipeline, a small code sketch and the failures to test for.
Read articleAn embedding turns a sentence into a list of numbers so search can match meaning, not just words. Learn how it works, what it misses and how to check it on your own content.
Read articleRAG gives a model the right passages at question time. Build a minimal version in six steps, see where it breaks and decide when to use a platform instead.
Read article