AI & Generative AI

RAG Chatbot Giving Wrong or Made-Up Answers? How to Fix Retrieval

Why retrieval-augmented generation (RAG) apps answer wrongly even when the information is in your documents, and a step-by-step way to fix them.

Quick answer: Most RAG failures are retrieval failures, not model failures: the right chunk never reaches the prompt. First log which chunks were retrieved for a failing question. Then fix chunking (sensible size, overlap, keep headings), use the same good embedding model for documents and queries, add hybrid keyword and vector search with a re-ranker, filter by metadata, and instruct the model to answer only from the context and say when it doesn't know.

You built a chatbot over your company documents with an LLM, a vector database and a framework such as LangChain or LlamaIndex. It demos well, but users report answers that are wrong, vague, or confidently made up, even when the answer is clearly in a PDF.

The instinct is to switch to a bigger model. In most cases that's the wrong fix.

What is actually going wrong

A RAG app has two halves: retrieval (find the right chunks) and generation (the LLM writes an answer from them). If retrieval returns the wrong chunks, even the best model can only guess. So always debug retrieval first.

Step 1: See what was retrieved

For a question that fails, print the chunks that reached the prompt, with their sources:

docs = retriever.invoke(question)
for i, d in enumerate(docs, 1):
    print(i, d.metadata.get("source"), d.metadata.get("page"))
    print(d.page_content[:300], "\n---")
  • Right chunk present, answer still wrong → a generation problem (prompt, context order, too much noise).
  • Right chunk missing → a retrieval problem (most cases). Use the fixes below.

Collect 20-50 real user questions with the expected source page. This small test set lets you measure each change instead of guessing.

8 fixes, in order of impact

1. Fix your chunking

Chunks that are too large dilute the meaning; chunks that are too small lose context. Split on document structure (headings, sections, table boundaries), add some overlap, and keep the section heading in each chunk's text or metadata.

2. Use the same, good embedding model for documents and queries

Documents and questions must be embedded with the same model. If you changed the model, re-embed the whole collection. Domain-heavy content (legal, medical, code) benefits from stronger embedding models.

3. Add hybrid search (keywords + vectors)

Vector search is weak on exact terms: error codes, product names, IDs. Combining BM25 keyword search with vector search fixes many "it's right there in the document" failures.

4. Re-rank the results

Retrieve more candidates (say 20-30), then use a re-ranker (a cross-encoder model) to keep the best 4-6. This often improves answer quality more than any other single change.

5. Filter with metadata

Store metadata such as product, version, department and date. Filter before searching so a question about version 3 doesn't get answers from version 1.

6. Rewrite vague or conversational questions

Follow-up questions like "and for Azure?" don't retrieve well on their own. Have the LLM rewrite the question into a standalone query using the chat history before retrieval.

7. Ground the prompt and ask for citations

Tell the model to answer only from the context, cite the source for each claim, and reply "I don't know" when the context doesn't contain the answer:

Answer the question using ONLY the context below.
If the answer is not in the context, say "I couldn't find this in the documents."
Cite the source file and page for each fact.

Context:
{context}

Question: {question}

8. Keep the index fresh

Wrong answers are sometimes correct answers from old documents. Re-index on a schedule or on document change, and remove deleted files from the vector store.

How to prevent it

  • Keep an evaluation set and re-run it after every change to chunking, models or prompts.
  • Log questions, retrieved sources and user feedback in production.
  • Monitor the RAG pipeline like any other service, as covered in MLOps & LLMOps.
  • Start simple: good chunking, hybrid search and re-ranking beat a complicated agent on a bad index.

RAG, vector databases (FAISS, ChromaDB, Pinecone, Qdrant), LangChain, LangGraph and MCP are built hands-on in our Generative AI & AI Agents training.

Frequently asked questions

Why does my RAG chatbot hallucinate?

Usually because the relevant text was not retrieved, so the model fills the gap from its own knowledge. Improving retrieval and telling the model to answer only from the provided context reduces hallucination most.

What chunk size should I use for RAG?

There is no single best size; a few hundred tokens with some overlap is a common starting point. Split on document structure (headings, sections) and test different sizes against a set of real questions.

What is hybrid search in RAG?

It combines keyword search (such as BM25) with vector similarity search. Keywords catch exact terms like product codes and error messages; vectors catch meaning. Results are merged and often re-ranked.

How do I measure if my RAG system is improving?

Build a small test set of real questions with expected answers and sources, then track how often the right source is retrieved and whether answers are faithful to the retrieved context.

Learn Generative AI & AI Agents hands-on with expert trainers

Fixing problems like this one is part of our Generative AI & AI Agents training: live online classes for individuals and on-site corporate training for teams, with real projects and labs.

Training available in Hyderabad, Bangalore, Pune, Mumbai, Delhi, Chennai and online across India.