A context window is not a warehouse. RAG is not a truth machine.
Select evidence that is relevant, current, and allowed. Stacking documents only gives the problem more room.
The first problem may not be the prompt.
Someone asks about the return period. The collection contains a current public policy for seven days, an old policy for fourteen days, and a thirty-day internal memo for a particular group. All of them use the word “refund.” A similarity-only search can retrieve the wrong version or audience. The model may then answer confidently because the wrong material looks like evidence.
RAG combines retrieval and generation. The paper by Lewis and colleagues introduced a formulation that connects a model to external memory. That is an architectural foundation, not a guarantee that every implementation is correct. Sources, retrieval, and the use of evidence still need testing.
Allowed to view is different from relevant to answer.
Enforce access rights before a document enters context. Do not ask the model to keep it secret. Tenant, group, and version filters should follow the product's authorization system. Search can then find relevant evidence within the permitted space. High similarity does not turn an internal document public.
In the visual, current version and public access are separate filters. Turning one on does not solve the other. Even after both are right, relevance to the question still needs checking. Metadata filtering is not a replacement for search, and search is not a replacement for authorization.
Let chunks follow meaning.
Cutting text every fixed number of characters can separate an exception from its rule. A chunk saying “valid for seven days” may be retrieved while the exception for a particular product is left behind. Keep the title, section, version, effective date, and origin with the chunk. Test chunk size and overlap with real questions instead of assuming one number works for every document.
Lexical and semantic search can complement each other when exact IDs, precise terms, and paraphrases all matter. Reranking can reorder candidates, but it adds cost and latency. Compare methods on the same cases. A longer technique name is not evidence of better results.
Assemble context. Do not pour in the warehouse.
Anthropic emphasizes selecting useful context within limits on tokens and model attention. For a store assistant, assemble the task, action boundaries, selected evidence, and relevant history. Outdated documents or unrelated conversation can obscure the goal. Retrieved material is data, not authority to replace system instructions.
Link answer claims to supporting sources. When evidence conflicts or cannot be found, the product can ask for clarification or hold its answer. Saying “according to the document” without showing which passage supports the claim just puts a lab coat on a guess.
Measure retrieval separately from the answer.
Prepare questions with the evidence they should retrieve. Check whether the evidence entered the candidate set, whether important chunks stayed intact, and whether the answer used them correctly. If the right document was available but the answer was wrong, making the index bigger may not help. If the evidence was never retrieved, tuning the writing style will not fix it.
Track index updates and source versions. Give document deletion a clear path. Production RAG needs a knowledge lifecycle, not just an upload-PDF button. Test unanswered questions, duplicate documents, and malicious instructions planted in a source. Evaluate abstaining as seriously as answering.
Example to inspect
Conceptual flow
1. Identify the user and permitted access scope
2. Search only allowed candidates
3. Check relevance, version, and conflicts
4. Assemble context with provenance
5. Answer or abstain; evaluate both
Exercise: An internal document is the closest match to a public question. Is it enough to tell the model to keep sensitive material secret?
Answer: No. Restrict the document before it becomes context. A model instruction does not replace access control.
Three things to keep: Store version, owner, and access rights. Evaluate retrieval and answers separately. Test conflicts, missing evidence, and prompt injection.
Sources: Lewis et al., “Retrieval-Augmented Generation”; Anthropic, “Effective context engineering for AI agents.” Primary references reviewed 7 November 2026. Explanations, examples, and visuals by RapiApp. The diagram simplifies the issue for learning; assumptions are stated in the article.