What Makes RAG Answers Accurate
Accurate RAG answers come from the retrieval pipeline, not the generator. In our system the pipeline that works is: structure-aware parsing, heading-labelled chunks, hybrid dense plus BM25 sparse search merged with reciprocal rank fusion, a cross-encoder style reranker over a wide candidate set, a relevance floor, and parent-section expansion before the passages reach the model with numbered citations. Each stage fixes a specific failure the others cannot.
I'm Mahmoud Zalt, an AI architect, and through Sista AI I spend a lot of my time on retrieval layers that have to survive real business documents.
Everything below comes from building the knowledge engine inside Sistava, where AI agents answer from customers' own files. I will name every component and setting, and where we measured something I will give you the number and what it was measured on. Where we did not measure, I will say so.
The core lesson: the question is never "how smart is the model", it is "how often does the right page reach it". A frontier model handed the wrong passage writes a fluent wrong answer. A modest model handed the right section with a citation rarely does.
The Three Ways a RAG Answer Goes Wrong
Before the pipeline, the failure taxonomy, because every stage maps to one of these:
- Wrong document retrieved. The answer is confident and about the wrong client, last year's price list, or a neighbouring policy. This is a ranking problem.
- Right document, unsupported claim. The passage was there, but the answer added a detail nobody wrote. This is a grounding problem.
- No answer exists, and the model answers anyway. Your corpus is silent and the generator fills the gap with the nearest plausible text. This is an abstention problem.
Underneath all three sits a fourth that is not a quality metric at all: a passage reaching someone who was never allowed to read it. I treat that as a hard constraint on the search itself, covered in its own section below and in more depth in my piece on RAG access control.
If you have been fighting the first one for a while, my older article on why RAG returns wrong answers covers the diagnosis side. This one is the build side: the exact pipeline we settled on.
1. Parse for Structure, Chunk at Headings, Label Every Chunk
Retrieval quality is capped by what the parser preserves. We use Docling for PDFs, Word, slides, spreadsheets, HTML and images: it keeps layout and tables, and runs OCR on scanned pages. Without OCR a scanned invoice produces zero text, which means it can never be retrieved by anything. Files over 200 pages or two million characters are refused rather than silently truncated.
Chunking uses Docling's HybridChunker for files and a Markdown heading splitter for text sources. The rules:
- At most 512 tokens per chunk, cut at headings, tables kept whole. We swept 256 to 1,024 tokens and saw no measurable difference, so 512 stayed as the common default. Chunk size is rarely the lever people think it is.
- Every chunk carries its heading path (for example "Returns and Repairs > How to start a return") as a context prefix, and that prefix is embedded with the text.
- Every chunk points to its parent section, stored once as a separate record, for the expansion step later.
The heading prefix is the single cheapest win in this article. Business files often name the client only in the title, so a chunk from page three of a statement of work has no idea whose contract it is. In a run on our agency test set with stand-in open models, the proving sentence was found for 97% of questions with the prefix included and 54% without it.
2. Hybrid Search: Dense Plus BM25 Sparse, Fused With RRF
Each chunk is stored in Qdrant with two vectors. A dense vector of 1,536 dimensions from OpenAI's text-embedding-3-small captures meaning. A sparse BM25 vector, computed locally with FastEmbed and stored with Qdrant's IDF modifier so rare terms weigh more, captures exact terms.
You need both because they fail differently. Dense search matches "cancel" to "terminate the agreement" and misses "SKU-4471". BM25 nails the SKU and misses the paraphrase. Product codes, order numbers and people's names are exactly the tokens business questions hinge on.
At query time both searches run inside Qdrant, filtered to the caller's allowed scopes, 50 candidates each. The two ranked lists are merged with reciprocal rank fusion: each document scores the sum of 1/(k + rank) across the lists it appears in. RRF ignores the raw scores, which live on incomparable scales for dense and sparse, and rewards documents that rank well in either list. It is boring, well established since Cormack and colleagues published it in 2009, and needs no tuning per corpus, which is what you want in front of a reranker.
The honest measurement: with a working reranker behind it, hybrid search tied dense-only on our quality measure. Its value showed up when the reranker failed, where hybrid kept quality about 0.05 higher on our internal composite score. I keep it on as insurance, and because the cost is a sparse vector computed on our own servers.
3. Rerank 50 Candidates With a Cross-Encoder
Bi-encoder search compares precomputed vectors; it is fast and approximate. A reranker reads the query and each candidate together, one pair at a time, the way a cross-encoder does, and outputs a relevance score from 0 to 1. Search finds candidates. The reranker picks the winners.
In production we rerank with Voyage rerank-2.5-lite through OpenRouter, with a three second timeout. If the reranker fails or times out, we keep the RRF order rather than failing the question. That fallback is why hybrid search earns its keep.
The numbers that set our candidate count: reranking 50 candidates scored 0.83 on our internal quality measure against 0.66 with no rerank at all. Dropping to 20 candidates lost 0.03. The reranker is the single largest quality step in the pipeline, and it is also a per-question paid call, so the candidate count is a direct cost and quality dial.
| Setting | Value | Why |
|---|---|---|
| Chunk size | 512 tokens | 256 to 1,024 made no measurable difference |
| Heading prefix | On | Proving sentence found 97% with it, 54% without (stand-in models) |
| Hybrid search | On | Ties dense-only with rerank; about +0.05 quality when rerank fails |
| Rerank candidates | 50 | 0.83 against 0.66 with no rerank; 20 candidates lost 0.03 |
| Relevance floor | 0.6 | Below it, unanswerable questions get junk instead of nothing |
| Top-k after floor | 8 | 12 scored the same with 30% more tokens; 5 lost a little |
| Section window | 4,000 chars | About 1,000 tokens per section, bounded total context |
4. A Relevance Floor, Then the Top Eight
Every reranked candidate scoring under 0.6 is dropped. If nothing survives, the agent is told so explicitly and answers that the information is not in its knowledge. This is the abstention mechanism, and it is the most consequential number in the pipeline.
We started at 0.2. With the production reranker, every question in our test set that had no answer still got passages back, so the model had to recognise unaided that eight plausible chunks did not answer the question. A threshold sweep moved it to 0.6. The trade-off has enough depth that I wrote it up separately; the short version is that a floor trades a few found answers for far fewer confident wrong ones.
One warning that cost us a test cycle to learn: the floor belongs to the reranker model. Scores from a different reranker sit on a different distribution, so 0.6 means nothing once you swap models. Re-run the sweep before any reranker change, and pin the value in a test so nobody edits it casually.
After the floor we keep the top eight. Twelve scored the same on our evaluation with about 30% more tokens; five lost a little. Eight is where the curve flattened.
5. Parent-Section Expansion, Centred on the Hit
A 512 token chunk is the right size to search and often the wrong size to answer from. The price row without the plan name above it. The exception clause without the rule it modifies. So each of the eight hits is replaced by a window of its parent section, at most 4,000 characters, one window per section.
The detail that matters is where the window sits. Our first version cut long sections from the top, which looked fine on our own documents with their short sections. Then we ran SQuAD 2.0, where articles are long and have a single heading: the right article was found for 85% of questions, but the proving sentence reached the model for only 24%. The window was cutting off before the matching passage. It is now centred on the hit, and that change came straight out of a public benchmark finding a bug our own test set could not.
Two more mechanics finish the context. For short follow-ups ("and the second one?") the previous user message is attached before embedding, because the follow-up alone carries almost no meaning. And retrieval is also exposed as a search tool, so the agent can search again for the second half of a multi-part or cross-document question.
6. Numbered Citations, Appended After the Conversation
Each passage reaches the model with a number and a source line naming the document, the section and the page, and the agent cites those numbers inline: "The Team plan is billed per seat on annual terms [1: Pricing 2026, Plans, page 1]." A citation is what lets a human verify an answer in seconds rather than trust it.
Placement is a cost decision. The knowledge block is appended as a trailing message after the conversation, never spliced into the system prompt. Retrieved passages change on every turn; the system prompt should not, or provider prompt caching misses on every request.
7. Multitenancy and Permissions Inside the Search
All customers share one Qdrant collection, isolated by a scope id in every point's payload. The scope is marked as Qdrant's tenant key, and the HNSW config is set to m=0 with payload_m=16: no global graph, one small graph per tenant. Searches are filtered on that key, so a query only ever walks its own tenant's graph. Vectors are int8-quantized in RAM for roughly four times less memory at a small accuracy cost, and every payload field we filter on is indexed, guarded by a test.
Inside a tenant, whoever adds a document chooses its audience: only themselves, the default, or the whole workspace. That scope travels with every chunk and the search filters on it before ranking, so a passage the caller may not see is never a candidate and no later stage can leak it. Who the caller is gets resolved server-side: a person in chat sees what they may see, a scheduled routine sees the agent's linked documents, its creator's documents and workspace documents, a delegated teammate inherits exactly the delegating run's access, and an unidentified caller sees nothing.
Postgres, not Qdrant, is the source of truth for what exists and who may see it. Qdrant is a search index. Deleting a source deletes its points, and a full data erasure deletes and then verifies that zero remain.
What We Measured
We evaluated on two business corpora we wrote ourselves, because public benchmarks are built from Wikipedia and annual reports and your files look nothing like that: a fictional 19-person marketing agency (96 documents, 130 questions, including two versions of statements of work, scanned invoices and look-alike quarterly reports) and a fictional hardware company (32 documents, 106 hand-written questions with the proving sentence for each). Retrieval was scored by code against the golden set: right document in the top one, five and eight, proving sentence found, citation correctness, leaks. Grounding was scored by an LLM judge on a sample.
| Measure (production models, low floor) | Hardware set | Agency set |
|---|---|---|
| Right document in top five | 98.9% | 100% |
| Proving sentence among passages | 97.8% | 99.2% |
| Numbered sources pointing to the right document | 96.3% | 97.7% |
| Claims backed by sources (judge, 9 and 11 answers) | 100% | 92.4% |
| Passages from another workspace | 0 | 0 |
Finding and ranking took a median of 0.66 seconds per question, with 95% of searches under 0.82 seconds, before generation starts. And for calibration: with free stand-in models (bge-small-en-v1.5 and a MiniLM cross-encoder) the same hardware set scored 78.6% in the top five, against 98.9% with production models. Model choice in the retrieval stages matters a great deal, and it is where I would spend first.
Where It Still Falls Short
Top five is enough to answer, because the agent reads all eight passages. Rank one tells you how sure the system is, and that is where the weak spots show:
- Tables: always in the top five, ranked first 59% of the time. On the agency set the right table came first for 3 of 13 questions, because many quarterly reports share one layout. That is the next thing we are testing.
- Cross-document questions: found every time, ranked first 56%. The agent can search again; whether it chooses to is measured separately.
- Follow-ups: 7 of 8 found their document in the top five, the weakest type, on a sample too small to say more.
- Grounding is sampled: 20 judged answers. Two agency answers each added a detail the passages did not support, which is exactly the failure citations exist to expose.
- Our corpora, English only. They resemble real business files but they are not yours.
Frequently Asked Questions
Is hybrid search worth it if I already rerank?
In our measurements hybrid tied dense-only when the reranker worked and helped when it failed. Keep it if sparse vectors are cheap for you; it is insurance for exact codes, names and reranker outages.
How many candidates should a reranker see?
We settled on 50 merged candidates. Fewer (20) lost a little quality; skipping rerank entirely dropped our quality measure from 0.83 to 0.66.
Does chunk size matter?
Less than people think. 256 to 1,024 tokens made no measurable difference for us. Cutting at headings, keeping tables whole and embedding the heading path mattered far more.
Should I use one vector collection per tenant?
Not necessarily. One collection with a tenant key, per-tenant HNSW graphs and filtered search gives strong isolation with simpler operations. You still need per-document scope inside the tenant.
What is parent-section expansion?
Searching small chunks but handing the model the larger section around each hit, so it sees the context that explains the match. Centre the window on the hit or long sections lose the answer.
Three Things to Take Away
One. Label every chunk with its document title and section path and embed the label. It is the cheapest accuracy win available.
Two. Spend on the reranker, not the generator. Retrieve wide with hybrid search and RRF, rerank 50, keep eight, expand to sections centred on the hit.
Three. Put permissions inside the search, and treat the relevance floor as a calibrated property of one reranker, re-swept before any model change.
If your retrieval layer is producing fluent wrong answers and you want it reviewed stage by stage, that is a common starting point for an agent development engagement.








