Skip to content
Guide

Designing your own custom RAG pipeline.

A RAG pipeline is a sequence of decisions, not a product you install. Four of them deserve most of your attention — get these right and the rest follows.

The steps below are sequential. Each choice constrains the next — your use case shapes what you need from a parser, your parser shapes what document processing is possible, and your processing shapes how you can chunk. The expensive mistakes happen when a step gets skipped, or decided by default instead of on purpose.

The four decisions

01

Design the use case

What questions should the system answer?

Everything downstream is shaped by this. Define who is asking, what they ask, and what a good answer looks like — including the data sources those answers live in: PDFs, wikis, SharePoint, Confluence, ticket systems, websites. Scope kills more RAG projects than technology does — a system built to answer 'anything about the company' ends up answering nothing well. Decide up front what happens when there's no good answer: saying 'not found' beats a confident guess.

How to decide

Write down twenty real questions your users will actually ask, and find the documents that answer them. That list is your spec — every later decision gets tested against it.

Step 01 in depth

Design the use case

Your question set does two jobs at once. It's a product spec — the concrete thing you're building toward — and it's an evaluation set — the thing you'll measure every later decision against. Most teams skip straight to picking a vector database because that feels like progress. It isn't; it's motion without direction.

Scope is the real risk. A RAG system aimed at 'anything about the company' has no way to know what a good answer looks like, so it can't tell a grounded answer from a confident-sounding fabrication. Narrow the target first: which team, which documents, which questions. You can always widen later — widening a system that never worked narrowly just multiplies the failure.

Define the failure mode you want, not just the success mode. A good answer is grounded in a real source, cited, and current. A missing answer should say so plainly — 'I couldn't find this in the documentation' is a better outcome than a fluent guess. Then inventory your sources honestly: where the documents actually live, how often they change, and who is allowed to see what. That inventory becomes the access and freshness constraints every later step has to respect.

Where real questions come from

Support tickets

Zendesk, Intercom, or Freshdesk exports are a goldmine of verbatim user questions.

Internal search logs

What people already type into your wiki or intranet search — failed searches are unmet retrieval demand.

Slack and Teams threads

The questions people ask each other are the ones your system should answer.

Evaluation harnesses

Ragas or promptfoo to turn your question list into a repeatable benchmark — a spreadsheet works on day one.

Tip

If you can't collect twenty real questions, you don't have a use case yet — you have a hunch.

Tools change fast. The test — your documents, your questions — doesn't.

02

Select the parser

Can it read your documents — not documents in general?

Parsers are benchmarked on clean text. Your corpus has scanned pages, tables, forms, and odd layouts. Parsing quality is corpus-specific, so evaluate on your own files, not a vendor's demo set. This is the highest-leverage, least-glamorous choice in the whole pipeline — a mistake here survives every downstream step, because you can't chunk, embed, or retrieve information the parser already threw away.

How to decide

Run ten representative documents — your worst ones, not your cleanest — through each candidate parser and read the raw output side by side. Pick the one that preserves what your answers depend on.

Step 02 in depth

Select the parser

Parsing is unglamorous because it produces no demo-able output — nobody screenshots a clean text file. But it's the highest-leverage decision in the pipeline: garbage in at this step survives every downstream step unchanged. A model can't reason about a table it never saw, because the parser flattened it into word soup.

Read outputs looking for specific failure modes, not a vague 'does it look okay.' Tables collapsed into unstructured text with rows and columns scrambled together. Reading order broken on multi-column layouts, so a sentence jumps from column one to column two mid-thought. Headers and footers bleeding into every page's content, polluting the actual text. Scanned pages silently skipped entirely — the most dangerous failure, because nothing in the output tells you it happened.

Then weigh the operational trade-off: hosted parsers send your documents to someone else's infrastructure in exchange for less engineering work; local, open-source parsers keep data in-house but you own the compute and the upkeep. At corpus scale, price per page adds up fast — model it before you commit, not after the invoice arrives.

Parsers worth evaluating

Docling

IBM's open-source parser. Strong layout and table structure, runs entirely on your own hardware.

LlamaParse

LlamaIndex's hosted parser. Good on complex PDFs, output designed for LLM consumption.

Landing.AI Agentic Document Extraction

Vision-model-driven extraction. Strong on forms, charts, and visually dense documents.

Unstructured

Open source with a hosted option. Very broad file-type coverage.

AWS Textract / Azure Document Intelligence / Google Document AI

The cloud OCR heavyweights. Reliable on scans and forms, pay-per-page.

Marker

Fast open-source PDF-to-markdown conversion.

Reducto

Hosted, accuracy-focused parsing for complex layouts.

Tip

Shortlist two or three, run the ten-document test, and keep the losers' outputs — they're your regression baseline when you re-evaluate next year.

Tools change fast. The test — your documents, your questions — doesn't.

03

Design document processing

What structure do you keep, and what do you throw away?

