Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Blog/Retrieval

Why your RAG chatbot gives bad answers (it's not the search)

When an AI answers badly from your own documents, people blame the search. Every time I've debugged it, the search was fine. The documents were the problem.

Derpx0627 Aug · 4 min read
Contents
The time we blamed the wrong thingJust read what it foundCutting is a decision, not a settingTwo fixes that beat any search upgradeCheck the two halves separatelySometimes it really is the searchThe order I'd work in
0% read · 4 min leftBack to top ↑
On this page0%
Contents
The time we blamed the wrong thingJust read what it foundCutting is a decision, not a settingTwo fixes that beat any search upgradeCheck the two halves separatelySometimes it really is the searchThe order I'd work in

Imagine asking a very smart person a question about a subject they have never studied. You hand them a few pages to read first. If the pages are wrong, being smart won't help. If the pages are right but torn in half, it's even worse.

That's RAG, short for retrieval-augmented generation. The name is fancy, but the idea is simple. You search your documents for the parts that matter, paste them in front of the question, and the AI answers using only those parts.

When the answers are bad, everybody blames the searching. I think the searching is usually innocent.

The time we blamed the wrong thing

Every system I've worked on hit the same problem. Answers were poor, so we swapped the search model. We added a re-ranker (a second step that re-sorts the results). We added keyword search, rewrote the question three ways, and fetched more results. Each change sounded smart. Each one made things slower. The answers stayed bad.

The search was finding the right pages the whole time. The pages just weren't worth finding.

Just read what it found

First, print exactly what got handed to the AI and read it like you have to answer the question yourself. On AssistFlow AI, a support tool that reads a customer's website and answers from it, the answers were vague. So I printed the pages for one failing question. The top result was a navigation menu. The second was a cookie banner. The third was the correct paragraph, chopped in half right at the sentence with the answer.

The ten-minute diagnosis

Save the exact text given to the AI next to every answer. Read twenty bad ones. You'll see whether the problem is the search or the documents, and it's almost always the documents.

Cutting is a decision, not a setting

Documents are too big to hand over whole, so you cut them into small pieces called chunks. Most people start with "cut every thousand characters, with a little overlap." That quietly assumes meaning comes in thousand-character lumps, and for most real documents it doesn't.

Cut at 1,000 charactersHeader row in one chunk, numbers in another
→
Cut by meaningWhole table in one chunk

Think of a recipe cut in the middle of step four. You're left with half a procedure. Or a "Refund policy" page that says this does not apply to annual plans. Cut it badly and one chunk now says the opposite of the truth. So for each kind of document, decide the smallest piece that still makes full sense: one FAQ answer, one API endpoint, one policy section with its heading attached. Sometimes the right setting is don't cut this at all.

Two fixes that beat any search upgrade

Both happen when you store the documents.

Put the lost context back. Paste the document title and the heading trail on top of each chunk, so it reads Refund policy → Annual plans → the text. It's like writing the subject name at the top of every page. In my experience this one change has saved more systems than every re-ranker I've ever added.

Store labels, then filter on them. The AI can't tell that a page is out of date, so it'll happily hand over a pricing page from two years ago. Product, version, date, language and customer are cheap labels. With them, many "the AI made something up" complaints become a simple filter.

1Cut by meaning
2Add title and headings
3Add labels
4Store
Do the careful work when you store.

Check the two halves separately

Without test questions, every change only feels like it helps. Write thirty questions where you already know which document has the answer. Then check two things. Did the right chunk show up? And given those chunks, was the answer right?

One mixed score can't tell you what to fix tomorrow

Measure the two steps separately, even if you only report one total.

Sometimes it really is the search

Two honest signs. Exact codes failing: to a meaning-based search, ERR_4021 and ERR_4012 look almost the same, so run old-style keyword search alongside it. Questions that are secretly two questions, like how do I move off the free plan, and what happens to my old exports? Split those into two searches.

Reach for these when your tests point at them, not by default.

The order I'd work in

  1. Read twenty failing examples word for word.
  2. Write thirty test questions with known sources.
  3. Fix chunking so no chunk is half a thought.
  4. Paste the title and headings onto every chunk.
  5. Add filters for date, version and customer.
  6. Only now check whether a re-ranker is worth the extra waiting time.
Key takeaways
  • Before changing anything, read the exact text the AI was given.
  • Chunks should be whole thoughts. Never cut a table, a guide or a policy in half.
  • Add titles and headings to each chunk, and store labels you can filter on.
  • Keep about thirty test questions, and check "right chunk found" separately from "answer right."
ShareXLinkedInEmail
Written by Derpx06A developer who builds AI search tools and the code around them. I explain what I got wrong first, so you can skip it. Spotted a mistake? Tell me — corrections get credited.
Foundations · 3 minWhy is 0.1 + 0.2 not 0.3 in code?Foundations · 4 minHow does Git work inside? (Snapshots, not changes)Distributed Systems · 6 minHow does your computer know the time? (And why it can be wrong)
Start here
01Why is 0.1 + 0.2 not 0.3 in code?02How does Git work inside? (Snapshots, not changes)03How does your computer know the time? (And why it can be wrong)