RAG (retrieval-augmented generation) promises « answer from your docs ». Without discipline, it invents credible citations. Three lines of defense.
1. Clean documents
We clean, split into coherent chunks (not mid-sentence), and store in pgvector. A rotten chunk = a rotten source.
2. An evaluated retriever
We measure precision@k: on a labelled question set, do the right chunks surface? If not, we fix chunking or embedding before touching the LLM.
3. A constrained prompt
The instruction forbids answering without retrieved context and requires citing the source. Not « per the docs », but « source #2 ».
RAG isn't magic: it's a pipeline you test like code.