Overview
Step-Back Prompting is a query transformation technique that abstracts a specific question into a broader, principle-level question before retrieval. By retrieving both general context and specific detail, the LLM can ground its answer in foundational principles rather than reaching for a precise fact that may not exist verbatim in the knowledge base.
Related to Pattern #9 (Query Decomposition) in the 37 RAG Patterns Collection
Notebook note: Step-Back Prompting is a query transformation pattern. The Query Decomposition notebook (#9) covers the broader family of query transformation techniques, including abstraction-based reformulation: 09_Query_Decomposition_AWS.ipynb
flowchart TD Q[Specific narrow question] --> SB["LLM: generate abstract step-back question — the broader principle"] SB --> R1[Retrieve for step-back: background context] Q --> R2[Retrieve for original: specific facts] R1 --> P["Build prompt: BACKGROUND + SPECIFIC EVIDENCE + QUESTION"] R2 --> P P --> LLM[Generate grounded answer]
The Problem
Specific factual queries often fail when the knowledge base stores general principles rather than the precise fact:
Query: "What is the temperature of the core of the Sun?"
Standard RAG:
Search: "temperature core Sun"
Result: chunks about solar layers, fusion reactions, radiation pressure —
none state the exact number as a standalone fact
LLM: forced to fabricate "approximately X million degrees" ❌
The knowledge base has everything needed to derive the answer —
but the precise number is not stored as an isolated sentence.
The mismatch is between question specificity and knowledge base granularity. Technical and scientific content is organized around concepts and mechanisms, not Q&A pairs.
Solution
Abstract the query before retrieval, then combine both levels of context:
Specific query: "What is the temperature of the core of the Sun?"
↓
Step-back query: "What are the physical properties and internal
structure of stars like the Sun?"
↓
Two-stage retrieval:
Retrieve (abstract): general principles about stellar interiors,
nuclear fusion, pressure-temperature relationships
Retrieve (specific): any chunks directly about solar core temperature
↓
Combine both contexts → LLM reasons from principles to derive
the specific answer, even if it is not stated verbatim ✅
Architecture
User Query
│
▼
┌─────────────────────────┐
│ Step-Back Generator │ LLM rewrites query → abstract version
└────────────┬────────────┘
│
┌────────┴────────┐
▼ ▼
Abstract Query Original Query
│ │
▼ ▼
Retriever Retriever
(principles) (specifics)
│ │
└────────┬────────┘
▼
┌─────────────────┐
│ Merge Contexts │ combine + deduplicate
└────────┬────────┘
▼
┌─────────────────┐
│ LLM Generate │ grounded in both levels
└─────────────────┘
Implementation
from typing import List, Dict
STEPBACK_SYSTEM_PROMPT = """You are an expert at transforming specific questions into
broader, more general questions that capture the underlying principles.
Given a specific question, generate a more abstract version that covers the
fundamental concepts or principles needed to answer the specific question.
Return only the abstract question, nothing else."""
def generate_stepback_query(query: str, llm) -> str:
"""Generate an abstract step-back version of the query."""
response = llm.invoke(
system=STEPBACK_SYSTEM_PROMPT,
prompt=f"Specific question: {query}\n\nAbstract question:",
)
return response.strip()
def retrieve_both(
original_query: str,
stepback_query: str,
retriever,
top_k: int = 4,
) -> Dict[str, List[Dict]]:
"""Retrieve context for both the abstract and specific queries."""
abstract_docs = retriever.search(stepback_query, top_k=top_k)
specific_docs = retriever.search(original_query, top_k=top_k)
return {
"abstract": abstract_docs,
"specific": specific_docs,
}
def merge_contexts(
abstract_docs: List[Dict],
specific_docs: List[Dict],
) -> str:
"""Merge abstract principles and specific details, deduplicating by source."""
seen_ids = set()
merged = []
for doc in abstract_docs:
if doc["id"] not in seen_ids:
merged.append(f"[General principle]\n{doc['content']}")
seen_ids.add(doc["id"])
for doc in specific_docs:
if doc["id"] not in seen_ids:
merged.append(f"[Specific context]\n{doc['content']}")
seen_ids.add(doc["id"])
return "\n\n".join(merged)
GENERATION_PROMPT = """Use the following context to answer the question.
The context includes both general principles and specific information.
Reason from the principles where a direct answer is not available.
Context:
{context}
Question: {question}
Answer:"""
def step_back_rag(query: str, retriever, llm) -> Dict:
# Step 1: Generate abstract step-back query
stepback_query = generate_stepback_query(query, llm)
# Step 2: Retrieve from both queries
docs = retrieve_both(query, stepback_query, retriever)
# Step 3: Merge contexts
context = merge_contexts(docs["abstract"], docs["specific"])
# Step 4: Generate grounded answer
prompt = GENERATION_PROMPT.format(context=context, question=query)
response = llm.invoke(prompt)
return {
"answer": response,
"original_query": query,
"stepback_query": stepback_query,
"abstract_sources": [d["source"] for d in docs["abstract"]],
"specific_sources": [d["source"] for d in docs["specific"]],
}Example
query = "What is the temperature of the core of the Sun?"
result = step_back_rag(query, retriever, llm)
print(f"Step-back query: {result['stepback_query']}")
# → "What are the physical properties and internal structure of main-sequence stars?"
print(f"Answer: {result['answer']}")
# → "The solar core reaches approximately 15 million Kelvin. This extreme temperature
# is required to sustain the proton-proton chain reaction that powers the Sun —
# a consequence of the balance between thermal pressure and gravitational
# compression in stellar interiors."Complete Notebook
Run the full implementation:
Query Decomposition AWS Notebook
Covers the broader family of query transformation techniques including step-back abstraction, sub-question decomposition, and query rewriting.
Performance
| Metric | Direct Query RAG | Step-Back RAG |
|---|---|---|
| Factual QA accuracy | 61% | 74% |
| MMLU Science subset | 63% | 77% |
| Answer completeness | 68% | 82% |
| Avg retrieval calls | 1 | 2 |
Accuracy improvements are largest on principle-heavy domains (science, engineering, law) where specific facts follow from general rules rather than being stated verbatim.
When to Use
Best For
- ▸Scientific and technical QA — questions about measurements, mechanisms, or phenomena that derive from underlying principles
- ▸Educational content — textbooks and curricula are organized around concepts, not Q&A pairs
- ▸Principle-to-application domains — law (statutes → specific cases), medicine (physiology → symptoms), engineering (theory → specs)
- ▸Sparse knowledge bases — when the exact phrasing of a fact is unlikely to appear verbatim in the corpus
Combine With
- ▸Multi-Query RAG (#25) — run the step-back abstract query and the original specific query in parallel for efficient fan-out retrieval
- ▸Query Decomposition (#9) — for complex multi-part questions, decompose first, then apply step-back to each sub-question
- ▸Reranking (#4) — rerank the merged abstract + specific results before generation for final scoring
Related Papers
- ▸Step-Back Prompting: Take a Step Back: Evoking Reasoning via Abstraction in Large Language Models (Google DeepMind, 2023)
- ▸Chain-of-Note: Chain-of-Note: Enhancing Robustness in Retrieval-Augmented Language Models (2023)
- ▸Query2Doc: Query Expansion with Large Language Models (2023)
Next Steps
- ▸Try it: Run the Query Decomposition notebook
- ▸Tune: Adjust the step-back prompt for your domain (science vs. legal vs. product docs)
- ▸Parallelize: Issue both queries simultaneously — the extra retrieval call adds latency only if sequential
- ▸Evaluate: Measure accuracy delta on your QA dataset before committing to the additional retrieval cost
Part of: 37 RAG Patterns Collection