Ship a chatbot over your own docs and prove it works
For engineers
Build a support bot over a help center: parse and chunk the pages, add hybrid search, force cited answers, test it with an eval set and show honest trust signals.
A docs chatbot is trustworthy only when you can show, with numbers, that it finds the right passage, answers from it, and says so when it cannot.
The case
Ledgerly is a small invoicing product. Its help center has 400 HTML pages and a few two-column PDF guides. Support gets the same questions all day: refund windows, plan limits, error codes. The team wants a bot on the help page that answers from the docs. This is retrieval-augmented generation (RAG): search your own documents, hand the best passages to a model such as Claude, ChatGPT or Gemini, and have it answer from them.
The first demo looks good. Three weeks later a customer is told annual plans are refundable pro rata, which is false. This lesson follows the five places where that failure could have been stopped.
Step 1: parse and chunk so passages keep their meaning
The model never sees your pages. It sees chunks, the slices you cut them into. If the cut is bad, nothing downstream can repair it.
- Parse first. A two-column PDF read in the wrong order gives scrambled sentences. Use a layout-aware parser and read a few parsed pages by eye.
- Remove boilerplate, such as menus and cookie notices, at parse time. Keep headings.
- Split along structure: by heading, with tables kept whole or with the header row repeated.
- Store metadata on every chunk: URL, section path, version, effective date.
Before: a table split so that "30 days | Yes" sits alone with no header. After: the whole refund table in one chunk under "Billing > Refunds".
Step 2: retrieve with hybrid search
Vector search finds passages with similar meaning. It is weak on exact strings such as ERR_PLAN_409 or a SKU. Keyword search (BM25) is the reverse. Run both and fuse the two ranked lists, for example with reciprocal rank fusion, which scores each document 1/(k + rank) per list. Do not add raw BM25 and cosine scores: they live on different scales.
Then consider a reranker that rescores the top 20 to 50 candidates. It costs latency, so set a budget and measure.
Step 3: force grounded, cited answers
Give each passage an id. Tell the model to answer only from the sources and to end every claim with the id that supports it. Add a not-found path: when the best score is below a threshold you chose from real data, say the docs do not cover it and show the nearest pages. Never let the prompt say "use your general knowledge if the sources fall short".
Also handle conflicts. If two policy versions are retrieved, prefer the one in force and say so.
Step 4: prove it with an eval set
A demo is not evidence. Build a golden set of real questions from tickets and search logs, with an expert answer and source for each. Match its mix to real traffic. Add edge cases: out-of-scope questions, conflicting sources, typos, injection attempts. Synthetic cases are useful if you generate them from stated dimensions and filter duplicates.
Run the set after every change, and change one thing at a time. If you ship a reranker and contextual retrieval together, you cannot say which one helped. Keep eval cases out of prompts, or the score will lie.
Step 5: show trust signals that are true
Each answer shows citations a reader can open at the exact passage. Do not show a confidence percentage that nobody measured. Do not write "Verified" unless a check against sources really ran. For irreversible actions, such as deleting an account, show the cited steps and send the user to a screen with real confirmation.
What goes wrong
- The answer is cited, but the source says something else. Check claims, not only the presence of a citation.
- The bot scores 96% on a set of easy questions and fails on the first out-of-scope one.
- A fix lifts the score because the test answer leaked into the prompt.
Work through the practice set with the Ledgerly artefacts in mind: each question asks what you would change, or what you would not trust.
Steps
Parse the pages and chunk by structure
Use a layout-aware parser for the PDFs and strip menu and cookie text from the HTML. Split by heading, keep tables whole and attach URL, section path, version and date to every chunk. Open ten parsed pages and read them before indexing.
Ingestion settings ingest/config.json
{ "parser": "layout-aware", "strip": ["nav", "footer", "cookie-banner"], "split": "by-heading", "keep_tables_whole": true, "metadata": ["url", "section_path", "version", "effective_date"]}Retrieve with keyword plus vector, then rerank
Run BM25 and vector search in parallel and fuse the lists with reciprocal rank fusion. Rerank only the top 20 candidates if the latency budget is tight. Compare baseline, hybrid and reranked runs on the same question set before keeping each upgrade.
Write the grounded, cited answer prompt
Tag every passage with an id, require a source id after each claim and add a not-found reply for weak retrieval. Prefer the newest effective policy when versions conflict, and say that a conflict exists.
Build the eval set and run it on every change
Sample real tickets and search logs, write expert answers with sources, and match the category mix to traffic. Add out-of-scope, conflicting-source and injection cases. Change one thing per run and keep eval cases out of prompts.
Show citations and confidence the user can trust
Link each citation to the exact passage with section and date. Show only signals that were measured or checked. Add real confirmation for irreversible actions and say plainly when the docs do not cover a question.
Skills this scenario uses
Where to study
- Introducing Contextual Retrieval (Anthropic) (opens in a new tab)ArticleFree
Shows how chunk context, hybrid search and reranking are compared on one benchmark.
- Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (opens in a new tab)PaperFree
The original RAG paper: the idea of retrieving documents to ground generation.
- Chunking strategies for LLM applications (Pinecone) (opens in a new tab)ArticleFree
Compares fixed, recursive and structure-aware splitting with their trade-offs.
- Reciprocal rank fusion (Elasticsearch docs) (opens in a new tab)DocsFree
Defines the fusion formula used to merge keyword and vector result lists.
- Citations (Claude API docs) (opens in a new tab)DocsFree
How a provider feature returns claim-level citations to source passages.
- Your AI product needs evals (Hamel Husain) (opens in a new tab)ArticleFree
A practical case for building evals from real data and error analysis.
- People + AI Guidebook (Google PAIR) (opens in a new tab)ArticleFree
Design patterns for explaining AI output and calibrating user trust.