The question behind the acronym
You've probably heard the term RAG by now. Retrieval-Augmented Generation. It shows up in every AI product pitch, every consulting conversation, and half the LinkedIn posts in your feed. But when you strip away the marketing, what is actually happening inside the machine when you ask an AI a question about your documents?
This article is for the person who wants to understand the machinery. Not the buzzword version. The actual pipeline. I'll walk you through every step — from the moment your document enters the system to the moment the AI speaks the answer — and I'll be honest about where each step can go wrong.
You don't need a computer science degree. You do need patience, because there are eight distinct steps and each one matters. Skip one or do it badly, and the whole system becomes unreliable.
"AI is not magic. It's a very fast, very patient, very literal assistant that has read most of the internet and can pattern-match against what you give it. The trick is knowing what to ask and how to keep it honest."
— The working definition I use with clients
The librarian analogy
Before we get technical, imagine a very fast librarian. This librarian has read every book in your business — policy manuals, past quotes, client correspondence, compliance documents, training guides. But instead of remembering the books word for word, the librarian makes a peculiar kind of notes.
For every page, the librarian writes down a set of coordinates. Not page numbers — coordinates in a vast, invisible space where similar ideas sit close together. A page about tax deductions sits near other tax pages. A page about refund policies sits near complaint-handling procedures. The librarian has turned meaning into geometry.
When you ask a question — "What's our policy on commercial deposit refunds?" — the librarian doesn't search for the word "refund." Instead, the librarian converts your question into coordinates too, looks at the map, and says: "The ideas closest to this question are on pages 14, 47, and 112. Let me fetch those."
The librarian hands those pages to a writer — the language model — and says: "Answer the question using only what's on these pages."
That's RAG. The librarian is retrieval. The writer is generation. The coordinates are embeddings. The map is a vector database. Everything else is implementation detail — but as you'll see, the devil lives enthusiastically in those details.
Step 1: Chunking — cutting documents into pieces
Language models have a limit on how much text they can process at once. That limit is called the context window. Even the most generous models top out at a few hundred thousand words. Your business might have millions of words in its document library. So the first thing we do is chop the documents into manageable pieces.
These pieces are called chunks. A chunk might be a paragraph, a page, a section, or a fixed number of tokens — usually somewhere between 200 and 1,000 words.
Here's where it gets tricky. If you cut a document blindly every 500 words, you will slice through the middle of explanations. Imagine a sentence that starts in one chunk and finishes in another: "The warranty does not cover damage caused by..." [chunk boundary] "...flooding, unless the property is in a designated flood zone." If someone asks about warranty coverage for flood damage, the first chunk says "not covered" and the second says "covered, sometimes." The retrieval step might only find the first chunk. The AI answers "not covered" and gives the client bad advice.
Chunking strategies that actually work
- Fixed-size with overlap: Cut every 500 tokens, but overlap the last 50 tokens of each chunk into the next. This preserves context across boundaries.
- Semantic chunking: Cut at natural boundaries — paragraph breaks, section headers, or topic shifts. More complex to implement, but preserves meaning.
- Recursive splitting: Try to split by paragraph. If a paragraph is too long, split by sentence. If a sentence is too long, split by token count. A hierarchy of fallbacks.
For most small business RAG systems, fixed-size with overlap is the pragmatic starting point. It's simple, predictable, and good enough. Semantic chunking is better but adds complexity that only pays off when you have very large, very structured document sets.
Step 2: Embedding — turning text into coordinates
This is the step that sounds like science fiction until you see it work. We take each chunk of text and run it through an embedding model — a specialised neural network trained for one purpose: to convert text into a long list of numbers.
That list might have 384 numbers, or 768, or 1,536, depending on the model. The length is called the dimension of the embedding. Each number represents a feature the model has learned to detect. One dimension might loosely correspond to "formality." Another to "financial content." Another to "negation" or "legal language." The model doesn't label these dimensions — they emerge from training on billions of text pairs.
The crucial property is that similar texts produce similar lists of numbers. Two chunks about tax deductions will have embedding vectors that point in nearly the same direction in this high-dimensional space. A chunk about tax deductions and a chunk about catering menus will point in very different directions.
Analogy: Imagine every concept in the world has a location in a city with thousands of dimensions. "Invoice" lives near "receipt" and "payment" but far from "barbecue" and "holiday." Embedding models are the cartographers who map this city. They don't understand the concepts — they've just learned, statistically, which concepts tend to appear together in human writing.
2 What an embedding actually looks like
A 384-dimensional embedding for the phrase "commercial deposit refund policy" might start like this:
[0.042, -0.118, 0.307, 0.891, -0.034, 0.562, -0.201, 0.445, ... 376 more numbers]
Not human-readable. Not magic. Just a compressed statistical fingerprint of the text's meaning, as inferred from patterns in the model's training data.
Step 3: The vector database — a map of meaning
Once every chunk has been turned into a vector, we need to store them in a way that makes searching fast. A normal database — the kind that powers your accounting software or your website — is built for exact matches. Find the row where invoice_number equals 10472. That's fast because you can index it alphabetically or numerically.
Vectors don't work that way. You can't sort 384-dimensional space alphabetically. What you need is a database that understands distance and similarity. When a user asks a question, the database must quickly find the vectors closest to the question's vector — not exact matches, but neighbours.
Specialised vector databases — like Pinecone, Weaviate, Chroma, Qdrant, or pgvector (a Postgres extension) — solve this with clever indexing structures. The most common is called HNSW: Hierarchical Navigable Small World. It builds a network of shortcuts through the vector space, letting the database find approximate nearest neighbours in milliseconds, even across millions of chunks.
The key word is approximate. HNSW trades a tiny amount of accuracy for enormous speed. In practice, it finds the right chunks about 95–99% of the time. The other 1–5% is where your RAG system silently fails — retrieving irrelevant chunks and basing the answer on the wrong information.
Step 4: The question — embedding the query
When someone asks "What's our warranty for commercial roofing?" the system doesn't search for those exact words. It runs the question through the same embedding model used on the chunks, producing a vector that represents the meaning of the question.
This is elegant but fragile. The embedding model must be the same one used during chunking, or at least trained on the same principles, or the coordinate systems won't align. If you embed chunks with one model and queries with another, it's like asking your librarian to find a book using a map drawn by a different cartographer who used a different scale and orientation.
There's also the problem of query expansion. A user asks "warranty" but your documents use "guarantee," "coverage," "protection plan," or "service agreement." A basic embedding model might not bridge that gap. More advanced systems rewrite or expand the query before embedding it — adding synonyms, clarifying ambiguous terms, or even generating hypothetical answers and embedding those to search for supporting chunks. This is called HyDE (Hypothetical Document Embedding) and it can improve retrieval accuracy significantly, at the cost of extra computation.
Step 5: Similarity search — finding the nearest neighbours
The vector database takes the query vector and finds the chunks whose vectors are closest to it. Typically you ask for the top 5 or top 10 nearest neighbours. The database returns those chunks, along with their similarity scores.
How similarity is measured: The most common metric is cosine similarity. It measures the angle between two vectors, not their absolute distance. Two chunks that say the same thing in different lengths will have vectors pointing in the same direction but with different magnitudes. Cosine similarity ignores magnitude and focuses on direction — which is what you want for semantic matching.
There's a subtle but important decision here: how many chunks to retrieve? Too few — say, 3 — and you might miss the one chunk that contains the specific exception or qualification the user is asking about. Too many — say, 50 — and you flood the language model with irrelevant text, diluting the signal and increasing cost. Most systems settle on 5 to 10 chunks as a practical default, then tune from there based on testing.
Step 6: Reranking — a second opinion
The initial similarity search is fast but coarse. It finds chunks that are generally about the right topic. A reranker is a second model that looks at the retrieved chunks alongside the original question and scores each one on how directly it answers the specific query.
Think of it like this: the vector search is a librarian pulling ten books from the shelf that look relevant. The reranker is a subject-matter expert who quickly flips through those ten books and reorders them by how precisely each one answers your exact question.
Rerankers are typically smaller, faster models — or even cross-encoders that look at the query and chunk together rather than separately. They can boost accuracy by 10–20% in many cases. The trade-off is latency: every reranked chunk adds a small delay. For internal business systems where users expect answers in 2–3 seconds, reranking is usually worth it. For high-volume public chatbots, the delay might be prohibitive.
Step 7: Context assembly — packing the prompt
Now we have our ranked chunks. We need to present them to the language model in a way that makes the model answer accurately. This is called context assembly or prompt engineering, and it's where a lot of RAG systems quietly fail.
The typical prompt structure looks like this:
You are a helpful assistant. Answer the user's question using ONLY the information provided below. If the answer is not in the provided documents, say "I don't have that information." Do not make anything up.
---
Document 1: [chunk text]
Document 2: [chunk text]
Document 3: [chunk text]
---
Question: What's our warranty for commercial roofing?
The instruction "Do not make anything up" is called an anti-hallucination guardrail. It reduces but does not eliminate hallucinations. Language models are fundamentally completion engines. If the context doesn't contain a clear answer, the model's next-word prediction will often generate something plausible-sounding rather than admitting ignorance.
There's also a size constraint. The chunks plus the question plus the instructions must fit inside the model's context window. If you retrieve too many chunks, or the chunks are too long, you'll exceed the limit and have to truncate — potentially cutting off the very information the user needs.
Step 8: Generation — the AI answers with notes in hand
Finally, the assembled prompt goes to the language model. The model reads the instructions, reads the chunks, and generates an answer token by token.
Because the chunks are present in the prompt, the model's attention mechanism can directly reference them. This is the "augmented" part of Retrieval-Augmented Generation: the generation process is augmented by retrieved documents. Without retrieval, the model would answer from its training data — which might be outdated, generic, or outright wrong about your specific policies.
A well-built RAG system also asks the model to cite its sources — to say which chunk it used for each claim. This lets a human verify the answer against the original document. Citation generation is not perfect — models sometimes cite the wrong chunk or hallucinate citations entirely — but it's better than no transparency at all.
What goes wrong at every step
I've built enough RAG systems to have scars. Here's what actually breaks, in order of how often it ruins an otherwise good demo.
Bad chunking splits the truth in half
This is the most common failure I see. A policy says "Cover is included unless the property is over 40 years old, in which case a structural assessment is required." The chunk boundary falls between "unless" and "the property is over 40 years old." Someone asks about cover for a 45-year-old property. The system retrieves only the first half and says "Cover is included." That's a serious error, and it came from a mechanical decision made during preprocessing.
Embedding models don't understand your jargon
Every industry has specialised language. A mortgage broker talks about LVRs, LMI, and servicing buffers. A tradesperson talks about RCDs, DWV, and rough-ins. General-purpose embedding models, trained on the broad internet, may not map these terms precisely. The result is retrieved chunks that are topically close but technically wrong.
The vector database retrieves noise
Similarity search finds similar things, not correct things. A user asks about "termination clauses" in an employment context. The database might retrieve chunks about "contract termination" from supplier agreements instead of employee contracts. The answer will sound right and be wrong.
Context windows overflow
You retrieve ten chunks of 500 tokens each. That's 5,000 tokens. Add the prompt template, the question, and the system instructions. If you're using a model with a 4,000-token context window, you've blown past the limit. The model truncates from the bottom — often cutting off the most recently retrieved chunks, which might contain the exact answer.
The model ignores the instructions
You told it "say 'I don't know' if the answer isn't in the documents." But the model's training includes a strong bias toward being helpful. A user asks a question that's only partially covered by the chunks. The model stitches together what it found with what it remembers from training, producing a confident-sounding answer that's 70% right and 30% hallucinated. That 30% is where trust dies.
"The demo is the easy part. The hard part is making it survive contact with real people, real data, and real deadlines for six months without breaking someone's trust."
What this actually costs and takes
Let's talk about the economics. A basic RAG pipeline involves:
- Embedding model API calls: Roughly $0.01–$0.10 per 1,000 chunks embedded, depending on the model and provider. For a small business with 5,000 pages of documents, expect under $50 to do the initial embedding.
- Vector database hosting: Pinecone or Weaviate Cloud start around $25–$70/month for small indexes. Running pgvector on an existing Postgres server adds effectively zero marginal cost. Chroma or Qdrant self-hosted on a $20 VPS handles most small business loads comfortably.
- Language model generation: This is the ongoing cost. A typical RAG query with 5 chunks might consume 2,000–4,000 tokens (input + output). At current API rates, that's roughly $0.005–$0.03 per query. A team of five people doing 50 queries a day costs $3–$15 a day, or $90–$450 a month.
- Reranker (optional): Adds roughly $0.001–$0.005 per query if you use a hosted reranking API.
Realistic monthly costs for a small business RAG system
- Minimal (open-source models, self-hosted): $30–$80/month in server costs, plus your time for maintenance.
- Mid-tier (API-based embedding + generation, hosted vector DB): $150–$400/month.
- Full-service (custom build, monitoring, support): $500–$1,200/month, including human oversight and refinement.
Time to build: A weekend warrior can assemble a crude RAG demo in 4–8 hours using LangChain or LlamaIndex. A production-ready system — with proper chunking, error handling, source citations, permission controls, and integration into an existing workflow — typically takes 30–80 hours of development, plus ongoing maintenance.
Can you build this yourself?
Yes, with caveats. The open-source tooling for RAG is remarkably good in 2026. Frameworks like LangChain, LlamaIndex, and Haystack abstract away much of the plumbing. You can find tutorials that walk you through a working demo in an afternoon.
But the gap between "demo" and "business tool" is the same gap we discussed in the overview article. The demo doesn't handle:
- Document updates (what happens when your policy changes?)
- Access control (should every staff member see every document?)
- Error recovery (what happens when the vector database is down?)
- Accuracy monitoring (are answers getting worse over time?)
- User feedback loops (how do you learn from wrong answers?)
If you're technically inclined and patient, DIY is a great learning path. You'll understand the system deeply, which makes you a better buyer if you later decide to hire help. If you're not technically inclined, the money spent on professional implementation is usually recovered within a few months in saved time and avoided mistakes.
Stuck on chunking, retrieval, or accuracy?
I've built RAG systems for mortgage brokers, accountants, trades businesses, and professional services firms. If your DIY RAG works in the demo but falls over on real questions — or if you want it built properly the first time — get in touch for a no-pressure assessment.
What to do next
If you've made it this far, you now understand RAG better than most people selling it. That's a powerful position. You can ask informed questions, spot weak implementations, and know what "good enough" actually looks like.
Here's what I'd do with that knowledge:
- Audit your document quality. RAG cannot retrieve what doesn't exist. If your policies are scattered, contradictory, or out of date, the system will surface those problems rather than solve them.
- Test chunk boundaries manually. Pick three important documents. Look at where a 500-token chunker would cut them. Ask yourself: would a partial chunk mislead someone? If yes, you need overlap or semantic chunking.
- Run a blind test. Give a technical friend 20 real questions your staff asks. Have them query your RAG system without looking at the documents. Score the answers for accuracy and completeness. A score below 85% means the system isn't ready for untrained users.
- Plan for maintenance. Documents change. Embedding models improve. Vector databases need occasional reindexing. Someone needs to own this system, or it will slowly rot.
RAG is one of the most genuinely useful AI technologies available to small businesses today. It's also one of the easiest to build badly. The difference between a system that saves you hours and a system that quietly misinforms your staff is the attention you pay to each of the eight steps above.