Structure: a clear instruction (answer only from the context, say when the answer is not there, cite sources), the retrieved chunks each wrapped with an ID and source metadata, then the user question.
Budget tokens: count tokens, reserve space for the answer and chat history, rank chunks by relevance, and truncate or drop the weakest rather than cutting a chunk mid-sentence.
Order chunks deliberately (best first, or best at the start and end), deduplicate overlapping chunks, and merge adjacent chunks from the same document.
Treat retrieved text as untrusted data and delimit it, to reduce prompt injection risk.
Loading…