Decide deliberately what survives parsing: OCR for scans, table structure, images, headers and footers, and the metadata worth extracting — dates, document type, owner, access rules. Cleaning is a design decision, not a chore. This step is mostly decisions and glue code rather than a single product you buy, and the access rules you establish here need to carry through the rest of the pipeline from day one.

How to decide

For each document type, decide what a chunk must carry for an answer to be trustworthy — then process for that, and discard the rest.

Step 03 in depth

Design document processing

There's no single product called 'document processing' — it's a set of decisions and the glue code that implements them, made per document type. A scanned invoice, a wiki page, and a 300-page manual all need different treatment, and treating them identically is how quality quietly degrades for whichever type didn't fit the default path.

The metadata you extract here is what makes retrieval filterable later — you can't filter search results by date, document type, product line, or access level if that information was never pulled out during processing. It's much easier to decide this now than to re-derive it from raw chunks after the fact.

Access rules deserve special attention: they must be carried through the pipeline from the very first step, tagged onto documents and chunks alike. Bolting security on after the fact means re-processing your entire corpus, because the permission information was never captured when it was cheapest to capture.

The processing toolbox

Tesseract / PaddleOCR

Open-source OCR for scanned pages, if your parser doesn't handle it.

Camelot / pdfplumber

Python libraries for surgical table extraction when the parser's output isn't enough.

GLiNER / spaCy

Fast, cheap entity extraction for names, dates, and domain terms.

LLM structured extraction

For bespoke fields — an LLM with a JSON schema pulls the metadata no off-the-shelf model knows about.

Tip

Write the target schema for each document type first — what fields, what structure, what gets discarded — then pick tools to fill it.

Tools change fast. The test — your documents, your questions — doesn't.

04

Choose a chunking strategy

Where do answers actually live in your documents?

Page-based, semantic, hierarchical, or hybrid — none is best in general. The right boundaries match how information sits in your corpus: a procedure step, a spec table, a contract clause. Chunk size is a trade-off, not a setting to get right once — smaller chunks favor precision, larger ones favor recall, and retrieval-time tricks can recover context a hard boundary cut off.

How to decide

Take your twenty questions and find the passage that answers each one. The shape of those passages is your chunking strategy — test it by checking whether each answer survives inside a single chunk.

Step 04 in depth

Choose a chunking strategy

Chunking failures are easy to spot once you know what to look for: a table split from its header, so the numbers lose their meaning; a procedure step separated from the rest of the procedure; a contract clause cut off from the definitions it depends on. Each of these turns a perfectly good document into a chunk that can't answer the question it was supposed to.

In plain terms, the strategies break down like this. Fixed or page-based chunking is dumb but predictable — it always produces the same shape, which makes it easy to reason about even though it ignores meaning. Semantic chunking places boundaries where the meaning actually shifts. Hierarchical chunking keeps small chunks for precise search but links them to larger parent chunks for context. Hybrid — different rules for different document types — is usually the right answer, because a manual and a spreadsheet don't share a natural chunk shape.

Chunk size trades recall against precision: smaller chunks retrieve more precisely but each one carries less context; larger chunks carry more context but dilute relevance. You don't have to solve this purely at chunking time — retrieval-time tricks like fetching neighboring chunks or pulling in the parent document can recover context that a hard boundary cut off.

Chunking implementations

LangChain text splitters

Recursive and markdown-aware splitters — the workhorse baseline.

LlamaIndex node parsers

Sentence-window and hierarchical parsers with parent-child retrieval built in.

Chonkie

A lightweight library dedicated to chunking, with most modern strategies implemented.

Semantic chunking

Boundary detection via embedding similarity — available in LlamaIndex and Chonkie.

Late chunking (Jina AI)

Embed the whole document first, then pool per chunk — keeps document-wide context in every chunk vector.

Docling's hybrid chunker

Layout-aware chunks straight from the parse, so structure survives into retrieval.

Tip

Pick the strategy from your documents, then the library that implements it — never the other way around.

Tools change fast. The test — your documents, your questions — doesn't.

The rest of the pipeline

What comes after.

The remaining decisions matter too — but they inherit from the four above.

05

Metadata

Tags, dates, document type, ownership, access.

06

Embedding model

Fit to your domain, cost, and latency.

07

Storage

Vector, keyword, relational, or graph — usually a mix.

08

Indexing

Hybrid search and relationships, not just vectors.

09

Retrieval logic

Filters, reranking, query rewriting, multi-stage retrieval.

10

The LLM

Quality, context window, latency, cost.

11

Prompts

Grounding, citations, formatting, hallucination control.

12

Evaluation

Accuracy and recall measured on your twenty questions.

13

Deployment

Your cloud, with authentication, scaling, and monitoring.

14

Operations

Re-indexing, document updates, versioning, feedback loops.

Or design it with us

These are the decisions we make with clients every week.

Bring your documents and your questions — we'll come back with an architecture.