LLM Learning Hub

workspace/llm-course/home

Context Construction

Context construction is the step of assembling the retrieved chunks, a system prompt, and the user query into a single prompt string that is sent to the LLM for grounded generation.

What is Context Construction?

Context construction is the step of assembling the retrieved chunks, a system prompt, and the user query into a single prompt string that is sent to the LLM for grounded generation.

Context construction is the step of assembling the retrieved chunks, a system prompt, and the user query into a single prompt string that is sent to the LLM for grounded generation.

Where is it used?

LangChain prompt templates and LlamaIndex `PromptHelper` construct context; production RAG systems also inject metadata, citations, and token-budget truncation logic here.

How to build it

Build a template string `f"Context: {context}\n\nQuestion: {query}\nAnswer:"` where `context = "\n".join(doc.page_content for doc in retrieved)`, and pass it to the LLM.