0
0
LangChainframework~10 mins

Source citation in RAG responses in LangChain - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the LangChain retriever class.

LangChain
from langchain.vectorstores import [1]
Drag options to blanks, or click blank then click option'
ATensorFlow
BPandas
CNumPy
DChroma
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing unrelated libraries like Pandas or TensorFlow.
2fill in blank
medium

Complete the code to initialize the retriever with the vector store.

LangChain
retriever = [1](embedding_function=embeddings, persist_directory='db')
Drag options to blanks, or click blank then click option'
AChroma
BWeaviate
CFAISS
DPinecone
Attempts:
3 left
💡 Hint
Common Mistakes
Using other vector stores not imported or configured.
3fill in blank
hard

Fix the error in the code to enable source citation in the RAG chain.

LangChain
qa_chain = RetrievalQAWithSourcesChain(llm=llm, retriever=[1], return_source_documents=True)
Drag options to blanks, or click blank then click option'
Aretriever()
Bretriever
Cretriever.run()
Dretriever.get()
Attempts:
3 left
💡 Hint
Common Mistakes
Calling retriever as a function instead of passing the object.
4fill in blank
hard

Fill both blanks to extract answer and sources from the RAG output.

LangChain
answer = result[[1]]
sources = result[[2]]
Drag options to blanks, or click blank then click option'
A'answer'
B'sources'
C'source_documents'
D'text'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sources' key which does not exist in output.
5fill in blank
hard

Fill all three blanks to create a dictionary of source texts from documents.

LangChain
source_texts = [1](doc.page_content for doc in [2])
source_dict = {i: text for i, text in [3](source_texts)}
Drag options to blanks, or click blank then click option'
Alist
Bresult['source_documents']
Cenumerate
Ddict
Attempts:
3 left
💡 Hint
Common Mistakes
Using dict() instead of enumerate() in the comprehension.