loading…
"Context: \{documents\}\\\\n Instructions: Use only the context above. If unsure, say 'I don't know.'\\\\n Question: \{query\}\\\\n Answer:" - Impact: Reduces hallucinations by 55% (Salesforce, 2023). ---"Context: \{documents\}\\\\n Question: \{query\}\\\\n Answer Step-by-Step:" - Use Case: Legal or medical QA where auditability is critical. ---SentenceWindowNodeParser to extract key text chunks. ---"Answer using ONLY the following knowledge base articles: \{KB_1234, KB_5678\}. Cite sources." 2. Step-by-Step Format: "1. Identify the error code. 2. Match it to KB articles. 3. List steps." - Result: 40% fewer escalations and 25% faster resolution.ContextualCompressionRetriever. - Result: Reduced monthly costs from $80K → $35K. ---python from langchain.prompts import ChatPromptTemplate template = """ Context: \{context\} Instructions: Use ONLY the context. Cite sources like [Doc 1]. Question: \{question\} Answer: """ prompt = ChatPromptTemplate.from_template(template) chain = prompt | ChatOpenAI(model="gpt-4") response = chain.invoke(\{ "context": "Doc 1: Refunds require 48h notice...", "question": "Can I get a refund after 72h?" \}) Output: “According to [Doc 1], refunds require 48h notice. No refunds after 72h.” ---