Code lab 3.1 – Adding sources to your RAG
Many of the aforementioned applications mentioned include an element of adding more data to the response. For example, you are likely going to want to quote the sources of your response if you have a RAG pipeline that crawls legal documents or scientific research papers as a part of the efforts described in the Expanding and enhancing private data with general external knowledge bases or Innovation scouting and trend analysis sections.
We will continue the code from Chapter 2 and add this valuable step of returning the retrieved documents in the RAG response.
Starting with the code from Chapter 2, we need to introduce these elements to this code, which I will walk through and explain what is happening:
from langchain_core.runnables import RunnableParallel
This is a new import: the RunnableParallel
object from LangChain runnables. This introduces the concept of running the retriever and question in parallel. This can improve...