0
0
LangChainframework~10 mins

Basic RAG chain with LCEL 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 RetrievalQA class.

LangChain
from langchain.chains import [1]
Drag options to blanks, or click blank then click option'
AVectorStore
BTextSplitter
CRetrievalQA
DOpenAI
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated classes like TextSplitter or OpenAI instead of RetrievalQA.
2fill in blank
medium

Complete the code to initialize the RetrievalQA chain with the retriever.

LangChain
qa_chain = RetrievalQA.from_chain_type(llm=llm, retriever=[1])
Drag options to blanks, or click blank then click option'
Aquery
Bembedding
Cdocument
Dretriever
Attempts:
3 left
💡 Hint
Common Mistakes
Passing embedding or document instead of the retriever.
3fill in blank
hard

Fix the error in the code to run the RAG chain and get the answer.

LangChain
result = qa_chain.[1](query)
Drag options to blanks, or click blank then click option'
Arun
Bsearch
Cpredict
Danswer
Attempts:
3 left
💡 Hint
Common Mistakes
Using search or predict instead of run to execute the chain.
4fill in blank
hard

Fill both blanks to create a LangChain LLMChain with a prompt template and an LLM.

LangChain
from langchain.chains import [1]
from langchain.prompts import [2]
llm_chain = LLMChain(llm=llm, prompt=prompt)
Drag options to blanks, or click blank then click option'
ALLMChain
BPromptTemplate
CRetriever
DVectorStore
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated classes like Retriever or VectorStore here.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension filtering documents by length and score.

LangChain
filtered_docs = {doc: score for doc, score in docs.items() if len(doc) [1] 100 and score [2] 0.5 and doc not in [3]
Drag options to blanks, or click blank then click option'
A<
B>
C>=
Dexcluded_docs
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or forgetting to exclude documents.