Every organisation has the same problem: the answer exists somewhere, in a policy PDF, a support thread, a contract or a wiki page nobody can find. Retrieval-augmented generation (RAG) is the most practical way to put a language model on top of that knowledge. Instead of relying on what the model learned during training, the system first finds the relevant passages in your own documents, then asks the model to answer using only those passages.
The basic pipeline
A RAG system has two halves: preparing the knowledge, and answering questions.
Ingestion: documents -> clean text -> chunks -> embeddings -> vector index (+ metadata)
Answering: question -> embedding -> search -> top passages -> model prompt -> cited answer
An embedding is a list of numbers that represents the meaning of a piece of text, so passages about the same thing end up close together even when they use different words. The vector index finds the passages closest to the question. The model then writes an answer from those passages, with references back to the sources.
Chunking decides quality more than the model does
How documents are split into chunks matters more than most teams expect. Chunks that are too small lose context ("it" with no idea what "it" is); chunks that are too large dilute the match and waste the model's attention. What works in practice:
- Split on structure, not character counts. Headings, sections and list items are natural boundaries.
- Keep the heading path with each chunk. "Leave policy > Parental leave > Eligibility" turns an ambiguous paragraph into a precise one.
- Store metadata alongside the text. Source document, date, owner, language and access rules all become filters later.
Hybrid search beats pure vector search
Vector search is good at meaning but weak at exact terms: product codes, names, clause numbers. Keyword search is the opposite. Combining the two (often called hybrid search) and then re-ranking the merged results with a small model that scores relevance gives noticeably better retrieval than either alone. For company knowledge full of internal names and codes, this is usually the single biggest quality improvement.
Permissions belong in retrieval
The fastest way to turn a helpful assistant into a data leak is to index everything and let anyone ask. Every chunk should inherit the access rules of its source, and the search query should only return chunks the current user can see. Filtering the answer afterwards is too late: the model has already read the restricted text and may paraphrase it.
Make answers checkable
- Cite sources. Every answer links to the passages it used, so a reader can verify it in one click.
- Refuse gracefully. If nothing relevant was retrieved, the right answer is "I could not find this in our documents", not a guess.
- Keep the index fresh. Re-ingest documents when they change, and remove chunks when a document is deleted or superseded. An assistant quoting last year's policy is worse than no assistant.
Measure it before trusting it
Build a set of real questions with known answers and the documents that contain them. Run it after every change to chunking, search or prompts, and track two things separately: did retrieval find the right passages, and did the model answer correctly from them. When quality drops, that split tells you which half to fix.
Where RAG fits
RAG is the right tool when the knowledge changes, must be cited, or is subject to access rules: internal policies, product documentation, support history, contracts. It is the wrong tool for teaching a model a new task or tone, which is what fine-tuning is for. Many production systems use both: a lightly tuned model for the format, and retrieval for the facts.