Notes

Context Synthesis

Retrieval hands you a pile of passages. Context synthesis is the unglamorous step that decides which of them the model actually reads, in what order, and under what instructions.

What the step does

Once the retriever returns its candidates, synthesis assembles the final prompt: near-duplicate passages are dropped, each survivor is labelled with its source so the answer can be attributed, the set is ordered, and the whole block is trimmed to the token budget left after the question and the instructions. Long passages are compressed — summarised, or filtered sentence by sentence — rather than cut off mid-thought. The assembled block is then wrapped in an instruction telling the model to answer from these passages and to say so when they do not contain the answer.

Why order and budget matter
  • Models read the beginning and end of a long context more reliably than the middle, so burying the best passage in position seven wastes the retrieval that found it.
  • Twenty retrieved chunks of 400 tokens will not fit beside a long chat history. Something gets dropped — by you, deliberately, or by the API, arbitrarily.
  • Without per-passage source labels, citation becomes guesswork and a hallucination is impossible to trace back.

In LlamaIndex this step is the response synthesizer, with modes that either stuff everything into one call or refine an answer across several; LangChain frames the same choice as stuff against map-reduce. Many complaints that RAG does not work trace to here rather than to the retriever: the right passage was found, and then crowded out.

Context synthesis is the step in a retrieval pipeline that turns retrieved passages into the prompt the model actually sees: deduplicating them, labelling each with its source, ordering them, and trimming or compressing the set to fit the remaining context window. It decides what the generator can use and what it must cite. Done carelessly, correctly retrieved evidence gets crowded out, or buried where the model reads least reliably.

Think of a student allowed to bring one page of notes into an exam. The library has everything, but only one page fits — so somebody has to choose which facts make the cut, put the most useful ones where they will be seen, and write down where each came from. Context synthesis is that choosing. An AI assistant searching your company documents might find forty relevant paragraphs, and it can only be handed a few. This step packs the page: it throws out repeats, keeps the strongest material, and tags each piece so the answer can point back to the document it came from.