Retrieval-Augmented Generation (RAG) Explained for Business Applications

A plain explanation of retrieval-augmented generation: how documents are chunked, embedded and searched, how answers cite sources, and how to evaluate and secure a business RAG system.

Large language models write fluent answers, but they know nothing about your company's policies, product manuals, contracts or support history, and when they do not know something they may still answer confidently. Fine-tuning a model on internal documents is expensive, hard to keep current and does not let you show where an answer came from.

Retrieval-augmented generation, or RAG, is the common alternative. Instead of teaching the model your documents, you search them at question time and give the most relevant passages to the model along with the question. This article explains each part of a RAG system in business terms, the decisions that most affect quality, and the controls you need before letting staff or customers rely on it.

The pipeline in words

A RAG system has two halves: an indexing pipeline that runs whenever documents change, and a query pipeline that runs for every question.

Indexing:

  1. Collect documents from their sources: a shared drive, a help centre, an ERP, a ticketing system.
  2. Extract clean text and keep metadata: title, source, date, owner, and who is allowed to see it.
  3. Split the text into chunks of a few hundred words.
  4. Convert each chunk into an embedding, a list of numbers that represents its meaning.
  5. Store chunks, embeddings and metadata in a vector index.

Answering:

  1. Convert the user's question into an embedding with the same model.
  2. Search the index for the chunks closest in meaning, filtered to what this user may see.
  3. Assemble a prompt: instructions, the retrieved chunks with their source labels, and the question.
  4. Send it to the language model and return the answer with citations to the sources used.

Picture it as a librarian and a writer. The retrieval step is the librarian who fetches the right pages; the model is the writer who reads only those pages and drafts a reply. If the librarian brings the wrong pages, the writer cannot produce a good answer, which is why most quality problems in RAG are retrieval problems.

Chunking: the unglamorous decision that matters

Chunks that are too large dilute the relevant sentence with unrelated text and use up the model's context. Chunks that are too small lose the surrounding meaning: a line saying "this applies only to annual plans" is useless if separated from the paragraph it qualifies. Practical guidelines:

  • Split along the document's own structure (headings, sections, list items) before falling back to fixed lengths.
  • Use a small overlap between neighbouring chunks so that sentences on a boundary are not lost.
  • Prefix each chunk with its document title and section heading, so that "Refund timelines" still makes sense on its own.
  • Treat tables, FAQs and scanned PDFs separately; they often need custom extraction.

Embeddings and vector search

An embedding model maps text to vectors so that passages with similar meaning sit close together, even when they use different words. "How do I get my money back?" can find a section titled "Refund policy". You can use a hosted embedding API or an open model run on your own server; if your documents include personal data, the second option keeps that data within your infrastructure.

The vectors live in a vector index. Dedicated vector databases exist, but PostgreSQL with the pgvector extension, or the vector features of search engines such as OpenSearch, are often enough for business document collections. Two refinements are worth adding early:

  • Hybrid search. Combine vector search with ordinary keyword search. Embeddings are weak at exact matches such as invoice numbers, GSTINs, part codes and names; keywords handle those well.
  • Re-ranking. Retrieve a larger candidate set, say 20 to 50 chunks, and use a re-ranking model to choose the best few for the prompt.

Prompt assembly and citations

The prompt should tell the model to answer only from the supplied passages, to say plainly when they do not contain the answer, and to cite the passage labels it used. Your application then turns those labels into links to the source documents. Citations matter for two reasons: users can verify answers, and reviewers can tell whether a wrong answer came from bad retrieval or from the model misreading good retrieval.

The sketch below shows the query side. It is Python-style pseudocode: embed, index and llm stand in for whichever embedding model, vector store and language model you use.

def answer(question, user):
    q_vec = embed(question)
    hits = index.search(
        vector=q_vec,
        top_k=20,
        filter={"allowed_groups": user.groups},  # access control
    )
    passages = rerank(question, hits)[:5]

    context = "\n\n".join(
        f"[{i + 1}] {p.title} ({p.source})\n{p.text}"
        for i, p in enumerate(passages)
    )
    prompt = (
        "Answer using only the numbered passages below. "
        "Cite passages like [1]. If they do not contain the answer, say so.\n\n"
        f"{context}\n\nQuestion: {question}"
    )
    reply = llm.generate(prompt)
    return reply, [(i + 1, p.source) for i, p in enumerate(passages)]

Access control and data protection

A RAG system can become a very efficient way to leak information. If the index contains HR files and salary sheets, a clever question from any employee may surface them. Rules to follow:

  • Store permissions as metadata on every chunk, copied from the source system, and filter at search time, as in the example above. Never retrieve everything and rely on the model to withhold restricted content.
  • Keep permissions in sync: when someone leaves a team or a document is deleted, the index must reflect it.
  • Treat retrieved text as untrusted. A document can contain instructions ("ignore previous rules and...") that try to steer the model; keep the model's abilities limited and do not let it take actions based solely on retrieved text.
  • Under the DPDP Act 2023, personal data in your documents still needs a lawful purpose and appropriate safeguards. Exclude data that the assistant does not need, and log queries securely for audit.

Evaluating before and after launch

"It seemed fine when we tried it" is not an evaluation. Build a test set of real questions, collected from support tickets or staff, each with the correct answer and the document that contains it. Then measure separately:

  • Retrieval: is the right document among the top results?
  • Faithfulness: does the answer stick to the retrieved passages, without additions?
  • Correctness and completeness: does it actually answer the question?
  • Refusals: does it say "I don't know" when the documents have no answer?

Rerun the test set whenever you change chunking, embedding model, prompt or language model. After launch, add a thumbs-up or thumbs-down control and review the negative cases regularly; they become new test questions.

How NextWebGen can help

NextWebGen builds business software that connects to your existing data, including document search and question-answering features with permission-aware retrieval, hosted on infrastructure you control. If you have a knowledge base, CRM or ERP data you want staff to query in plain language, contact us to discuss a scoped pilot.