An LLM RAG pipeline is a set of steps that finds the right passages in your own documents and gives them to a language model, so it answers from your sources instead of from memory. RAG stands for retrieval-augmented generation. I have built three of them:
- A contract reviewer: it answers questions about a contract from Indonesian employment law.
- A keyword search: it feeds my AI agents from my personal wiki, with no embeddings.
- A private prototype: it ran fully offline, with local models and a permission filter.
If you searched for this, you have probably seen many diagrams with a vector database in the middle. They are a good start. In my work, the most useful choices were not in the diagram:
- What to retrieve: some documents are small enough to send whole.
- Whether to use embeddings: keyword search was enough for my wiki.
- Where to check access: who is allowed to see a document, before anything is retrieved.
In this guide, I will explain what a RAG pipeline is and the five steps inside it. Then I will show the three pipelines I built and what each one taught me. At the end, I will share what is not finished yet.
What Is an LLM RAG Pipeline?
A language model only knows what it saw in training. It does not know your contracts, your company handbook or your notes. A RAG pipeline fixes that. Before the model answers, a search step finds a few passages that match the question. The model then reads the question and those passages together and answers from them.
This is why I chose RAG over fine-tuning when I researched private AI for companies. Fine-tuning changes how a model writes. RAG changes what it knows. With RAG, you can:
- Update quickly: change a document today, and the next answer uses it.
- Show sources: every answer can name the passage it came from.
- Control access: hide a document from people who are not allowed to see it.
What Are the Steps in a RAG Pipeline?
Every RAG pipeline I have built has the same five steps. The first three run once for each document. The last two run every time someone asks a question.
- Ingest: turn PDFs, scans and pages into plain text. Scanned documents need OCR first.
- Chunk: split the text into pieces that make sense on their own, such as one clause or one article of a law.
- Index: store the pieces so they can be found. This can be a keyword index, vectors from an embedding model, or both.
- Retrieve: for each question, find the best few pieces.
- Generate: send the question and the pieces to the model, and ask it to answer from them and name its sources.
Most of the quality comes from the chunk and retrieve steps. If a chunk does not make sense on its own, the model cannot use it. If retrieval returns the wrong pieces, the best model in the world will still answer the wrong question.
How I Built One for Contract Review
My first RAG pipeline was in Kontrakku, a tool I built in May 2025. It helps job seekers understand an Indonesian employment contract before they sign it. You upload the contract as a PDF, and the tool explains each clause, flags vague or risky ones and lets you ask questions in a chat.
The backend is Django, with a task queue for the slow work. The steps look like this:
- Ingest: Mistral OCR reads the PDF and turns it into Markdown.
- Chunk: the law, Indonesia's Manpower Law (UU 13/2003), is split by article. Each article keeps its chapter and section as metadata.
- Index: the articles are stored as embeddings in Chroma, a vector database.
- Retrieve: for each chat question, the two closest articles come back.
- Generate: o4-mini gets the whole contract, the two articles and the last 20 chat turns, and answers with the article numbers it used.
The most useful decision here was what not to retrieve. A contract is a few pages long, so it fits in the prompt. Cutting it into chunks would only lose context between clauses. The law is much longer, so that is the part I retrieved. The lesson I took from it: retrieve only what does not fit.
Do You Need Embeddings in a RAG Pipeline?
Not always. My personal wiki has about 1,200 pages about my projects, clients and decisions, and my AI coding agents read it before they ask me anything. I wrote about that setup in LLM Wiki for Coding Agents. Its search has no embeddings and no vector database at all.
It uses BM25, a classic keyword ranking, with a few additions:
- Field boosts: a word in a page's title or aliases counts more than a word in the body.
- Page types: a summary page about a project ranks above the raw notes it was built from.
- Two languages: I write questions in Indonesian and English, so Indonesian words also match their English meaning through a small word map.
- A test set: 80 real questions with the page that should come first. I run it after every change to the search.
Today, 69 of the 80 questions find the right page first, and 75 find it in the top three. The weak spot is clear in the numbers: when a question uses none of the page's own words, only 5 of 10 come first. That is the case where embeddings help, because they match meaning instead of words.
So my answer is to start with keywords and a test set. Add embeddings when the test set shows that meaning-based questions are failing, not before. Keyword search is easier to debug too, because you can see exactly why a page matched.
How I Kept Private Documents Private
In October 2026, I researched RAG for companies that cannot send their documents to a cloud AI provider. I built a prototype where everything ran on one machine:
- Models: qwen3:8b for answers and bge-m3 for embeddings, both running locally in Ollama.
- Storage: Postgres 17 with pgvector, so the documents and their vectors sit in one normal database.
- Access: sign-in with public sign-up turned off. Each document belongs to one or more groups.
- Permission filter: the group check runs inside retrieval, so a person can never get a chunk from a document they cannot open.
The permission filter is the part I would keep in any company RAG. If you filter after retrieval, the model may already have read a passage the user should not see, and it can leak into the answer. The SDK I used could only filter on simple equal-to checks, so I stored each group as its own flag on the chunk, such as "group 12 is true".
Hardware is the other lesson. My research showed that an 8B model on a 16 GB graphics card serves only a few people at the same time. A 16B model needs about 32 to 64 GB of graphics memory. Private AI is possible, but it costs more than most companies expect.
What Is Not Finished Yet?
None of these pipelines is a finished product, and I want to be clear about that.
- Kontrakku: the MVP from May 2025 has no login and no tests, and I have not worked on it since 24 May 2025.
- The private prototype: I stopped it on the day I built it, and its code and database were deleted. The research notes are what remain.
- Embeddings in Indonesian: at work, I am building a knowledge base with pgvector and Gemini embeddings. Retrieval for Indonesian documents is not good enough yet, and I am still testing embedding models.
- Numbers: I have no latency or accuracy numbers from real users. The only pipeline I measure is my wiki search, with its 80 test questions.
What I Would Do Again
- Retrieve only what does not fit: send small documents whole and retrieve from the large ones.
- Start with keywords: BM25 is fast, free and easy to debug. Add embeddings when a test shows you need them.
- Write a test set first: even 80 questions with the right answer tell you more than any demo.
- Chunk by meaning: one clause, one article or one page per chunk, with its headings as metadata.
- Filter by permission inside retrieval: never after.
- Ask for sources: an answer that names its article or page is an answer you can check.
FAQs
What is an example of a RAG pipeline?
A contract reviewer is a good example. The pipeline stores a law split into articles, finds the two articles closest to a user's question and sends them to the model with the contract. The model answers and names the articles it used.
What does a RAG pipeline architecture look like?
It has two parts. An indexing part reads, chunks and stores your documents once. A question part runs every time: it retrieves the best chunks and sends them to the model with the question. Add a permission filter inside retrieval if different people can see different documents.
Is RAG better than fine-tuning?
They solve different problems. Fine-tuning changes how a model writes, while RAG changes what it knows. For answers from your own documents that change over time and need sources, RAG is the better fit.
Do I need a vector database for RAG?
No. My wiki search uses keyword ranking only and finds the right page first for 69 of 80 test questions. A vector database helps when people ask questions in words that do not appear in the documents. If you already use Postgres, pgvector adds vectors without a new database.
How do I build a RAG pipeline from scratch?
Start small. Pick one set of documents, split them into chunks that make sense alone and index them with keyword search. Write 20 to 80 test questions with the right answers, then connect a model and ask it to cite its sources. Add embeddings, reranking or OCR only when your tests show you need them.