Loading notes...
Loading notes...
RAG • Chapter 7
RAG engineering module on Prompt Engineering for RAG.
The effectiveness of a RAG system heavily depends on how the prompt is structured. The LLM must be explicitly instructed on how to handle the provided context.
Advanced System Mechanics
A robust RAG prompt typically includes: the Persona, the strict instruction to ONLY use the provided context, the Context itself, and a fallback instruction (e.g., 'If the answer is not in the context, say I do not know'). Advanced techniques like 'Chain of Thought' prompting can also be combined with RAG to force the model to explain its reasoning based on the retrieved chunks.
Implementation Blueprint
RAG_PROMPT_TEMPLATE = """
You are an expert technical support agent.
Context information is below.
---------------------
{context}
---------------------
Given the context information and not prior knowledge, answer the query.
If you don't know the answer based on the context, just say "I don't have enough information."
Query: {query}
Answer:
"""