§Document retrieval
Ask your documents. Check every answer.
Retrieval-augmented generation puts your own documents in front of the model before it answers. The system searches them, pulls the passages that bear on the question, and hands those over as source material. The answer comes back with a citation to the page each claim came from, so a reviewer can open the page and check.
The failure mode
Where retrieval systems go wrong.
A general-purpose assistant answers from what it memorized in training. It has never seen your contracts or your case files, so when you ask about them it produces something plausible.
Adding retrieval helps, but it isn’t enough on its own. A system can retrieve the right passage and then paraphrase it into something the passage doesn’t say. That failure is hard to spot, because the citation is right there and the answer looks checked.
Finding the document is the easy part. The work is making sure every sentence you read can be traced, word for word, to a document you were allowed to see.
The pipeline
The seven stages.
Each stage records how long it took, and the trace is stored with the answer. When something is slow or wrong, the trace shows which stage did it.
- 01Ingest
The document is split along its headings, and each chunk keeps its character position in the original file. The quote stage depends on those positions.
- 02Retrieve
A dense search and a keyword search run at the same time, each carrying the reader’s permission filter. The two result lists are merged by reciprocal rank fusion.
- 03Expand
Parent sections are pulled in under the same permission filter, so expansion can’t reach a section the reader isn’t allowed to see.
- 04Generate
The model writes to a fixed schema. Each retrieved source has a temporary label for that request, and the model can only cite from that set.
- 05Quote
Quotations are copied from the stored file at the recorded positions. The model doesn’t write them.
- 06Verify
A deterministic check on numbers and wording runs first. Claims it can’t settle go to a second model, one that didn’t write the answer.
- 07Gate
Claims that fail verification are dropped. If too much of the answer fails, the whole answer is withheld and the system reports that it couldn’t support one.
Permission-aware retrieval
Permissions are checked inside the search.
Once a restricted passage has been retrieved and placed in a prompt, the model has already read it. Hiding it from the display afterward doesn't undo that. The permission check has to run inside the query.
- Post-filter results
What happens
Restricted passages are retrieved and enter the prompt, then get hidden from the displayHolds up under review
No - Separate index per group
What happens
Works until one document belongs to two groups, or a group’s membership changesHolds up under review
Partly - Permission filter inside each retrieval arm
What happens
A restricted passage is never a candidate, in either the dense or the keyword searchHolds up under review
Yes - Row-level security in the database
What happens
The database itself refuses the query when a code path forgets to set the reader’s scope. This catches anything the retrieval filter misses.Holds up under review
Yes
| Approach | What happens | Holds up under review |
|---|---|---|
| Post-filter results | Restricted passages are retrieved and enter the prompt, then get hidden from the display | No |
| Separate index per group | Works until one document belongs to two groups, or a group’s membership changes | Partly |
| Permission filter inside each retrieval arm | A restricted passage is never a candidate, in either the dense or the keyword search | Yes |
| Row-level security in the database | The database itself refuses the query when a code path forgets to set the reader’s scope. This catches anything the retrieval filter misses. | Yes |
Two smaller points follow from that. A refusal for a restricted document is byte-identical to a refusal for a document that does not exist, so nobody can probe the system to learn what it holds. And a document identifier copied out of someone else’s answer returns nothing, because holding the identifier is not the same as being allowed to read the document.
Questions
Common questions.
- What makes one RAG system better than another?
- Mostly the retrieval step. When a system disappoints, it is usually pulling the wrong passages and the model is doing its best with bad input. Retrieval quality can be measured, so we measure it and report the number.
- Can it respect our existing permissions?
- Yes. If a document is restricted, it never becomes a retrieval candidate in the first place. Filtering results after the search is too late, because by then the passage has already gone into the prompt. We put the permission check inside each retrieval arm and back it with row-level security in the database.
- What document formats can you ingest?
- PDF, DOCX, and Markdown. Ingestion follows the document’s headings when it splits the text, and it records where each chunk sits in the original file. Those positions are what let the system quote a passage exactly later on.