Learnixo

Advanced RAG · Lesson 8 of 14

Step-Back Prompting for Abstract Queries

What Step-Back Prompting Solves

Specific questions often require background knowledge to answer correctly:

Specific question: "Why would a patient's INR suddenly rise to 4.5 after
                   adding clarithromycin to Warfarin therapy?"

To answer this correctly, you need to understand:
  - General: CYP450 enzyme inhibition mechanism
  - General: Warfarin metabolism via CYP2C9
  - General: Clarithromycin as a CYP3A4/CYP2C9 inhibitor
  - Specific: drug interaction consequence

If the knowledge base has general pharmacology documents,
they might not be retrieved by the specific question.
Step-back retrieves the general concepts first, then the specific case.

The Algorithm

Step 1: Generate a "step-back" question
  From the specific question, generate a more general/abstract version
  that retrieves foundational knowledge

Step 2: Retrieve for BOTH questions
  Retrieve for the original specific question
  Retrieve for the step-back (general) question

Step 3: Merge and answer
  Inject both sets of retrieved documents
  The general context provides the mechanism
  The specific results provide the clinical guidance

Implementation

Python
from anthropic import Anthropic

client = Anthropic()

def generate_step_back_question(specific_question: str) -> str:
    """Generate a more abstract/general version of the specific question."""
    response = client.messages.create(
        model="claude-haiku-4-5-20251001",
        max_tokens=200,
        messages=[{"role": "user", "content":
            f"""Generate a more general or abstract version of this specific question.
The general version should ask about the broader principle or mechanism,
not the specific case. Return only the general question.

Specific question: {specific_question}
General question:"""}]
    )
    return response.content[0].text.strip()

def step_back_retrieve(
    query: str,
    retriever,
    top_k: int = 5
) -> tuple[list[dict], list[dict]]:
    """Retrieve for both specific and step-back queries."""
    step_back_query = generate_step_back_question(query)

    specific_results = retriever(query, top_k=top_k)
    general_results = retriever(step_back_query, top_k=top_k)

    return specific_results, general_results

def step_back_answer(
    query: str,
    specific_docs: list[dict],
    general_docs: list[dict],
    llm_client
) -> str:
    """Generate an answer using both specific and general context."""
    general_context = "\n\n".join(d["content"] for d in general_docs[:3])
    specific_context = "\n\n".join(d["content"] for d in specific_docs[:3])

    prompt = f"""Answer the following question using the provided context.

GENERAL BACKGROUND CONTEXT (pharmacology/mechanisms):
{general_context}

SPECIFIC CONTEXT (clinical guidance):
{specific_context}

Question: {query}

Answer:"""

    response = llm_client.messages.create(
        model="claude-sonnet-4-6",
        max_tokens=512,
        messages=[{"role": "user", "content": prompt}]
    )
    return response.content[0].text

Clinical Step-Back Examples

Specific: "Why did adding clarithromycin cause the patient's INR to rise to 4.5?"
Step-back: "How do CYP450 enzyme inhibitors affect Warfarin metabolism?"

Specific: "Should we hold Warfarin before a colonoscopy in a patient with AF?"
Step-back: "What are the general principles of peri-procedural anticoagulation management?"

Specific: "The patient's eGFR dropped to 30. How should we adjust Apixaban dosing?"
Step-back: "How does renal impairment affect direct oral anticoagulant dosing?"

Specific: "Patient had an embolic stroke despite INR of 2.5. What are the options?"
Step-back: "What are the mechanisms of anticoagulation failure in atrial fibrillation?"

When Step-Back Helps Most

Best cases:
  Mechanistic questions ("why did X happen?")
  Clinical reasoning questions requiring background knowledge
  Complex drug interactions requiring pharmacology context
  Cases where the specific answer requires understanding the general rule

Less useful:
  Simple factual lookup ("What is the standard dose of Warfarin?")
  Questions where the specific document contains all needed context
  High-volume real-time systems (doubles retrieval latency)

Empirical results (Zheng et al., 2023):
  Step-back improves performance on MMLU by ~5%
  Larger gains on reasoning-heavy tasks
  Smaller gains on factual retrieval

Integration with Multi-Query

Step-back and multi-query are complementary — can be combined:

Queries generated:
  1. Original specific question
  2. Step-back (general) question
  3. 2-3 paraphrases of the specific question (multi-query)

Retrieve for all 4-5 queries
Merge with RRF
Pass merged context to the LLM

Total: 4-5 queries instead of 1 — 4-5× retrieval cost
Use when the task is complex enough to justify the cost.

Interview Answer

"Step-back prompting improves RAG by generating a more general/abstract version of the user's specific question, retrieving background knowledge for that general question, and combining it with specific retrieval results. For a question like 'Why did clarithromycin raise the patient's INR?', the step-back question might be 'How do CYP450 inhibitors affect Warfarin metabolism?' — retrieving the pharmacological mechanism that explains the specific event. The LLM answers with both the general mechanism and the specific clinical guidance in context. Most valuable for mechanistic and clinical reasoning questions; less useful for simple factual lookups."