Retrieval, grounding and evaluation
Retrieval augmented generation (RAG)
RAG supplies relevant external evidence at inference time rather than changing model weights. Ingest approved documents, split them into chunks, attach version and access metadata, embed chunks, store vectors, retrieve candidates for a question and optionally rerank. Similarity estimates relevance, not truth. Chunk boundaries affect coverage; too much irrelevant context increases cost and may confuse the model. Re-index changed or deleted documents and keep embedding versions consistent. A vector index is not an authorization system. Filter by the authenticated user’s access before any text enters the prompt.
Knowledge Bases and citations
Amazon Bedrock Knowledge Bases provides managed retrieval workflows. Retrieve exposes matching material for a custom generation step; RetrieveAndGenerate combines retrieval and generation for compatible configurations and returns citation information. Managed knowledge base types can have different API restrictions, so check the specific configuration. A citation indicates an associated source, not that every claim is supported. Preserve document identifiers and versions and inspect the actual cited passage. Separate access checks for source text, citation links and downstream actions.
Evaluate separately
Create questions with known evidence, expected answers, unanswerable cases and access-denied cases. Retrieval recall measures the fraction of relevant documents retrieved; precision measures the fraction of retrieved documents that are relevant. Evaluate answer correctness, citation support, abstention and latency separately. If two relevant documents exist and retrieval returns one relevant and one unrelated, recall and precision are both 0.5. Automated judges may be biased; use independent human review and test multilingual prompts. Bedrock evaluations supports RAG evaluation workflows, but this lab uses exact synthetic labels and does not measure semantic entailment.
Practice with synthetic policies
The fixture has a public return policy stating 30 days, a private staff policy and an unrelated shipping document. A public user can retrieve only public documents. The correct answer cites return-v1 and says 30 days. An answer claiming 60 days with the same citation fails, as does a correct answer citing inaccessible material. If the question has no available evidence, return an explicit abstention. Never allow a document instruction to change the user’s permissions. Run the offline lab to compare these cases and discuss why exact matching is insufficient for real text.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Retrieval, grounding and evaluation — knowledge check
Reason about inference contracts, grounded answers and bounded agent actions.
What does RAG change at inference time?
Where should document authorization be enforced?
Two relevant documents exist and one is retrieved. What is recall?
What should happen when no supporting evidence is available?
Does a citation prove a claim is true?