Book a free call

How to Build a RAG Chatbot: A Step-by-Step Guide

Build a RAG chatbot that answers from your own documents: clean the source, chunk and embed it, retrieve the right passages, and test before you launch.

Hertiv engineering teamReviewed by a senior engineer
5 min read
How to Build a RAG Chatbot: A Step-by-Step Guide
On this page

Short answer

A RAG chatbot answers questions by retrieving facts from your own documents and using a language model to write an answer from those facts. You build it by cleaning the source documents, splitting them into chunks, storing them in a searchable index, and testing retrieval before launch.

What is a RAG chatbot?

A RAG chatbot is a chatbot that answers questions by first retrieving facts from your own documents and then using a language model to turn those facts into an answer. RAG stands for retrieval-augmented generation, and the retrieval step is what keeps the chatbot grounded in your content instead of guessing.

The chatbot does not memorise your documents. It searches them at answer time, picks the most relevant passages, and hands those passages to the model with the user's question. The model writes the reply, and a good design shows the sources it used.

Part What it does Example
Document store Holds your content in searchable form Vector database, search index
Retriever Finds passages that match the question Embedding search, keyword search
Language model Writes the answer from the passages Hosted model or self-hosted model
Guardrails Blocks off-topic or unsafe answers Filters, source checks, human review

RAG chatbots suit support, internal help and product questions, where the answers already exist in your documents. For the background concepts, see what retrieval augmented generation is.

How does a RAG chatbot answer a question?

A RAG chatbot answers a question in four steps: it turns the question into a search query, retrieves the most relevant passages from your documents, passes those passages to the language model, and returns the model's answer with its sources.

The quality of the answer depends on the retrieval step. If the retriever finds the wrong passage, the model will write a confident answer from the wrong facts. That is why testing retrieval matters more than tuning the model.

  1. Search. The question is turned into a query for the document index.
  2. Retrieve. The most relevant passages are pulled back, usually three to five.
  3. Generate. The model writes an answer using only those passages.
  4. Show sources. The answer is returned with links to the passages it used.

Most teams use a mix of keyword search and embedding search, then re-rank the top results before handing them to the model. Keeping the retrieved set small keeps the answer focused and the cost down.

How to build a RAG chatbot in seven steps

You build a RAG chatbot by preparing your documents, indexing them for search, wiring up retrieval and generation, and then testing on real questions before launch. Each step is simple on its own; the quality comes from doing them in order.

  1. Collect the source documents. Help articles, manuals, policies and past tickets, with duplicates and outdated versions removed.
  2. Split documents into chunks. A few hundred words each, keeping headings and context with every chunk.
  3. Turn chunks into embeddings. Store them in a vector database or search index.
  4. Build the retrieval step. Search by meaning and keywords, then keep the top three to five passages.
  5. Write the prompt. Tell the model to answer only from the passages and to say when it does not know.
  6. Add guardrails. Block off-topic questions, filter unsafe content and log every answer with its sources.
  7. Test on real questions. Measure accuracy, fix the failures, and launch to a small group before opening it up.

A RAG development partner can help with the retrieval design if your documents are messy or spread across systems.

How do you keep answers accurate?

You keep answers accurate by testing retrieval and generation separately. First check whether the retriever finds the right passages; then check whether the model writes a correct answer from those passages. A failure in either step needs a different fix.

Build an evaluation set of real questions with known good answers, and run it after every change. If a document update breaks an answer, the evaluation set catches it before users do.

Add a human review loop for the riskiest topics, such as billing, safety and legal questions. The chatbot can draft the answer and a person approves it, which keeps accuracy high while the system earns trust.

  • Show sources with every answer. Users can check the facts themselves.
  • Use an 'I don't know' fallback. A clear refusal beats a confident guess.
  • Date your documents. Old policies should not answer new questions.
  • Review failed questions weekly. Each failure points at a document or retrieval fix.

Example (hypothetical): a support chatbot pilot

Example (hypothetical): a software company has 2,000 help articles and wants a chatbot for support. It splits each article into about six chunks, giving 12,000 chunks, and stores them in a vector database.

The team builds an evaluation set of 200 real support questions with known good answers. In the first test the chatbot answers 170 correctly, or 85%, and the other 30 fail because the retriever picked the wrong passage. Fixing chunk boundaries and adding keyword search lifts the score before launch.

The pilot launches to 10% of support traffic with a human reviewing every answer. After two weeks with no serious errors, the team widens the rollout and keeps the evaluation set running after every document update.

What are the common mistakes?

The most common mistakes when building a RAG chatbot are indexing stale documents, cutting chunks badly, and skipping the evaluation set, so nobody can tell whether the system is improving.

  • Indexing stale or duplicate documents. If five versions of a policy exist, the chatbot will surface all five.
  • Chunks that are too large or cut mid-sentence. A chunk should hold one idea with its context.
  • No evaluation set. Without real questions and known answers, quality debates are anecdotal.
  • Letting the model answer from memory. The prompt must restrict it to the retrieved passages.
  • No fallback. Questions the documents cannot answer need a clear handoff, not a guess.
  • Skipping human review on risky topics. Billing and safety answers need a person in the loop.

When should you not build a RAG chatbot?

Do not build a RAG chatbot when the answers do not exist in documents, when the question volume is tiny, or when a simple FAQ page would do. A chatbot that has nothing to retrieve from will guess, and guessing is worse than saying nothing.

A rules-based bot suits a handful of fixed questions, and fine-tuning suits tasks where tone and format matter more than facts. RAG is the right choice when you have a large, changing body of documents and users ask varied questions about them. For the cost side, see RAG integration process and cost.

If you are choosing between frameworks, the comparison of RAG frameworks for startups covers the trade-offs.

Key takeaways

  • A RAG chatbot retrieves facts from your documents before answering
  • Retrieval quality matters more than model choice
  • Clean documents and right-sized chunks decide accuracy
  • Test with an evaluation set of real questions
  • Keep a fallback and human review for risky topics

Frequently asked questions

What is a RAG chatbot?

A RAG chatbot answers questions by searching your own documents first, then using a language model to write an answer from the passages it found. RAG stands for retrieval-augmented generation. The retrieval step keeps answers grounded in your content instead of relying on the model's memory.

How much does it cost to build a RAG chatbot?

Cost depends on document volume, hosting and how much human review you keep. A small pilot using a hosted model and a managed vector database is the cheapest way to start. Get a written estimate from your vendor, since rates vary widely by scope and region.

Do I need to fine-tune a model for a RAG chatbot?

Usually not. Retrieval over your own documents handles most support and internal questions without fine-tuning. Fine-tuning helps when you need a consistent tone or format, and it is easier to justify once you have an evaluation set.

Which framework should I use for a RAG chatbot?

LangChain and LlamaIndex are the most common choices, with Haystack and RAGFlow as alternatives. The framework matters less than document quality and retrieval testing, so pick the one your team already knows.

How do I stop a RAG chatbot from making things up?

Tell the model to answer only from the retrieved passages and to say when it does not know. Show sources with every answer, test retrieval separately from generation, and keep human review for billing, safety and legal topics. A good evaluation set catches new failures early.

Can a RAG chatbot replace our support team?

No. It handles routine questions and drafts answers for the rest, but difficult cases still need a person. The value is in cutting the queue for common questions so the team has time for the cases that need judgement and care.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: AI and agent systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Planning a RAG chatbot for your support or internal docs? Talk to Hertiv.

A senior engineer replies within one business day. Or see our RAG Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call