RAG Formation Continue · 02 · Build a RAG baseline

Build your own RAG chatbot from zero.

A copy-paste prompt, build plan, and checklist for creating a working, grounded document-Q&A baseline with Codex or Claude Code.

The teaching goal

Build one working document-Q&A path, then extend it into four complementary retrieval channels. Every answer must stay grounded in retrieved context, name its source documents, or explicitly refuse.

1 · Give an AI coding assistant this build prompt

Use this as a complete build brief for Claude Code, Codex, or your own implementation. Finish each step against a real question before moving to the next one.

You are building a document-Q&A chatbot for a fixed internal corpus. Build it end to end, one working step at a time; do not move on before the current step answers a real question.

Corpus & ingestion
- Accept a folder of source documents, starting with plain text or PDFs converted to text.
- Parse and chunk each document into overlapping passages sized for retrieval, not display.
- Generate and store a short summary of each whole document.

Four retrieval channels — build all four:
1. Chunk-vector: embed each passage and support top-k similarity search.
2. Summary-vector: embed document summaries and support top-k similarity search.
3. Full-text/keyword: exact and near-exact term search over raw text.
4. Graph: extract entities and relations across documents, with multi-hop traversal.

Merge and assemble
- Query all four channels in parallel for every question.
- Deduplicate overlapping results before applying a context-size budget.
- A channel that cannot be queried is a status, not an exception that takes the request down.

Generate and cite
- Answer strictly from the assembled context, never from outside knowledge.
- Name the document(s) used by every answer.
- Refuse explicitly when the retrieved context does not support an answer.

Out of scope for this baseline
- Per-answer feedback capture and comments.
- Multi-turn or follow-up handling: treat every question as independent.

Definition of done: ask ten real questions spanning paraphrase, broad document discovery, exact-code lookup, and multi-hop relationships. Each receives a grounded, cited answer—or an honest refusal.

2 · Build one end-to-end path before expanding

Start with chunks, a vector index, and cited generation. Once that path answers a real question, add the other channels one at a time. This keeps every failure inspectable.

  1. Corpus and parsing. Give every source stable, referenceable IDs before writing retrieval code.
  2. Chunks, chunk-vector, and generation. Ship this one channel all the way to a cited answer.
  3. Summaries and summary-vector index. Generate each document summary once, store it, then embed it.
  4. Full-text index. Use an established search engine rather than hand-rolling matching and ranking.
  5. Graph index. Add entities and relations last; it is the most expensive channel to maintain.
  6. Merge, dedupe, context budget. Make this independently testable without calling an LLM.
  7. Grounded generation and citations. Require named sources and an explicit refusal when evidence is missing.
  8. Ten-question smoke test. Run one question per channel specialty before calling the baseline complete.

3 · Baseline checklist

  • Documents can be added and re-indexed without a full restart.
  • Each of the four channels can be queried and inspected on its own.
  • The merge step measurably removes overlapping hits before applying the context budget.
  • Every generated answer names the document(s) it used.
  • The chatbot refuses instead of guessing when retrieval has no relevant evidence.
  • The ten-question smoke test records which channel contributed to every answer.
  • Feedback capture and follow-up handling remain deliberately out of scope for this baseline.

Next lesson

Once this baseline works, add interaction logs, user feedback, and follow-up handling. That turns isolated answers into an evidence-backed production improvement loop.

Open the production improvement loop