0
0
LangChainframework~10 mins

Why document loading is the RAG foundation in LangChain - Test Your Understanding

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

Complete the code to load documents using LangChain's loader.

LangChain
from langchain.document_loaders import TextLoader
docs = TextLoader('[1]').load()
Drag options to blanks, or click blank then click option'
Amodel.pkl
Bdata.txt
Cconfig.json
Doutput.csv
Attempts:
3 left
💡 Hint
Common Mistakes
Using a model or config file instead of a text document.
2fill in blank
medium

Complete the code to split documents into chunks for better retrieval.

LangChain
from langchain.text_splitter import RecursiveCharacterTextSplitter
splitter = RecursiveCharacterTextSplitter(chunk_size=[1], chunk_overlap=20)
docs = splitter.split_documents(docs)
Drag options to blanks, or click blank then click option'
A1000
B10
C5000
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Using too small or too large chunk sizes that hurt retrieval quality.
3fill in blank
hard

Fix the error in the code to create a vector store from documents.

LangChain
from langchain.vectorstores import FAISS
from langchain.embeddings.openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
vectorstore = FAISS.from_documents(docs, [1])
Drag options to blanks, or click blank then click option'
AOpenAIEmbeddings
BFAISS
Cembeddings
Ddocs
Attempts:
3 left
💡 Hint
Common Mistakes
Passing documents or class names instead of embeddings instance.
4fill in blank
hard

Fill both blanks to create a RetrievalQA chain with the vector store retriever.

LangChain
from langchain.chains import RetrievalQA
retriever = vectorstore.[1]()
qa_chain = RetrievalQA.from_chain_type(llm=llm, retriever=[2])
Drag options to blanks, or click blank then click option'
Aas_retriever
Bget_retriever
Cretriever
Dretrieve
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names or variable names for retriever.
5fill in blank
hard

Fill all three blanks to run a query and print the answer from the RetrievalQA chain.

LangChain
query = '[1]'
result = qa_chain.[2](query)
print(result['[3]'])
Drag options to blanks, or click blank then click option'
AWhat is RAG?
Brun
Cresult
Danswer
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names or dictionary keys for the result.