 Hi, this is Lance from LangChain. This is the fourth video in our deep dive on query translation in the Rag from Scratch series. And we're going to be focused on step back prompting. So query translation, as we said in some of the prior videos, kind of sits at the kind of first stage of kind of a RAG pipeline or flow. And the main aim is to take an input question and to translate it or modify it in such a way that it improves retrieval. Now, we talked through a few different ways to approach this problem. So one general approach involves rewriting a question, and we talked about two ways to do that rag fusion, multi query. And again, this is, this is really about taking a question and modifying it to capture a few different perspectives, which may improve the retrieval process. Now, another approach is to take a question and kind of make it less abstract, like break it down into sub questions, and then solve each of those independently. So that's what we saw with least to most prompting and a bunch of other variants kind of in that vein of sub-problem solving and then consolidating those solutions into a final answer. Now, a different approach presented by, again, Google as well, is step- back prompting so step back prompting can't take see the opposite approach where it tries to ask a more abstract question so the paper talks a lot about using few-shot prompting to produce what they call these step back or more abstract questions. And the way it does it is it provides a number of examples of step back questions, given your original question. So like, this is like, this is, for example, they're like, for prompt template, you're an expert in world knowledge, I ask you a question, your response should be comprehensive, not contradict with the following. You're an expert in world knowledge, I ask you a question, your response should be comprehensive, not contradict with the following. And this is kind of where you provide your like original and then step back. So here's like some example questions. So like, like, at year saw the creation of the region where the country is located. Which region of the country is the county of Hertford related? Janssen-Dill is born in what country? What is Janssen-Dill's personal history? So that's going to be a more intuitive example. So it's like you ask a very specific question about the country someone's born. The more abstract question is like, just give me the general history of this individual without worrying about that particular more specific question. So let's actually just walk through how this can be done in practice. So again, here's kind of like a diagram of the various approaches from less abstraction to more abstraction. Now, here is where we're formulating our prompt using a few of the few shot examples from the paper. So again, like input, yeah, something about like the police performing lawful arrests and what camp members of the police do. So like it basically gives the model a few examples. We basically formulate this into a prompt. That's really all that's going on here. Again, we repeat this overall prompt, which we saw from the paper. Your next spread of world knowledge, your test is to step back and paraphrase a question, generate a more generic step back question, which is easier to answer. Here's some examples. So it's like a very intuitive prompt. So, okay, let's start with the question, what is task composition for LLN agents? And we're going to say generate step back question. Okay, so this is pretty intuitive, right? What is the process of task composition? So like, not worrying as much about agents, but what is a process of task composition in general? And then hopefully that can be independently retrieved. We can independently retrieve documents related to the step back question. And in addition, retrieve documents related to the actual question and combine those to produce kind of final answer. So that's really all that's going on. And here's the response template where we're plumbing in the step-back context and our question context. And so what we're gonna do here is we're gonna take our input question and perform retrieval on that. We're also gonna generate our step-back question and perform retrieval on that. We're gonna plumb those into the prompt as here's our very, here's our basically a prompt keys, normal questions, step back question. And our overall question, again, we formulate those as a dict. We plumb those into our response prompt. And then we go ahead and attempt to answer our overall question. So we're going to run to answer our overall question. So we're gonna run that, that's running, and okay, we have our answer. Now I wanna hop over to Langsmith and attempt to show you kind of what that looked like under the hood. So let's see, let's go into each of these steps. So here was our prompt, right? You're an expert in world knowledge, your task is to step back and paraphrase a question. So here were our few-shot prompts. And this was our step-back question. So what is the process of task composition? Good. From the input, what is task composition for LLM agents? We perform retrieval on both. What is process task composition? And what is task composition for LLM agents? We perform both retrievals. We then populate our prompt with both. Original question, answer, and then here's the context retrieved from both the question and the step back question.'s our final answer so again this is kind of a nice technique probably depends on a lot of the types of like the type of domain you want to perform retrieval on but in some domains where for example there's a lot of kind of conceptual knowledge that underpins questions you expect users to ask. This step back approach could be really convenient to automatically formulate a higher level question to, for example, try to improve retrieval. I can imagine if you're working with like kind of textbooks or like technical documentation where you've made independent chapters focused on more high level kind of like concepts, and then other chapters on like more detailed, like implementations, this kind of like step back approach and independent retrieval could be really helpful. Thanks.
RAG from scratch: Part 8 (Query Translation -- Step Back)
Step-back prompting is an approach to improve retrieval that builds on chain-of-thought reasoning. From a question, it generates a step-back (higher level, more abstract) question that can serve as a precondition to correctly answering the original question. This is especially useful in cases where background knowledge or more fundamental understanding is helpful to answer a specific question.

Slides:
https://docs.google.com/presentation/d/1L0MRGVDxYA1eLOR0L_6Ze1l2YV8AhN1QKUtmNA-fJlU/edit?usp=sharing

Code:
https://github.com/langchain-ai/rag-from-scratch/blob/main/rag_from_scratch_5_to_9.ipynb

Reference:
https://arxiv.org/pdf/2310.06117.pdf